@dignetwork/dig-sdk 0.0.1-alpha.85 → 0.0.1-alpha.87

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":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,OAAO,CAAC;AAyB1B,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,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAOtB;;OAEG;IACH,gBAAgB;IAQhB;;OAEG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA0C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAuDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAyBlD;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAoGhD;;OAEG;IACG,mBAAmB;IAgCzB;;OAEG;WACU,WAAW,C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AO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA0C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAuDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAyBlD;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAoGhD;;OAEG;IACG,mBAAmB;IAgCzB;;OAEG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IA2DnB;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0ElD;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA0B7C;;;OAGG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM;IA+FjB;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA2FpB"}
@@ -506,7 +506,9 @@ class PropagationServer {
506
506
  for (const [fileKey, fileData] of Object.entries(root.files)) {
507
507
  const dataPath = (0, hashUtils_1.getFilePathFromSha256)(root.files[fileKey].sha256, "data");
508
508
  if (!fs_1.default.existsSync(path_1.default.join(tempDir, dataPath))) {
509
- throw new Error(`Missing file: ${Buffer.from(fileKey, "hex")}, aborting session.`);
509
+ if (!fs_1.default.existsSync(path_1.default.join(config_1.STORE_PATH, storeId, dataPath))) {
510
+ throw new Error(`Missing file: ${Buffer.from(fileKey, "hex")}, aborting session.`);
511
+ }
510
512
  }
511
513
  }
512
514
  // After all downloads are complete, copy from temp directory to the main directory
@@ -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,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,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAShE,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BhE,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;mBAWpB,mBAAmB;IAM3B,2BAA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A6BL,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"}
@@ -182,25 +182,56 @@ class Wallet {
182
182
  }
183
183
  async selectUnspentCoins(peer, coinAmount, feeBigInt, omitCoins = []) {
184
184
  const cache = new FileCache_1.FileCache(path_1.default.join(config_2.USER_DIR_PATH, "reserved_coins"));
185
- const cachedReservedCoins = cache.getCachedKeys();
186
- const now = Date.now();
187
- const omitCoinIds = omitCoins.map((coin) => (0, datalayer_driver_1.getCoinId)(coin).toString("hex"));
188
- cachedReservedCoins.forEach((coinId) => {
189
- const reservation = cache.get(coinId);
190
- if (reservation && reservation.expiry > now) {
191
- omitCoinIds.push(coinId);
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;
192
215
  }
193
216
  else {
194
- cache.delete(coinId);
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
+ }
195
232
  }
196
- });
197
- const ownerPuzzleHash = await this.getOwnerPuzzleHash();
198
- const coinsResp = await peer.getAllUnspentCoins(ownerPuzzleHash, config_1.MIN_HEIGHT, buffer_1.Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
199
- const unspentCoins = coinsResp.coins.filter((coin) => !omitCoinIds.includes((0, datalayer_driver_1.getCoinId)(coin).toString("hex")));
200
- const selectedCoins = (0, datalayer_driver_1.selectCoins)(unspentCoins, feeBigInt + coinAmount);
201
- if (selectedCoins.length === 0) {
202
- throw new Error("No unspent coins available.");
203
233
  }
234
+ // Reserve the selected coins
204
235
  selectedCoins.forEach((coin) => {
205
236
  const coinId = (0, datalayer_driver_1.getCoinId)(coin).toString("hex");
206
237
  cache.set(coinId, { coinId, expiry: Date.now() + CACHE_DURATION });
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6BrE,CAAC"}
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6CrE,CAAC"}
@@ -4,31 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPublicIpAddress = void 0;
7
+ /*
8
+ * Stopgap until better solution for finding public IPS found
9
+ */
7
10
  const superagent_1 = __importDefault(require("superagent"));
8
11
  const MAX_RETRIES = 5;
9
12
  const RETRY_DELAY = 2000; // in milliseconds
13
+ // Regular expression for validating both IPv4 and IPv6 addresses
14
+ const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
15
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|(([0-9a-fA-F]{1,4}:){1,7}|:):(([0-9a-fA-F]{1,4}:){1,6}|:):([0-9a-fA-F]{1,4}|:):([0-9a-fA-F]{1,4}|:)|::)$/;
16
+ // Helper function to validate the IP address
17
+ const isValidIp = (ip) => {
18
+ return ipv4Regex.test(ip) || ipv6Regex.test(ip);
19
+ };
10
20
  const getPublicIpAddress = async () => {
11
21
  const publicIp = process.env.PUBLIC_IP;
12
22
  if (publicIp) {
13
- console.log('Public IP address from env:', publicIp);
14
- return publicIp;
23
+ console.log("Public IP address from env:", publicIp);
24
+ if (isValidIp(publicIp)) {
25
+ return publicIp;
26
+ }
27
+ console.error("Invalid public IP address in environment variable");
28
+ return undefined;
15
29
  }
16
30
  let attempt = 0;
17
31
  while (attempt < MAX_RETRIES) {
18
32
  try {
19
- const response = await superagent_1.default.get('https://api.datalayer.storage/user/v1/get_user_ip');
33
+ const response = await superagent_1.default.get("https://api.datalayer.storage/user/v1/get_user_ip");
20
34
  if (response.body && response.body.success) {
21
- return response.body.ip_address;
22
- }
23
- else {
24
- throw new Error('Failed to retrieve public IP address');
35
+ const ipAddress = response.body.ip_address;
36
+ if (isValidIp(ipAddress)) {
37
+ return ipAddress;
38
+ }
39
+ throw new Error("Invalid IP address format received");
25
40
  }
41
+ throw new Error("Failed to retrieve public IP address");
26
42
  }
27
43
  catch (error) {
28
44
  attempt++;
29
45
  console.error(`Error fetching public IP address (Attempt ${attempt}):`, error.message);
30
46
  if (attempt >= MAX_RETRIES) {
31
- throw new Error('Could not retrieve public IP address after several attempts');
47
+ throw new Error("Could not retrieve public IP address after several attempts");
32
48
  }
33
49
  await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
34
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.85",
3
+ "version": "0.0.1-alpha.87",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",