@keetanetwork/anchor 0.0.85 → 0.0.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.
Files changed (39) hide show
  1. package/lib/asset.d.ts +2 -0
  2. package/lib/asset.d.ts.map +1 -1
  3. package/lib/asset.js +4 -0
  4. package/lib/asset.js.map +1 -1
  5. package/lib/chaining.d.ts +106 -6
  6. package/lib/chaining.d.ts.map +1 -1
  7. package/lib/chaining.js +705 -247
  8. package/lib/chaining.js.map +1 -1
  9. package/lib/queue/index.d.ts.map +1 -1
  10. package/lib/queue/index.js +7 -6
  11. package/lib/queue/index.js.map +1 -1
  12. package/lib/resolver.d.ts.map +1 -1
  13. package/lib/resolver.js +128 -90
  14. package/lib/resolver.js.map +1 -1
  15. package/npm-shrinkwrap.json +2 -2
  16. package/package.json +1 -1
  17. package/services/asset-movement/client.js +1 -1
  18. package/services/asset-movement/client.js.map +1 -1
  19. package/services/asset-movement/common.d.ts +10 -4
  20. package/services/asset-movement/common.d.ts.map +1 -1
  21. package/services/asset-movement/common.js +16 -3
  22. package/services/asset-movement/common.js.map +1 -1
  23. package/services/asset-movement/common.server.generated.js +47 -12
  24. package/services/asset-movement/common.server.generated.js.map +1 -1
  25. package/services/storage/client.d.ts +12 -1
  26. package/services/storage/client.d.ts.map +1 -1
  27. package/services/storage/client.js +17 -0
  28. package/services/storage/client.js.map +1 -1
  29. package/services/storage/clients/profile.d.ts +76 -0
  30. package/services/storage/clients/profile.d.ts.map +1 -0
  31. package/services/storage/clients/profile.generated.d.ts +5 -0
  32. package/services/storage/clients/profile.generated.d.ts.map +1 -0
  33. package/services/storage/clients/profile.generated.js +162 -0
  34. package/services/storage/clients/profile.generated.js.map +1 -0
  35. package/services/storage/clients/profile.js +115 -0
  36. package/services/storage/clients/profile.js.map +1 -0
  37. package/services/storage/common.d.ts +16 -0
  38. package/services/storage/common.d.ts.map +1 -1
  39. package/services/storage/common.js.map +1 -1
package/lib/resolver.js CHANGED
@@ -3,7 +3,7 @@ import * as CurrencyInfo from '@keetanetwork/currency-info';
3
3
  import { assertNever } from './utils/never.js';
4
4
  import { Buffer } from './utils/buffer.js';
5
5
  import crypto from './utils/crypto.js';
6
- import { convertAssetLocationInputToCanonical, convertAssetOrPairSearchInputToCanonical, assertKeetaSupportedAssetsMetadata } from '../services/asset-movement/common.js';
6
+ import { convertAssetLocationInputToCanonical, convertAssetOrPairSearchInputToCanonical, assertKeetaSupportedAssetsMetadataItem } from '../services/asset-movement/common.js';
7
7
  import { checksumEVMAsset, isEVMAsset } from './asset.js';
8
8
  import { SignData } from './utils/signing.js';
9
9
  import { addSignatureToURL, assertHTTPSignedField } from './http-server/common.js';
@@ -480,12 +480,20 @@ class Metadata {
480
480
  }
481
481
  const metadataBytes = Buffer.from(metadataUncompressed);
482
482
  const metadataDecoded = metadataBytes.toString('utf-8');
483
- /*
484
- * JSON.parse() will always return a JSONSerializable,
485
- * and not `unknown`, so we can safely cast it.
486
- */
487
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
488
- const retval = await this.resolveValue(JSON.parse(metadataDecoded));
483
+ let parsed;
484
+ try {
485
+ /*
486
+ * JSON.parse() will always return a JSONSerializable,
487
+ * and not `unknown`, so we can safely cast it.
488
+ */
489
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
490
+ parsed = JSON.parse(metadataDecoded);
491
+ }
492
+ catch (parseError) {
493
+ this.#logger?.warn(`Resolver:${this.#resolver.id}`, 'Failed to parse metadata JSON from', this.#url.toString(), ':', parseError);
494
+ throw (parseError);
495
+ }
496
+ const retval = await this.resolveValue(parsed);
489
497
  return (retval);
490
498
  }
491
499
  async readKeetaNetURL(url) {
@@ -1227,95 +1235,112 @@ class Resolver {
1227
1235
  const fromCanonical = criteria.from ? convertAssetLocationInputToCanonical(criteria.from) : undefined;
1228
1236
  const toCanonical = criteria.to ? convertAssetLocationInputToCanonical(criteria.to) : undefined;
1229
1237
  const resolvedService = await Metadata.fullyResolveValuizable(assetService.supportedAssets);
1230
- const supportedAssets = assertKeetaSupportedAssetsMetadata(resolvedService);
1238
+ if (!Array.isArray(resolvedService)) {
1239
+ throw (new Error('Expected "supportedAssets" to be an array'));
1240
+ }
1241
+ const supportedAssets = [];
1242
+ for (let supportedAssetIndex = 0; supportedAssetIndex < resolvedService.length; supportedAssetIndex++) {
1243
+ const resolvedSupportedAsset = resolvedService[supportedAssetIndex];
1244
+ try {
1245
+ supportedAssets.push(assertKeetaSupportedAssetsMetadataItem(resolvedSupportedAsset));
1246
+ }
1247
+ catch (assertError) {
1248
+ this.#logger?.warn(`Resolver:${this.id}`, 'Error parsing supportedAssets entry', supportedAssetIndex, ':', assertError, '-- ignoring entry');
1249
+ }
1250
+ }
1231
1251
  const filteredAssetMovement = [];
1232
1252
  for (const supportedAsset of supportedAssets) {
1233
1253
  let matchFound = false;
1234
1254
  for (const path of supportedAsset.paths) {
1235
- for (const [fromAsset, toAsset] of [[path.pair[0], path.pair[1]], [path.pair[1], path.pair[0]]]) {
1236
- const fromId = this.#canonicalizeMetadataAssetId(fromAsset.id);
1237
- const toId = this.#canonicalizeMetadataAssetId(toAsset.id);
1238
- if (fromCanonical && fromCanonical !== fromAsset.location) {
1239
- continue;
1240
- }
1241
- if (toCanonical && toCanonical !== toAsset.location) {
1242
- continue;
1243
- }
1244
- if (assetCanonical) {
1245
- if (typeof assetCanonical === 'string') {
1246
- if (!([fromId, toId].includes(assetCanonical))) {
1247
- continue;
1248
- }
1255
+ try {
1256
+ for (const [fromAsset, toAsset] of [[path.pair[0], path.pair[1]], [path.pair[1], path.pair[0]]]) {
1257
+ const fromId = this.#canonicalizeMetadataAssetId(fromAsset.id);
1258
+ const toId = this.#canonicalizeMetadataAssetId(toAsset.id);
1259
+ if (fromCanonical && fromCanonical !== fromAsset.location) {
1260
+ continue;
1249
1261
  }
1250
- else if (fromId !== assetCanonical.from || toId !== assetCanonical.to) {
1262
+ if (toCanonical && toCanonical !== toAsset.location) {
1251
1263
  continue;
1252
1264
  }
1253
- }
1254
- const supportedRails = {
1255
- inbound: [...(fromAsset.rails.inbound ?? []), ...(fromAsset.rails.common ?? [])],
1256
- outbound: [...(toAsset.rails.outbound ?? []), ...(toAsset.rails.common ?? [])]
1257
- };
1258
- if ((supportedRails.inbound.length + supportedRails.outbound.length) === 0) {
1259
- continue;
1260
- }
1261
- const checkSupportedRailIncludes = (searchFor, searchIn) => {
1262
- for (const checkRail of searchIn) {
1263
- if (typeof checkRail === 'string') {
1264
- if (checkRail === searchFor) {
1265
- return (true);
1265
+ if (assetCanonical) {
1266
+ if (typeof assetCanonical === 'string') {
1267
+ if (!([fromId, toId].includes(assetCanonical))) {
1268
+ continue;
1266
1269
  }
1267
1270
  }
1268
- else {
1269
- if (checkRail.rail === searchFor) {
1270
- return (true);
1271
- }
1271
+ else if (fromId !== assetCanonical.from || toId !== assetCanonical.to) {
1272
+ continue;
1272
1273
  }
1273
1274
  }
1274
- return (false);
1275
- };
1276
- if (criteria.rail !== undefined) {
1277
- let railMatchFound = false;
1278
- for (const direction of ['inbound', 'outbound']) {
1279
- let searchFor;
1280
- let searchIn;
1281
- let eitherDirectionSharedSearch;
1282
- if (typeof criteria.rail === 'object' && !Array.isArray(criteria.rail)) {
1283
- searchFor = criteria.rail[direction];
1284
- searchIn = supportedRails[direction];
1285
- eitherDirectionSharedSearch = false;
1286
- }
1287
- else {
1288
- searchFor = criteria.rail;
1289
- searchIn = [...supportedRails.inbound, ...supportedRails.outbound];
1290
- eitherDirectionSharedSearch = true;
1275
+ const supportedRails = {
1276
+ inbound: [...(fromAsset.rails.inbound ?? []), ...(fromAsset.rails.common ?? [])],
1277
+ outbound: [...(toAsset.rails.outbound ?? []), ...(toAsset.rails.common ?? [])]
1278
+ };
1279
+ if ((supportedRails.inbound.length + supportedRails.outbound.length) === 0) {
1280
+ continue;
1281
+ }
1282
+ const checkSupportedRailIncludes = (searchFor, searchIn) => {
1283
+ for (const checkRail of searchIn) {
1284
+ if (typeof checkRail === 'string') {
1285
+ if (checkRail === searchFor) {
1286
+ return (true);
1287
+ }
1288
+ }
1289
+ else {
1290
+ if (checkRail.rail === searchFor) {
1291
+ return (true);
1292
+ }
1293
+ }
1291
1294
  }
1292
- if (searchFor !== undefined) {
1293
- if (typeof searchFor === 'string') {
1294
- railMatchFound = checkSupportedRailIncludes(searchFor, searchIn);
1295
+ return (false);
1296
+ };
1297
+ if (criteria.rail !== undefined) {
1298
+ let railMatchFound = false;
1299
+ for (const direction of ['inbound', 'outbound']) {
1300
+ let searchFor;
1301
+ let searchIn;
1302
+ let eitherDirectionSharedSearch;
1303
+ if (typeof criteria.rail === 'object' && !Array.isArray(criteria.rail)) {
1304
+ searchFor = criteria.rail[direction];
1305
+ searchIn = supportedRails[direction];
1306
+ eitherDirectionSharedSearch = false;
1295
1307
  }
1296
1308
  else {
1297
- for (const checkRail of searchFor) {
1298
- railMatchFound = checkSupportedRailIncludes(checkRail, searchIn);
1299
- if (railMatchFound) {
1300
- break;
1309
+ searchFor = criteria.rail;
1310
+ searchIn = [...supportedRails.inbound, ...supportedRails.outbound];
1311
+ eitherDirectionSharedSearch = true;
1312
+ }
1313
+ if (searchFor !== undefined) {
1314
+ if (typeof searchFor === 'string') {
1315
+ railMatchFound = checkSupportedRailIncludes(searchFor, searchIn);
1316
+ }
1317
+ else {
1318
+ for (const checkRail of searchFor) {
1319
+ railMatchFound = checkSupportedRailIncludes(checkRail, searchIn);
1320
+ if (railMatchFound) {
1321
+ break;
1322
+ }
1301
1323
  }
1302
1324
  }
1303
1325
  }
1326
+ // If we are doing a shared search across both directions, then we only need to find a match in one direction, so we can break early. If we are doing separate searches for each direction, then we need to continue and check the next direction if we don't find a match in the first direction.
1327
+ if (eitherDirectionSharedSearch) {
1328
+ break;
1329
+ }
1330
+ if (railMatchFound) {
1331
+ break;
1332
+ }
1304
1333
  }
1305
- // If we are doing a shared search across both directions, then we only need to find a match in one direction, so we can break early. If we are doing separate searches for each direction, then we need to continue and check the next direction if we don't find a match in the first direction.
1306
- if (eitherDirectionSharedSearch) {
1307
- break;
1308
- }
1309
- if (railMatchFound) {
1310
- break;
1334
+ if (!railMatchFound) {
1335
+ continue;
1311
1336
  }
1312
1337
  }
1313
- if (!railMatchFound) {
1314
- continue;
1315
- }
1338
+ matchFound = true;
1339
+ break;
1316
1340
  }
1317
- matchFound = true;
1318
- break;
1341
+ }
1342
+ catch (pathError) {
1343
+ this.#logger?.warn(`Resolver:${this.id}`, 'Error parsing asset movement path:', pathError, '-- ignoring path');
1319
1344
  }
1320
1345
  if (matchFound) {
1321
1346
  break;
@@ -1333,14 +1358,14 @@ class Resolver {
1333
1358
  }
1334
1359
  const retval = {};
1335
1360
  for (const checkAssetMovementServiceID in assetServices) {
1336
- const checkAssetMovementService = await assetServices[checkAssetMovementServiceID]?.('object');
1337
- if (checkAssetMovementService === undefined) {
1338
- return (undefined);
1339
- }
1340
- if (!('operations' in checkAssetMovementService)) {
1341
- return (undefined);
1342
- }
1343
1361
  try {
1362
+ const checkAssetMovementService = await assetServices[checkAssetMovementServiceID]?.('object');
1363
+ if (checkAssetMovementService === undefined) {
1364
+ continue;
1365
+ }
1366
+ if (!('operations' in checkAssetMovementService)) {
1367
+ continue;
1368
+ }
1344
1369
  const supportedAssets = await this.filterSupportedAssets(checkAssetMovementService, criteria);
1345
1370
  if (supportedAssets.length === 0) {
1346
1371
  continue;
@@ -1348,7 +1373,7 @@ class Resolver {
1348
1373
  retval[checkAssetMovementServiceID] = await assertResolverLookupAssetMovementResults(checkAssetMovementService);
1349
1374
  }
1350
1375
  catch (parseError) {
1351
- this.#logger?.debug(`Resolver:${this.id}`, 'Error checking AssetMovement service', checkAssetMovementServiceID, ':', parseError, ' -- ignoring');
1376
+ this.#logger?.warn(`Resolver:${this.id}`, 'Error checking AssetMovement service', checkAssetMovementServiceID, ':', parseError, '-- ignoring');
1352
1377
  }
1353
1378
  }
1354
1379
  if (Object.keys(retval).length === 0) {
@@ -1421,21 +1446,22 @@ class Resolver {
1421
1446
  const rootMetadata = await metadata.value('object');
1422
1447
  this.#logger?.debug(`Resolver:${this.id}`, 'Root Metadata for', root.publicKeyString.get(), ':', rootMetadata);
1423
1448
  if (!('version' in rootMetadata)) {
1424
- this.#logger?.debug(`Resolver:${this.id}`, 'Root metadata for', root.publicKeyString.get(), 'is missing "version" property, skipping');
1449
+ this.#logger?.warn(`Resolver:${this.id}`, 'Root metadata for', root.publicKeyString.get(), 'is missing "version" property -- ignoring root');
1425
1450
  continue;
1426
1451
  }
1427
1452
  const rootMetadataVersion = await rootMetadata.version?.('primitive');
1428
1453
  if (rootMetadataVersion !== 1) {
1429
- this.#logger?.debug(`Resolver:${this.id}`, 'Unsupported metadata version', rootMetadataVersion, 'for', root.publicKeyString.get(), ', skipping');
1454
+ this.#logger?.warn(`Resolver:${this.id}`, 'Unsupported metadata version', rootMetadataVersion, 'for', root.publicKeyString.get(), '-- ignoring root');
1430
1455
  continue;
1431
1456
  }
1432
1457
  allRootMetadata.push(rootMetadata);
1433
1458
  }
1434
1459
  catch (error) {
1435
- this.#logger?.debug(`Resolver:${this.id}`, 'Error fetching metadata for', root.publicKeyString.get(), ':', error, ' -- skipping');
1460
+ this.#logger?.warn(`Resolver:${this.id}`, 'Error fetching metadata for', root.publicKeyString.get(), ':', error, '-- ignoring root');
1436
1461
  }
1437
1462
  }
1438
1463
  if (allRootMetadata.length === 0) {
1464
+ this.#logger?.warn(`Resolver:${this.id}`, 'No valid root metadata found among', this.#roots.length, 'configured root(s)');
1439
1465
  throw (new Error('No valid root metadata found'));
1440
1466
  }
1441
1467
  this.#logger?.debug(`Resolver:${this.id}`, 'Total valid root metadata count:', allRootMetadata.length);
@@ -1472,9 +1498,14 @@ class Resolver {
1472
1498
  continue;
1473
1499
  }
1474
1500
  if ('currencyMap' in metadata && metadata.currencyMap !== undefined) {
1475
- const currencyMap = await metadata.currencyMap('object');
1476
- for (const [currencyCode, tokenValue] of Object.entries(currencyMap)) {
1477
- mergedCurrencyMap[currencyCode] = tokenValue;
1501
+ try {
1502
+ const currencyMap = await metadata.currencyMap('object');
1503
+ for (const [currencyCode, tokenValue] of Object.entries(currencyMap)) {
1504
+ mergedCurrencyMap[currencyCode] = tokenValue;
1505
+ }
1506
+ }
1507
+ catch (mergeError) {
1508
+ this.#logger?.warn(`Resolver:${this.id}`, 'Error merging currencyMap from root index', i, ':', mergeError, '-- ignoring root currencyMap');
1478
1509
  }
1479
1510
  }
1480
1511
  }
@@ -1499,7 +1530,14 @@ class Resolver {
1499
1530
  continue;
1500
1531
  }
1501
1532
  if ('services' in metadata && metadata.services !== undefined) {
1502
- const services = await metadata.services('object');
1533
+ let services;
1534
+ try {
1535
+ services = await metadata.services('object');
1536
+ }
1537
+ catch (mergeError) {
1538
+ this.#logger?.warn(`Resolver:${this.id}`, 'Error merging services from root index', i, ':', mergeError, '-- ignoring root services');
1539
+ continue;
1540
+ }
1503
1541
  for (const [serviceType, serviceValue] of Object.entries(services)) {
1504
1542
  if (serviceValue === undefined) {
1505
1543
  continue;