@metamask/connect-multichain 0.5.2 → 0.5.3

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 (137) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/README.md +409 -3
  3. package/dist/browser/es/connect-multichain.d.mts +6 -5
  4. package/dist/browser/es/connect-multichain.mjs +308 -224
  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 +6 -5
  8. package/dist/browser/iife/connect-multichain.js +24209 -24108
  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 +6 -5
  12. package/dist/browser/umd/connect-multichain.js +309 -225
  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 +6 -5
  16. package/dist/node/cjs/connect-multichain.js +311 -228
  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 +6 -5
  20. package/dist/node/es/connect-multichain.mjs +311 -226
  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 +6 -5
  24. package/dist/react-native/es/connect-multichain.mjs +308 -224
  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/logger/index.d.ts +1 -1
  28. package/dist/src/domain/logger/index.d.ts.map +1 -1
  29. package/dist/src/domain/logger/index.js.map +1 -1
  30. package/dist/src/domain/multichain/api/constants.js.map +1 -1
  31. package/dist/src/domain/multichain/api/types.d.ts +1 -1
  32. package/dist/src/domain/multichain/api/types.d.ts.map +1 -1
  33. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  34. package/dist/src/domain/multichain/index.js.map +1 -1
  35. package/dist/src/domain/multichain/types.d.ts +2 -0
  36. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  37. package/dist/src/domain/platform/index.d.ts.map +1 -1
  38. package/dist/src/domain/platform/index.js +1 -0
  39. package/dist/src/domain/platform/index.js.map +1 -1
  40. package/dist/src/index.browser.d.ts.map +1 -1
  41. package/dist/src/index.browser.js +9 -4
  42. package/dist/src/index.browser.js.map +1 -1
  43. package/dist/src/index.native.d.ts.map +1 -1
  44. package/dist/src/index.native.js +9 -4
  45. package/dist/src/index.native.js.map +1 -1
  46. package/dist/src/index.node.d.ts.map +1 -1
  47. package/dist/src/index.node.js +8 -4
  48. package/dist/src/index.node.js.map +1 -1
  49. package/dist/src/multichain/index.d.ts +1 -1
  50. package/dist/src/multichain/index.d.ts.map +1 -1
  51. package/dist/src/multichain/index.js +34 -9
  52. package/dist/src/multichain/index.js.map +1 -1
  53. package/dist/src/multichain/rpc/handlers/rpcClient.d.ts +9 -2
  54. package/dist/src/multichain/rpc/handlers/rpcClient.d.ts.map +1 -1
  55. package/dist/src/multichain/rpc/handlers/rpcClient.js +13 -3
  56. package/dist/src/multichain/rpc/handlers/rpcClient.js.map +1 -1
  57. package/dist/src/multichain/rpc/requestRouter.d.ts +14 -1
  58. package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
  59. package/dist/src/multichain/rpc/requestRouter.js +27 -5
  60. package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
  61. package/dist/src/multichain/transports/default/index.d.ts +2 -2
  62. package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
  63. package/dist/src/multichain/transports/default/index.js +14 -17
  64. package/dist/src/multichain/transports/default/index.js.map +1 -1
  65. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +0 -2
  66. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
  67. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +18 -11
  68. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
  69. package/dist/src/multichain/transports/mwp/KeyManager.d.ts.map +1 -1
  70. package/dist/src/multichain/transports/mwp/KeyManager.js.map +1 -1
  71. package/dist/src/multichain/transports/mwp/index.d.ts +1 -1
  72. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  73. package/dist/src/multichain/transports/mwp/index.js +2 -1
  74. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  75. package/dist/src/multichain/utils/analytics.d.ts.map +1 -1
  76. package/dist/src/multichain/utils/analytics.js +1 -0
  77. package/dist/src/multichain/utils/analytics.js.map +1 -1
  78. package/dist/src/multichain/utils/index.d.ts +25 -0
  79. package/dist/src/multichain/utils/index.d.ts.map +1 -1
  80. package/dist/src/multichain/utils/index.js +38 -6
  81. package/dist/src/multichain/utils/index.js.map +1 -1
  82. package/dist/src/polyfills/buffer-shim.js +7 -3
  83. package/dist/src/polyfills/buffer-shim.js.map +1 -1
  84. package/dist/src/store/adapters/node.d.ts +1 -1
  85. package/dist/src/store/adapters/node.d.ts.map +1 -1
  86. package/dist/src/store/adapters/node.js +11 -4
  87. package/dist/src/store/adapters/node.js.map +1 -1
  88. package/dist/src/store/adapters/rn.d.ts.map +1 -1
  89. package/dist/src/store/adapters/rn.js +1 -0
  90. package/dist/src/store/adapters/rn.js.map +1 -1
  91. package/dist/src/store/adapters/web.d.ts +4 -4
  92. package/dist/src/store/adapters/web.d.ts.map +1 -1
  93. package/dist/src/store/adapters/web.js +6 -0
  94. package/dist/src/store/adapters/web.js.map +1 -1
  95. package/dist/src/store/index.d.ts.map +1 -1
  96. package/dist/src/store/index.js +2 -0
  97. package/dist/src/store/index.js.map +1 -1
  98. package/dist/src/ui/ModalFactory.d.ts.map +1 -1
  99. package/dist/src/ui/ModalFactory.js +1 -4
  100. package/dist/src/ui/ModalFactory.js.map +1 -1
  101. package/dist/src/ui/index.d.ts.map +1 -1
  102. package/dist/src/ui/index.js +2 -0
  103. package/dist/src/ui/index.js.map +1 -1
  104. package/dist/src/ui/index.native.d.ts.map +1 -1
  105. package/dist/src/ui/index.native.js +4 -1
  106. package/dist/src/ui/index.native.js.map +1 -1
  107. package/dist/src/ui/modals/base/AbstractInstallModal.d.ts +2 -3
  108. package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -1
  109. package/dist/src/ui/modals/base/AbstractInstallModal.js +28 -12
  110. package/dist/src/ui/modals/base/AbstractInstallModal.js.map +1 -1
  111. package/dist/src/ui/modals/base/AbstractOTPModal.d.ts +2 -2
  112. package/dist/src/ui/modals/base/AbstractOTPModal.d.ts.map +1 -1
  113. package/dist/src/ui/modals/base/AbstractOTPModal.js.map +1 -1
  114. package/dist/src/ui/modals/base/utils.d.ts +12 -0
  115. package/dist/src/ui/modals/base/utils.d.ts.map +1 -1
  116. package/dist/src/ui/modals/base/utils.js +16 -5
  117. package/dist/src/ui/modals/base/utils.js.map +1 -1
  118. package/dist/src/ui/modals/node/install.d.ts.map +1 -1
  119. package/dist/src/ui/modals/node/install.js +1 -1
  120. package/dist/src/ui/modals/node/install.js.map +1 -1
  121. package/dist/src/ui/modals/node/otp.d.ts.map +1 -1
  122. package/dist/src/ui/modals/node/otp.js +6 -2
  123. package/dist/src/ui/modals/node/otp.js.map +1 -1
  124. package/dist/src/ui/modals/rn/install.d.ts.map +1 -1
  125. package/dist/src/ui/modals/rn/install.js +7 -3
  126. package/dist/src/ui/modals/rn/install.js.map +1 -1
  127. package/dist/src/ui/modals/rn/otp.d.ts.map +1 -1
  128. package/dist/src/ui/modals/rn/otp.js +6 -2
  129. package/dist/src/ui/modals/rn/otp.js.map +1 -1
  130. package/dist/src/ui/modals/web/install.d.ts.map +1 -1
  131. package/dist/src/ui/modals/web/install.js +1 -1
  132. package/dist/src/ui/modals/web/install.js.map +1 -1
  133. package/dist/src/ui/modals/web/otp.d.ts.map +1 -1
  134. package/dist/src/ui/modals/web/otp.js +6 -2
  135. package/dist/src/ui/modals/web/otp.js.map +1 -1
  136. package/dist/types/connect-multichain.d.ts +6 -5
  137. package/package.json +3 -3
@@ -55,6 +55,14 @@ 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
+ });
58
66
  var __async = (__this, __arguments, generator) => {
59
67
  return new Promise((resolve, reject) => {
60
68
  var fulfilled = (value) => {
@@ -623,8 +631,9 @@ function getDappId(dapp) {
623
631
  return (_a2 = dapp.url) != null ? _a2 : dapp.name;
624
632
  }
625
633
  function openDeeplink(options, deeplink, universalLink) {
634
+ var _a2;
626
635
  const { mobile } = options;
627
- const useDeeplink = mobile && mobile.useDeeplink !== void 0 ? mobile.useDeeplink : true;
636
+ const useDeeplink = (_a2 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a2 : true;
628
637
  if (useDeeplink) {
629
638
  if (typeof window !== "undefined") {
630
639
  window.location.href = deeplink;
@@ -665,7 +674,7 @@ function setupDappMetadata(options) {
665
674
  throw new Error("You must provide dapp url");
666
675
  }
667
676
  const BASE_64_ICON_MAX_LENGTH = 163400;
668
- const urlPattern = /^(http|https):\/\/[^\s]*$/;
677
+ const urlPattern = /^(http|https):\/\/[^\s]*$/u;
669
678
  if (options.dapp) {
670
679
  if ("iconUrl" in options.dapp) {
671
680
  if (options.dapp.iconUrl && !urlPattern.test(options.dapp.iconUrl)) {
@@ -714,9 +723,12 @@ function getValidAccounts(caipAccountIds) {
714
723
  (caipAccounts, caipAccountId) => {
715
724
  try {
716
725
  return [...caipAccounts, (0, import_utils.parseCaipAccountId)(caipAccountId)];
717
- } catch (err) {
726
+ } catch (error) {
718
727
  const stringifiedAccountId = JSON.stringify(caipAccountId);
719
- console.error(`Invalid CAIP account ID: ${stringifiedAccountId}`, err);
728
+ console.error(
729
+ `Invalid CAIP account ID: ${stringifiedAccountId}`,
730
+ error
731
+ );
720
732
  return caipAccounts;
721
733
  }
722
734
  },
@@ -772,12 +784,12 @@ function addValidAccounts(optionalScopes, validAccounts) {
772
784
  }
773
785
  return result;
774
786
  }
775
- var import_pako, import_utils, extractFavicon;
787
+ var import_utils, import_pako, extractFavicon;
776
788
  var init_utils = __esm({
777
789
  "src/multichain/utils/index.ts"() {
778
790
  "use strict";
779
- import_pako = require("pako");
780
791
  import_utils = require("@metamask/utils");
792
+ import_pako = require("pako");
781
793
  init_domain();
782
794
  extractFavicon = () => {
783
795
  var _a2;
@@ -879,7 +891,9 @@ var init_domain = __esm({
879
891
 
880
892
  // src/ui/modals/base/utils.ts
881
893
  function formatRemainingTime(milliseconds) {
882
- if (milliseconds <= 0) return "EXPIRED";
894
+ if (milliseconds <= 0) {
895
+ return "EXPIRED";
896
+ }
883
897
  const seconds = Math.floor(milliseconds / 1e3);
884
898
  return `${seconds}s`;
885
899
  }
@@ -892,9 +906,8 @@ function shouldLogCountdown(remainingSeconds) {
892
906
  return remainingSeconds % 10 === 0;
893
907
  } else if (remainingSeconds <= 300) {
894
908
  return remainingSeconds % 30 === 0;
895
- } else {
896
- return remainingSeconds % 60 === 0;
897
909
  }
910
+ return remainingSeconds % 60 === 0;
898
911
  }
899
912
  var init_utils3 = __esm({
900
913
  "src/ui/modals/base/utils.ts"() {
@@ -903,18 +916,18 @@ var init_utils3 = __esm({
903
916
  });
904
917
 
905
918
  // src/ui/modals/base/AbstractInstallModal.ts
906
- var logger3, AbstractInstallModal;
919
+ var logger3, _expirationInterval, _lastLoggedCountdown, AbstractInstallModal;
907
920
  var init_AbstractInstallModal = __esm({
908
921
  "src/ui/modals/base/AbstractInstallModal.ts"() {
909
922
  "use strict";
910
- init_domain();
911
923
  init_utils3();
924
+ init_domain();
912
925
  logger3 = createLogger("metamask-sdk:ui");
913
926
  AbstractInstallModal = class extends Modal {
914
927
  constructor() {
915
928
  super(...arguments);
916
- this.expirationInterval = null;
917
- this.lastLoggedCountdown = -1;
929
+ __privateAdd(this, _expirationInterval, null);
930
+ __privateAdd(this, _lastLoggedCountdown, -1);
918
931
  }
919
932
  get link() {
920
933
  return this.data;
@@ -942,17 +955,17 @@ var init_AbstractInstallModal = __esm({
942
955
  startExpirationCheck(connectionRequest) {
943
956
  this.stopExpirationCheck();
944
957
  let currentConnectionRequest = connectionRequest;
945
- this.expirationInterval = setInterval(() => __async(this, null, function* () {
958
+ __privateSet(this, _expirationInterval, setInterval(() => __async(this, null, function* () {
946
959
  const { sessionRequest } = currentConnectionRequest;
947
960
  const now = Date.now();
948
961
  const remainingMs = sessionRequest.expiresAt - now;
949
962
  const remainingSeconds = Math.floor(remainingMs / 1e3);
950
- if (remainingMs > 0 && shouldLogCountdown(remainingSeconds) && this.lastLoggedCountdown !== remainingSeconds) {
963
+ if (remainingMs > 0 && shouldLogCountdown(remainingSeconds) && __privateGet(this, _lastLoggedCountdown) !== remainingSeconds) {
951
964
  const formattedTime = formatRemainingTime(remainingMs);
952
965
  logger3(
953
966
  `[UI: InstallModal-nodejs()] QR code expires in: ${formattedTime} (${remainingSeconds}s)`
954
967
  );
955
- this.lastLoggedCountdown = remainingSeconds;
968
+ __privateSet(this, _lastLoggedCountdown, remainingSeconds);
956
969
  }
957
970
  if (now >= sessionRequest.expiresAt) {
958
971
  this.stopExpirationCheck();
@@ -964,7 +977,7 @@ var init_AbstractInstallModal = __esm({
964
977
  const generateQRCode = yield this.options.generateQRCode(
965
978
  currentConnectionRequest
966
979
  );
967
- this.lastLoggedCountdown = -1;
980
+ __privateSet(this, _lastLoggedCountdown, -1);
968
981
  this.updateLink(generateQRCode);
969
982
  this.updateExpiresIn(remainingSeconds);
970
983
  this.renderQRCode(generateQRCode, currentConnectionRequest);
@@ -974,18 +987,20 @@ var init_AbstractInstallModal = __esm({
974
987
  );
975
988
  }
976
989
  }
977
- }), 1e3);
990
+ }), 1e3));
978
991
  }
979
992
  stopExpirationCheck() {
980
- if (this.expirationInterval) {
981
- clearInterval(this.expirationInterval);
982
- this.expirationInterval = null;
993
+ if (__privateGet(this, _expirationInterval)) {
994
+ clearInterval(__privateGet(this, _expirationInterval));
995
+ __privateSet(this, _expirationInterval, null);
983
996
  logger3(
984
997
  "[UI: InstallModal-nodejs()] \u{1F6D1} Stopped QR code expiration checking"
985
998
  );
986
999
  }
987
1000
  }
988
1001
  };
1002
+ _expirationInterval = new WeakMap();
1003
+ _lastLoggedCountdown = new WeakMap();
989
1004
  }
990
1005
  });
991
1006
 
@@ -994,8 +1009,8 @@ var import_qr, logger4, InstallModal;
994
1009
  var init_install = __esm({
995
1010
  "src/ui/modals/node/install.ts"() {
996
1011
  "use strict";
997
- init_domain();
998
1012
  import_qr = __toESM(require("@paulmillr/qr"));
1013
+ init_domain();
999
1014
  init_AbstractInstallModal();
1000
1015
  init_utils3();
1001
1016
  logger4 = createLogger("metamask-sdk:ui");
@@ -1098,7 +1113,7 @@ var node_exports2 = {};
1098
1113
  __export(node_exports2, {
1099
1114
  StoreAdapterNode: () => StoreAdapterNode
1100
1115
  });
1101
- var StoreAdapterNode;
1116
+ var _storage, StoreAdapterNode;
1102
1117
  var init_node2 = __esm({
1103
1118
  "src/store/adapters/node.ts"() {
1104
1119
  "use strict";
@@ -1107,25 +1122,26 @@ var init_node2 = __esm({
1107
1122
  constructor() {
1108
1123
  super(...arguments);
1109
1124
  this.platform = "node";
1110
- this.storage = /* @__PURE__ */ new Map();
1125
+ __privateAdd(this, _storage, /* @__PURE__ */ new Map());
1111
1126
  }
1112
1127
  get(key) {
1113
1128
  return __async(this, null, function* () {
1114
1129
  var _a2;
1115
- return (_a2 = this.storage.get(key)) != null ? _a2 : null;
1130
+ return (_a2 = __privateGet(this, _storage).get(key)) != null ? _a2 : null;
1116
1131
  });
1117
1132
  }
1118
1133
  set(key, value) {
1119
1134
  return __async(this, null, function* () {
1120
- this.storage.set(key, value);
1135
+ __privateGet(this, _storage).set(key, value);
1121
1136
  });
1122
1137
  }
1123
1138
  delete(key) {
1124
1139
  return __async(this, null, function* () {
1125
- this.storage.delete(key);
1140
+ __privateGet(this, _storage).delete(key);
1126
1141
  });
1127
1142
  }
1128
1143
  };
1144
+ _storage = new WeakMap();
1129
1145
  }
1130
1146
  });
1131
1147
 
@@ -1161,6 +1177,7 @@ __export(index_node_exports, {
1161
1177
  isSecure: () => isSecure
1162
1178
  });
1163
1179
  module.exports = __toCommonJS(index_node_exports);
1180
+ init_domain();
1164
1181
 
1165
1182
  // src/multichain/index.ts
1166
1183
  var import_analytics4 = require("@metamask/analytics");
@@ -1197,7 +1214,9 @@ var RpcClient = class {
1197
1214
  }
1198
1215
  /**
1199
1216
  * Routes the request to a configured RPC node.
1200
- * @param options - The invoke method options
1217
+ *
1218
+ * @param options - The invoke method options.
1219
+ * @returns The JSON response from the RPC node.
1201
1220
  */
1202
1221
  request(options) {
1203
1222
  return __async(this, null, function* () {
@@ -1209,7 +1228,13 @@ var RpcClient = class {
1209
1228
  id: getNextRpcId()
1210
1229
  });
1211
1230
  const rpcEndpoint = this.getRpcEndpoint(options.scope);
1212
- const rpcRequest = yield this.fetchWithTimeout(rpcEndpoint, body, "POST", this.getHeaders(rpcEndpoint), 3e4);
1231
+ const rpcRequest = yield this.fetchWithTimeout(
1232
+ rpcEndpoint,
1233
+ body,
1234
+ "POST",
1235
+ this.getHeaders(rpcEndpoint),
1236
+ 3e4
1237
+ );
1213
1238
  const response = yield this.parseResponse(rpcRequest);
1214
1239
  return response;
1215
1240
  });
@@ -1219,7 +1244,9 @@ var RpcClient = class {
1219
1244
  const supportedNetworks = (_c = (_b = (_a2 = this.config) == null ? void 0 : _a2.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
1220
1245
  const rpcEndpoint = supportedNetworks[scope];
1221
1246
  if (!rpcEndpoint) {
1222
- throw new MissingRpcEndpointErr(`No RPC endpoint found for scope ${scope}`);
1247
+ throw new MissingRpcEndpointErr(
1248
+ `No RPC endpoint found for scope ${scope}`
1249
+ );
1223
1250
  }
1224
1251
  return rpcEndpoint;
1225
1252
  }
@@ -1247,7 +1274,7 @@ var RpcClient = class {
1247
1274
  if (error instanceof Error && error.name === "AbortError") {
1248
1275
  throw new RPCReadonlyRequestErr(`Request timeout after ${timeout}ms`);
1249
1276
  }
1250
- throw new RPCReadonlyRequestErr(error instanceof Error ? error.message : "Unknown error");
1277
+ throw new RPCReadonlyRequestErr(error.message);
1251
1278
  }
1252
1279
  });
1253
1280
  }
@@ -1292,10 +1319,12 @@ var RequestRouter = class {
1292
1319
  * The main entry point for invoking an RPC method.
1293
1320
  * This method acts as a router, determining the correct handling strategy
1294
1321
  * for the request and delegating to the appropriate private handler.
1322
+ *
1323
+ * @param options
1295
1324
  */
1296
1325
  invokeMethod(options) {
1297
1326
  return __async(this, null, function* () {
1298
- const method = options.request.method;
1327
+ const { method } = options.request;
1299
1328
  if (RPC_HANDLED_METHODS.has(method)) {
1300
1329
  return this.handleWithRpcNode(options);
1301
1330
  }
@@ -1307,6 +1336,8 @@ var RequestRouter = class {
1307
1336
  }
1308
1337
  /**
1309
1338
  * Forwards the request directly to the wallet via the transport.
1339
+ *
1340
+ * @param options
1310
1341
  */
1311
1342
  handleWithWallet(options) {
1312
1343
  return __async(this, null, function* () {
@@ -1335,7 +1366,10 @@ var RequestRouter = class {
1335
1366
  }
1336
1367
  const response = yield request;
1337
1368
  if (response.error) {
1338
- throw new RPCInvokeMethodErr(`RPC Request failed with code ${response.error.code}: ${response.error.message}`);
1369
+ const { error } = response;
1370
+ throw new RPCInvokeMethodErr(
1371
+ `RPC Request failed with code ${error.code}: ${error.message}`
1372
+ );
1339
1373
  }
1340
1374
  return response.result;
1341
1375
  }));
@@ -1343,6 +1377,8 @@ var RequestRouter = class {
1343
1377
  }
1344
1378
  /**
1345
1379
  * Routes the request to a configured RPC node.
1380
+ *
1381
+ * @param options
1346
1382
  */
1347
1383
  handleWithRpcNode(options) {
1348
1384
  return __async(this, null, function* () {
@@ -1360,10 +1396,14 @@ var RequestRouter = class {
1360
1396
  }
1361
1397
  /**
1362
1398
  * Responds directly from the SDK's session state.
1399
+ *
1400
+ * @param options
1363
1401
  */
1364
1402
  handleWithSdkState(options) {
1365
1403
  return __async(this, null, function* () {
1366
- console.warn(`Method "${options.request.method}" is configured for SDK state handling, but this is not yet implemented. Falling back to wallet passthrough.`);
1404
+ console.warn(
1405
+ `Method "${options.request.method}" is configured for SDK state handling, but this is not yet implemented. Falling back to wallet passthrough.`
1406
+ );
1367
1407
  return this.handleWithWallet(options);
1368
1408
  });
1369
1409
  }
@@ -1383,31 +1423,50 @@ withAnalyticsTracking_fn = function(options, execute) {
1383
1423
  } else {
1384
1424
  yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options);
1385
1425
  }
1426
+ if (error instanceof RPCInvokeMethodErr) {
1427
+ throw error;
1428
+ }
1386
1429
  throw new RPCInvokeMethodErr(error.message);
1387
1430
  }
1388
1431
  });
1389
1432
  };
1390
1433
  trackWalletActionRequested_fn = function(options) {
1391
1434
  return __async(this, null, function* () {
1392
- const props = yield getWalletActionAnalyticsProperties(this.config, this.config.storage, options);
1435
+ const props = yield getWalletActionAnalyticsProperties(
1436
+ this.config,
1437
+ this.config.storage,
1438
+ options
1439
+ );
1393
1440
  import_analytics2.analytics.track("mmconnect_wallet_action_requested", props);
1394
1441
  });
1395
1442
  };
1396
1443
  trackWalletActionSucceeded_fn = function(options) {
1397
1444
  return __async(this, null, function* () {
1398
- const props = yield getWalletActionAnalyticsProperties(this.config, this.config.storage, options);
1445
+ const props = yield getWalletActionAnalyticsProperties(
1446
+ this.config,
1447
+ this.config.storage,
1448
+ options
1449
+ );
1399
1450
  import_analytics2.analytics.track("mmconnect_wallet_action_succeeded", props);
1400
1451
  });
1401
1452
  };
1402
1453
  trackWalletActionFailed_fn = function(options) {
1403
1454
  return __async(this, null, function* () {
1404
- const props = yield getWalletActionAnalyticsProperties(this.config, this.config.storage, options);
1455
+ const props = yield getWalletActionAnalyticsProperties(
1456
+ this.config,
1457
+ this.config.storage,
1458
+ options
1459
+ );
1405
1460
  import_analytics2.analytics.track("mmconnect_wallet_action_failed", props);
1406
1461
  });
1407
1462
  };
1408
1463
  trackWalletActionRejected_fn = function(options) {
1409
1464
  return __async(this, null, function* () {
1410
- const props = yield getWalletActionAnalyticsProperties(this.config, this.config.storage, options);
1465
+ const props = yield getWalletActionAnalyticsProperties(
1466
+ this.config,
1467
+ this.config.storage,
1468
+ options
1469
+ );
1411
1470
  import_analytics2.analytics.track("mmconnect_wallet_action_rejected", props);
1412
1471
  });
1413
1472
  };
@@ -1469,7 +1528,7 @@ var DefaultTransport = class {
1469
1528
  }
1470
1529
  connect(options) {
1471
1530
  return __async(this, null, function* () {
1472
- var _a2, _b, _c, _d, _e, _f, _g;
1531
+ var _a2, _b, _c, _d, _e;
1473
1532
  __privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
1474
1533
  yield __privateGet(this, _transport).connect();
1475
1534
  const sessionRequest = yield this.request(
@@ -1480,12 +1539,19 @@ var DefaultTransport = class {
1480
1539
  throw new Error(sessionRequest.error.message);
1481
1540
  }
1482
1541
  let walletSession = sessionRequest.result;
1542
+ const createSessionParams = {
1543
+ optionalScopes: addValidAccounts(
1544
+ getOptionalScopes((_a2 = options == null ? void 0 : options.scopes) != null ? _a2 : []),
1545
+ getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
1546
+ ),
1547
+ sessionProperties: options == null ? void 0 : options.sessionProperties
1548
+ };
1483
1549
  if (walletSession && options && !options.forceRequest) {
1484
1550
  const currentScopes = Object.keys(
1485
- (_a2 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a2 : {}
1551
+ (_c = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _c : {}
1486
1552
  );
1487
- const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
1488
- const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
1553
+ const proposedScopes = (_d = options == null ? void 0 : options.scopes) != null ? _d : [];
1554
+ const proposedCaipAccountIds = (_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [];
1489
1555
  const hasSameScopesAndAccounts = isSameScopesAndAccounts(
1490
1556
  currentScopes,
1491
1557
  proposedScopes,
@@ -1497,13 +1563,6 @@ var DefaultTransport = class {
1497
1563
  { method: "wallet_revokeSession", params: walletSession },
1498
1564
  __privateGet(this, _defaultRequestOptions)
1499
1565
  );
1500
- const optionalScopes = addValidAccounts(
1501
- getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
1502
- getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
1503
- );
1504
- const createSessionParams = {
1505
- optionalScopes
1506
- };
1507
1566
  const response = yield this.request(
1508
1567
  { method: "wallet_createSession", params: createSessionParams },
1509
1568
  __privateGet(this, _defaultRequestOptions)
@@ -1514,14 +1573,6 @@ var DefaultTransport = class {
1514
1573
  walletSession = response.result;
1515
1574
  }
1516
1575
  } else if (!walletSession || (options == null ? void 0 : options.forceRequest)) {
1517
- const optionalScopes = addValidAccounts(
1518
- getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
1519
- getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
1520
- );
1521
- const createSessionParams = {
1522
- optionalScopes,
1523
- sessionProperties: options == null ? void 0 : options.sessionProperties
1524
- };
1525
1576
  const response = yield this.request(
1526
1577
  { method: "wallet_createSession", params: createSessionParams },
1527
1578
  __privateGet(this, _defaultRequestOptions)
@@ -1573,7 +1624,11 @@ var DefaultTransport = class {
1573
1624
  };
1574
1625
  }
1575
1626
  getActiveSession() {
1576
- throw new Error("getActiveSession is purposely not implemented for the DefaultTransport");
1627
+ return __async(this, null, function* () {
1628
+ throw new Error(
1629
+ "getActiveSession is purposely not implemented for the DefaultTransport"
1630
+ );
1631
+ });
1577
1632
  }
1578
1633
  };
1579
1634
  _notificationCallbacks = new WeakMap();
@@ -1647,6 +1702,164 @@ setupMessageListener_fn = function() {
1647
1702
  window.addEventListener("message", __privateGet(this, _handleNotificationListener));
1648
1703
  };
1649
1704
 
1705
+ // src/multichain/transports/multichainApiClientWrapper/index.ts
1706
+ var import_rpc_errors = require("@metamask/rpc-errors");
1707
+ var MAX = 4294967295;
1708
+ var idCounter = Math.floor(Math.random() * MAX);
1709
+ var getUniqueId = () => {
1710
+ idCounter = (idCounter + 1) % MAX;
1711
+ return idCounter;
1712
+ };
1713
+ var _requestId, _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
1714
+ var MultichainApiClientWrapperTransport = class {
1715
+ constructor(metamaskConnectMultichain) {
1716
+ this.metamaskConnectMultichain = metamaskConnectMultichain;
1717
+ __privateAdd(this, _MultichainApiClientWrapperTransport_instances);
1718
+ __privateAdd(this, _requestId, getUniqueId());
1719
+ __privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
1720
+ }
1721
+ isTransportDefined() {
1722
+ try {
1723
+ return Boolean(this.metamaskConnectMultichain.transport);
1724
+ } catch (_error) {
1725
+ return false;
1726
+ }
1727
+ }
1728
+ clearNotificationCallbacks() {
1729
+ __privateGet(this, _notificationCallbacks2).clear();
1730
+ }
1731
+ notifyCallbacks(data) {
1732
+ __privateGet(this, _notificationCallbacks2).forEach((callback) => {
1733
+ callback(data);
1734
+ });
1735
+ }
1736
+ setupNotifcationListener() {
1737
+ this.metamaskConnectMultichain.transport.onNotification(
1738
+ this.notifyCallbacks.bind(this)
1739
+ );
1740
+ }
1741
+ connect() {
1742
+ return __async(this, null, function* () {
1743
+ console.log("\u{1F4DA} connect");
1744
+ return Promise.resolve();
1745
+ });
1746
+ }
1747
+ disconnect() {
1748
+ return __async(this, null, function* () {
1749
+ return Promise.resolve();
1750
+ });
1751
+ }
1752
+ isConnected() {
1753
+ return true;
1754
+ }
1755
+ request(_0) {
1756
+ return __async(this, arguments, function* (params, _options = {}) {
1757
+ const id = __privateWrapper(this, _requestId)._++;
1758
+ const requestPayload = __spreadValues({
1759
+ id,
1760
+ jsonrpc: "2.0"
1761
+ }, params);
1762
+ switch (requestPayload.method) {
1763
+ case "wallet_createSession":
1764
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
1765
+ case "wallet_getSession":
1766
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
1767
+ case "wallet_revokeSession":
1768
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
1769
+ case "wallet_invokeMethod":
1770
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
1771
+ default:
1772
+ throw new Error(`Unsupported method: ${requestPayload.method}`);
1773
+ }
1774
+ throw new Error(`Unknown method: ${requestPayload.method}`);
1775
+ });
1776
+ }
1777
+ onNotification(callback) {
1778
+ if (!this.isTransportDefined()) {
1779
+ __privateGet(this, _notificationCallbacks2).add(callback);
1780
+ return () => {
1781
+ __privateGet(this, _notificationCallbacks2).delete(callback);
1782
+ };
1783
+ }
1784
+ return this.metamaskConnectMultichain.transport.onNotification(callback);
1785
+ }
1786
+ };
1787
+ _requestId = new WeakMap();
1788
+ _notificationCallbacks2 = new WeakMap();
1789
+ _MultichainApiClientWrapperTransport_instances = new WeakSet();
1790
+ walletCreateSession_fn = function(request) {
1791
+ return __async(this, null, function* () {
1792
+ console.log("\u{1F4DA} #walletCreateSession", request);
1793
+ const createSessionParams = request.params;
1794
+ const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
1795
+ const scopeAccounts = [];
1796
+ scopes.forEach((scope) => {
1797
+ var _a2, _b, _c, _d;
1798
+ const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
1799
+ const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
1800
+ if (requiredScope) {
1801
+ scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
1802
+ }
1803
+ if (optionalScope) {
1804
+ scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
1805
+ }
1806
+ });
1807
+ const accounts = [...new Set(scopeAccounts)];
1808
+ console.log("\u{1F4DA} SDK connect");
1809
+ yield this.metamaskConnectMultichain.connect(
1810
+ scopes,
1811
+ accounts,
1812
+ createSessionParams.sessionProperties
1813
+ );
1814
+ console.log("\u{1F4DA} SDK connected");
1815
+ return this.metamaskConnectMultichain.transport.request({
1816
+ method: "wallet_getSession"
1817
+ });
1818
+ });
1819
+ };
1820
+ walletGetSession_fn = function(request) {
1821
+ return __async(this, null, function* () {
1822
+ if (!this.isTransportDefined()) {
1823
+ return {
1824
+ jsonrpc: "2.0",
1825
+ id: request.id,
1826
+ result: {
1827
+ sessionScopes: {}
1828
+ }
1829
+ };
1830
+ }
1831
+ return this.metamaskConnectMultichain.transport.request({
1832
+ method: "wallet_getSession"
1833
+ });
1834
+ });
1835
+ };
1836
+ walletRevokeSession_fn = function(request) {
1837
+ return __async(this, null, function* () {
1838
+ if (!this.isTransportDefined()) {
1839
+ return { jsonrpc: "2.0", id: request.id, result: true };
1840
+ }
1841
+ try {
1842
+ this.metamaskConnectMultichain.disconnect();
1843
+ return { jsonrpc: "2.0", id: request.id, result: true };
1844
+ } catch (_error) {
1845
+ return { jsonrpc: "2.0", id: request.id, result: false };
1846
+ }
1847
+ });
1848
+ };
1849
+ walletInvokeMethod_fn = function(request) {
1850
+ return __async(this, null, function* () {
1851
+ if (!this.isTransportDefined()) {
1852
+ return { error: import_rpc_errors.providerErrors.unauthorized() };
1853
+ }
1854
+ const result = this.metamaskConnectMultichain.invokeMethod(
1855
+ request.params
1856
+ );
1857
+ return {
1858
+ result
1859
+ };
1860
+ });
1861
+ };
1862
+
1650
1863
  // src/multichain/transports/mwp/index.ts
1651
1864
  var import_mobile_wallet_protocol_core = require("@metamask/mobile-wallet-protocol-core");
1652
1865
  var import_multichain_api_client2 = require("@metamask/multichain-api-client");
@@ -2206,164 +2419,6 @@ var keymanager = new KeyManager();
2206
2419
 
2207
2420
  // src/multichain/index.ts
2208
2421
  init_utils();
2209
-
2210
- // src/multichain/transports/multichainApiClientWrapper/index.ts
2211
- var import_rpc_errors = require("@metamask/rpc-errors");
2212
- var MAX = 4294967295;
2213
- var idCounter = Math.floor(Math.random() * MAX);
2214
- var getUniqueId = () => {
2215
- idCounter = (idCounter + 1) % MAX;
2216
- return idCounter;
2217
- };
2218
- var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
2219
- var MultichainApiClientWrapperTransport = class {
2220
- constructor(metamaskConnectMultichain) {
2221
- this.metamaskConnectMultichain = metamaskConnectMultichain;
2222
- __privateAdd(this, _MultichainApiClientWrapperTransport_instances);
2223
- this.requestId = getUniqueId();
2224
- this.notificationCallbacks = /* @__PURE__ */ new Set();
2225
- }
2226
- isTransportDefined() {
2227
- try {
2228
- return Boolean(this.metamaskConnectMultichain.transport);
2229
- } catch (error) {
2230
- return false;
2231
- }
2232
- }
2233
- clearNotificationCallbacks() {
2234
- this.notificationCallbacks.clear();
2235
- }
2236
- notifyCallbacks(data) {
2237
- this.notificationCallbacks.forEach((callback) => {
2238
- callback(data);
2239
- });
2240
- }
2241
- setupNotifcationListener() {
2242
- this.metamaskConnectMultichain.transport.onNotification(
2243
- this.notifyCallbacks.bind(this)
2244
- );
2245
- }
2246
- connect() {
2247
- return __async(this, null, function* () {
2248
- console.log("\u{1F4DA} connect");
2249
- return Promise.resolve();
2250
- });
2251
- }
2252
- disconnect() {
2253
- return __async(this, null, function* () {
2254
- return Promise.resolve();
2255
- });
2256
- }
2257
- isConnected() {
2258
- return true;
2259
- }
2260
- request(_0) {
2261
- return __async(this, arguments, function* (params, _options = {}) {
2262
- const id = this.requestId++;
2263
- const requestPayload = __spreadValues({
2264
- id,
2265
- jsonrpc: "2.0"
2266
- }, params);
2267
- switch (requestPayload.method) {
2268
- case "wallet_createSession":
2269
- return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
2270
- case "wallet_getSession":
2271
- return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
2272
- case "wallet_revokeSession":
2273
- return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
2274
- case "wallet_invokeMethod":
2275
- return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
2276
- default:
2277
- throw new Error(`Unsupported method: ${requestPayload.method}`);
2278
- }
2279
- throw new Error(`Unknown method: ${requestPayload.method}`);
2280
- });
2281
- }
2282
- onNotification(callback) {
2283
- if (!this.isTransportDefined()) {
2284
- this.notificationCallbacks.add(callback);
2285
- return () => {
2286
- this.notificationCallbacks.delete(callback);
2287
- };
2288
- }
2289
- return this.metamaskConnectMultichain.transport.onNotification(callback);
2290
- }
2291
- };
2292
- _MultichainApiClientWrapperTransport_instances = new WeakSet();
2293
- walletCreateSession_fn = function(request) {
2294
- return __async(this, null, function* () {
2295
- console.log("\u{1F4DA} #walletCreateSession", request);
2296
- const createSessionParams = request.params;
2297
- const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
2298
- const scopeAccounts = [];
2299
- scopes.forEach((scope) => {
2300
- var _a2, _b, _c, _d;
2301
- const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
2302
- const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
2303
- if (requiredScope) {
2304
- scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
2305
- }
2306
- if (optionalScope) {
2307
- scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
2308
- }
2309
- });
2310
- const accounts = [...new Set(scopeAccounts)];
2311
- console.log("\u{1F4DA} SDK connect");
2312
- yield this.metamaskConnectMultichain.connect(
2313
- scopes,
2314
- accounts,
2315
- createSessionParams.sessionProperties
2316
- );
2317
- console.log("\u{1F4DA} SDK connected");
2318
- return this.metamaskConnectMultichain.transport.request({
2319
- method: "wallet_getSession"
2320
- });
2321
- });
2322
- };
2323
- walletGetSession_fn = function(request) {
2324
- return __async(this, null, function* () {
2325
- if (!this.isTransportDefined()) {
2326
- return {
2327
- jsonrpc: "2.0",
2328
- id: request.id,
2329
- result: {
2330
- sessionScopes: {}
2331
- }
2332
- };
2333
- }
2334
- return this.metamaskConnectMultichain.transport.request({
2335
- method: "wallet_getSession"
2336
- });
2337
- });
2338
- };
2339
- walletRevokeSession_fn = function(request) {
2340
- return __async(this, null, function* () {
2341
- if (!this.isTransportDefined()) {
2342
- return { jsonrpc: "2.0", id: request.id, result: true };
2343
- }
2344
- try {
2345
- this.metamaskConnectMultichain.disconnect();
2346
- return { jsonrpc: "2.0", id: request.id, result: true };
2347
- } catch (error) {
2348
- return { jsonrpc: "2.0", id: request.id, result: false };
2349
- }
2350
- });
2351
- };
2352
- walletInvokeMethod_fn = function(request) {
2353
- return __async(this, null, function* () {
2354
- if (!this.isTransportDefined()) {
2355
- return { error: import_rpc_errors.providerErrors.unauthorized() };
2356
- }
2357
- const result = this.metamaskConnectMultichain.invokeMethod(
2358
- request.params
2359
- );
2360
- return {
2361
- result
2362
- };
2363
- });
2364
- };
2365
-
2366
- // src/multichain/index.ts
2367
2422
  var logger2 = createLogger("metamask-sdk:core");
2368
2423
  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;
2369
2424
  var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
@@ -2391,8 +2446,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2391
2446
  this._status = "pending";
2392
2447
  __privateAdd(this, _listener);
2393
2448
  __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}`);
2394
- __privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
2395
- __privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({ transport: __privateGet(this, _providerTransportWrapper) }));
2449
+ __privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
2450
+ this
2451
+ ));
2452
+ __privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({
2453
+ transport: __privateGet(this, _providerTransportWrapper)
2454
+ }));
2396
2455
  }
2397
2456
  get status() {
2398
2457
  return this._status;
@@ -2478,7 +2537,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2478
2537
  }
2479
2538
  const nonEmptySessionProperites = Object.keys(sessionProperties != null ? sessionProperties : {}).length > 0 ? sessionProperties : void 0;
2480
2539
  if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
2481
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties: nonEmptySessionProperites, forceRequest }).then(() => __async(this, null, function* () {
2540
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({
2541
+ scopes,
2542
+ caipAccountIds,
2543
+ sessionProperties: nonEmptySessionProperites,
2544
+ forceRequest
2545
+ }).then(() => __async(this, null, function* () {
2482
2546
  if (__privateGet(this, _transport2) instanceof MWPTransport) {
2483
2547
  return this.storage.setTransport("mwp" /* MWP */);
2484
2548
  }
@@ -2487,11 +2551,21 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
2487
2551
  }
2488
2552
  if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
2489
2553
  const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
2490
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties: nonEmptySessionProperites, forceRequest }), scopes, transportType);
2554
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
2555
+ scopes,
2556
+ caipAccountIds,
2557
+ sessionProperties: nonEmptySessionProperites,
2558
+ forceRequest
2559
+ }), scopes, transportType);
2491
2560
  }
2492
2561
  if (isWeb && hasExtensionInstalled && preferExtension) {
2493
2562
  const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
2494
- return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties: nonEmptySessionProperites, forceRequest }), scopes, transportType);
2563
+ return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
2564
+ scopes,
2565
+ caipAccountIds,
2566
+ sessionProperties: nonEmptySessionProperites,
2567
+ forceRequest
2568
+ }), scopes, transportType);
2495
2569
  }
2496
2570
  yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
2497
2571
  const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
@@ -2753,7 +2827,11 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
2753
2827
  (() => __async(this, null, function* () {
2754
2828
  var _a2;
2755
2829
  try {
2756
- yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
2830
+ yield this.transport.connect({
2831
+ scopes,
2832
+ caipAccountIds,
2833
+ sessionProperties
2834
+ });
2757
2835
  yield this.options.ui.factory.unload();
2758
2836
  (_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
2759
2837
  this.status = "connected";
@@ -2861,7 +2939,7 @@ setupDefaultTransport_fn = function() {
2861
2939
  };
2862
2940
  deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
2863
2941
  return __async(this, null, function* () {
2864
- return new Promise((resolve, reject) => {
2942
+ return new Promise((resolve, reject) => __async(this, null, function* () {
2865
2943
  const dappClientMessageHandler = (payload) => {
2866
2944
  var _a2;
2867
2945
  if (typeof payload !== "object" || payload === null || !("data" in payload)) {
@@ -2920,7 +2998,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
2920
2998
  clearTimeout(timeout);
2921
2999
  }
2922
3000
  });
2923
- });
3001
+ }));
2924
3002
  });
2925
3003
  };
2926
3004
  handleConnection_fn = function(promise, scopes, transportType) {
@@ -3213,7 +3291,9 @@ var BaseModalFactory = class {
3213
3291
  }
3214
3292
  createConnectionDeeplink(connectionRequest) {
3215
3293
  if (!connectionRequest) {
3216
- throw new Error("createConnectionDeeplink can only be called with a connection request");
3294
+ throw new Error(
3295
+ "createConnectionDeeplink can only be called with a connection request"
3296
+ );
3217
3297
  }
3218
3298
  const json = JSON.stringify(connectionRequest);
3219
3299
  const compressed = compressString(json);
@@ -3319,14 +3399,17 @@ var ModalFactory = class extends BaseModalFactory {
3319
3399
  // src/index.node.ts
3320
3400
  init_domain();
3321
3401
  var createMultichainClient = (options) => __async(null, null, function* () {
3402
+ if (options.debug) {
3403
+ enableDebug("metamask-sdk:*");
3404
+ }
3322
3405
  const uiModules = yield Promise.resolve().then(() => (init_node(), node_exports));
3323
3406
  let storage;
3324
- if (!options.storage) {
3407
+ if (options.storage) {
3408
+ storage = options.storage;
3409
+ } else {
3325
3410
  const { StoreAdapterNode: StoreAdapterNode2 } = yield Promise.resolve().then(() => (init_node2(), node_exports2));
3326
3411
  const adapter = new StoreAdapterNode2();
3327
3412
  storage = new Store(adapter);
3328
- } else {
3329
- storage = options.storage;
3330
3413
  }
3331
3414
  const factory = new ModalFactory(uiModules);
3332
3415
  return MetaMaskConnectMultichain.create(__spreadProps(__spreadValues({}, options), {