@metamask/connect-multichain 0.5.3 → 0.6.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +9 -3
  3. package/dist/browser/es/connect-multichain.d.mts +27 -4
  4. package/dist/browser/es/connect-multichain.mjs +603 -333
  5. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  6. package/dist/browser/es/metafile-esm.json +1 -1
  7. package/dist/browser/iife/connect-multichain.d.ts +27 -4
  8. package/dist/browser/iife/connect-multichain.js +3363 -2993
  9. package/dist/browser/iife/connect-multichain.js.map +1 -1
  10. package/dist/browser/iife/metafile-iife.json +1 -1
  11. package/dist/browser/umd/connect-multichain.d.ts +27 -4
  12. package/dist/browser/umd/connect-multichain.js +603 -333
  13. package/dist/browser/umd/connect-multichain.js.map +1 -1
  14. package/dist/browser/umd/metafile-cjs.json +1 -1
  15. package/dist/node/cjs/connect-multichain.d.ts +27 -4
  16. package/dist/node/cjs/connect-multichain.js +421 -151
  17. package/dist/node/cjs/connect-multichain.js.map +1 -1
  18. package/dist/node/cjs/metafile-cjs.json +1 -1
  19. package/dist/node/es/connect-multichain.d.mts +27 -4
  20. package/dist/node/es/connect-multichain.mjs +421 -151
  21. package/dist/node/es/connect-multichain.mjs.map +1 -1
  22. package/dist/node/es/metafile-esm.json +1 -1
  23. package/dist/react-native/es/connect-multichain.d.mts +27 -4
  24. package/dist/react-native/es/connect-multichain.mjs +596 -326
  25. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  26. package/dist/react-native/es/metafile-esm.json +1 -1
  27. package/dist/src/domain/multichain/index.d.ts +15 -4
  28. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  29. package/dist/src/domain/multichain/index.js +14 -0
  30. package/dist/src/domain/multichain/index.js.map +1 -1
  31. package/dist/src/domain/multichain/types.d.ts +12 -0
  32. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  33. package/dist/src/multichain/index.d.ts +3 -2
  34. package/dist/src/multichain/index.d.ts.map +1 -1
  35. package/dist/src/multichain/index.js +158 -61
  36. package/dist/src/multichain/index.js.map +1 -1
  37. package/dist/src/multichain/transports/default/index.d.ts +3 -1
  38. package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
  39. package/dist/src/multichain/transports/default/index.js +17 -11
  40. package/dist/src/multichain/transports/default/index.js.map +1 -1
  41. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +3 -1
  42. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
  43. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +28 -31
  44. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
  45. package/dist/src/multichain/transports/mwp/index.d.ts +15 -2
  46. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  47. package/dist/src/multichain/transports/mwp/index.js +155 -38
  48. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  49. package/dist/src/multichain/utils/index.d.ts +23 -0
  50. package/dist/src/multichain/utils/index.d.ts.map +1 -1
  51. package/dist/src/multichain/utils/index.js +57 -4
  52. package/dist/src/multichain/utils/index.js.map +1 -1
  53. package/dist/src/polyfills/buffer-shim.js +4 -14
  54. package/dist/src/polyfills/buffer-shim.js.map +1 -1
  55. package/dist/src/store/adapters/web.d.ts +1 -1
  56. package/dist/src/store/adapters/web.d.ts.map +1 -1
  57. package/dist/src/store/adapters/web.js +1 -1
  58. package/dist/src/store/adapters/web.js.map +1 -1
  59. package/dist/types/connect-multichain.d.ts +27 -4
  60. package/package.json +1 -1
@@ -55,14 +55,6 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
55
55
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
56
56
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
57
57
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
58
- var __privateWrapper = (obj, member, setter, getter) => ({
59
- set _(value) {
60
- __privateSet(obj, member, value, setter);
61
- },
62
- get _() {
63
- return __privateGet(obj, member, getter);
64
- }
65
- });
66
58
  var __async = (__this, __arguments, generator) => {
67
59
  return new Promise((resolve, reject) => {
68
60
  var fulfilled = (value) => {
@@ -264,8 +256,8 @@ var init_logger = __esm({
264
256
  import_debug.default.enable(namespace);
265
257
  };
266
258
  isEnabled = (namespace, storage) => __async(null, null, function* () {
267
- var _a2;
268
- if ("process" in globalThis && ((_a2 = process == null ? void 0 : process.env) == null ? void 0 : _a2.DEBUG)) {
259
+ var _a3;
260
+ if ("process" in globalThis && ((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3.DEBUG)) {
269
261
  const { DEBUG } = process.env;
270
262
  return isNamespaceEnabled(DEBUG, namespace);
271
263
  }
@@ -428,41 +420,69 @@ var init_multichain = __esm({
428
420
  super();
429
421
  this.options = options;
430
422
  }
423
+ /**
424
+ * Merges the given options into the current instance options.
425
+ * Only the mergeable keys are updated (api.supportedNetworks, ui.*, mobile.*, transport.extensionId, debug).
426
+ * The main thing to note is that the value for `dapp` is not merged as it does not make sense for
427
+ * subsequent calls to `createMultichainClient` to have a different `dapp` value.
428
+ * Used when createMultichainClient is called with an existing singleton.
429
+ *
430
+ * @param partial - Options to merge/overwrite onto the current instance
431
+ */
432
+ mergeOptions(partial) {
433
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
434
+ const opts = this.options;
435
+ this.options = __spreadProps(__spreadValues({}, opts), {
436
+ api: __spreadProps(__spreadValues({}, opts.api), {
437
+ supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_b = (_a3 = partial.api) == null ? void 0 : _a3.supportedNetworks) != null ? _b : {})
438
+ }),
439
+ ui: __spreadProps(__spreadValues({}, opts.ui), {
440
+ headless: (_d = (_c = partial.ui) == null ? void 0 : _c.headless) != null ? _d : opts.ui.headless,
441
+ preferExtension: (_f = (_e = partial.ui) == null ? void 0 : _e.preferExtension) != null ? _f : opts.ui.preferExtension,
442
+ showInstallModal: (_h = (_g = partial.ui) == null ? void 0 : _g.showInstallModal) != null ? _h : opts.ui.showInstallModal
443
+ }),
444
+ mobile: __spreadValues(__spreadValues({}, opts.mobile), (_i = partial.mobile) != null ? _i : {}),
445
+ transport: __spreadProps(__spreadValues({}, (_j = opts.transport) != null ? _j : {}), {
446
+ extensionId: (_m = (_k = partial.transport) == null ? void 0 : _k.extensionId) != null ? _m : (_l = opts.transport) == null ? void 0 : _l.extensionId
447
+ }),
448
+ debug: (_n = partial.debug) != null ? _n : opts.debug
449
+ });
450
+ }
431
451
  };
432
452
  }
433
453
  });
434
454
 
435
455
  // src/domain/platform/index.ts
436
456
  function isNotBrowser() {
437
- var _a2;
457
+ var _a3;
438
458
  if (typeof window === "undefined") {
439
459
  return true;
440
460
  }
441
461
  if (!(window == null ? void 0 : window.navigator)) {
442
462
  return true;
443
463
  }
444
- if (typeof global !== "undefined" && ((_a2 = global == null ? void 0 : global.navigator) == null ? void 0 : _a2.product) === "ReactNative") {
464
+ if (typeof global !== "undefined" && ((_a3 = global == null ? void 0 : global.navigator) == null ? void 0 : _a3.product) === "ReactNative") {
445
465
  return true;
446
466
  }
447
467
  return (navigator == null ? void 0 : navigator.product) === "ReactNative";
448
468
  }
449
469
  function isReactNative() {
450
- var _a2;
470
+ var _a3;
451
471
  const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
452
472
  const nav = hasWindowNavigator ? window.navigator : void 0;
453
473
  if (!nav) {
454
474
  return false;
455
475
  }
456
- return hasWindowNavigator && ((_a2 = window.navigator) == null ? void 0 : _a2.product) === "ReactNative";
476
+ return hasWindowNavigator && ((_a3 = window.navigator) == null ? void 0 : _a3.product) === "ReactNative";
457
477
  }
458
478
  function isMetaMaskMobileWebView() {
459
479
  return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
460
480
  Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
461
481
  }
462
482
  function isMobile() {
463
- var _a2, _b;
483
+ var _a3, _b;
464
484
  const browser = import_bowser.default.parse(window.navigator.userAgent);
465
- return ((_a2 = browser == null ? void 0 : browser.platform) == null ? void 0 : _a2.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
485
+ return ((_a3 = browser == null ? void 0 : browser.platform) == null ? void 0 : _a3.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
466
486
  }
467
487
  function getPlatformType() {
468
488
  if (isReactNative()) {
@@ -480,11 +500,11 @@ function getPlatformType() {
480
500
  return "web-desktop" /* DesktopWeb */;
481
501
  }
482
502
  function isMetamaskExtensionInstalled() {
483
- var _a2;
503
+ var _a3;
484
504
  if (typeof window === "undefined") {
485
505
  return false;
486
506
  }
487
- return Boolean((_a2 = window.ethereum) == null ? void 0 : _a2.isMetaMask);
507
+ return Boolean((_a3 = window.ethereum) == null ? void 0 : _a3.isMetaMask);
488
508
  }
489
509
  function isSecure() {
490
510
  const platformType = getPlatformType();
@@ -516,8 +536,8 @@ var init_platform = __esm({
516
536
  return new Promise((resolve) => {
517
537
  const providers = [];
518
538
  const handler = (event) => {
519
- var _a2, _b;
520
- if ((_b = (_a2 = event == null ? void 0 : event.detail) == null ? void 0 : _a2.info) == null ? void 0 : _b.rdns) {
539
+ var _a3, _b;
540
+ if ((_b = (_a3 = event == null ? void 0 : event.detail) == null ? void 0 : _a3.info) == null ? void 0 : _b.rdns) {
521
541
  providers.push(event.detail);
522
542
  }
523
543
  };
@@ -527,8 +547,8 @@ var init_platform = __esm({
527
547
  window.removeEventListener("eip6963:announceProvider", handler);
528
548
  const hasMetaMask = providers.some(
529
549
  (provider) => {
530
- var _a2, _b;
531
- return (_b = (_a2 = provider == null ? void 0 : provider.info) == null ? void 0 : _a2.rdns) == null ? void 0 : _b.startsWith("io.metamask");
550
+ var _a3, _b;
551
+ return (_b = (_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) == null ? void 0 : _b.startsWith("io.metamask");
532
552
  }
533
553
  );
534
554
  resolve(hasMetaMask);
@@ -612,7 +632,103 @@ var init_ui = __esm({
612
632
  }
613
633
  });
614
634
 
635
+ // src/multichain/utils/analytics.ts
636
+ function isRejectionError(error) {
637
+ var _a3, _b;
638
+ if (typeof error !== "object" || error === null) {
639
+ return false;
640
+ }
641
+ const errorObj = error;
642
+ const errorCode = errorObj.code;
643
+ const errorMessage = (_b = (_a3 = errorObj.message) == null ? void 0 : _a3.toLowerCase()) != null ? _b : "";
644
+ return errorCode === 4001 || // User rejected request (common EIP-1193 code)
645
+ errorCode === 4100 || // Unauthorized (common rejection code)
646
+ errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
647
+ }
648
+ function getBaseAnalyticsProperties(options, storage) {
649
+ return __async(this, null, function* () {
650
+ var _a3, _b;
651
+ const version = getVersion();
652
+ const dappId = getDappId(options.dapp);
653
+ const platform = getPlatformType();
654
+ const anonId = yield storage.getAnonId();
655
+ const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
656
+ return {
657
+ mmconnect_version: version,
658
+ dapp_id: dappId,
659
+ platform,
660
+ integration_type: integrationType,
661
+ anon_id: anonId
662
+ };
663
+ });
664
+ }
665
+ function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
666
+ return __async(this, null, function* () {
667
+ var _a3, _b;
668
+ const version = getVersion();
669
+ const dappId = getDappId(options.dapp);
670
+ const anonId = yield storage.getAnonId();
671
+ const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown";
672
+ return {
673
+ mmconnect_version: version,
674
+ dapp_id: dappId,
675
+ method: invokeOptions.request.method,
676
+ integration_type: integrationType,
677
+ caip_chain_id: invokeOptions.scope,
678
+ anon_id: anonId
679
+ };
680
+ });
681
+ }
682
+ var init_analytics = __esm({
683
+ "src/multichain/utils/analytics.ts"() {
684
+ "use strict";
685
+ init_utils2();
686
+ init_domain();
687
+ }
688
+ });
689
+
690
+ // src/domain/utils/index.ts
691
+ function getVersion() {
692
+ return "0.0.0";
693
+ }
694
+ var init_utils = __esm({
695
+ "src/domain/utils/index.ts"() {
696
+ "use strict";
697
+ init_analytics();
698
+ }
699
+ });
700
+
701
+ // src/domain/index.ts
702
+ var init_domain = __esm({
703
+ "src/domain/index.ts"() {
704
+ "use strict";
705
+ init_errors();
706
+ init_events();
707
+ init_logger();
708
+ init_multichain();
709
+ init_platform();
710
+ init_store();
711
+ init_ui();
712
+ init_utils();
713
+ }
714
+ });
715
+
615
716
  // src/multichain/utils/index.ts
717
+ function getGlobalObject() {
718
+ if (typeof globalThis !== "undefined") {
719
+ return globalThis;
720
+ }
721
+ if (typeof global !== "undefined") {
722
+ return global;
723
+ }
724
+ if (typeof self !== "undefined") {
725
+ return self;
726
+ }
727
+ if (typeof window !== "undefined") {
728
+ return window;
729
+ }
730
+ throw new Error("Unable to locate global object");
731
+ }
616
732
  function base64Encode(str) {
617
733
  if (typeof btoa !== "undefined") {
618
734
  return btoa(str);
@@ -627,13 +743,13 @@ function compressString(str) {
627
743
  return base64Encode(binaryString);
628
744
  }
629
745
  function getDappId(dapp) {
630
- var _a2;
631
- return (_a2 = dapp.url) != null ? _a2 : dapp.name;
746
+ var _a3;
747
+ return (_a3 = dapp.url) != null ? _a3 : dapp.name;
632
748
  }
633
749
  function openDeeplink(options, deeplink, universalLink) {
634
- var _a2;
750
+ var _a3;
635
751
  const { mobile } = options;
636
- const useDeeplink = (_a2 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a2 : true;
752
+ const useDeeplink = (_a3 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a3 : true;
637
753
  if (useDeeplink) {
638
754
  if (typeof window !== "undefined") {
639
755
  window.location.href = deeplink;
@@ -646,6 +762,29 @@ function openDeeplink(options, deeplink, universalLink) {
646
762
  link.click();
647
763
  }
648
764
  }
765
+ function mergeRequestedSessionWithExisting(sessionData, scopes, caipAccountIds, sessionProperties) {
766
+ const existingCaipChainIds = Object.keys(sessionData.sessionScopes);
767
+ const existingCaipAccountIds = [];
768
+ Object.values(sessionData.sessionScopes).forEach((scopeObject) => {
769
+ if ((scopeObject == null ? void 0 : scopeObject.accounts) && Array.isArray(scopeObject.accounts)) {
770
+ scopeObject.accounts.forEach((account) => {
771
+ existingCaipAccountIds.push(account);
772
+ });
773
+ }
774
+ });
775
+ const mergedScopes = Array.from(
776
+ /* @__PURE__ */ new Set([...existingCaipChainIds, ...scopes])
777
+ );
778
+ const mergedCaipAccountIds = Array.from(
779
+ /* @__PURE__ */ new Set([...existingCaipAccountIds, ...caipAccountIds])
780
+ );
781
+ const mergedSessionProperties = __spreadValues(__spreadValues({}, sessionData.sessionProperties), sessionProperties);
782
+ return {
783
+ mergedScopes,
784
+ mergedCaipAccountIds,
785
+ mergedSessionProperties
786
+ };
787
+ }
649
788
  function getOptionalScopes(scopes) {
650
789
  return scopes.reduce(
651
790
  (prev, scope) => __spreadProps(__spreadValues({}, prev), {
@@ -659,10 +798,10 @@ function getOptionalScopes(scopes) {
659
798
  );
660
799
  }
661
800
  function setupDappMetadata(options) {
662
- var _a2, _b;
801
+ var _a3, _b;
663
802
  const platform = getPlatformType();
664
803
  const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
665
- if (!((_a2 = options.dapp) == null ? void 0 : _a2.name)) {
804
+ if (!((_a3 = options.dapp) == null ? void 0 : _a3.name)) {
666
805
  throw new Error("You must provide dapp name");
667
806
  }
668
807
  if (isBrowser) {
@@ -736,17 +875,17 @@ function getValidAccounts(caipAccountIds) {
736
875
  );
737
876
  }
738
877
  function addValidAccounts(optionalScopes, validAccounts) {
739
- var _a2;
878
+ var _a3;
740
879
  if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
741
880
  return optionalScopes;
742
881
  }
743
882
  const result = Object.fromEntries(
744
883
  Object.entries(optionalScopes).map(([scope, scopeData]) => {
745
- var _a3, _b, _c;
884
+ var _a4, _b, _c;
746
885
  return [
747
886
  scope,
748
887
  {
749
- methods: [...(_a3 = scopeData == null ? void 0 : scopeData.methods) != null ? _a3 : []],
888
+ methods: [...(_a4 = scopeData == null ? void 0 : scopeData.methods) != null ? _a4 : []],
750
889
  notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
751
890
  accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
752
891
  }
@@ -760,7 +899,7 @@ function addValidAccounts(optionalScopes, validAccounts) {
760
899
  if (!accountsByChain.has(chainKey)) {
761
900
  accountsByChain.set(chainKey, []);
762
901
  }
763
- (_a2 = accountsByChain.get(chainKey)) == null ? void 0 : _a2.push(accountId);
902
+ (_a3 = accountsByChain.get(chainKey)) == null ? void 0 : _a3.push(accountId);
764
903
  }
765
904
  for (const [scopeKey, scopeData] of Object.entries(result)) {
766
905
  if (!(scopeData == null ? void 0 : scopeData.accounts)) {
@@ -784,15 +923,15 @@ function addValidAccounts(optionalScopes, validAccounts) {
784
923
  }
785
924
  return result;
786
925
  }
787
- var import_utils, import_pako, extractFavicon;
788
- var init_utils = __esm({
926
+ var import_utils, import_pako, extractFavicon, MAX, idCounter, getUniqueRequestId;
927
+ var init_utils2 = __esm({
789
928
  "src/multichain/utils/index.ts"() {
790
929
  "use strict";
791
930
  import_utils = require("@metamask/utils");
792
931
  import_pako = require("pako");
793
932
  init_domain();
794
933
  extractFavicon = () => {
795
- var _a2;
934
+ var _a3;
796
935
  if (typeof document === "undefined") {
797
936
  return void 0;
798
937
  }
@@ -800,92 +939,17 @@ var init_utils = __esm({
800
939
  const nodeList = document.getElementsByTagName("link");
801
940
  for (let i = 0; i < nodeList.length; i++) {
802
941
  if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
803
- favicon = (_a2 = nodeList[i].getAttribute("href")) != null ? _a2 : void 0;
942
+ favicon = (_a3 = nodeList[i].getAttribute("href")) != null ? _a3 : void 0;
804
943
  }
805
944
  }
806
945
  return favicon;
807
946
  };
808
- }
809
- });
810
-
811
- // src/multichain/utils/analytics.ts
812
- function isRejectionError(error) {
813
- var _a2, _b;
814
- if (typeof error !== "object" || error === null) {
815
- return false;
816
- }
817
- const errorObj = error;
818
- const errorCode = errorObj.code;
819
- const errorMessage = (_b = (_a2 = errorObj.message) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
820
- return errorCode === 4001 || // User rejected request (common EIP-1193 code)
821
- errorCode === 4100 || // Unauthorized (common rejection code)
822
- errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
823
- }
824
- function getBaseAnalyticsProperties(options, storage) {
825
- return __async(this, null, function* () {
826
- var _a2, _b;
827
- const version = getVersion();
828
- const dappId = getDappId(options.dapp);
829
- const platform = getPlatformType();
830
- const anonId = yield storage.getAnonId();
831
- const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
832
- return {
833
- mmconnect_version: version,
834
- dapp_id: dappId,
835
- platform,
836
- integration_type: integrationType,
837
- anon_id: anonId
947
+ MAX = 4294967295;
948
+ idCounter = Math.floor(Math.random() * MAX);
949
+ getUniqueRequestId = () => {
950
+ idCounter = (idCounter + 1) % MAX;
951
+ return idCounter;
838
952
  };
839
- });
840
- }
841
- function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
842
- return __async(this, null, function* () {
843
- var _a2, _b;
844
- const version = getVersion();
845
- const dappId = getDappId(options.dapp);
846
- const anonId = yield storage.getAnonId();
847
- const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
848
- return {
849
- mmconnect_version: version,
850
- dapp_id: dappId,
851
- method: invokeOptions.request.method,
852
- integration_type: integrationType,
853
- caip_chain_id: invokeOptions.scope,
854
- anon_id: anonId
855
- };
856
- });
857
- }
858
- var init_analytics = __esm({
859
- "src/multichain/utils/analytics.ts"() {
860
- "use strict";
861
- init_utils();
862
- init_domain();
863
- }
864
- });
865
-
866
- // src/domain/utils/index.ts
867
- function getVersion() {
868
- return "0.0.0";
869
- }
870
- var init_utils2 = __esm({
871
- "src/domain/utils/index.ts"() {
872
- "use strict";
873
- init_analytics();
874
- }
875
- });
876
-
877
- // src/domain/index.ts
878
- var init_domain = __esm({
879
- "src/domain/index.ts"() {
880
- "use strict";
881
- init_errors();
882
- init_events();
883
- init_logger();
884
- init_multichain();
885
- init_platform();
886
- init_store();
887
- init_ui();
888
- init_utils2();
889
953
  }
890
954
  });
891
955
 
@@ -1014,7 +1078,7 @@ var init_install = __esm({
1014
1078
  renderQRCode() {
1015
1079
  }
1016
1080
  mount() {
1017
- var _a2;
1081
+ var _a3;
1018
1082
  const { options } = this;
1019
1083
  const modal = document.createElement(
1020
1084
  "mm-install-modal"
@@ -1031,14 +1095,14 @@ var init_install = __esm({
1031
1095
  );
1032
1096
  modal.link = options.link;
1033
1097
  this.instance = modal;
1034
- (_a2 = options.parentElement) == null ? void 0 : _a2.appendChild(modal);
1098
+ (_a3 = options.parentElement) == null ? void 0 : _a3.appendChild(modal);
1035
1099
  this.startExpirationCheck(options.connectionRequest);
1036
1100
  }
1037
1101
  unmount() {
1038
- var _a2;
1102
+ var _a3;
1039
1103
  const { options, instance: modal } = this;
1040
1104
  this.stopExpirationCheck();
1041
- if (modal && ((_a2 = options.parentElement) == null ? void 0 : _a2.contains(modal))) {
1105
+ if (modal && ((_a3 = options.parentElement) == null ? void 0 : _a3.contains(modal))) {
1042
1106
  options.parentElement.removeChild(modal);
1043
1107
  this.instance = void 0;
1044
1108
  }
@@ -1150,8 +1214,8 @@ var init_web2 = __esm({
1150
1214
  const request = store.get(key);
1151
1215
  request.onerror = () => reject(new Error("Failed to get value from IndexedDB."));
1152
1216
  request.onsuccess = () => {
1153
- var _a2;
1154
- return resolve((_a2 = request.result) != null ? _a2 : null);
1217
+ var _a3;
1218
+ return resolve((_a3 = request.result) != null ? _a3 : null);
1155
1219
  };
1156
1220
  } catch (error) {
1157
1221
  reject(error);
@@ -1195,7 +1259,7 @@ var init_web2 = __esm({
1195
1259
  }
1196
1260
  };
1197
1261
  _StoreAdapterWeb.stores = ["sdk-kv-store", "key-value-pairs"];
1198
- _StoreAdapterWeb.DB_NAME = "mmsdk";
1262
+ _StoreAdapterWeb.DB_NAME = "mmconnect";
1199
1263
  StoreAdapterWeb = _StoreAdapterWeb;
1200
1264
  }
1201
1265
  });
@@ -1235,10 +1299,10 @@ module.exports = __toCommonJS(index_browser_exports);
1235
1299
 
1236
1300
  // src/polyfills/buffer-shim.ts
1237
1301
  var import_buffer = require("buffer");
1238
- var globalObj = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
1239
- if (!globalObj.Buffer) {
1240
- globalObj.Buffer = import_buffer.Buffer;
1241
- }
1302
+ init_utils2();
1303
+ var globalObj = getGlobalObject();
1304
+ var _a;
1305
+ (_a = globalObj.Buffer) != null ? _a : globalObj.Buffer = import_buffer.Buffer;
1242
1306
 
1243
1307
  // src/index.browser.ts
1244
1308
  init_domain();
@@ -1304,8 +1368,8 @@ var RpcClient = class {
1304
1368
  });
1305
1369
  }
1306
1370
  getRpcEndpoint(scope) {
1307
- var _a2, _b, _c;
1308
- const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
1371
+ var _a3, _b, _c;
1372
+ const supportedNetworks = (_c = (_b = (_a3 = this.config) == null ? void 0 : _a3.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
1309
1373
  const rpcEndpoint = supportedNetworks[scope];
1310
1374
  if (!rpcEndpoint) {
1311
1375
  throw new MissingRpcEndpointErr(
@@ -1369,7 +1433,7 @@ var RpcClient = class {
1369
1433
  // src/multichain/rpc/requestRouter.ts
1370
1434
  var import_analytics2 = require("@metamask/analytics");
1371
1435
  init_domain();
1372
- init_utils();
1436
+ init_utils2();
1373
1437
  init_analytics();
1374
1438
  var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
1375
1439
  var RequestRouter = class {
@@ -1537,9 +1601,9 @@ trackWalletActionRejected_fn = function(options) {
1537
1601
 
1538
1602
  // src/multichain/transports/default/index.ts
1539
1603
  var import_multichain_api_client = require("@metamask/multichain-api-client");
1540
- init_utils();
1604
+ init_utils2();
1541
1605
  var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
1542
- var _notificationCallbacks, _transport, _defaultRequestOptions, _reqId, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
1606
+ var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
1543
1607
  var DefaultTransport = class {
1544
1608
  constructor() {
1545
1609
  __privateAdd(this, _DefaultTransport_instances);
@@ -1548,8 +1612,6 @@ var DefaultTransport = class {
1548
1612
  __privateAdd(this, _defaultRequestOptions, {
1549
1613
  timeout: DEFAULT_REQUEST_TIMEOUT
1550
1614
  });
1551
- // Use timestamp-based ID to avoid conflicts across disconnect/reconnect cycles
1552
- __privateAdd(this, _reqId, Date.now());
1553
1615
  __privateAdd(this, _pendingRequests, /* @__PURE__ */ new Map());
1554
1616
  __privateAdd(this, _handleResponseListener);
1555
1617
  __privateAdd(this, _handleNotificationListener);
@@ -1557,18 +1619,17 @@ var DefaultTransport = class {
1557
1619
  sendEip1193Message(payload, options) {
1558
1620
  return __async(this, null, function* () {
1559
1621
  __privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
1560
- __privateSet(this, _reqId, __privateGet(this, _reqId) + 1);
1561
- const requestId = `${__privateGet(this, _reqId)}`;
1622
+ const requestId = String(getUniqueRequestId());
1562
1623
  const request = __spreadValues({
1563
1624
  jsonrpc: "2.0",
1564
1625
  id: requestId
1565
1626
  }, payload);
1566
1627
  return new Promise((resolve, reject) => {
1567
- var _a2;
1628
+ var _a3;
1568
1629
  const timeout = setTimeout(() => {
1569
1630
  __privateGet(this, _pendingRequests).delete(requestId);
1570
1631
  reject(new Error("Request timeout"));
1571
- }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : __privateGet(this, _defaultRequestOptions).timeout);
1632
+ }, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : __privateGet(this, _defaultRequestOptions).timeout);
1572
1633
  __privateGet(this, _pendingRequests).set(requestId, {
1573
1634
  resolve: (response) => {
1574
1635
  resolve(response);
@@ -1592,7 +1653,7 @@ var DefaultTransport = class {
1592
1653
  }
1593
1654
  connect(options) {
1594
1655
  return __async(this, null, function* () {
1595
- var _a2, _b, _c, _d, _e;
1656
+ var _a3, _b, _c, _d, _e;
1596
1657
  __privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
1597
1658
  yield __privateGet(this, _transport).connect();
1598
1659
  const sessionRequest = yield this.request(
@@ -1605,7 +1666,7 @@ var DefaultTransport = class {
1605
1666
  let walletSession = sessionRequest.result;
1606
1667
  const createSessionParams = {
1607
1668
  optionalScopes: addValidAccounts(
1608
- getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
1669
+ getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
1609
1670
  getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
1610
1671
  ),
1611
1672
  sessionProperties: options == null ? void 0 : options.sessionProperties
@@ -1623,10 +1684,6 @@ var DefaultTransport = class {
1623
1684
  proposedCaipAccountIds
1624
1685
  );
1625
1686
  if (!hasSameScopesAndAccounts) {
1626
- yield this.request(
1627
- { method: "wallet_revokeSession", params: walletSession },
1628
- __privateGet(this, _defaultRequestOptions)
1629
- );
1630
1687
  const response = yield this.request(
1631
1688
  { method: "wallet_createSession", params: createSessionParams },
1632
1689
  __privateGet(this, _defaultRequestOptions)
@@ -1653,9 +1710,14 @@ var DefaultTransport = class {
1653
1710
  });
1654
1711
  }
1655
1712
  disconnect() {
1656
- return __async(this, null, function* () {
1713
+ return __async(this, arguments, function* (scopes = []) {
1714
+ yield this.request({ method: "wallet_revokeSession", params: { scopes } });
1715
+ const response = yield this.request({ method: "wallet_getSession" });
1716
+ const { sessionScopes } = response.result;
1717
+ if (Object.keys(sessionScopes).length > 0) {
1718
+ return;
1719
+ }
1657
1720
  __privateGet(this, _notificationCallbacks).clear();
1658
- yield this.request({ method: "wallet_revokeSession", params: {} });
1659
1721
  if (__privateGet(this, _handleResponseListener)) {
1660
1722
  window.removeEventListener("message", __privateGet(this, _handleResponseListener));
1661
1723
  __privateSet(this, _handleResponseListener, void 0);
@@ -1669,7 +1731,7 @@ var DefaultTransport = class {
1669
1731
  request.reject(new Error("Transport disconnected"));
1670
1732
  }
1671
1733
  __privateGet(this, _pendingRequests).clear();
1672
- return __privateGet(this, _transport).disconnect();
1734
+ yield __privateGet(this, _transport).disconnect();
1673
1735
  });
1674
1736
  }
1675
1737
  isConnected() {
@@ -1694,11 +1756,17 @@ var DefaultTransport = class {
1694
1756
  );
1695
1757
  });
1696
1758
  }
1759
+ getStoredPendingSessionRequest() {
1760
+ return __async(this, null, function* () {
1761
+ throw new Error(
1762
+ "getStoredPendingSessionRequest is purposely not implemented for the DefaultTransport"
1763
+ );
1764
+ });
1765
+ }
1697
1766
  };
1698
1767
  _notificationCallbacks = new WeakMap();
1699
1768
  _transport = new WeakMap();
1700
1769
  _defaultRequestOptions = new WeakMap();
1701
- _reqId = new WeakMap();
1702
1770
  _pendingRequests = new WeakMap();
1703
1771
  _handleResponseListener = new WeakMap();
1704
1772
  _handleNotificationListener = new WeakMap();
@@ -1716,16 +1784,16 @@ notifyCallbacks_fn = function(data) {
1716
1784
  }
1717
1785
  };
1718
1786
  isMetamaskProviderEvent_fn = function(event) {
1719
- var _a2, _b;
1720
- return ((_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
1787
+ var _a3, _b;
1788
+ return ((_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
1721
1789
  event.origin === location.origin;
1722
1790
  };
1723
1791
  handleResponse_fn = function(event) {
1724
- var _a2, _b;
1792
+ var _a3, _b;
1725
1793
  if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
1726
1794
  return;
1727
1795
  }
1728
- const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
1796
+ const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
1729
1797
  if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
1730
1798
  return;
1731
1799
  }
@@ -1747,11 +1815,11 @@ handleResponse_fn = function(event) {
1747
1815
  }
1748
1816
  };
1749
1817
  handleNotification_fn = function(event) {
1750
- var _a2, _b;
1818
+ var _a3, _b;
1751
1819
  if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
1752
1820
  return;
1753
1821
  }
1754
- const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
1822
+ const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
1755
1823
  if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
1756
1824
  __privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
1757
1825
  }
@@ -1768,18 +1836,12 @@ setupMessageListener_fn = function() {
1768
1836
 
1769
1837
  // src/multichain/transports/multichainApiClientWrapper/index.ts
1770
1838
  var import_rpc_errors = require("@metamask/rpc-errors");
1771
- var MAX = 4294967295;
1772
- var idCounter = Math.floor(Math.random() * MAX);
1773
- var getUniqueId = () => {
1774
- idCounter = (idCounter + 1) % MAX;
1775
- return idCounter;
1776
- };
1777
- var _requestId, _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
1839
+ init_utils2();
1840
+ var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
1778
1841
  var MultichainApiClientWrapperTransport = class {
1779
1842
  constructor(metamaskConnectMultichain) {
1780
1843
  this.metamaskConnectMultichain = metamaskConnectMultichain;
1781
1844
  __privateAdd(this, _MultichainApiClientWrapperTransport_instances);
1782
- __privateAdd(this, _requestId, getUniqueId());
1783
1845
  __privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
1784
1846
  }
1785
1847
  isTransportDefined() {
@@ -1797,15 +1859,23 @@ var MultichainApiClientWrapperTransport = class {
1797
1859
  callback(data);
1798
1860
  });
1799
1861
  }
1800
- setupNotifcationListener() {
1801
- this.metamaskConnectMultichain.transport.onNotification(
1862
+ clearTransportNotificationListener() {
1863
+ var _a3;
1864
+ (_a3 = this.notificationListener) == null ? void 0 : _a3.call(this);
1865
+ this.notificationListener = void 0;
1866
+ }
1867
+ setupTransportNotificationListener() {
1868
+ if (!this.isTransportDefined() || this.notificationListener) {
1869
+ return;
1870
+ }
1871
+ this.notificationListener = this.metamaskConnectMultichain.transport.onNotification(
1802
1872
  this.notifyCallbacks.bind(this)
1803
1873
  );
1804
1874
  }
1805
1875
  connect() {
1806
1876
  return __async(this, null, function* () {
1807
1877
  console.log("\u{1F4DA} connect");
1808
- return Promise.resolve();
1878
+ yield this.metamaskConnectMultichain.emitSessionChanged();
1809
1879
  });
1810
1880
  }
1811
1881
  disconnect() {
@@ -1818,7 +1888,7 @@ var MultichainApiClientWrapperTransport = class {
1818
1888
  }
1819
1889
  request(_0) {
1820
1890
  return __async(this, arguments, function* (params, _options = {}) {
1821
- const id = __privateWrapper(this, _requestId)._++;
1891
+ const id = getUniqueRequestId();
1822
1892
  const requestPayload = __spreadValues({
1823
1893
  id,
1824
1894
  jsonrpc: "2.0"
@@ -1839,16 +1909,13 @@ var MultichainApiClientWrapperTransport = class {
1839
1909
  });
1840
1910
  }
1841
1911
  onNotification(callback) {
1842
- if (!this.isTransportDefined()) {
1843
- __privateGet(this, _notificationCallbacks2).add(callback);
1844
- return () => {
1845
- __privateGet(this, _notificationCallbacks2).delete(callback);
1846
- };
1847
- }
1848
- return this.metamaskConnectMultichain.transport.onNotification(callback);
1912
+ this.setupTransportNotificationListener();
1913
+ __privateGet(this, _notificationCallbacks2).add(callback);
1914
+ return () => {
1915
+ __privateGet(this, _notificationCallbacks2).delete(callback);
1916
+ };
1849
1917
  }
1850
1918
  };
1851
- _requestId = new WeakMap();
1852
1919
  _notificationCallbacks2 = new WeakMap();
1853
1920
  _MultichainApiClientWrapperTransport_instances = new WeakSet();
1854
1921
  walletCreateSession_fn = function(request) {
@@ -1858,8 +1925,8 @@ walletCreateSession_fn = function(request) {
1858
1925
  const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
1859
1926
  const scopeAccounts = [];
1860
1927
  scopes.forEach((scope) => {
1861
- var _a2, _b, _c, _d;
1862
- const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
1928
+ var _a3, _b, _c, _d;
1929
+ const requiredScope = (_a3 = createSessionParams.requiredScopes) == null ? void 0 : _a3[scope];
1863
1930
  const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
1864
1931
  if (requiredScope) {
1865
1932
  scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
@@ -1899,11 +1966,14 @@ walletGetSession_fn = function(request) {
1899
1966
  };
1900
1967
  walletRevokeSession_fn = function(request) {
1901
1968
  return __async(this, null, function* () {
1969
+ var _a3;
1902
1970
  if (!this.isTransportDefined()) {
1903
1971
  return { jsonrpc: "2.0", id: request.id, result: true };
1904
1972
  }
1973
+ const revokeSessionParams = request.params;
1974
+ const scopes = (_a3 = revokeSessionParams == null ? void 0 : revokeSessionParams.scopes) != null ? _a3 : [];
1905
1975
  try {
1906
- this.metamaskConnectMultichain.disconnect();
1976
+ yield this.metamaskConnectMultichain.disconnect(scopes);
1907
1977
  return { jsonrpc: "2.0", id: request.id, result: true };
1908
1978
  } catch (_error) {
1909
1979
  return { jsonrpc: "2.0", id: request.id, result: false };
@@ -1927,8 +1997,9 @@ walletInvokeMethod_fn = function(request) {
1927
1997
  // src/multichain/transports/mwp/index.ts
1928
1998
  var import_mobile_wallet_protocol_core = require("@metamask/mobile-wallet-protocol-core");
1929
1999
  var import_multichain_api_client2 = require("@metamask/multichain-api-client");
2000
+ var import_rpc_errors2 = require("@metamask/rpc-errors");
1930
2001
  init_domain();
1931
- init_utils();
2002
+ init_utils2();
1932
2003
 
1933
2004
  // src/multichain/transports/constants.ts
1934
2005
  var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
@@ -1941,6 +2012,7 @@ var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
1941
2012
  var SESSION_STORE_KEY = "cache_wallet_getSession";
1942
2013
  var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
1943
2014
  var CHAIN_STORE_KEY = "cache_eth_chainId";
2015
+ var PENDING_SESSION_REQUEST_KEY = "pending_session_request";
1944
2016
  var CACHED_METHOD_LIST = [
1945
2017
  "wallet_getSession",
1946
2018
  "wallet_createSession",
@@ -1960,10 +2032,15 @@ var MWPTransport = class {
1960
2032
  this.dappClient = dappClient;
1961
2033
  this.kvstore = kvstore;
1962
2034
  this.options = options;
1963
- this.__reqId = 0;
1964
2035
  this.__pendingRequests = /* @__PURE__ */ new Map();
1965
2036
  this.notificationCallbacks = /* @__PURE__ */ new Set();
1966
2037
  this.dappClient.on("message", this.handleMessage.bind(this));
2038
+ this.dappClient.on("session_request", (sessionRequest) => {
2039
+ this.currentSessionRequest = sessionRequest;
2040
+ this.kvstore.set(PENDING_SESSION_REQUEST_KEY, JSON.stringify(sessionRequest)).catch((err) => {
2041
+ logger("Failed to store pending session request", err);
2042
+ });
2043
+ });
1967
2044
  if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
1968
2045
  this.windowFocusHandler = this.onWindowFocus.bind(this);
1969
2046
  window.addEventListener("focus", this.windowFocusHandler);
@@ -1978,6 +2055,34 @@ var MWPTransport = class {
1978
2055
  get sessionRequest() {
1979
2056
  return this.currentSessionRequest;
1980
2057
  }
2058
+ /**
2059
+ * Returns the stored pending session request from the dappClient session_request event, if any.
2060
+ *
2061
+ * @returns The stored SessionRequest, or null if none or invalid.
2062
+ */
2063
+ getStoredPendingSessionRequest() {
2064
+ return __async(this, null, function* () {
2065
+ try {
2066
+ const raw = yield this.kvstore.get(PENDING_SESSION_REQUEST_KEY);
2067
+ if (!raw) {
2068
+ return null;
2069
+ }
2070
+ return JSON.parse(raw);
2071
+ } catch (e) {
2072
+ return null;
2073
+ }
2074
+ });
2075
+ }
2076
+ /**
2077
+ * Removes the stored pending session request from the KVStore.
2078
+ * This is necessary to ensure that ConnectMultichain is able to correctly
2079
+ * infer the MWP Transport connection attempt status.
2080
+ */
2081
+ removeStoredPendingSessionRequest() {
2082
+ return __async(this, null, function* () {
2083
+ yield this.kvstore.delete(PENDING_SESSION_REQUEST_KEY);
2084
+ });
2085
+ }
1981
2086
  onWindowFocus() {
1982
2087
  if (!this.isConnected()) {
1983
2088
  this.dappClient.reconnect();
@@ -1994,6 +2099,17 @@ var MWPTransport = class {
1994
2099
  request.reject(error);
1995
2100
  }
1996
2101
  }
2102
+ parseWalletError(errorPayload) {
2103
+ const errorData = errorPayload;
2104
+ if (typeof errorData.code === "number" && typeof errorData.message === "string") {
2105
+ return import_rpc_errors2.providerErrors.custom({
2106
+ code: errorData.code,
2107
+ message: errorData.message
2108
+ });
2109
+ }
2110
+ const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
2111
+ return import_rpc_errors2.rpcErrors.internal({ message });
2112
+ }
1997
2113
  handleMessage(message) {
1998
2114
  if (typeof message === "object" && message !== null) {
1999
2115
  if ("data" in message) {
@@ -2001,6 +2117,12 @@ var MWPTransport = class {
2001
2117
  if ("id" in messagePayload && typeof messagePayload.id === "string") {
2002
2118
  const request = this.pendingRequests.get(messagePayload.id);
2003
2119
  if (request) {
2120
+ clearTimeout(request.timeout);
2121
+ if ("error" in messagePayload && messagePayload.error) {
2122
+ this.pendingRequests.delete(messagePayload.id);
2123
+ request.reject(this.parseWalletError(messagePayload.error));
2124
+ return;
2125
+ }
2004
2126
  const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
2005
2127
  method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method
2006
2128
  });
@@ -2008,7 +2130,6 @@ var MWPTransport = class {
2008
2130
  method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method,
2009
2131
  params: requestWithName.result
2010
2132
  });
2011
- clearTimeout(request.timeout);
2012
2133
  this.notifyCallbacks(notification);
2013
2134
  request.resolve(requestWithName);
2014
2135
  this.pendingRequests.delete(messagePayload.id);
@@ -2044,7 +2165,7 @@ var MWPTransport = class {
2044
2165
  }
2045
2166
  onResumeSuccess(resumeResolve, resumeReject, options) {
2046
2167
  return __async(this, null, function* () {
2047
- var _a2, _b, _c, _d, _e, _f, _g;
2168
+ var _a3, _b, _c, _d, _e, _f, _g;
2048
2169
  try {
2049
2170
  yield this.waitForWalletSessionIfNotCached();
2050
2171
  const sessionRequest = yield this.request({
@@ -2056,7 +2177,7 @@ var MWPTransport = class {
2056
2177
  let walletSession = sessionRequest.result;
2057
2178
  if (walletSession && options) {
2058
2179
  const currentScopes = Object.keys(
2059
- (_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
2180
+ (_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
2060
2181
  );
2061
2182
  const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
2062
2183
  const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
@@ -2098,6 +2219,7 @@ var MWPTransport = class {
2098
2219
  }
2099
2220
  walletSession = response.result;
2100
2221
  }
2222
+ yield this.removeStoredPendingSessionRequest();
2101
2223
  this.notifyCallbacks({
2102
2224
  method: "wallet_sessionChanged",
2103
2225
  params: walletSession
@@ -2113,7 +2235,7 @@ var MWPTransport = class {
2113
2235
  return __async(this, null, function* () {
2114
2236
  const request = __spreadValues({
2115
2237
  jsonrpc: "2.0",
2116
- id: `${this.__reqId++}`
2238
+ id: String(getUniqueRequestId())
2117
2239
  }, payload);
2118
2240
  const cachedWalletSession = yield this.getCachedResponse(request);
2119
2241
  if (cachedWalletSession) {
@@ -2121,10 +2243,10 @@ var MWPTransport = class {
2121
2243
  return cachedWalletSession;
2122
2244
  }
2123
2245
  return new Promise((resolve, reject) => {
2124
- var _a2;
2246
+ var _a3;
2125
2247
  const timeout = setTimeout(() => {
2126
2248
  this.rejectRequest(request.id, new import_multichain_api_client2.TransportTimeoutError());
2127
- }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
2249
+ }, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : this.options.requestTimeout);
2128
2250
  this.pendingRequests.set(request.id, {
2129
2251
  request,
2130
2252
  method: request.method,
@@ -2149,28 +2271,29 @@ var MWPTransport = class {
2149
2271
  if (session) {
2150
2272
  logger("active session found", session);
2151
2273
  }
2274
+ const storedSessionRequestBeforeConnectionAttempt = yield this.getStoredPendingSessionRequest();
2152
2275
  let timeout;
2153
2276
  let initialConnectionMessageHandler;
2154
2277
  const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
2155
2278
  let connection;
2156
2279
  if (session) {
2157
2280
  connection = new Promise((resumeResolve, resumeReject) => {
2158
- var _a2;
2281
+ var _a3;
2159
2282
  if (this.dappClient.state === "CONNECTED") {
2160
2283
  this.onResumeSuccess(resumeResolve, resumeReject, options);
2161
2284
  } else {
2162
2285
  this.dappClient.once("connected", () => __async(this, null, function* () {
2163
2286
  this.onResumeSuccess(resumeResolve, resumeReject, options);
2164
2287
  }));
2165
- dappClient.resume((_a2 = session == null ? void 0 : session.id) != null ? _a2 : "");
2288
+ dappClient.resume((_a3 = session == null ? void 0 : session.id) != null ? _a3 : "");
2166
2289
  }
2167
2290
  });
2168
2291
  } else {
2169
2292
  connection = new Promise(
2170
2293
  (resolveConnection, rejectConnection) => {
2171
- var _a2, _b;
2294
+ var _a3, _b;
2172
2295
  const optionalScopes = addValidAccounts(
2173
- getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
2296
+ getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
2174
2297
  getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
2175
2298
  );
2176
2299
  const sessionRequest = {
@@ -2179,33 +2302,35 @@ var MWPTransport = class {
2179
2302
  };
2180
2303
  const request = {
2181
2304
  jsonrpc: "2.0",
2182
- id: `${this.__reqId++}`,
2305
+ id: String(getUniqueRequestId()),
2183
2306
  method: "wallet_createSession",
2184
2307
  params: sessionRequest
2185
2308
  };
2186
2309
  initialConnectionMessageHandler = (message) => __async(this, null, function* () {
2187
- if (typeof message === "object" && message !== null) {
2188
- if ("data" in message) {
2189
- const messagePayload = message.data;
2190
- if (messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged") {
2191
- if (messagePayload.error) {
2192
- if (initialConnectionMessageHandler) {
2193
- this.dappClient.off(
2194
- "message",
2195
- initialConnectionMessageHandler
2196
- );
2197
- }
2198
- return rejectConnection(messagePayload.error);
2199
- }
2200
- yield this.storeWalletSession(
2201
- request,
2202
- messagePayload
2203
- );
2204
- this.notifyCallbacks(messagePayload);
2205
- return resolveConnection();
2206
- }
2207
- }
2310
+ if (typeof message !== "object" || message === null) {
2311
+ return;
2312
+ }
2313
+ if (!("data" in message)) {
2314
+ return;
2208
2315
  }
2316
+ const messagePayload = message.data;
2317
+ const isMatchingId = messagePayload.id === request.id;
2318
+ const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
2319
+ if (!isMatchingId && !isMatchingMethod) {
2320
+ return;
2321
+ }
2322
+ if (messagePayload.error) {
2323
+ return rejectConnection(
2324
+ this.parseWalletError(messagePayload.error)
2325
+ );
2326
+ }
2327
+ yield this.storeWalletSession(
2328
+ request,
2329
+ messagePayload
2330
+ );
2331
+ yield this.removeStoredPendingSessionRequest();
2332
+ this.notifyCallbacks(messagePayload);
2333
+ return resolveConnection();
2209
2334
  });
2210
2335
  this.dappClient.on("message", initialConnectionMessageHandler);
2211
2336
  dappClient.connect({
@@ -2226,14 +2351,18 @@ var MWPTransport = class {
2226
2351
  }
2227
2352
  );
2228
2353
  }
2229
- timeout = setTimeout(() => {
2230
- reject(new import_multichain_api_client2.TransportTimeoutError());
2231
- }, this.options.connectionTimeout);
2354
+ timeout = setTimeout(
2355
+ () => {
2356
+ reject(new import_multichain_api_client2.TransportTimeoutError());
2357
+ },
2358
+ storedSessionRequestBeforeConnectionAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
2359
+ );
2232
2360
  connection.then(resolve).catch(reject);
2233
2361
  }));
2234
- return connectionPromise.catch((error) => {
2362
+ return connectionPromise.catch((error) => __async(this, null, function* () {
2363
+ yield this.dappClient.disconnect();
2235
2364
  throw error;
2236
- }).finally(() => {
2365
+ })).finally(() => {
2237
2366
  if (timeout) {
2238
2367
  clearTimeout(timeout);
2239
2368
  }
@@ -2241,24 +2370,68 @@ var MWPTransport = class {
2241
2370
  this.dappClient.off("message", initialConnectionMessageHandler);
2242
2371
  initialConnectionMessageHandler = void 0;
2243
2372
  }
2373
+ this.removeStoredPendingSessionRequest();
2244
2374
  });
2245
2375
  });
2246
2376
  }
2247
2377
  /**
2248
2378
  * Disconnects from the Mobile Wallet Protocol
2249
2379
  *
2380
+ * @param [scopes] - The scopes to revoke. If not provided or empty, all scopes will be revoked.
2250
2381
  * @returns Nothing
2251
2382
  */
2252
2383
  disconnect() {
2253
- return __async(this, null, function* () {
2254
- if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && this.windowFocusHandler) {
2255
- window.removeEventListener("focus", this.windowFocusHandler);
2256
- this.windowFocusHandler = void 0;
2257
- }
2258
- this.kvstore.delete(SESSION_STORE_KEY);
2259
- this.kvstore.delete(ACCOUNTS_STORE_KEY);
2260
- this.kvstore.delete(CHAIN_STORE_KEY);
2261
- return this.dappClient.disconnect();
2384
+ return __async(this, arguments, function* (scopes = []) {
2385
+ var _a3, _b;
2386
+ const cachedSession = yield this.getCachedResponse({
2387
+ jsonrpc: "2.0",
2388
+ id: "0",
2389
+ method: "wallet_getSession"
2390
+ });
2391
+ const cachedSessionScopes = (_b = (_a3 = cachedSession == null ? void 0 : cachedSession.result) == null ? void 0 : _a3.sessionScopes) != null ? _b : {};
2392
+ const remainingScopes = scopes.length === 0 ? [] : Object.keys(cachedSessionScopes).filter(
2393
+ (scope) => !scopes.includes(scope)
2394
+ );
2395
+ const newSessionScopes = Object.fromEntries(
2396
+ Object.entries(cachedSessionScopes).filter(
2397
+ ([key]) => remainingScopes.includes(key)
2398
+ )
2399
+ );
2400
+ this.request({ method: "wallet_revokeSession", params: { scopes } }).catch(
2401
+ (err) => {
2402
+ console.error("error revoking session", err);
2403
+ }
2404
+ );
2405
+ const remainingScopesIncludeEip155 = remainingScopes.some(
2406
+ (scope) => scope.includes("eip155")
2407
+ );
2408
+ if (!remainingScopesIncludeEip155) {
2409
+ this.kvstore.delete(ACCOUNTS_STORE_KEY);
2410
+ this.kvstore.delete(CHAIN_STORE_KEY);
2411
+ }
2412
+ if (remainingScopes.length > 0) {
2413
+ this.kvstore.set(
2414
+ SESSION_STORE_KEY,
2415
+ JSON.stringify({
2416
+ result: {
2417
+ sessionScopes: newSessionScopes
2418
+ }
2419
+ })
2420
+ );
2421
+ } else {
2422
+ this.kvstore.delete(SESSION_STORE_KEY);
2423
+ if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && this.windowFocusHandler) {
2424
+ window.removeEventListener("focus", this.windowFocusHandler);
2425
+ this.windowFocusHandler = void 0;
2426
+ }
2427
+ yield this.dappClient.disconnect();
2428
+ }
2429
+ this.notifyCallbacks({
2430
+ method: "wallet_sessionChanged",
2431
+ params: {
2432
+ sessionScopes: newSessionScopes
2433
+ }
2434
+ });
2262
2435
  });
2263
2436
  }
2264
2437
  /**
@@ -2303,7 +2476,7 @@ var MWPTransport = class {
2303
2476
  }
2304
2477
  getCachedResponse(request) {
2305
2478
  return __async(this, null, function* () {
2306
- var _a2;
2479
+ var _a3;
2307
2480
  if (request.method === "wallet_getSession") {
2308
2481
  const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
2309
2482
  if (walletGetSession) {
@@ -2311,7 +2484,7 @@ var MWPTransport = class {
2311
2484
  return {
2312
2485
  id: request.id,
2313
2486
  jsonrpc: "2.0",
2314
- result: (_a2 = walletSession.params) != null ? _a2 : walletSession.result,
2487
+ result: (_a3 = walletSession.params) != null ? _a3 : walletSession.result,
2315
2488
  // "what?... why walletSession.params?.."
2316
2489
  method: request.method
2317
2490
  };
@@ -2364,7 +2537,7 @@ var MWPTransport = class {
2364
2537
  return __async(this, null, function* () {
2365
2538
  const request = __spreadValues({
2366
2539
  jsonrpc: "2.0",
2367
- id: `${this.__reqId++}`
2540
+ id: String(getUniqueRequestId())
2368
2541
  }, payload);
2369
2542
  const cachedWalletSession = yield this.getCachedResponse(request);
2370
2543
  if (cachedWalletSession) {
@@ -2375,10 +2548,10 @@ var MWPTransport = class {
2375
2548
  yield this.attemptResumeSession();
2376
2549
  }
2377
2550
  return new Promise((resolve, reject) => {
2378
- var _a2;
2551
+ var _a3;
2379
2552
  const timeout = setTimeout(() => {
2380
2553
  this.rejectRequest(request.id, new import_multichain_api_client2.TransportTimeoutError());
2381
- }, (_a2 = options == null ? void 0 : options.timeout) != null ? _a2 : this.options.requestTimeout);
2554
+ }, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : this.options.requestTimeout);
2382
2555
  this.pendingRequests.set(request.id, {
2383
2556
  request,
2384
2557
  method: request.method,
@@ -2446,6 +2619,7 @@ var MWPTransport = class {
2446
2619
  const timeoutPromise = new Promise((_resolve, reject) => {
2447
2620
  setTimeout(() => {
2448
2621
  unsubscribe();
2622
+ this.removeStoredPendingSessionRequest();
2449
2623
  reject(new import_multichain_api_client2.TransportTimeoutError());
2450
2624
  }, this.options.resumeTimeout);
2451
2625
  });
@@ -2482,14 +2656,15 @@ var KeyManager = class {
2482
2656
  var keymanager = new KeyManager();
2483
2657
 
2484
2658
  // src/multichain/index.ts
2485
- init_utils();
2659
+ init_utils2();
2486
2660
  var logger2 = createLogger("metamask-sdk:core");
2487
- var _a, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
2661
+ var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
2662
+ var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
2488
2663
  var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
2489
2664
  constructor(options) {
2490
- var _a2, _b, _c, _d, _e, _f;
2665
+ var _a3, _b, _c, _d, _e, _f;
2491
2666
  const withDappMetadata = setupDappMetadata(options);
2492
- const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
2667
+ const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "direct";
2493
2668
  const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
2494
2669
  ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
2495
2670
  preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
@@ -2509,7 +2684,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2509
2684
  __privateAdd(this, _beforeUnloadListener);
2510
2685
  this._status = "pending";
2511
2686
  __privateAdd(this, _listener);
2512
- __privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
2687
+ __privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a2 = this.options.dapp.url) != null ? _a2 : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
2513
2688
  __privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
2514
2689
  this
2515
2690
  ));
@@ -2521,9 +2696,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2521
2696
  return this._status;
2522
2697
  }
2523
2698
  set status(value) {
2524
- var _a2, _b;
2699
+ var _a3, _b;
2525
2700
  this._status = value;
2526
- (_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
2701
+ (_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, {
2527
2702
  method: "stateChanged",
2528
2703
  params: value
2529
2704
  });
@@ -2549,27 +2724,54 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2549
2724
  get transportType() {
2550
2725
  return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
2551
2726
  }
2727
+ // Creates a singleton instance of MetaMaskConnectMultichain.
2728
+ // If the singleton already exists, it merges the incoming options with the
2729
+ // existing singleton options for the following keys: `api.supportedNetworks`,
2730
+ // `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note that the
2731
+ // value for `dapp` is not merged as it does not make sense for subsequent calls to
2732
+ // `createMultichainClient` to have a different `dapp` value.
2552
2733
  static create(options) {
2553
2734
  return __async(this, null, function* () {
2554
- var _a2;
2555
- const instance = new _MetaMaskConnectMultichain(options);
2556
- const isEnabled2 = yield isEnabled(
2557
- "metamask-sdk:core",
2558
- instance.options.storage
2559
- );
2560
- if (isEnabled2) {
2561
- enableDebug("metamask-sdk:core");
2562
- }
2563
- yield __privateMethod(_a2 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a2);
2564
- return instance;
2735
+ const globalObject = getGlobalObject();
2736
+ const existing = globalObject[SINGLETON_KEY];
2737
+ if (existing) {
2738
+ const instance = yield existing;
2739
+ instance.mergeOptions(options);
2740
+ if (options.debug) {
2741
+ enableDebug("metamask-sdk:*");
2742
+ }
2743
+ return instance;
2744
+ }
2745
+ const instancePromise = (() => __async(null, null, function* () {
2746
+ var _a3;
2747
+ const instance = new _MetaMaskConnectMultichain(options);
2748
+ const isEnabled2 = yield isEnabled(
2749
+ "metamask-sdk:core",
2750
+ instance.options.storage
2751
+ );
2752
+ if (isEnabled2) {
2753
+ enableDebug("metamask-sdk:core");
2754
+ }
2755
+ yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a3);
2756
+ return instance;
2757
+ }))();
2758
+ globalObject[SINGLETON_KEY] = instancePromise;
2759
+ instancePromise.catch((error) => {
2760
+ globalObject[SINGLETON_KEY] = void 0;
2761
+ console.error("Error initializing MetaMaskConnectMultichain", error);
2762
+ });
2763
+ return instancePromise;
2565
2764
  });
2566
2765
  }
2567
2766
  // TODO: make this into param object
2568
2767
  connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
2569
2768
  return __async(this, null, function* () {
2570
- var _a2;
2571
- if (this.status !== "connected") {
2572
- yield this.disconnect();
2769
+ var _a3;
2770
+ if (this.status === "connecting" && this.transportType === "mwp" /* MWP */) {
2771
+ yield __privateMethod(this, _MetaMaskConnectMultichain_instances, openConnectDeeplinkIfNeeded_fn).call(this);
2772
+ throw new Error(
2773
+ "Existing connection is pending. Please check your MetaMask Mobile app to continue."
2774
+ );
2573
2775
  }
2574
2776
  const { ui } = this.options;
2575
2777
  const platformType = getPlatformType();
@@ -2599,12 +2801,19 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2599
2801
  } catch (error) {
2600
2802
  logger2("Error tracking connection_initiated event", error);
2601
2803
  }
2602
- const nonEmptySessionProperites = Object.keys(sessionProperties != null ? sessionProperties : {}).length > 0 ? sessionProperties : void 0;
2603
- if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
2804
+ const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
2805
+ const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
2806
+ sessionData,
2807
+ scopes,
2808
+ caipAccountIds,
2809
+ sessionProperties
2810
+ );
2811
+ const nonEmptySessionProperties = Object.keys(mergedSessionProperties != null ? mergedSessionProperties : {}).length > 0 ? mergedSessionProperties : void 0;
2812
+ if (((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) && !secure) {
2604
2813
  return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({
2605
- scopes,
2606
- caipAccountIds,
2607
- sessionProperties: nonEmptySessionProperites,
2814
+ scopes: mergedScopes,
2815
+ caipAccountIds: mergedCaipAccountIds,
2816
+ sessionProperties: nonEmptySessionProperties,
2608
2817
  forceRequest
2609
2818
  }).then(() => __async(this, null, function* () {
2610
2819
  if (__privateGet(this, _transport2) instanceof MWPTransport) {
@@ -2616,47 +2825,53 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2616
2825
  if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
2617
2826
  const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
2618
2827
  return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
2619
- scopes,
2620
- caipAccountIds,
2621
- sessionProperties: nonEmptySessionProperites,
2828
+ scopes: mergedScopes,
2829
+ caipAccountIds: mergedCaipAccountIds,
2830
+ sessionProperties: nonEmptySessionProperties,
2622
2831
  forceRequest
2623
2832
  }), scopes, transportType);
2624
2833
  }
2625
2834
  if (isWeb && hasExtensionInstalled && preferExtension) {
2626
2835
  const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
2627
2836
  return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
2628
- scopes,
2629
- caipAccountIds,
2630
- sessionProperties: nonEmptySessionProperites,
2837
+ scopes: mergedScopes,
2838
+ caipAccountIds: mergedCaipAccountIds,
2839
+ sessionProperties: nonEmptySessionProperties,
2631
2840
  forceRequest
2632
2841
  }), scopes, transportType);
2633
2842
  }
2634
2843
  yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
2635
2844
  const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
2636
2845
  if (secure && !shouldShowInstallModal) {
2637
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, nonEmptySessionProperites), scopes, transportType);
2846
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
2638
2847
  }
2639
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, nonEmptySessionProperites), scopes, transportType);
2848
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
2640
2849
  });
2641
2850
  }
2642
2851
  emit(event, args) {
2643
- var _a2, _b;
2644
- (_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, { method: event, params: args });
2852
+ var _a3, _b;
2853
+ (_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, { method: event, params: args });
2645
2854
  super.emit(event, args);
2646
2855
  }
2647
2856
  disconnect() {
2648
- return __async(this, null, function* () {
2649
- var _a2, _b, _c;
2650
- yield (_a2 = __privateGet(this, _listener)) == null ? void 0 : _a2.call(this);
2651
- (_b = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _b.call(this);
2652
- yield (_c = __privateGet(this, _transport2)) == null ? void 0 : _c.disconnect();
2653
- yield this.storage.removeTransport();
2654
- this.emit("stateChanged", "disconnected");
2655
- __privateSet(this, _listener, void 0);
2656
- __privateSet(this, _beforeUnloadListener, void 0);
2657
- __privateSet(this, _transport2, void 0);
2658
- __privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
2659
- __privateSet(this, _dappClient, void 0);
2857
+ return __async(this, arguments, function* (scopes = []) {
2858
+ var _a3, _b, _c;
2859
+ const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
2860
+ const remainingScopes = scopes.length === 0 ? [] : Object.keys(sessionData.sessionScopes).filter(
2861
+ (scope) => !scopes.includes(scope)
2862
+ );
2863
+ yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
2864
+ if (remainingScopes.length === 0) {
2865
+ yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
2866
+ (_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
2867
+ yield this.storage.removeTransport();
2868
+ __privateSet(this, _listener, void 0);
2869
+ __privateSet(this, _beforeUnloadListener, void 0);
2870
+ __privateSet(this, _transport2, void 0);
2871
+ __privateGet(this, _providerTransportWrapper).clearTransportNotificationListener();
2872
+ __privateSet(this, _dappClient, void 0);
2873
+ this.status = "disconnected";
2874
+ }
2660
2875
  });
2661
2876
  }
2662
2877
  invokeMethod(request) {
@@ -2668,7 +2883,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2668
2883
  });
2669
2884
  }
2670
2885
  // DRY THIS WITH REQUEST ROUTER
2671
- openDeeplinkIfNeeded() {
2886
+ openSimpleDeeplinkIfNeeded() {
2672
2887
  const { ui, mobile } = this.options;
2673
2888
  const { showInstallModal = false } = ui != null ? ui : {};
2674
2889
  const secure = isSecure();
@@ -2688,6 +2903,23 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2688
2903
  }), 10);
2689
2904
  }
2690
2905
  }
2906
+ // Provides a way for ecosystem clients (EVM, Solana, etc.) to get the current CAIP session data
2907
+ // when instantiating themselves (as they would have already missed any initial sessionChanged events emitted by ConnectMultichain)
2908
+ // without having to concern themselves with the current transport connection status.
2909
+ emitSessionChanged() {
2910
+ return __async(this, null, function* () {
2911
+ var _a3;
2912
+ const emptySession = { sessionScopes: {} };
2913
+ if (this.status !== "connected" && this.status !== "connecting") {
2914
+ this.emit("wallet_sessionChanged", emptySession);
2915
+ return;
2916
+ }
2917
+ const response = yield this.transport.request({
2918
+ method: "wallet_getSession"
2919
+ });
2920
+ this.emit("wallet_sessionChanged", (_a3 = response.result) != null ? _a3 : emptySession);
2921
+ });
2922
+ }
2691
2923
  };
2692
2924
  _provider = new WeakMap();
2693
2925
  _providerTransportWrapper = new WeakMap();
@@ -2699,7 +2931,7 @@ _sdkInfo = new WeakMap();
2699
2931
  _MetaMaskConnectMultichain_instances = new WeakSet();
2700
2932
  setupAnalytics_fn = function() {
2701
2933
  return __async(this, null, function* () {
2702
- var _a2;
2934
+ var _a3;
2703
2935
  const platform = getPlatformType();
2704
2936
  const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
2705
2937
  const isReactNative2 = platform === "react-native" /* ReactNative */;
@@ -2709,7 +2941,7 @@ setupAnalytics_fn = function() {
2709
2941
  const version = getVersion();
2710
2942
  const dappId = getDappId(this.options.dapp);
2711
2943
  const anonId = yield this.storage.getAnonId();
2712
- const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
2944
+ const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
2713
2945
  integrationType: ""
2714
2946
  };
2715
2947
  import_analytics4.analytics.setGlobalProperty("mmconnect_version", version);
@@ -2722,9 +2954,9 @@ setupAnalytics_fn = function() {
2722
2954
  };
2723
2955
  onTransportNotification_fn = function(payload) {
2724
2956
  return __async(this, null, function* () {
2725
- var _a2;
2957
+ var _a3;
2726
2958
  if (typeof payload === "object" && payload !== null && "method" in payload) {
2727
- this.emit(payload.method, (_a2 = payload.params) != null ? _a2 : payload.result);
2959
+ this.emit(payload.method, (_a3 = payload.params) != null ? _a3 : payload.result);
2728
2960
  }
2729
2961
  });
2730
2962
  };
@@ -2737,7 +2969,7 @@ getStoredTransport_fn = function() {
2737
2969
  if (hasExtensionInstalled) {
2738
2970
  const apiTransport = new DefaultTransport();
2739
2971
  __privateSet(this, _transport2, apiTransport);
2740
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
2972
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2741
2973
  __privateSet(this, _listener, apiTransport.onNotification(
2742
2974
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2743
2975
  ));
@@ -2749,7 +2981,7 @@ getStoredTransport_fn = function() {
2749
2981
  const apiTransport = new MWPTransport(dappClient, kvstore);
2750
2982
  __privateSet(this, _dappClient, dappClient);
2751
2983
  __privateSet(this, _transport2, apiTransport);
2752
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
2984
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2753
2985
  __privateSet(this, _listener, apiTransport.onNotification(
2754
2986
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2755
2987
  ));
@@ -2781,25 +3013,17 @@ setupTransport_fn = function() {
2781
3013
  };
2782
3014
  init_fn = function() {
2783
3015
  return __async(this, null, function* () {
2784
- var _a2;
2785
3016
  try {
2786
- if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
2787
- logger2("MetaMaskSDK: init already initialized");
2788
- } else {
2789
- yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
2790
- yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
2791
- try {
2792
- const baseProps = yield getBaseAnalyticsProperties(
2793
- this.options,
2794
- this.storage
2795
- );
2796
- import_analytics4.analytics.track("mmconnect_initialized", baseProps);
2797
- } catch (error) {
2798
- logger2("Error tracking initialized event", error);
2799
- }
2800
- if (typeof window !== "undefined") {
2801
- window.mmsdk = this;
2802
- }
3017
+ yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
3018
+ yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
3019
+ try {
3020
+ const baseProps = yield getBaseAnalyticsProperties(
3021
+ this.options,
3022
+ this.storage
3023
+ );
3024
+ import_analytics4.analytics.track("mmconnect_initialized", baseProps);
3025
+ } catch (error) {
3026
+ logger2("Error tracking initialized event", error);
2803
3027
  }
2804
3028
  } catch (error) {
2805
3029
  yield this.storage.removeTransport();
@@ -2835,7 +3059,7 @@ setupMWP_fn = function() {
2835
3059
  __privateSet(this, _dappClient, dappClient);
2836
3060
  const apiTransport = new MWPTransport(dappClient, kvstore);
2837
3061
  __privateSet(this, _transport2, apiTransport);
2838
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
3062
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
2839
3063
  __privateSet(this, _listener, this.transport.onNotification(
2840
3064
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2841
3065
  ));
@@ -2844,22 +3068,20 @@ setupMWP_fn = function() {
2844
3068
  };
2845
3069
  onBeforeUnload_fn = function() {
2846
3070
  return __async(this, null, function* () {
2847
- var _a2;
2848
- if ((_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.isMounted) {
3071
+ var _a3;
3072
+ if ((_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.isMounted) {
2849
3073
  yield this.storage.removeTransport();
2850
3074
  }
2851
3075
  });
2852
3076
  };
2853
3077
  createBeforeUnloadListener_fn = function() {
3078
+ const handler = __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this);
2854
3079
  if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
2855
- window.addEventListener("beforeunload", __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this));
3080
+ window.addEventListener("beforeunload", handler);
2856
3081
  }
2857
3082
  return () => {
2858
3083
  if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
2859
- window.removeEventListener(
2860
- "beforeunload",
2861
- __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this)
2862
- );
3084
+ window.removeEventListener("beforeunload", handler);
2863
3085
  }
2864
3086
  };
2865
3087
  };
@@ -2889,7 +3111,7 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2889
3111
  }
2890
3112
  );
2891
3113
  (() => __async(this, null, function* () {
2892
- var _a2;
3114
+ var _a3;
2893
3115
  try {
2894
3116
  yield this.transport.connect({
2895
3117
  scopes,
@@ -2897,20 +3119,21 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2897
3119
  sessionProperties
2898
3120
  });
2899
3121
  yield this.options.ui.factory.unload();
2900
- (_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
3122
+ (_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
2901
3123
  this.status = "connected";
2902
3124
  yield this.storage.setTransport("mwp" /* MWP */);
2903
3125
  } catch (error) {
2904
3126
  if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
2905
3127
  if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
2906
3128
  this.status = "disconnected";
3129
+ yield this.options.ui.factory.unload(error);
2907
3130
  reject(error);
2908
3131
  }
2909
3132
  } else {
2910
3133
  this.status = "disconnected";
2911
- reject(
2912
- error instanceof Error ? error : new Error(String(error))
2913
- );
3134
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
3135
+ yield this.options.ui.factory.unload(normalizedError);
3136
+ reject(normalizedError);
2914
3137
  }
2915
3138
  }
2916
3139
  }))().catch(() => {
@@ -2937,8 +3160,8 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2937
3160
  };
2938
3161
  showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
2939
3162
  return __async(this, null, function* () {
2940
- var _a2;
2941
- (_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
3163
+ var _a3;
3164
+ (_a3 = __privateGet(this, _beforeUnloadListener)) != null ? _a3 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
2942
3165
  if (this.options.ui.headless) {
2943
3166
  yield __privateMethod(this, _MetaMaskConnectMultichain_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
2944
3167
  } else {
@@ -2997,7 +3220,7 @@ setupDefaultTransport_fn = function() {
2997
3220
  __privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
2998
3221
  ));
2999
3222
  __privateSet(this, _transport2, transport);
3000
- __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
3223
+ __privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
3001
3224
  return transport;
3002
3225
  });
3003
3226
  };
@@ -3005,7 +3228,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
3005
3228
  return __async(this, null, function* () {
3006
3229
  return new Promise((resolve, reject) => __async(this, null, function* () {
3007
3230
  const dappClientMessageHandler = (payload) => {
3008
- var _a2;
3231
+ var _a3;
3009
3232
  if (typeof payload !== "object" || payload === null || !("data" in payload)) {
3010
3233
  return;
3011
3234
  }
@@ -3015,7 +3238,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
3015
3238
  this.dappClient.off("message", dappClientMessageHandler);
3016
3239
  reject(data.error);
3017
3240
  }
3018
- if ((_a2 = data == null ? void 0 : data.result) == null ? void 0 : _a2.sessionScopes) {
3241
+ if ((_a3 = data == null ? void 0 : data.result) == null ? void 0 : _a3.sessionScopes) {
3019
3242
  this.dappClient.off("message", dappClientMessageHandler);
3020
3243
  }
3021
3244
  }
@@ -3024,13 +3247,13 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
3024
3247
  let timeout;
3025
3248
  if (this.transport.isConnected()) {
3026
3249
  timeout = setTimeout(() => {
3027
- this.openDeeplinkIfNeeded();
3250
+ this.openSimpleDeeplinkIfNeeded();
3028
3251
  }, 250);
3029
3252
  } else {
3030
3253
  this.dappClient.once(
3031
3254
  "session_request",
3032
3255
  (sessionRequest) => {
3033
- var _a2;
3256
+ var _a3;
3034
3257
  const connectionRequest = {
3035
3258
  sessionRequest,
3036
3259
  metadata: {
@@ -3045,7 +3268,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
3045
3268
  connectionRequest
3046
3269
  );
3047
3270
  this.emit("display_uri", deeplink);
3048
- if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
3271
+ if ((_a3 = this.options.mobile) == null ? void 0 : _a3.preferredOpenLink) {
3049
3272
  this.options.mobile.preferredOpenLink(deeplink, "_self");
3050
3273
  } else {
3051
3274
  openDeeplink(this.options, deeplink, universalLink);
@@ -3107,6 +3330,53 @@ handleConnection_fn = function(promise, scopes, transportType) {
3107
3330
  }));
3108
3331
  });
3109
3332
  };
3333
+ getCaipSession_fn = function() {
3334
+ return __async(this, null, function* () {
3335
+ let sessionData = {
3336
+ sessionScopes: {},
3337
+ sessionProperties: {}
3338
+ };
3339
+ if (this.status === "connected") {
3340
+ const response = yield this.transport.request({
3341
+ method: "wallet_getSession"
3342
+ });
3343
+ if (response.result) {
3344
+ sessionData = response.result;
3345
+ }
3346
+ }
3347
+ return sessionData;
3348
+ });
3349
+ };
3350
+ openConnectDeeplinkIfNeeded_fn = function() {
3351
+ return __async(this, null, function* () {
3352
+ var _a3, _b;
3353
+ const { ui } = this.options;
3354
+ const { showInstallModal = false } = ui != null ? ui : {};
3355
+ const secure = isSecure();
3356
+ const shouldOpenDeeplink = secure && !showInstallModal;
3357
+ if (!shouldOpenDeeplink) {
3358
+ return;
3359
+ }
3360
+ const storedSessionRequest = yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.getStoredPendingSessionRequest();
3361
+ if (!storedSessionRequest) {
3362
+ return;
3363
+ }
3364
+ const connectionRequest = {
3365
+ sessionRequest: storedSessionRequest,
3366
+ metadata: {
3367
+ dapp: this.options.dapp,
3368
+ sdk: { version: getVersion(), platform: getPlatformType() }
3369
+ }
3370
+ };
3371
+ const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
3372
+ const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
3373
+ if ((_b = this.options.mobile) == null ? void 0 : _b.preferredOpenLink) {
3374
+ this.options.mobile.preferredOpenLink(deeplink, "_self");
3375
+ } else {
3376
+ openDeeplink(this.options, deeplink, universalLink);
3377
+ }
3378
+ });
3379
+ };
3110
3380
  var MetaMaskConnectMultichain = _MetaMaskConnectMultichain;
3111
3381
 
3112
3382
  // src/store/index.ts
@@ -3291,7 +3561,7 @@ var Store = class extends StoreClient {
3291
3561
  // src/ui/ModalFactory.ts
3292
3562
  var import_onboarding = __toESM(require("@metamask/onboarding"));
3293
3563
  init_domain();
3294
- init_utils();
3564
+ init_utils2();
3295
3565
  var BaseModalFactory = class {
3296
3566
  /**
3297
3567
  * Creates a new modal factory instance.
@@ -3314,8 +3584,8 @@ var BaseModalFactory = class {
3314
3584
  }
3315
3585
  unload(error) {
3316
3586
  return __async(this, null, function* () {
3317
- var _a2, _b;
3318
- (_a2 = this.modal) == null ? void 0 : _a2.unmount();
3587
+ var _a3, _b;
3588
+ (_a3 = this.modal) == null ? void 0 : _a3.unmount();
3319
3589
  yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
3320
3590
  });
3321
3591
  }
@@ -3385,8 +3655,8 @@ var BaseModalFactory = class {
3385
3655
  }
3386
3656
  renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
3387
3657
  return __async(this, null, function* () {
3388
- var _a2, _b;
3389
- (_a2 = this.modal) == null ? void 0 : _a2.unmount();
3658
+ var _a3, _b;
3659
+ (_a3 = this.modal) == null ? void 0 : _a3.unmount();
3390
3660
  yield this.preload();
3391
3661
  this.successCallback = successCallback;
3392
3662
  this.displayUriCallback = onDisplayUri;
@@ -3402,9 +3672,9 @@ var BaseModalFactory = class {
3402
3672
  link: qrCodeLink,
3403
3673
  sdkVersion: getVersion(),
3404
3674
  generateQRCode: (request) => __async(this, null, function* () {
3405
- var _a3;
3675
+ var _a4;
3406
3676
  const newLink = this.createConnectionDeeplink(request);
3407
- (_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
3677
+ (_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
3408
3678
  return newLink;
3409
3679
  }),
3410
3680
  onClose: this.onCloseModal.bind(this),
@@ -3418,8 +3688,8 @@ var BaseModalFactory = class {
3418
3688
  }
3419
3689
  renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
3420
3690
  return __async(this, null, function* () {
3421
- var _a2;
3422
- (_a2 = this.modal) == null ? void 0 : _a2.unmount();
3691
+ var _a3;
3692
+ (_a3 = this.modal) == null ? void 0 : _a3.unmount();
3423
3693
  yield this.preload();
3424
3694
  this.successCallback = successCallback;
3425
3695
  const container = this.getMountedContainer();