@partylayer/sdk 0.7.0 → 0.9.0

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.js CHANGED
@@ -78,6 +78,153 @@ var GenericAnnounceAdapter = class {
78
78
  });
79
79
  }
80
80
  };
81
+ var GenericDiscoveryAdapter = class {
82
+ walletId;
83
+ name;
84
+ icon;
85
+ /**
86
+ * Resolved official adapter. Set at construction for the instance form; for
87
+ * the factory form it stays null until {@link resolveOfficial} constructs it
88
+ * with the network-resolved host.
89
+ */
90
+ official;
91
+ /** Factory form (null for the instance form). */
92
+ factory;
93
+ /** Network→host map for the factory form; injected by the SDK post-registry. */
94
+ networkHosts;
95
+ /** Lazily resolved from `official.provider()` — NOT at construction (SSR-safe). */
96
+ providerInstance = null;
97
+ constructor(args) {
98
+ if (args.official) {
99
+ this.official = args.official;
100
+ this.factory = null;
101
+ this.networkHosts = {};
102
+ this.walletId = args.walletId ?? core.toWalletId(args.official.providerId);
103
+ this.name = args.name && args.name.length > 0 ? args.name : args.official.name;
104
+ this.icon = args.icon ?? args.official.icon;
105
+ } else if (args.factory) {
106
+ this.official = null;
107
+ this.factory = args.factory;
108
+ this.networkHosts = args.networkHosts ?? {};
109
+ this.walletId = args.walletId ?? core.toWalletId(args.factory.providerId);
110
+ this.name = args.name && args.name.length > 0 ? args.name : args.factory.name ?? args.factory.providerId;
111
+ this.icon = args.icon ?? args.factory.icon;
112
+ } else {
113
+ throw new Error(
114
+ "GenericDiscoveryAdapter requires either `official` (instance) or `factory`."
115
+ );
116
+ }
117
+ }
118
+ /** Whether this bridge resolves its host from `networkHosts` (factory form). */
119
+ usesFactory() {
120
+ return this.factory !== null;
121
+ }
122
+ /**
123
+ * Inject the registry's network→host map (factory form only). SYNCHRONOUS —
124
+ * the SDK calls this during the async warm phase once the registry entry is
125
+ * loaded, BEFORE the (possibly gesture-synchronous) connect.
126
+ */
127
+ setNetworkHosts(networkHosts) {
128
+ if (this.factory) this.networkHosts = networkHosts ?? {};
129
+ }
130
+ /**
131
+ * Resolve + construct the official adapter for `network` — SYNCHRONOUS, so the
132
+ * popup-safe gesture path reaches `window.open` with NO awaits. Idempotent.
133
+ * The SDK pre-calls it during warm-up; `connect()` also calls it as its first
134
+ * statement so a cold (un-warmed) connect is still gesture-safe.
135
+ *
136
+ * Failure is CLEAR, never a silent wrong-network host: a factory wallet with
137
+ * no host for `network` in `networkHosts` throws, naming the network.
138
+ */
139
+ resolveOfficial(network) {
140
+ if (this.official) return;
141
+ if (!this.factory) return;
142
+ const host = this.networkHosts[network];
143
+ if (!host) {
144
+ throw new Error(
145
+ `Wallet "${String(this.walletId)}" has no host for network "${network}". Add it to the registry entry's adapter.networkHosts, or supply a pre-constructed official adapter with an explicit host.`
146
+ );
147
+ }
148
+ this.official = this.factory.create(host);
149
+ }
150
+ /** Lazily obtain (and cache) the official provider — deferred off the init/SSR path.
151
+ * `official.provider()` is typed `OfficialProvider` (loose `request` so real
152
+ * official adapters are assignable); it is call-compatible with CIP0103Provider
153
+ * (the bridge only ever calls `request({ method, params })`). */
154
+ get provider() {
155
+ if (this.providerInstance === null) {
156
+ if (!this.official) {
157
+ throw new Error(
158
+ `Wallet "${String(this.walletId)}" provider requested before host resolution \u2014 call resolveOfficial(network) first.`
159
+ );
160
+ }
161
+ this.providerInstance = this.official.provider();
162
+ }
163
+ return this.providerInstance;
164
+ }
165
+ /**
166
+ * Baseline CIP-0103 capabilities. NEVER includes `'events'`: popup/remote
167
+ * wallets expose the event surface but do not emit (truthfulness doctrine).
168
+ */
169
+ getCapabilities() {
170
+ return ["connect", "disconnect", "signMessage", "submitTransaction"];
171
+ }
172
+ /** Install/availability probe — delegated to the official adapter (popup-free). */
173
+ async detectInstalled() {
174
+ if (!this.official) {
175
+ return { installed: true, reason: "Popup/remote wallet (resolved at connect)" };
176
+ }
177
+ try {
178
+ const installed = await this.official.detect();
179
+ return {
180
+ installed,
181
+ reason: installed ? void 0 : "Wallet reported not available"
182
+ };
183
+ } catch {
184
+ return { installed: false, reason: "Detection failed" };
185
+ }
186
+ }
187
+ async connect(ctx) {
188
+ this.resolveOfficial(ctx.network);
189
+ await this.provider.request({ method: "connect" });
190
+ const account = await this.provider.request({
191
+ method: "getPrimaryAccount"
192
+ });
193
+ let reportedNetwork;
194
+ try {
195
+ const status = await this.provider.request({
196
+ method: "status"
197
+ });
198
+ reportedNetwork = status?.network?.networkId;
199
+ } catch {
200
+ }
201
+ const partyId = core.toPartyId(account.partyId);
202
+ const session = {
203
+ walletId: this.walletId,
204
+ partyId,
205
+ network: reportedNetwork ?? account.networkId ?? ctx.network
206
+ };
207
+ return { partyId, session, capabilities: this.getCapabilities() };
208
+ }
209
+ async disconnect() {
210
+ try {
211
+ await this.provider.request({ method: "disconnect" });
212
+ } catch {
213
+ }
214
+ }
215
+ async signMessage(_ctx, _session, params) {
216
+ return this.provider.request({
217
+ method: "signMessage",
218
+ params: { message: params.message }
219
+ });
220
+ }
221
+ async submitTransaction(_ctx, _session, params) {
222
+ return this.provider.request({
223
+ method: "prepareExecute",
224
+ params
225
+ });
226
+ }
227
+ };
81
228
 
82
229
  // src/config.ts
83
230
  var DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
@@ -432,6 +579,13 @@ var SESSION_STORAGE_KEY = "active_session";
432
579
  var PartyLayerClient = class {
433
580
  config;
434
581
  adapters = /* @__PURE__ */ new Map();
582
+ /**
583
+ * Pre-resolved connect plans for popup/remote (GenericDiscoveryAdapter)
584
+ * wallets, warmed on `listWallets()` (which the modal calls on open) so a
585
+ * subsequent click can connect gesture-synchronously. Consumed (deleted) on
586
+ * use and cleared on disconnect; a cold miss falls back to the normal path.
587
+ */
588
+ warmPlans = /* @__PURE__ */ new Map();
435
589
  eventHandlers = /* @__PURE__ */ new Map();
436
590
  activeSession = null;
437
591
  registryClient;
@@ -462,6 +616,10 @@ var PartyLayerClient = class {
462
616
  let adapter;
463
617
  if (typeof adapterOrClass === "function") {
464
618
  adapter = new adapterOrClass();
619
+ } else if (core.isOfficialAdapterFactory(adapterOrClass)) {
620
+ adapter = new GenericDiscoveryAdapter({ factory: adapterOrClass });
621
+ } else if (core.isOfficialProviderAdapter(adapterOrClass)) {
622
+ adapter = new GenericDiscoveryAdapter({ official: adapterOrClass });
465
623
  } else {
466
624
  adapter = adapterOrClass;
467
625
  }
@@ -546,7 +704,9 @@ var PartyLayerClient = class {
546
704
  channel: "stable"
547
705
  });
548
706
  }
707
+ registryWallets = await this.gateDiscoveryAdapterEntries(registryWallets);
549
708
  registryWallets = await this.aggregateAnnouncedWallets(registryWallets);
709
+ void this.warmDiscoveryPlans(registryWallets);
550
710
  if (filter?.requiredCapabilities) {
551
711
  return registryWallets.filter(
552
712
  (walletInfo) => filter.requiredCapabilities.every(
@@ -559,6 +719,31 @@ var PartyLayerClient = class {
559
719
  }
560
720
  return registryWallets;
561
721
  }
722
+ /**
723
+ * Hide `transport: 'discovery-adapter'` registry entries whose matching
724
+ * adapter is NOT registered. A discovery-adapter wallet's provider is supplied
725
+ * by the app (an official ProviderAdapter the SDK bridges under
726
+ * `toWalletId(providerId)`); without it, clicking the entry can only fail. So
727
+ * the entry surfaces only when its adapter is present. No-op when the registry
728
+ * is unavailable (list is already adapters-only) or has no such entries.
729
+ */
730
+ async gateDiscoveryAdapterEntries(wallets) {
731
+ let hidden = null;
732
+ try {
733
+ const registry = await this.registryClient.getRegistry();
734
+ for (const entry of registry.wallets) {
735
+ if (entry.adapter?.transport !== "discovery-adapter") continue;
736
+ const walletId = core.toWalletId(entry.id);
737
+ if (!this.adapters.has(walletId)) {
738
+ (hidden ??= /* @__PURE__ */ new Set()).add(String(walletId));
739
+ }
740
+ }
741
+ } catch {
742
+ return wallets;
743
+ }
744
+ if (!hidden || hidden.size === 0) return wallets;
745
+ return wallets.filter((w) => !hidden.has(String(w.walletId)));
746
+ }
562
747
  /**
563
748
  * Whether announce discovery is active: explicit `discovery.announce`, else
564
749
  * ON in the browser and OFF under SSR (no `window`). Canonical: provider.md.
@@ -665,138 +850,217 @@ var PartyLayerClient = class {
665
850
  async connect(options) {
666
851
  this.telemetry?.increment?.(core.METRICS.WALLET_CONNECT_ATTEMPTS);
667
852
  try {
668
- const wallets = await this.listWallets({
669
- requiredCapabilities: options?.requiredCapabilities,
670
- includeExperimental: true
853
+ const fast = this.tryFastConnect(options);
854
+ if (fast) return await fast;
855
+ const plan = await this.resolveConnectPlan(options);
856
+ return await this.completeConnect(plan, options);
857
+ } catch (err) {
858
+ const timeoutMs = options?.timeoutMs || 3e4;
859
+ const error = core.mapUnknownErrorToPartyLayerError(err, {
860
+ phase: "connect",
861
+ walletId: options?.walletId ? String(options.walletId) : void 0,
862
+ timeoutMs
671
863
  });
672
- let availableWallets = wallets;
673
- if (options?.allowWallets) {
674
- availableWallets = wallets.filter(
675
- (w) => options.allowWallets.includes(w.walletId)
676
- );
677
- }
678
- let selectedWallet;
679
- let isNativeWallet = false;
680
- if (options?.walletId) {
681
- const found = availableWallets.find(
682
- (w) => w.walletId === options.walletId
683
- );
684
- if (found) {
685
- selectedWallet = found;
864
+ this.emit("error", { type: "error", error });
865
+ throw error;
866
+ }
867
+ }
868
+ /**
869
+ * Pre-resolve everything `adapter.connect()` needs WITHOUT calling it: wallet
870
+ * selection, origin-allowlist + capability + install guards, and the adapter
871
+ * context. `prefetchedWallets` (passed during warm-up from `listWallets`)
872
+ * avoids a recursive `listWallets()` call.
873
+ */
874
+ async resolveConnectPlan(options, prefetchedWallets) {
875
+ const wallets = prefetchedWallets ?? await this.listWallets({
876
+ requiredCapabilities: options?.requiredCapabilities,
877
+ includeExperimental: true
878
+ });
879
+ let availableWallets = wallets;
880
+ if (options?.allowWallets) {
881
+ availableWallets = wallets.filter(
882
+ (w) => options.allowWallets.includes(w.walletId)
883
+ );
884
+ }
885
+ let selectedWallet;
886
+ let isNativeWallet = false;
887
+ if (options?.walletId) {
888
+ const found = availableWallets.find(
889
+ (w) => w.walletId === options.walletId
890
+ );
891
+ if (found) {
892
+ selectedWallet = found;
893
+ } else {
894
+ const nativeAdapter = this.adapters.get(options.walletId);
895
+ if (nativeAdapter) {
896
+ isNativeWallet = true;
897
+ selectedWallet = {
898
+ walletId: options.walletId,
899
+ name: nativeAdapter.name,
900
+ website: "",
901
+ icons: {},
902
+ capabilities: nativeAdapter.getCapabilities(),
903
+ adapter: { packageName: "native-cip0103", versionRange: "*" },
904
+ docs: [],
905
+ networks: [this.config.network],
906
+ channel: "stable",
907
+ metadata: { source: "native-cip0103" }
908
+ };
686
909
  } else {
687
- const nativeAdapter = this.adapters.get(options.walletId);
688
- if (nativeAdapter) {
689
- isNativeWallet = true;
690
- selectedWallet = {
691
- walletId: options.walletId,
692
- name: nativeAdapter.name,
693
- website: "",
694
- icons: {},
695
- capabilities: nativeAdapter.getCapabilities(),
696
- adapter: { packageName: "native-cip0103", versionRange: "*" },
697
- docs: [],
698
- networks: [this.config.network],
699
- channel: "stable",
700
- metadata: { source: "native-cip0103" }
701
- };
702
- } else {
703
- throw new core.WalletNotFoundError(String(options.walletId));
704
- }
910
+ throw new core.WalletNotFoundError(String(options.walletId));
705
911
  }
706
- } else if (availableWallets.length === 0) {
707
- throw new core.WalletNotFoundError("No wallets available");
708
- } else {
709
- selectedWallet = availableWallets[0];
710
- }
711
- const adapter = this.adapters.get(selectedWallet.walletId);
712
- if (!adapter) {
713
- throw new core.WalletNotFoundError(String(selectedWallet.walletId));
714
912
  }
715
- if (!isNativeWallet) {
716
- try {
717
- const walletEntry = await this.registryClient.getWalletEntry(String(selectedWallet.walletId));
718
- if (walletEntry.originAllowlist && walletEntry.originAllowlist.length > 0) {
719
- if (!walletEntry.originAllowlist.includes(this.origin)) {
720
- const { OriginNotAllowedError: OriginNotAllowedError2 } = await import('@partylayer/core');
721
- throw new OriginNotAllowedError2(
722
- this.origin,
723
- walletEntry.originAllowlist
724
- );
725
- }
726
- }
727
- } catch (e) {
728
- if (!(e instanceof core.WalletNotFoundError)) {
729
- throw e;
913
+ } else if (availableWallets.length === 0) {
914
+ throw new core.WalletNotFoundError("No wallets available");
915
+ } else {
916
+ selectedWallet = availableWallets[0];
917
+ }
918
+ const adapter = this.adapters.get(selectedWallet.walletId);
919
+ if (!adapter) {
920
+ throw new core.WalletNotFoundError(String(selectedWallet.walletId));
921
+ }
922
+ if (!isNativeWallet) {
923
+ try {
924
+ const walletEntry = await this.registryClient.getWalletEntry(String(selectedWallet.walletId));
925
+ if (walletEntry.originAllowlist && walletEntry.originAllowlist.length > 0) {
926
+ if (!walletEntry.originAllowlist.includes(this.origin)) {
927
+ const { OriginNotAllowedError: OriginNotAllowedError2 } = await import('@partylayer/core');
928
+ throw new OriginNotAllowedError2(
929
+ this.origin,
930
+ walletEntry.originAllowlist
931
+ );
730
932
  }
731
933
  }
934
+ } catch (e) {
935
+ if (!(e instanceof core.WalletNotFoundError)) {
936
+ throw e;
937
+ }
732
938
  }
733
- if (options?.requiredCapabilities) {
734
- core.capabilityGuard(adapter, options.requiredCapabilities);
939
+ }
940
+ if (options?.requiredCapabilities) {
941
+ core.capabilityGuard(adapter, options.requiredCapabilities);
942
+ }
943
+ await core.installGuard(adapter);
944
+ const ctx = this.createAdapterContext();
945
+ if (adapter instanceof GenericDiscoveryAdapter && adapter.usesFactory()) {
946
+ let networkHosts = {};
947
+ try {
948
+ const entry = await this.registryClient.getWalletEntry(
949
+ String(selectedWallet.walletId)
950
+ );
951
+ networkHosts = entry.adapter?.networkHosts ?? {};
952
+ } catch {
735
953
  }
736
- await core.installGuard(adapter);
737
- const ctx = this.createAdapterContext();
738
- const timeoutMs = options?.timeoutMs || 12e4;
739
- const connectPromise = adapter.connect(ctx, {
740
- timeoutMs,
741
- partyId: void 0,
742
- preferInstalled: options?.preferInstalled,
743
- onDisplayUri: options?.onDisplayUri
744
- });
745
- const timeoutPromise = new Promise((_, reject) => {
746
- setTimeout(() => {
747
- reject(new Error(`Connection timed out after ${timeoutMs}ms - user did not complete wallet connection`));
748
- }, timeoutMs);
954
+ adapter.setNetworkHosts(networkHosts);
955
+ adapter.resolveOfficial(ctx.network);
956
+ }
957
+ return { selectedWallet, adapter, ctx, isNativeWallet };
958
+ }
959
+ /**
960
+ * Invoke `adapter.connect()` (its FIRST statement — no await precedes it) and
961
+ * build / persist / emit the session. Separated from plan resolution so the
962
+ * popup-safe fast-path can call it gesture-synchronously.
963
+ */
964
+ async completeConnect(plan, options) {
965
+ const { selectedWallet, adapter, ctx } = plan;
966
+ const timeoutMs = options?.timeoutMs || 12e4;
967
+ const connectPromise = adapter.connect(ctx, {
968
+ timeoutMs,
969
+ partyId: void 0,
970
+ preferInstalled: options?.preferInstalled,
971
+ onDisplayUri: options?.onDisplayUri
972
+ });
973
+ const timeoutPromise = new Promise((_, reject) => {
974
+ setTimeout(() => {
975
+ reject(new Error(`Connection timed out after ${timeoutMs}ms - user did not complete wallet connection`));
976
+ }, timeoutMs);
977
+ });
978
+ const result = await Promise.race([connectPromise, timeoutPromise]);
979
+ const session = {
980
+ sessionId: core.toSessionId(`session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`),
981
+ walletId: selectedWallet.walletId,
982
+ partyId: result.partyId,
983
+ // The wallet's reported network (adapters that read the live wallet —
984
+ // e.g. Console via getActiveNetwork — surface the actual network here;
985
+ // echo-only adapters report ctx.network === config.network). Used for
986
+ // mismatch detection; falls back to the configured network.
987
+ network: result.session.network ?? this.config.network,
988
+ createdAt: Date.now(),
989
+ expiresAt: result.session.expiresAt,
990
+ origin: this.origin,
991
+ capabilitiesSnapshot: result.capabilities,
992
+ metadata: result.session.metadata
993
+ };
994
+ const mismatch = this.networkMismatch(session);
995
+ if (mismatch) {
996
+ session.networkMismatch = mismatch;
997
+ this.emit("session:networkMismatch", {
998
+ type: "session:networkMismatch",
999
+ sessionId: session.sessionId,
1000
+ expected: mismatch.expected,
1001
+ actual: mismatch.actual,
1002
+ enforced: this.enforcement !== "off"
749
1003
  });
750
- const result = await Promise.race([connectPromise, timeoutPromise]);
751
- const session = {
752
- sessionId: core.toSessionId(`session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`),
753
- walletId: selectedWallet.walletId,
754
- partyId: result.partyId,
755
- // The wallet's reported network (adapters that read the live wallet —
756
- // e.g. Console via getActiveNetwork — surface the actual network here;
757
- // echo-only adapters report ctx.network === config.network). Used for
758
- // mismatch detection; falls back to the configured network.
759
- network: result.session.network ?? this.config.network,
760
- createdAt: Date.now(),
761
- expiresAt: result.session.expiresAt,
762
- origin: this.origin,
763
- capabilitiesSnapshot: result.capabilities,
764
- metadata: result.session.metadata
765
- };
766
- const mismatch = this.networkMismatch(session);
767
- if (mismatch) {
768
- session.networkMismatch = mismatch;
769
- this.emit("session:networkMismatch", {
770
- type: "session:networkMismatch",
771
- sessionId: session.sessionId,
772
- expected: mismatch.expected,
773
- actual: mismatch.actual,
774
- enforced: this.enforcement !== "off"
775
- });
776
- if (this.enforcement === "strict") {
777
- throw new core.NetworkMismatchError(mismatch.expected, mismatch.actual);
778
- }
1004
+ if (this.enforcement === "strict") {
1005
+ throw new core.NetworkMismatchError(mismatch.expected, mismatch.actual);
779
1006
  }
780
- await this.persistSession(session);
781
- this.activeSession = session;
782
- this.updateRegistryStatus();
783
- this.telemetry?.increment?.(core.METRICS.WALLET_CONNECT_SUCCESS);
784
- this.telemetry?.increment?.(core.METRICS.SESSIONS_CREATED);
785
- this.emit("session:connected", {
786
- type: "session:connected",
787
- session
788
- });
789
- return session;
790
- } catch (err) {
791
- const timeoutMs = options?.timeoutMs || 3e4;
792
- const error = core.mapUnknownErrorToPartyLayerError(err, {
793
- phase: "connect",
794
- walletId: options?.walletId ? String(options.walletId) : void 0,
795
- timeoutMs
796
- });
797
- this.emit("error", { type: "error", error });
798
- throw error;
799
1007
  }
1008
+ await this.persistSession(session);
1009
+ this.activeSession = session;
1010
+ this.updateRegistryStatus();
1011
+ this.telemetry?.increment?.(core.METRICS.WALLET_CONNECT_SUCCESS);
1012
+ this.telemetry?.increment?.(core.METRICS.SESSIONS_CREATED);
1013
+ this.emit("session:connected", {
1014
+ type: "session:connected",
1015
+ session
1016
+ });
1017
+ return session;
1018
+ }
1019
+ /**
1020
+ * PUBLIC popup-safe primitive: pre-resolve a connect plan ahead of the user
1021
+ * gesture; the returned `connect()` invokes `adapter.connect()` as its first
1022
+ * statement (no await precedes it) so a popup/remote wallet's `window.open`
1023
+ * survives the gesture. For consumers driving such a wallet outside the modal
1024
+ * (the modal gets this for free via the `listWallets` warm-up + `connect()`).
1025
+ */
1026
+ async prepareConnect(options) {
1027
+ const plan = await this.resolveConnectPlan(options);
1028
+ return {
1029
+ walletId: plan.selectedWallet.walletId,
1030
+ connect: (o) => this.completeConnect(plan, o ?? options)
1031
+ };
1032
+ }
1033
+ /**
1034
+ * Background warm-up of connect plans for popup/remote
1035
+ * (`GenericDiscoveryAdapter`) wallets. Popup-free — `resolveConnectPlan` only
1036
+ * runs read/guard probes. Skips already-warm entries; never throws.
1037
+ */
1038
+ async warmDiscoveryPlans(wallets) {
1039
+ for (const [walletId, adapter] of this.adapters) {
1040
+ if (!(adapter instanceof GenericDiscoveryAdapter)) continue;
1041
+ if (this.warmPlans.has(walletId)) continue;
1042
+ try {
1043
+ const plan = await this.resolveConnectPlan({ walletId }, wallets);
1044
+ this.warmPlans.set(walletId, plan);
1045
+ } catch {
1046
+ }
1047
+ }
1048
+ }
1049
+ /**
1050
+ * SYNCHRONOUS fast-path: if a fresh warm plan exists for a popup/remote wallet
1051
+ * — and `options` carries no plan-affecting guards — consume it and START
1052
+ * `completeConnect` immediately, reaching `adapter.connect()` with no awaits.
1053
+ * Returns the in-flight Session promise, or null to fall back to the normal
1054
+ * path (e.g. cold cache, or a non-discovery wallet).
1055
+ */
1056
+ tryFastConnect(options) {
1057
+ const walletId = options?.walletId;
1058
+ if (!walletId) return null;
1059
+ if (options?.requiredCapabilities || options?.allowWallets) return null;
1060
+ const plan = this.warmPlans.get(walletId);
1061
+ if (!plan) return null;
1062
+ this.warmPlans.delete(walletId);
1063
+ return this.completeConnect(plan, options);
800
1064
  }
801
1065
  /**
802
1066
  * Disconnect from wallet
@@ -814,6 +1078,7 @@ var PartyLayerClient = class {
814
1078
  const sessionId = this.activeSession.sessionId;
815
1079
  await this.removeSession(sessionId);
816
1080
  this.activeSession = null;
1081
+ this.warmPlans.clear();
817
1082
  this.emit("session:disconnected", {
818
1083
  type: "session:disconnected",
819
1084
  sessionId
@@ -1093,6 +1358,29 @@ var PartyLayerClient = class {
1093
1358
  if (session.origin !== this.origin) {
1094
1359
  return null;
1095
1360
  }
1361
+ const mismatch = this.networkMismatch(session);
1362
+ if (mismatch) {
1363
+ this.emit("session:networkMismatch", {
1364
+ type: "session:networkMismatch",
1365
+ sessionId: session.sessionId,
1366
+ expected: mismatch.expected,
1367
+ actual: mismatch.actual,
1368
+ enforced: this.enforcement !== "off"
1369
+ });
1370
+ if (this.enforcement !== "off") {
1371
+ this.logger.warn("Refused session restore \u2014 network mismatch", {
1372
+ expected: mismatch.expected,
1373
+ actual: mismatch.actual
1374
+ });
1375
+ await this.removeSession(session.sessionId);
1376
+ this.emit("session:expired", {
1377
+ type: "session:expired",
1378
+ sessionId: session.sessionId
1379
+ });
1380
+ return null;
1381
+ }
1382
+ session.networkMismatch = mismatch;
1383
+ }
1096
1384
  const adapter = this.adapters.get(session.walletId);
1097
1385
  if (adapter?.restore) {
1098
1386
  const ctx = this.createAdapterContext();
@@ -1263,6 +1551,14 @@ Object.defineProperty(exports, "errorMetricName", {
1263
1551
  enumerable: true,
1264
1552
  get: function () { return core.errorMetricName; }
1265
1553
  });
1554
+ Object.defineProperty(exports, "isOfficialAdapterFactory", {
1555
+ enumerable: true,
1556
+ get: function () { return core.isOfficialAdapterFactory; }
1557
+ });
1558
+ Object.defineProperty(exports, "isOfficialProviderAdapter", {
1559
+ enumerable: true,
1560
+ get: function () { return core.isOfficialProviderAdapter; }
1561
+ });
1266
1562
  Object.defineProperty(exports, "deriveGenericWalletName", {
1267
1563
  enumerable: true,
1268
1564
  get: function () { return registryClient.deriveGenericWalletName; }
@@ -1375,6 +1671,7 @@ exports.ANNOUNCED_WALLET_ID_PREFIX = ANNOUNCED_WALLET_ID_PREFIX;
1375
1671
  exports.CantonConnectClient = PartyLayerClient;
1376
1672
  exports.DEFAULT_REGISTRY_URL = DEFAULT_REGISTRY_URL;
1377
1673
  exports.GenericAnnounceAdapter = GenericAnnounceAdapter;
1674
+ exports.GenericDiscoveryAdapter = GenericDiscoveryAdapter;
1378
1675
  exports.MetricsTelemetryAdapter = MetricsTelemetryAdapter;
1379
1676
  exports.PartyLayerClient = PartyLayerClient;
1380
1677
  exports.announcedWalletId = announcedWalletId;