@partylayer/sdk 0.16.0 → 0.17.1

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
@@ -364,6 +364,46 @@ var GenericDiscoveryAdapter = class {
364
364
  };
365
365
  return { partyId, session, capabilities: this.getCapabilities() };
366
366
  }
367
+ /**
368
+ * Restore a persisted session by delegating to the official adapter's own `restore`.
369
+ *
370
+ * The official `ProviderAdapter` shape carries an optional `restore()` that reinstates a
371
+ * session (for example from the wallet's own storage) and returns a LIVE provider.
372
+ * Without this method the SDK revived the persisted record as-is and then built a fresh,
373
+ * SESSION-LESS provider from `provider()`, so a wallet that restores in `restore` looked
374
+ * connected after a reload but its first real request threw. This forwards to the
375
+ * official `restore` and, when it yields a provider, adopts it as the cached provider so
376
+ * the very next request uses the restored session.
377
+ *
378
+ * Popup-safe: this runs on the SDK's init/restore path, never inside a user gesture, so a
379
+ * popup could not open here even if an adapter tried (the browser would block it). Per
380
+ * the official contract `restore` is storage-based and gesture-free. If the official
381
+ * adapter has no `restore`, it returns null, or host resolution is not ready, this falls
382
+ * through to the previous behavior: the persisted session is returned and the provider is
383
+ * built lazily on first use, exactly as before.
384
+ */
385
+ async restore(ctx, persisted) {
386
+ const asIs = { ...persisted, walletId: this.walletId };
387
+ try {
388
+ this.resolveOfficial(ctx.network);
389
+ } catch {
390
+ return asIs;
391
+ }
392
+ const restore = this.official?.restore;
393
+ if (this.official && restore) {
394
+ let restored = null;
395
+ try {
396
+ restored = await restore.call(this.official);
397
+ } catch {
398
+ restored = null;
399
+ }
400
+ if (restored) {
401
+ this.providerInstance = restored;
402
+ return asIs;
403
+ }
404
+ }
405
+ return asIs;
406
+ }
367
407
  async disconnect() {
368
408
  try {
369
409
  await this.provider.request({ method: "disconnect" });
@@ -1775,6 +1815,19 @@ var PartyLayerClient = class {
1775
1815
  const adapter = this.adapters.get(session.walletId);
1776
1816
  if (adapter?.restore) {
1777
1817
  const ctx = this.createAdapterContext();
1818
+ if (adapter instanceof GenericDiscoveryAdapter && adapter.usesFactory()) {
1819
+ let networkHosts = {};
1820
+ try {
1821
+ const entry = await this.registryClient.getWalletEntry(String(session.walletId));
1822
+ networkHosts = entry.adapter?.networkHosts ?? {};
1823
+ } catch {
1824
+ }
1825
+ adapter.setNetworkHosts(networkHosts);
1826
+ try {
1827
+ adapter.resolveOfficial(session.network);
1828
+ } catch {
1829
+ }
1830
+ }
1778
1831
  const restored = await adapter.restore(ctx, {
1779
1832
  ...session,
1780
1833
  encrypted