@partylayer/sdk 0.22.1 → 0.22.2

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { toWalletId, toPartyId, isRecognizedNetwork, detectNetworkMismatch, ledgerApiBodyToObject, normalizeLedgerMethodLower, hashForPrivacy, createMetricsPayload, TransportError, toSignature, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, NetworkMismatchError, METRICS, WalletNotFoundError, AdapterNotRegisteredError, OriginNotAllowedError, capabilityGuard, installGuard, CapabilityNotSupportedError, toTransferIntent, errorMetricName, parseTokenHoldingV2, parseTokenHoldingV1, toCAIP2Network, toTransactionHash, generateSessionId, toSessionId } from '@partylayer/core';
1
+ import { toWalletId, toPartyId, isRecognizedNetwork, detectNetworkMismatch, ledgerApiBodyToObject, normalizeLedgerMethodLower, hashForPrivacy, createMetricsPayload, TransportError, toSignature, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, NetworkMismatchError, METRICS, WalletNotFoundError, AdapterNotRegisteredError, WalletNotInstalledError, OriginNotAllowedError, capabilityGuard, installGuard, CapabilityNotSupportedError, toTransferIntent, errorMetricName, parseTokenHoldingV2, parseTokenHoldingV1, toCAIP2Network, toTransactionHash, findMatchingWalletInfo, generateSessionId, toSessionId } from '@partylayer/core';
2
2
  export { AdapterNotRegisteredError, PartyLayerError as CantonConnectError, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, InternalError, METRICS, OriginNotAllowedError, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, SessionExpiredError, TRANSFER_INTENT_FIELDS, TimeoutError, TransportError, UserRejectedError, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter, toTransferIntent } from '@partylayer/core';
3
3
  import { RegistryClient } from '@partylayer/registry-client';
4
4
  export { deriveGenericWalletName, findMatchingWallet, findMatchingWalletInfo, isCip0103Native, matchesProviderDetection } from '@partylayer/registry-client';
@@ -1215,6 +1215,12 @@ function matchKnownByIdentity(providerId, base) {
1215
1215
  return providerId === String(w.walletId) || !!k && (providerId === k || providerId.startsWith(`${k}.`));
1216
1216
  });
1217
1217
  }
1218
+ function matchDiscoveredWallet(id, wallets) {
1219
+ return findMatchingWalletInfo(
1220
+ { provider: { id } },
1221
+ wallets
1222
+ ) ?? matchKnownByIdentity(id, wallets);
1223
+ }
1218
1224
  var DEFAULT_CONNECT_TIMEOUT_MS = 12e4;
1219
1225
  var PartyLayerClientBase = class {
1220
1226
  constructor(config, runtime = {}) {
@@ -1451,7 +1457,8 @@ var PartyLayerClientBase = class {
1451
1457
  }
1452
1458
  await Promise.all(registry.wallets.map(async (entry) => {
1453
1459
  const id = toWalletId(entry.id);
1454
- if (this.adapters.has(id) || !entry.supportedNetworks.includes(this.config.network) || entry.adapter?.transport === "discovery-adapter" && !entry.adapter.networkHosts?.[this.config.network]) return;
1460
+ const network = this.config.network;
1461
+ if (this.adapters.has(id) || !entry.supportedNetworks.includes(network) && !entry.additionalNetworks?.includes(network) || entry.adapter?.transport === "discovery-adapter" && !entry.adapter.networkHosts?.[network]) return;
1455
1462
  let pending = this.defaultLoads.get(entry.id);
1456
1463
  if (!pending) {
1457
1464
  pending = (async () => {
@@ -1464,8 +1471,9 @@ var PartyLayerClientBase = class {
1464
1471
  networkHosts: entry.adapter?.networkHosts,
1465
1472
  capabilities: entry.capabilities
1466
1473
  }) : entryAdapter;
1474
+ if (!this.registryNetworkSupported(entry, adapter)) return;
1467
1475
  if (typeof window !== "undefined" && adapter instanceof GenericDiscoveryAdapter) {
1468
- adapter.resolveOfficial(this.config.network);
1476
+ adapter.resolveOfficial(network);
1469
1477
  }
1470
1478
  this.registerAdapter(adapter);
1471
1479
  this.registryDefaultIds.add(id);
@@ -1482,6 +1490,10 @@ var PartyLayerClientBase = class {
1482
1490
  await pending;
1483
1491
  }));
1484
1492
  }
1493
+ registryNetworkSupported(entry, adapter) {
1494
+ const network = this.config.network;
1495
+ return entry.supportedNetworks.includes(network) || entry.additionalNetworks?.includes(network) === true && adapter?.supportsNetwork?.(network) === true;
1496
+ }
1485
1497
  /**
1486
1498
  * Hide registry entries whose wallet needs an app-registered adapter that is
1487
1499
  * NOT registered. This is the library default (RainbowKit-style): never show a
@@ -1503,19 +1515,23 @@ var PartyLayerClientBase = class {
1503
1515
  * adapters-only) or every non-announce entry is registered.
1504
1516
  */
1505
1517
  async gateUnconnectableEntries(wallets) {
1506
- if (!this.runtime.browserDiscovery) return wallets.filter((wallet) => this.adapters.has(wallet.walletId));
1518
+ if (!this.runtime.browserDiscovery) wallets = wallets.filter((wallet) => this.adapters.has(wallet.walletId));
1507
1519
  let hidden = null;
1508
1520
  const announceCapabilities = /* @__PURE__ */ new Map();
1521
+ const additionalNetworks = /* @__PURE__ */ new Map();
1509
1522
  try {
1510
1523
  const registry = await this.registryClient.getRegistry();
1511
1524
  for (const entry of registry.wallets) {
1525
+ const adapter = this.adapters.get(toWalletId(entry.id));
1526
+ if (entry.additionalNetworks && adapter) {
1527
+ additionalNetworks.set(entry.id, entry.additionalNetworks.filter((network) => adapter.supportsNetwork?.(network) === true));
1528
+ }
1512
1529
  if (entry.adapter?.transport === "announce" && this.runtime.browserDiscovery) {
1513
1530
  announceCapabilities.set(entry.id, getAnnounceCapabilities(deriveAnnounceConfig(entry)));
1514
1531
  continue;
1515
1532
  }
1516
- const walletId = toWalletId(entry.id);
1517
- if (!this.adapters.has(walletId)) {
1518
- (hidden ??= /* @__PURE__ */ new Set()).add(String(walletId));
1533
+ if (!adapter) {
1534
+ (hidden ??= /* @__PURE__ */ new Set()).add(entry.id);
1519
1535
  }
1520
1536
  }
1521
1537
  } catch {
@@ -1523,7 +1539,13 @@ var PartyLayerClientBase = class {
1523
1539
  }
1524
1540
  return wallets.filter((w) => !hidden?.has(String(w.walletId))).map((w) => {
1525
1541
  const capabilities = announceCapabilities.get(String(w.walletId));
1526
- return capabilities ? { ...w, capabilities } : w;
1542
+ const networks = additionalNetworks.get(String(w.walletId));
1543
+ if (!capabilities && !networks?.length) return w;
1544
+ return {
1545
+ ...w,
1546
+ capabilities: capabilities ?? w.capabilities,
1547
+ networks: networks?.length ? [.../* @__PURE__ */ new Set([...w.networks, ...networks])] : w.networks
1548
+ };
1527
1549
  });
1528
1550
  }
1529
1551
  /**
@@ -1618,17 +1640,26 @@ var PartyLayerClientBase = class {
1618
1640
  createProvider: (a) => this.announceChannel(a.target ?? a.id)
1619
1641
  });
1620
1642
  const byId = /* @__PURE__ */ new Map();
1621
- for (const d of snapshot) byId.set(d.id, d);
1622
- for (const d of this.announceRegistry.values())
1623
- if (!byId.has(d.id)) byId.set(d.id, d);
1643
+ const matchedAnnouncements = /* @__PURE__ */ new Set();
1644
+ for (const d of snapshot) {
1645
+ const announced = this.announceRegistry.get(d.id);
1646
+ if (d.announcementId) matchedAnnouncements.add(d.announcementId);
1647
+ byId.set(d.id, {
1648
+ ...d,
1649
+ name: d.name ?? announced?.name,
1650
+ icon: d.icon ?? announced?.icon
1651
+ });
1652
+ }
1653
+ for (const announced of this.announceRegistry.values()) {
1654
+ if (!byId.has(announced.id) && !matchedAnnouncements.has(announced.id)) {
1655
+ byId.set(announced.id, announced);
1656
+ }
1657
+ }
1624
1658
  const discovered = [...byId.values()];
1625
1659
  const entries = [];
1626
1660
  for (const d of discovered) {
1627
1661
  if (d.identityResolved === false) continue;
1628
- const known = findMatchingWalletInfo(
1629
- { provider: { id: d.id } },
1630
- base
1631
- ) ?? matchKnownByIdentity(d.id, base);
1662
+ const known = matchDiscoveredWallet(d.id, base) ?? (d.announcementId ? matchDiscoveredWallet(d.announcementId, base) : void 0);
1632
1663
  if (known) {
1633
1664
  if (this.adapters.has(known.walletId)) continue;
1634
1665
  try {
@@ -1692,7 +1723,7 @@ var PartyLayerClientBase = class {
1692
1723
  adapter: { packageName: "announced", versionRange: "*" },
1693
1724
  docs: [],
1694
1725
  networks: [this.config.network || "devnet"],
1695
- channel: "stable"
1726
+ channel: this.config.channel ?? "stable"
1696
1727
  });
1697
1728
  }
1698
1729
  this.announceEntriesCache = entries;
@@ -1788,7 +1819,7 @@ var PartyLayerClientBase = class {
1788
1819
  const nativeAdapter = this.adapters.get(options.walletId);
1789
1820
  if (nativeAdapter) {
1790
1821
  const entry = await this.registryClient.getWalletEntry(String(options.walletId)).catch(() => null);
1791
- if (entry?.supportedNetworks?.length && !entry.supportedNetworks.includes(this.config.network)) {
1822
+ if (entry?.supportedNetworks?.length && !this.registryNetworkSupported(entry, nativeAdapter)) {
1792
1823
  throw new WalletNotFoundError(`${String(options.walletId)} is unavailable on ${this.config.network}`);
1793
1824
  }
1794
1825
  isNativeWallet = true;
@@ -1819,7 +1850,14 @@ var PartyLayerClientBase = class {
1819
1850
  }
1820
1851
  const adapter = this.adapters.get(selectedWallet.walletId);
1821
1852
  if (!adapter) {
1822
- throw new WalletNotFoundError(String(selectedWallet.walletId));
1853
+ const walletId = String(selectedWallet.walletId);
1854
+ if (this.announceEnabled) {
1855
+ const entry = await this.registryClient.getWalletEntry(walletId).catch(() => null);
1856
+ if (entry?.adapter?.transport === "announce") {
1857
+ throw new WalletNotInstalledError(walletId);
1858
+ }
1859
+ }
1860
+ throw new WalletNotFoundError(walletId);
1823
1861
  }
1824
1862
  if (!isNativeWallet) {
1825
1863
  try {