@metamask/connect-multichain 0.4.0 → 0.5.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 (85) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/browser/es/connect-multichain.d.mts +26 -9
  3. package/dist/browser/es/connect-multichain.mjs +341 -78
  4. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  5. package/dist/browser/es/metafile-esm.json +1 -1
  6. package/dist/browser/iife/connect-multichain.d.ts +26 -9
  7. package/dist/browser/iife/connect-multichain.js +961 -151
  8. package/dist/browser/iife/connect-multichain.js.map +1 -1
  9. package/dist/browser/iife/metafile-iife.json +1 -1
  10. package/dist/browser/umd/connect-multichain.d.ts +26 -9
  11. package/dist/browser/umd/connect-multichain.js +341 -78
  12. package/dist/browser/umd/connect-multichain.js.map +1 -1
  13. package/dist/browser/umd/metafile-cjs.json +1 -1
  14. package/dist/node/cjs/connect-multichain.d.ts +26 -9
  15. package/dist/node/cjs/connect-multichain.js +342 -79
  16. package/dist/node/cjs/connect-multichain.js.map +1 -1
  17. package/dist/node/cjs/metafile-cjs.json +1 -1
  18. package/dist/node/es/connect-multichain.d.mts +26 -9
  19. package/dist/node/es/connect-multichain.mjs +341 -78
  20. package/dist/node/es/connect-multichain.mjs.map +1 -1
  21. package/dist/node/es/metafile-esm.json +1 -1
  22. package/dist/react-native/es/connect-multichain.d.mts +26 -9
  23. package/dist/react-native/es/connect-multichain.mjs +328 -69
  24. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  25. package/dist/react-native/es/metafile-esm.json +1 -1
  26. package/dist/src/domain/multichain/index.d.ts +4 -4
  27. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  28. package/dist/src/domain/multichain/index.js.map +1 -1
  29. package/dist/src/domain/multichain/types.d.ts +4 -3
  30. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  31. package/dist/src/domain/ui/types.d.ts +7 -0
  32. package/dist/src/domain/ui/types.d.ts.map +1 -1
  33. package/dist/src/domain/ui/types.js.map +1 -1
  34. package/dist/src/index.browser.d.ts +1 -1
  35. package/dist/src/index.browser.d.ts.map +1 -1
  36. package/dist/src/index.browser.js +1 -1
  37. package/dist/src/index.browser.js.map +1 -1
  38. package/dist/src/index.native.d.ts +1 -1
  39. package/dist/src/index.native.d.ts.map +1 -1
  40. package/dist/src/index.native.js +2 -2
  41. package/dist/src/index.native.js.map +1 -1
  42. package/dist/src/index.node.d.ts +1 -1
  43. package/dist/src/index.node.d.ts.map +1 -1
  44. package/dist/src/index.node.js +1 -1
  45. package/dist/src/index.node.js.map +1 -1
  46. package/dist/src/multichain/index.d.ts +6 -6
  47. package/dist/src/multichain/index.d.ts.map +1 -1
  48. package/dist/src/multichain/index.js +103 -43
  49. package/dist/src/multichain/index.js.map +1 -1
  50. package/dist/src/multichain/transports/default/index.d.ts +2 -1
  51. package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
  52. package/dist/src/multichain/transports/default/index.js +1 -0
  53. package/dist/src/multichain/transports/default/index.js.map +1 -1
  54. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +21 -0
  55. package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -0
  56. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +159 -0
  57. package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -0
  58. package/dist/src/multichain/transports/mwp/index.d.ts +4 -1
  59. package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
  60. package/dist/src/multichain/transports/mwp/index.js +54 -2
  61. package/dist/src/multichain/transports/mwp/index.js.map +1 -1
  62. package/dist/src/ui/ModalFactory.d.ts +54 -0
  63. package/dist/src/ui/ModalFactory.d.ts.map +1 -0
  64. package/dist/src/ui/ModalFactory.js +171 -0
  65. package/dist/src/ui/ModalFactory.js.map +1 -0
  66. package/dist/src/ui/index.d.ts +14 -38
  67. package/dist/src/ui/index.d.ts.map +1 -1
  68. package/dist/src/ui/index.js +24 -142
  69. package/dist/src/ui/index.js.map +1 -1
  70. package/dist/src/ui/index.native.d.ts +13 -0
  71. package/dist/src/ui/index.native.d.ts.map +1 -0
  72. package/dist/src/ui/{preload.native.js → index.native.js} +12 -6
  73. package/dist/src/ui/index.native.js.map +1 -0
  74. package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -1
  75. package/dist/src/ui/modals/base/AbstractInstallModal.js +0 -4
  76. package/dist/src/ui/modals/base/AbstractInstallModal.js.map +1 -1
  77. package/dist/types/connect-multichain.d.ts +26 -9
  78. package/package.json +4 -2
  79. package/dist/src/ui/preload.native.d.ts +0 -5
  80. package/dist/src/ui/preload.native.d.ts.map +0 -1
  81. package/dist/src/ui/preload.native.js.map +0 -1
  82. package/dist/src/ui/preload.web.d.ts +0 -5
  83. package/dist/src/ui/preload.web.d.ts.map +0 -1
  84. package/dist/src/ui/preload.web.js +0 -27
  85. package/dist/src/ui/preload.web.js.map +0 -1
@@ -73,6 +73,7 @@ var MetaMaskSDK = (() => {
73
73
  mod
74
74
  ));
75
75
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
76
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
76
77
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
77
78
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
78
79
  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);
@@ -692,19 +693,19 @@ var MetaMaskSDK = (() => {
692
693
  var eventsExports = events.exports;
693
694
  var EventEmitter$1 = /* @__PURE__ */ getDefaultExportFromCjs2(eventsExports);
694
695
  exports.errorCodes = void 0;
695
- (function(errorCodes) {
696
- errorCodes[errorCodes["timeout"] = 1] = "timeout";
697
- errorCodes[errorCodes["transportClosed"] = 2] = "transportClosed";
698
- errorCodes[errorCodes["clientDisconnected"] = 3] = "clientDisconnected";
699
- errorCodes[errorCodes["clientClosed"] = 4] = "clientClosed";
700
- errorCodes[errorCodes["clientConnectToken"] = 5] = "clientConnectToken";
701
- errorCodes[errorCodes["clientRefreshToken"] = 6] = "clientRefreshToken";
702
- errorCodes[errorCodes["subscriptionUnsubscribed"] = 7] = "subscriptionUnsubscribed";
703
- errorCodes[errorCodes["subscriptionSubscribeToken"] = 8] = "subscriptionSubscribeToken";
704
- errorCodes[errorCodes["subscriptionRefreshToken"] = 9] = "subscriptionRefreshToken";
705
- errorCodes[errorCodes["transportWriteError"] = 10] = "transportWriteError";
706
- errorCodes[errorCodes["connectionClosed"] = 11] = "connectionClosed";
707
- errorCodes[errorCodes["badConfiguration"] = 12] = "badConfiguration";
696
+ (function(errorCodes2) {
697
+ errorCodes2[errorCodes2["timeout"] = 1] = "timeout";
698
+ errorCodes2[errorCodes2["transportClosed"] = 2] = "transportClosed";
699
+ errorCodes2[errorCodes2["clientDisconnected"] = 3] = "clientDisconnected";
700
+ errorCodes2[errorCodes2["clientClosed"] = 4] = "clientClosed";
701
+ errorCodes2[errorCodes2["clientConnectToken"] = 5] = "clientConnectToken";
702
+ errorCodes2[errorCodes2["clientRefreshToken"] = 6] = "clientRefreshToken";
703
+ errorCodes2[errorCodes2["subscriptionUnsubscribed"] = 7] = "subscriptionUnsubscribed";
704
+ errorCodes2[errorCodes2["subscriptionSubscribeToken"] = 8] = "subscriptionSubscribeToken";
705
+ errorCodes2[errorCodes2["subscriptionRefreshToken"] = 9] = "subscriptionRefreshToken";
706
+ errorCodes2[errorCodes2["transportWriteError"] = 10] = "transportWriteError";
707
+ errorCodes2[errorCodes2["connectionClosed"] = 11] = "connectionClosed";
708
+ errorCodes2[errorCodes2["badConfiguration"] = 12] = "badConfiguration";
708
709
  })(exports.errorCodes || (exports.errorCodes = {}));
709
710
  exports.connectingCodes = void 0;
710
711
  (function(connectingCodes) {
@@ -6507,20 +6508,20 @@ var MetaMaskSDK = (() => {
6507
6508
  Object.defineProperty(exports, "__esModule", { value: true });
6508
6509
  exports.run = exports.toFailures = exports.toFailure = exports.shiftIterator = exports.print = exports.isPlainObject = exports.isObject = void 0;
6509
6510
  function isIterable2(value) {
6510
- return isObject2(value) && typeof value[Symbol.iterator] === "function";
6511
+ return isObject3(value) && typeof value[Symbol.iterator] === "function";
6511
6512
  }
6512
- function isObject2(value) {
6513
+ function isObject3(value) {
6513
6514
  return typeof value === "object" && value !== null;
6514
6515
  }
6515
- exports.isObject = isObject2;
6516
- function isPlainObject(value) {
6516
+ exports.isObject = isObject3;
6517
+ function isPlainObject2(value) {
6517
6518
  if (Object.prototype.toString.call(value) !== "[object Object]") {
6518
6519
  return false;
6519
6520
  }
6520
6521
  const prototype = Object.getPrototypeOf(value);
6521
6522
  return prototype === null || prototype === Object.prototype;
6522
6523
  }
6523
- exports.isPlainObject = isPlainObject;
6524
+ exports.isPlainObject = isPlainObject2;
6524
6525
  function print2(value) {
6525
6526
  if (typeof value === "symbol") {
6526
6527
  return value.toString();
@@ -6573,7 +6574,7 @@ var MetaMaskSDK = (() => {
6573
6574
  const context = { path, branch };
6574
6575
  if (coerce2) {
6575
6576
  value = struct.coercer(value, context);
6576
- if (mask2 && struct.type !== "type" && isObject2(struct.schema) && isObject2(value) && !Array.isArray(value)) {
6577
+ if (mask2 && struct.type !== "type" && isObject3(struct.schema) && isObject3(value) && !Array.isArray(value)) {
6577
6578
  for (const key in value) {
6578
6579
  if (struct.schema[key] === void 0) {
6579
6580
  delete value[key];
@@ -6607,7 +6608,7 @@ var MetaMaskSDK = (() => {
6607
6608
  value.set(innerKey, innerValue);
6608
6609
  } else if (value instanceof Set) {
6609
6610
  value.add(innerValue);
6610
- } else if (isObject2(value)) {
6611
+ } else if (isObject3(value)) {
6611
6612
  if (innerValue !== void 0 || innerKey in value) {
6612
6613
  value[innerKey] = innerValue;
6613
6614
  }
@@ -7520,10 +7521,10 @@ var MetaMaskSDK = (() => {
7520
7521
  return value === null || value === void 0;
7521
7522
  }
7522
7523
  exports.isNullOrUndefined = isNullOrUndefined;
7523
- function isObject2(value) {
7524
+ function isObject3(value) {
7524
7525
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
7525
7526
  }
7526
- exports.isObject = isObject2;
7527
+ exports.isObject = isObject3;
7527
7528
  var hasProperty2 = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
7528
7529
  exports.hasProperty = hasProperty2;
7529
7530
  function getKnownPropertyNames(object3) {
@@ -7542,7 +7543,7 @@ var MetaMaskSDK = (() => {
7542
7543
  JsonSize3[JsonSize3["Date"] = 24] = "Date";
7543
7544
  })(JsonSize2 = exports.JsonSize || (exports.JsonSize = {}));
7544
7545
  exports.ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
7545
- function isPlainObject(value) {
7546
+ function isPlainObject2(value) {
7546
7547
  if (typeof value !== "object" || value === null) {
7547
7548
  return false;
7548
7549
  }
@@ -7556,7 +7557,7 @@ var MetaMaskSDK = (() => {
7556
7557
  return false;
7557
7558
  }
7558
7559
  }
7559
- exports.isPlainObject = isPlainObject;
7560
+ exports.isPlainObject = isPlainObject2;
7560
7561
  function isASCII(character) {
7561
7562
  return character.charCodeAt(0) <= 127;
7562
7563
  }
@@ -9377,19 +9378,19 @@ var MetaMaskSDK = (() => {
9377
9378
  return propValue;
9378
9379
  }));
9379
9380
  });
9380
- function isValidJson(value) {
9381
+ function isValidJson2(value) {
9381
9382
  try {
9382
- getSafeJson(value);
9383
+ getSafeJson2(value);
9383
9384
  return true;
9384
9385
  } catch (e) {
9385
9386
  return false;
9386
9387
  }
9387
9388
  }
9388
- exports.isValidJson = isValidJson;
9389
- function getSafeJson(value) {
9389
+ exports.isValidJson = isValidJson2;
9390
+ function getSafeJson2(value) {
9390
9391
  return (0, superstruct_1.create)(value, exports.JsonStruct);
9391
9392
  }
9392
- exports.getSafeJson = getSafeJson;
9393
+ exports.getSafeJson = getSafeJson2;
9393
9394
  function getJsonSize(value) {
9394
9395
  (0, assert_1.assertStruct)(value, exports.JsonStruct, "Invalid JSON value");
9395
9396
  const json = JSON.stringify(value);
@@ -9485,10 +9486,10 @@ var MetaMaskSDK = (() => {
9485
9486
  (0, assert_1.assertStruct)(value, exports.JsonRpcFailureStruct, "Invalid JSON-RPC failure response", ErrorWrapper);
9486
9487
  }
9487
9488
  exports.assertIsJsonRpcFailure = assertIsJsonRpcFailure;
9488
- function isJsonRpcError(value) {
9489
+ function isJsonRpcError2(value) {
9489
9490
  return (0, superstruct_1.is)(value, exports.JsonRpcErrorStruct);
9490
9491
  }
9491
- exports.isJsonRpcError = isJsonRpcError;
9492
+ exports.isJsonRpcError = isJsonRpcError2;
9492
9493
  function assertIsJsonRpcError(value, ErrorWrapper) {
9493
9494
  (0, assert_1.assertStruct)(value, exports.JsonRpcErrorStruct, "Invalid JSON-RPC error", ErrorWrapper);
9494
9495
  }
@@ -18365,6 +18366,23 @@ var MetaMaskSDK = (() => {
18365
18366
  });
18366
18367
 
18367
18368
  // ../../node_modules/@metamask/utils/dist/misc.mjs
18369
+ function isObject2(value) {
18370
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
18371
+ }
18372
+ function isPlainObject(value) {
18373
+ if (typeof value !== "object" || value === null) {
18374
+ return false;
18375
+ }
18376
+ try {
18377
+ let proto = value;
18378
+ while (Object.getPrototypeOf(proto) !== null) {
18379
+ proto = Object.getPrototypeOf(proto);
18380
+ }
18381
+ return Object.getPrototypeOf(value) === proto;
18382
+ } catch (_) {
18383
+ return false;
18384
+ }
18385
+ }
18368
18386
  var hasProperty, JsonSize;
18369
18387
  var init_misc = __esm({
18370
18388
  "../../node_modules/@metamask/utils/dist/misc.mjs"() {
@@ -19445,7 +19463,7 @@ var MetaMaskSDK = (() => {
19445
19463
  var coreJsData = context["__core-js_shared__"];
19446
19464
  var funcToString = funcProto.toString;
19447
19465
  var hasOwnProperty = objectProto.hasOwnProperty;
19448
- var idCounter2 = 0;
19466
+ var idCounter3 = 0;
19449
19467
  var maskSrcKey = (function() {
19450
19468
  var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
19451
19469
  return uid ? "Symbol(src)_1." + uid : "";
@@ -19487,7 +19505,7 @@ var MetaMaskSDK = (() => {
19487
19505
  function object3() {
19488
19506
  }
19489
19507
  return function(proto) {
19490
- if (!isObject2(proto)) {
19508
+ if (!isObject3(proto)) {
19491
19509
  return {};
19492
19510
  }
19493
19511
  if (objectCreate) {
@@ -19889,7 +19907,7 @@ var MetaMaskSDK = (() => {
19889
19907
  if (result2 !== undefined2) {
19890
19908
  return result2;
19891
19909
  }
19892
- if (!isObject2(value)) {
19910
+ if (!isObject3(value)) {
19893
19911
  return value;
19894
19912
  }
19895
19913
  var isArr = isArray(value);
@@ -20236,7 +20254,7 @@ var MetaMaskSDK = (() => {
20236
20254
  return true;
20237
20255
  }
20238
20256
  function baseIsNative(value) {
20239
- if (!isObject2(value) || isMasked(value)) {
20257
+ if (!isObject3(value) || isMasked(value)) {
20240
20258
  return false;
20241
20259
  }
20242
20260
  var pattern2 = isFunction(value) ? reIsNative : reIsHostCtor;
@@ -20276,7 +20294,7 @@ var MetaMaskSDK = (() => {
20276
20294
  return result2;
20277
20295
  }
20278
20296
  function baseKeysIn(object3) {
20279
- if (!isObject2(object3)) {
20297
+ if (!isObject3(object3)) {
20280
20298
  return nativeKeysIn(object3);
20281
20299
  }
20282
20300
  var isProto = isPrototype(object3), result2 = [];
@@ -20321,7 +20339,7 @@ var MetaMaskSDK = (() => {
20321
20339
  }
20322
20340
  baseFor(source, function(srcValue, key) {
20323
20341
  stack || (stack = new Stack());
20324
- if (isObject2(srcValue)) {
20342
+ if (isObject3(srcValue)) {
20325
20343
  baseMergeDeep(object3, source, key, srcIndex, baseMerge, customizer, stack);
20326
20344
  } else {
20327
20345
  var newValue = customizer ? customizer(safeGet(object3, key), srcValue, key + "", object3, source, stack) : undefined2;
@@ -20357,11 +20375,11 @@ var MetaMaskSDK = (() => {
20357
20375
  } else {
20358
20376
  newValue = [];
20359
20377
  }
20360
- } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
20378
+ } else if (isPlainObject2(srcValue) || isArguments(srcValue)) {
20361
20379
  newValue = objValue;
20362
20380
  if (isArguments(objValue)) {
20363
20381
  newValue = toPlainObject(objValue);
20364
- } else if (!isObject2(objValue) || isFunction(objValue)) {
20382
+ } else if (!isObject3(objValue) || isFunction(objValue)) {
20365
20383
  newValue = initCloneObject(srcValue);
20366
20384
  }
20367
20385
  } else {
@@ -20500,7 +20518,7 @@ var MetaMaskSDK = (() => {
20500
20518
  return shuffleSelf(array2, baseClamp(n, 0, array2.length));
20501
20519
  }
20502
20520
  function baseSet(object3, path, value, customizer) {
20503
- if (!isObject2(object3)) {
20521
+ if (!isObject3(object3)) {
20504
20522
  return object3;
20505
20523
  }
20506
20524
  path = castPath(path, object3);
@@ -20514,7 +20532,7 @@ var MetaMaskSDK = (() => {
20514
20532
  var objValue = nested[key];
20515
20533
  newValue = customizer ? customizer(objValue, key, nested) : undefined2;
20516
20534
  if (newValue === undefined2) {
20517
- newValue = isObject2(objValue) ? objValue : isIndex(path[index + 1]) ? [] : {};
20535
+ newValue = isObject3(objValue) ? objValue : isIndex(path[index + 1]) ? [] : {};
20518
20536
  }
20519
20537
  }
20520
20538
  assignValue(nested, key, newValue);
@@ -20964,7 +20982,7 @@ var MetaMaskSDK = (() => {
20964
20982
  return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
20965
20983
  }
20966
20984
  var thisBinding = baseCreate(Ctor.prototype), result2 = Ctor.apply(thisBinding, args);
20967
- return isObject2(result2) ? result2 : thisBinding;
20985
+ return isObject3(result2) ? result2 : thisBinding;
20968
20986
  };
20969
20987
  }
20970
20988
  function createCurry(func, bitmask, arity) {
@@ -21300,7 +21318,7 @@ var MetaMaskSDK = (() => {
21300
21318
  return objValue;
21301
21319
  }
21302
21320
  function customDefaultsMerge(objValue, srcValue, key, object3, source, stack) {
21303
- if (isObject2(objValue) && isObject2(srcValue)) {
21321
+ if (isObject3(objValue) && isObject3(srcValue)) {
21304
21322
  stack.set(srcValue, objValue);
21305
21323
  baseMerge(objValue, srcValue, undefined2, customDefaultsMerge, stack);
21306
21324
  stack["delete"](srcValue);
@@ -21308,7 +21326,7 @@ var MetaMaskSDK = (() => {
21308
21326
  return objValue;
21309
21327
  }
21310
21328
  function customOmitClone(value) {
21311
- return isPlainObject(value) ? undefined2 : value;
21329
+ return isPlainObject2(value) ? undefined2 : value;
21312
21330
  }
21313
21331
  function equalArrays(array2, other, bitmask, customizer, equalFunc, stack) {
21314
21332
  var isPartial = bitmask & COMPARE_PARTIAL_FLAG, arrLength = array2.length, othLength = other.length;
@@ -21648,7 +21666,7 @@ var MetaMaskSDK = (() => {
21648
21666
  return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
21649
21667
  }
21650
21668
  function isIterateeCall(value, index, object3) {
21651
- if (!isObject2(object3)) {
21669
+ if (!isObject3(object3)) {
21652
21670
  return false;
21653
21671
  }
21654
21672
  var type = typeof index;
@@ -21691,7 +21709,7 @@ var MetaMaskSDK = (() => {
21691
21709
  return value === proto;
21692
21710
  }
21693
21711
  function isStrictComparable(value) {
21694
- return value === value && !isObject2(value);
21712
+ return value === value && !isObject3(value);
21695
21713
  }
21696
21714
  function matchesStrictComparable(key, srcValue) {
21697
21715
  return function(object3) {
@@ -22573,7 +22591,7 @@ var MetaMaskSDK = (() => {
22573
22591
  throw new TypeError2(FUNC_ERROR_TEXT);
22574
22592
  }
22575
22593
  wait = toNumber(wait) || 0;
22576
- if (isObject2(options)) {
22594
+ if (isObject3(options)) {
22577
22595
  leading = !!options.leading;
22578
22596
  maxing = "maxWait" in options;
22579
22597
  maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
@@ -22743,7 +22761,7 @@ var MetaMaskSDK = (() => {
22743
22761
  if (typeof func != "function") {
22744
22762
  throw new TypeError2(FUNC_ERROR_TEXT);
22745
22763
  }
22746
- if (isObject2(options)) {
22764
+ if (isObject3(options)) {
22747
22765
  leading = "leading" in options ? !!options.leading : leading;
22748
22766
  trailing = "trailing" in options ? !!options.trailing : trailing;
22749
22767
  }
@@ -22809,7 +22827,7 @@ var MetaMaskSDK = (() => {
22809
22827
  var isBuffer = nativeIsBuffer || stubFalse;
22810
22828
  var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
22811
22829
  function isElement(value) {
22812
- return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
22830
+ return isObjectLike(value) && value.nodeType === 1 && !isPlainObject2(value);
22813
22831
  }
22814
22832
  function isEmpty(value) {
22815
22833
  if (value == null) {
@@ -22845,13 +22863,13 @@ var MetaMaskSDK = (() => {
22845
22863
  return false;
22846
22864
  }
22847
22865
  var tag = baseGetTag(value);
22848
- return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
22866
+ return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject2(value);
22849
22867
  }
22850
22868
  function isFinite2(value) {
22851
22869
  return typeof value == "number" && nativeIsFinite(value);
22852
22870
  }
22853
22871
  function isFunction(value) {
22854
- if (!isObject2(value)) {
22872
+ if (!isObject3(value)) {
22855
22873
  return false;
22856
22874
  }
22857
22875
  var tag = baseGetTag(value);
@@ -22863,7 +22881,7 @@ var MetaMaskSDK = (() => {
22863
22881
  function isLength(value) {
22864
22882
  return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
22865
22883
  }
22866
- function isObject2(value) {
22884
+ function isObject3(value) {
22867
22885
  var type = typeof value;
22868
22886
  return value != null && (type == "object" || type == "function");
22869
22887
  }
@@ -22896,7 +22914,7 @@ var MetaMaskSDK = (() => {
22896
22914
  function isNumber(value) {
22897
22915
  return typeof value == "number" || isObjectLike(value) && baseGetTag(value) == numberTag;
22898
22916
  }
22899
- function isPlainObject(value) {
22917
+ function isPlainObject2(value) {
22900
22918
  if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
22901
22919
  return false;
22902
22920
  }
@@ -22970,9 +22988,9 @@ var MetaMaskSDK = (() => {
22970
22988
  if (isSymbol(value)) {
22971
22989
  return NAN;
22972
22990
  }
22973
- if (isObject2(value)) {
22991
+ if (isObject3(value)) {
22974
22992
  var other = typeof value.valueOf == "function" ? value.valueOf() : value;
22975
- value = isObject2(other) ? other + "" : other;
22993
+ value = isObject3(other) ? other + "" : other;
22976
22994
  }
22977
22995
  if (typeof value != "string") {
22978
22996
  return value === 0 ? value : +value;
@@ -23193,7 +23211,7 @@ var MetaMaskSDK = (() => {
23193
23211
  var Ctor = object3 && object3.constructor;
23194
23212
  if (isArrLike) {
23195
23213
  accumulator = isArr ? new Ctor() : [];
23196
- } else if (isObject2(object3)) {
23214
+ } else if (isObject3(object3)) {
23197
23215
  accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object3)) : {};
23198
23216
  } else {
23199
23217
  accumulator = {};
@@ -23478,7 +23496,7 @@ var MetaMaskSDK = (() => {
23478
23496
  }
23479
23497
  function truncate(string2, options) {
23480
23498
  var length = DEFAULT_TRUNC_LENGTH, omission = DEFAULT_TRUNC_OMISSION;
23481
- if (isObject2(options)) {
23499
+ if (isObject3(options)) {
23482
23500
  var separator = "separator" in options ? options.separator : separator;
23483
23501
  length = "length" in options ? toInteger(options.length) : length;
23484
23502
  omission = "omission" in options ? baseToString(options.omission) : omission;
@@ -23608,13 +23626,13 @@ var MetaMaskSDK = (() => {
23608
23626
  });
23609
23627
  function mixin(object3, source, options) {
23610
23628
  var props = keys(source), methodNames = baseFunctions(source, props);
23611
- if (options == null && !(isObject2(source) && (methodNames.length || !props.length))) {
23629
+ if (options == null && !(isObject3(source) && (methodNames.length || !props.length))) {
23612
23630
  options = source;
23613
23631
  source = object3;
23614
23632
  object3 = this;
23615
23633
  methodNames = baseFunctions(source, keys(source));
23616
23634
  }
23617
- var chain2 = !(isObject2(options) && "chain" in options) || !!options.chain, isFunc = isFunction(object3);
23635
+ var chain2 = !(isObject3(options) && "chain" in options) || !!options.chain, isFunc = isFunction(object3);
23618
23636
  arrayEach(methodNames, function(methodName) {
23619
23637
  var func = source[methodName];
23620
23638
  object3[methodName] = func;
@@ -23696,7 +23714,7 @@ var MetaMaskSDK = (() => {
23696
23714
  return isSymbol(value) ? [value] : copyArray(stringToPath(toString2(value)));
23697
23715
  }
23698
23716
  function uniqueId(prefix) {
23699
- var id = ++idCounter2;
23717
+ var id = ++idCounter3;
23700
23718
  return toString2(prefix) + id;
23701
23719
  }
23702
23720
  var add = createMathOperation(function(augend, addend) {
@@ -23960,9 +23978,9 @@ var MetaMaskSDK = (() => {
23960
23978
  lodash.isNil = isNil;
23961
23979
  lodash.isNull = isNull;
23962
23980
  lodash.isNumber = isNumber;
23963
- lodash.isObject = isObject2;
23981
+ lodash.isObject = isObject3;
23964
23982
  lodash.isObjectLike = isObjectLike;
23965
- lodash.isPlainObject = isPlainObject;
23983
+ lodash.isPlainObject = isPlainObject2;
23966
23984
  lodash.isRegExp = isRegExp;
23967
23985
  lodash.isSafeInteger = isSafeInteger;
23968
23986
  lodash.isSet = isSet;
@@ -24605,6 +24623,17 @@ var MetaMaskSDK = (() => {
24605
24623
  }
24606
24624
  return false;
24607
24625
  }
24626
+ function isValidJson(value) {
24627
+ try {
24628
+ getSafeJson(value);
24629
+ return true;
24630
+ } catch (e) {
24631
+ return false;
24632
+ }
24633
+ }
24634
+ function getSafeJson(value) {
24635
+ return create(value, JsonStruct);
24636
+ }
24608
24637
  var object2, UnsafeJsonStruct, JsonStruct, jsonrpc2, JsonRpcVersionStruct, JsonRpcIdStruct, JsonRpcErrorStruct, JsonRpcParamsStruct, JsonRpcRequestStruct, JsonRpcNotificationStruct, PendingJsonRpcResponseStruct, JsonRpcSuccessStruct, JsonRpcFailureStruct, JsonRpcResponseStruct;
24609
24638
  var init_json = __esm({
24610
24639
  "../../node_modules/@metamask/utils/dist/json.mjs"() {
@@ -32598,6 +32627,201 @@ var MetaMaskSDK = (() => {
32598
32627
  }
32599
32628
  });
32600
32629
 
32630
+ // ../../node_modules/fast-safe-stringify/index.js
32631
+ var require_fast_safe_stringify = __commonJS({
32632
+ "../../node_modules/fast-safe-stringify/index.js"(exports, module) {
32633
+ "use strict";
32634
+ module.exports = stringify;
32635
+ stringify.default = stringify;
32636
+ stringify.stable = deterministicStringify;
32637
+ stringify.stableStringify = deterministicStringify;
32638
+ var LIMIT_REPLACE_NODE = "[...]";
32639
+ var CIRCULAR_REPLACE_NODE = "[Circular]";
32640
+ var arr = [];
32641
+ var replacerStack = [];
32642
+ function defaultOptions() {
32643
+ return {
32644
+ depthLimit: Number.MAX_SAFE_INTEGER,
32645
+ edgesLimit: Number.MAX_SAFE_INTEGER
32646
+ };
32647
+ }
32648
+ function stringify(obj, replacer, spacer, options) {
32649
+ if (typeof options === "undefined") {
32650
+ options = defaultOptions();
32651
+ }
32652
+ decirc(obj, "", 0, [], void 0, 0, options);
32653
+ var res;
32654
+ try {
32655
+ if (replacerStack.length === 0) {
32656
+ res = JSON.stringify(obj, replacer, spacer);
32657
+ } else {
32658
+ res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
32659
+ }
32660
+ } catch (_) {
32661
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
32662
+ } finally {
32663
+ while (arr.length !== 0) {
32664
+ var part = arr.pop();
32665
+ if (part.length === 4) {
32666
+ Object.defineProperty(part[0], part[1], part[3]);
32667
+ } else {
32668
+ part[0][part[1]] = part[2];
32669
+ }
32670
+ }
32671
+ }
32672
+ return res;
32673
+ }
32674
+ function setReplace(replace, val, k, parent) {
32675
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
32676
+ if (propertyDescriptor.get !== void 0) {
32677
+ if (propertyDescriptor.configurable) {
32678
+ Object.defineProperty(parent, k, { value: replace });
32679
+ arr.push([parent, k, val, propertyDescriptor]);
32680
+ } else {
32681
+ replacerStack.push([val, k, replace]);
32682
+ }
32683
+ } else {
32684
+ parent[k] = replace;
32685
+ arr.push([parent, k, val]);
32686
+ }
32687
+ }
32688
+ function decirc(val, k, edgeIndex, stack, parent, depth, options) {
32689
+ depth += 1;
32690
+ var i;
32691
+ if (typeof val === "object" && val !== null) {
32692
+ for (i = 0; i < stack.length; i++) {
32693
+ if (stack[i] === val) {
32694
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
32695
+ return;
32696
+ }
32697
+ }
32698
+ if (typeof options.depthLimit !== "undefined" && depth > options.depthLimit) {
32699
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
32700
+ return;
32701
+ }
32702
+ if (typeof options.edgesLimit !== "undefined" && edgeIndex + 1 > options.edgesLimit) {
32703
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
32704
+ return;
32705
+ }
32706
+ stack.push(val);
32707
+ if (Array.isArray(val)) {
32708
+ for (i = 0; i < val.length; i++) {
32709
+ decirc(val[i], i, i, stack, val, depth, options);
32710
+ }
32711
+ } else {
32712
+ var keys = Object.keys(val);
32713
+ for (i = 0; i < keys.length; i++) {
32714
+ var key = keys[i];
32715
+ decirc(val[key], key, i, stack, val, depth, options);
32716
+ }
32717
+ }
32718
+ stack.pop();
32719
+ }
32720
+ }
32721
+ function compareFunction(a, b) {
32722
+ if (a < b) {
32723
+ return -1;
32724
+ }
32725
+ if (a > b) {
32726
+ return 1;
32727
+ }
32728
+ return 0;
32729
+ }
32730
+ function deterministicStringify(obj, replacer, spacer, options) {
32731
+ if (typeof options === "undefined") {
32732
+ options = defaultOptions();
32733
+ }
32734
+ var tmp = deterministicDecirc(obj, "", 0, [], void 0, 0, options) || obj;
32735
+ var res;
32736
+ try {
32737
+ if (replacerStack.length === 0) {
32738
+ res = JSON.stringify(tmp, replacer, spacer);
32739
+ } else {
32740
+ res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
32741
+ }
32742
+ } catch (_) {
32743
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
32744
+ } finally {
32745
+ while (arr.length !== 0) {
32746
+ var part = arr.pop();
32747
+ if (part.length === 4) {
32748
+ Object.defineProperty(part[0], part[1], part[3]);
32749
+ } else {
32750
+ part[0][part[1]] = part[2];
32751
+ }
32752
+ }
32753
+ }
32754
+ return res;
32755
+ }
32756
+ function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
32757
+ depth += 1;
32758
+ var i;
32759
+ if (typeof val === "object" && val !== null) {
32760
+ for (i = 0; i < stack.length; i++) {
32761
+ if (stack[i] === val) {
32762
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
32763
+ return;
32764
+ }
32765
+ }
32766
+ try {
32767
+ if (typeof val.toJSON === "function") {
32768
+ return;
32769
+ }
32770
+ } catch (_) {
32771
+ return;
32772
+ }
32773
+ if (typeof options.depthLimit !== "undefined" && depth > options.depthLimit) {
32774
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
32775
+ return;
32776
+ }
32777
+ if (typeof options.edgesLimit !== "undefined" && edgeIndex + 1 > options.edgesLimit) {
32778
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
32779
+ return;
32780
+ }
32781
+ stack.push(val);
32782
+ if (Array.isArray(val)) {
32783
+ for (i = 0; i < val.length; i++) {
32784
+ deterministicDecirc(val[i], i, i, stack, val, depth, options);
32785
+ }
32786
+ } else {
32787
+ var tmp = {};
32788
+ var keys = Object.keys(val).sort(compareFunction);
32789
+ for (i = 0; i < keys.length; i++) {
32790
+ var key = keys[i];
32791
+ deterministicDecirc(val[key], key, i, stack, val, depth, options);
32792
+ tmp[key] = val[key];
32793
+ }
32794
+ if (typeof parent !== "undefined") {
32795
+ arr.push([parent, k, val]);
32796
+ parent[k] = tmp;
32797
+ } else {
32798
+ return tmp;
32799
+ }
32800
+ }
32801
+ stack.pop();
32802
+ }
32803
+ }
32804
+ function replaceGetterValues(replacer) {
32805
+ replacer = typeof replacer !== "undefined" ? replacer : function(k, v) {
32806
+ return v;
32807
+ };
32808
+ return function(key, val) {
32809
+ if (replacerStack.length > 0) {
32810
+ for (var i = 0; i < replacerStack.length; i++) {
32811
+ var part = replacerStack[i];
32812
+ if (part[1] === key && part[0] === val) {
32813
+ val = part[2];
32814
+ replacerStack.splice(i, 1);
32815
+ break;
32816
+ }
32817
+ }
32818
+ }
32819
+ return replacer.call(this, key, val);
32820
+ };
32821
+ }
32822
+ }
32823
+ });
32824
+
32601
32825
  // ../../node_modules/ws/browser.js
32602
32826
  var require_browser2 = __commonJS({
32603
32827
  "../../node_modules/ws/browser.js"(exports, module) {
@@ -35459,11 +35683,6 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
35459
35683
  `[UI: InstallModal-nodejs()] \u274C Error generating new QR code: ${error}`
35460
35684
  );
35461
35685
  }
35462
- } else {
35463
- const generateQRCode = yield this.options.generateQRCode(
35464
- currentConnectionRequest
35465
- );
35466
- this.renderQRCode(generateQRCode, currentConnectionRequest);
35467
35686
  }
35468
35687
  }), 1e3);
35469
35688
  }
@@ -35693,7 +35912,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
35693
35912
  StoreClient: () => StoreClient,
35694
35913
  TransportType: () => TransportType,
35695
35914
  createLogger: () => createLogger,
35696
- createMetamaskConnect: () => createMetamaskConnect,
35915
+ createMultichainClient: () => createMultichainClient,
35697
35916
  enableDebug: () => enableDebug,
35698
35917
  getInfuraRpcUrls: () => getInfuraRpcUrls,
35699
35918
  getPlatformType: () => getPlatformType,
@@ -36189,13 +36408,17 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
36189
36408
  return url;
36190
36409
  }
36191
36410
 
36192
- // ../analytics/src/sender.ts
36411
+ // ../analytics/dist/index.mjs
36193
36412
  var Sender = class {
36194
36413
  constructor(options) {
36195
- this.batch = [];
36196
- this.maxTimeoutMs = 3e4;
36197
- this.timeoutId = null;
36198
- this.isSending = false;
36414
+ __publicField(this, "sendFn");
36415
+ __publicField(this, "batch", []);
36416
+ __publicField(this, "batchSize");
36417
+ __publicField(this, "baseTimeoutMs");
36418
+ __publicField(this, "currentTimeoutMs");
36419
+ __publicField(this, "maxTimeoutMs", 3e4);
36420
+ __publicField(this, "timeoutId", null);
36421
+ __publicField(this, "isSending", false);
36199
36422
  this.batchSize = options.batchSize;
36200
36423
  this.baseTimeoutMs = options.baseTimeoutMs;
36201
36424
  this.currentTimeoutMs = options.baseTimeoutMs;
@@ -36239,12 +36462,11 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
36239
36462
  }
36240
36463
  };
36241
36464
  var sender_default = Sender;
36242
-
36243
- // ../analytics/src/analytics.ts
36244
36465
  var Analytics = class {
36245
36466
  constructor(baseUrl) {
36246
- this.enabled = false;
36247
- this.properties = {};
36467
+ __publicField(this, "enabled", false);
36468
+ __publicField(this, "sender");
36469
+ __publicField(this, "properties", {});
36248
36470
  const client2 = createClient({ baseUrl });
36249
36471
  const sendFn = (batch) => __async(null, null, function* () {
36250
36472
  const res = yield client2.POST("/v2/events", { body: batch });
@@ -36273,8 +36495,6 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
36273
36495
  }
36274
36496
  };
36275
36497
  var analytics_default = Analytics;
36276
-
36277
- // ../analytics/src/index.ts
36278
36498
  var endpoint;
36279
36499
  var _a;
36280
36500
  if (typeof process !== "undefined" && process.env) {
@@ -37026,7 +37246,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37026
37246
  getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
37027
37247
  );
37028
37248
  const createSessionParams = {
37029
- optionalScopes
37249
+ optionalScopes,
37250
+ sessionProperties: options == null ? void 0 : options.sessionProperties
37030
37251
  };
37031
37252
  const response = yield this.request(
37032
37253
  { method: "wallet_createSession", params: createSessionParams },
@@ -37165,6 +37386,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37165
37386
  var DEFAULT_REQUEST_TIMEOUT3 = 60 * 1e3;
37166
37387
  var CONNECTION_GRACE_PERIOD = 60 * 1e3;
37167
37388
  var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT3 + CONNECTION_GRACE_PERIOD;
37389
+ var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
37168
37390
  var SESSION_STORE_KEY = "cache_wallet_getSession";
37169
37391
  var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
37170
37392
  var CHAIN_STORE_KEY = "cache_eth_chainId";
@@ -37181,7 +37403,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37181
37403
  var MWPTransport = class {
37182
37404
  constructor(dappClient, kvstore, options = {
37183
37405
  requestTimeout: DEFAULT_REQUEST_TIMEOUT3,
37184
- connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
37406
+ connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
37407
+ resumeTimeout: DEFAULT_RESUME_TIMEOUT
37185
37408
  }) {
37186
37409
  this.dappClient = dappClient;
37187
37410
  this.kvstore = kvstore;
@@ -37256,6 +37479,13 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37256
37479
  )
37257
37480
  );
37258
37481
  }
37482
+ if (message.data.method === "wallet_sessionChanged") {
37483
+ const notification = message.data;
37484
+ const response = {
37485
+ result: notification.params
37486
+ };
37487
+ this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
37488
+ }
37259
37489
  this.notifyCallbacks(message.data);
37260
37490
  }
37261
37491
  }
@@ -37265,6 +37495,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37265
37495
  return __async(this, null, function* () {
37266
37496
  var _a3, _b, _c, _d, _e, _f, _g;
37267
37497
  try {
37498
+ yield this.waitForWalletSessionIfNotCached();
37268
37499
  const sessionRequest = yield this.request({
37269
37500
  method: "wallet_getSession"
37270
37501
  });
@@ -37369,7 +37600,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37369
37600
  }
37370
37601
  let timeout;
37371
37602
  let initialConnectionMessageHandler;
37372
- const connectionPromise = new Promise((resolve, reject) => {
37603
+ const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
37373
37604
  let connection;
37374
37605
  if (session) {
37375
37606
  connection = new Promise((resumeResolve, resumeReject) => {
@@ -37392,7 +37623,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37392
37623
  getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
37393
37624
  );
37394
37625
  const sessionRequest = {
37395
- optionalScopes
37626
+ optionalScopes,
37627
+ sessionProperties: options == null ? void 0 : options.sessionProperties
37396
37628
  };
37397
37629
  const request2 = {
37398
37630
  jsonrpc: "2.0",
@@ -37447,7 +37679,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37447
37679
  reject(new TransportTimeoutError());
37448
37680
  }, this.options.connectionTimeout);
37449
37681
  connection.then(resolve).catch(reject);
37450
- });
37682
+ }));
37451
37683
  return connectionPromise.catch((error) => {
37452
37684
  throw error;
37453
37685
  }).finally(() => {
@@ -37632,6 +37864,43 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37632
37864
  }
37633
37865
  });
37634
37866
  }
37867
+ // This method checks if an existing CAIP session response is cached or waits for one
37868
+ // to be received from the wallet if not cached. This is necessary because there is an edge
37869
+ // case during the initial connection flow where after the user has accepted the permission approval
37870
+ // and returned back to the dapp from the wallet, the dapp page may have gotten unloaded and refreshed.
37871
+ // When it is unloaded and refreshed, it will try to resume the session by making a request for wallet_getSession
37872
+ // which should resolve from cache, but because a race condition makes it possible for the response from the wallet
37873
+ // for the initial wallet_createSession connection request to not have been handled and cached yet. This results
37874
+ // in the wallet_getSession request never resolving unless we wait for it explicitly as done in this method.
37875
+ waitForWalletSessionIfNotCached() {
37876
+ return __async(this, null, function* () {
37877
+ const cachedWalletGetSessionResponse = yield this.kvstore.get(SESSION_STORE_KEY);
37878
+ if (cachedWalletGetSessionResponse) {
37879
+ return;
37880
+ }
37881
+ let unsubscribe;
37882
+ const responsePromise = new Promise((resolve) => {
37883
+ unsubscribe = this.onNotification((message) => {
37884
+ if (typeof message === "object" && message !== null) {
37885
+ if ("data" in message) {
37886
+ const messagePayload = message.data;
37887
+ if (messagePayload.method === "wallet_getSession" || messagePayload.method === "wallet_sessionChanged") {
37888
+ unsubscribe();
37889
+ resolve();
37890
+ }
37891
+ }
37892
+ }
37893
+ });
37894
+ });
37895
+ const timeoutPromise = new Promise((_resolve, reject) => {
37896
+ setTimeout(() => {
37897
+ unsubscribe();
37898
+ reject(new TransportTimeoutError());
37899
+ }, this.options.resumeTimeout);
37900
+ });
37901
+ return Promise.race([responsePromise, timeoutPromise]);
37902
+ });
37903
+ }
37635
37904
  };
37636
37905
 
37637
37906
  // src/multichain/transports/mwp/KeyManager.ts
@@ -37663,8 +37932,488 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37663
37932
 
37664
37933
  // src/multichain/index.ts
37665
37934
  init_utils3();
37935
+
37936
+ // ../../node_modules/@metamask/rpc-errors/dist/classes.mjs
37937
+ init_dist2();
37938
+ var import_fast_safe_stringify = __toESM(require_fast_safe_stringify(), 1);
37939
+
37940
+ // ../../node_modules/@metamask/rpc-errors/dist/utils.mjs
37941
+ init_dist2();
37942
+
37943
+ // ../../node_modules/@metamask/rpc-errors/dist/error-constants.mjs
37944
+ var errorCodes = {
37945
+ rpc: {
37946
+ invalidInput: -32e3,
37947
+ resourceNotFound: -32001,
37948
+ resourceUnavailable: -32002,
37949
+ transactionRejected: -32003,
37950
+ methodNotSupported: -32004,
37951
+ limitExceeded: -32005,
37952
+ parse: -32700,
37953
+ invalidRequest: -32600,
37954
+ methodNotFound: -32601,
37955
+ invalidParams: -32602,
37956
+ internal: -32603
37957
+ },
37958
+ provider: {
37959
+ userRejectedRequest: 4001,
37960
+ unauthorized: 4100,
37961
+ unsupportedMethod: 4200,
37962
+ disconnected: 4900,
37963
+ chainDisconnected: 4901
37964
+ }
37965
+ };
37966
+ var errorValues = {
37967
+ "-32700": {
37968
+ standard: "JSON RPC 2.0",
37969
+ message: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
37970
+ },
37971
+ "-32600": {
37972
+ standard: "JSON RPC 2.0",
37973
+ message: "The JSON sent is not a valid Request object."
37974
+ },
37975
+ "-32601": {
37976
+ standard: "JSON RPC 2.0",
37977
+ message: "The method does not exist / is not available."
37978
+ },
37979
+ "-32602": {
37980
+ standard: "JSON RPC 2.0",
37981
+ message: "Invalid method parameter(s)."
37982
+ },
37983
+ "-32603": {
37984
+ standard: "JSON RPC 2.0",
37985
+ message: "Internal JSON-RPC error."
37986
+ },
37987
+ "-32000": {
37988
+ standard: "EIP-1474",
37989
+ message: "Invalid input."
37990
+ },
37991
+ "-32001": {
37992
+ standard: "EIP-1474",
37993
+ message: "Resource not found."
37994
+ },
37995
+ "-32002": {
37996
+ standard: "EIP-1474",
37997
+ message: "Resource unavailable."
37998
+ },
37999
+ "-32003": {
38000
+ standard: "EIP-1474",
38001
+ message: "Transaction rejected."
38002
+ },
38003
+ "-32004": {
38004
+ standard: "EIP-1474",
38005
+ message: "Method not supported."
38006
+ },
38007
+ "-32005": {
38008
+ standard: "EIP-1474",
38009
+ message: "Request limit exceeded."
38010
+ },
38011
+ "4001": {
38012
+ standard: "EIP-1193",
38013
+ message: "User rejected the request."
38014
+ },
38015
+ "4100": {
38016
+ standard: "EIP-1193",
38017
+ message: "The requested account and/or method has not been authorized by the user."
38018
+ },
38019
+ "4200": {
38020
+ standard: "EIP-1193",
38021
+ message: "The requested method is not supported by this Ethereum provider."
38022
+ },
38023
+ "4900": {
38024
+ standard: "EIP-1193",
38025
+ message: "The provider is disconnected from all chains."
38026
+ },
38027
+ "4901": {
38028
+ standard: "EIP-1193",
38029
+ message: "The provider is disconnected from the specified chain."
38030
+ }
38031
+ };
38032
+
38033
+ // ../../node_modules/@metamask/rpc-errors/dist/utils.mjs
38034
+ var FALLBACK_ERROR_CODE = errorCodes.rpc.internal;
38035
+ var FALLBACK_MESSAGE = "Unspecified error message. This is a bug, please report it.";
38036
+ var FALLBACK_ERROR = {
38037
+ code: FALLBACK_ERROR_CODE,
38038
+ message: getMessageFromCode(FALLBACK_ERROR_CODE)
38039
+ };
38040
+ var JSON_RPC_SERVER_ERROR_MESSAGE = "Unspecified server error.";
38041
+ function getMessageFromCode(code, fallbackMessage = FALLBACK_MESSAGE) {
38042
+ if (isValidCode(code)) {
38043
+ const codeString = code.toString();
38044
+ if (hasProperty(errorValues, codeString)) {
38045
+ return errorValues[codeString].message;
38046
+ }
38047
+ if (isJsonRpcServerError(code)) {
38048
+ return JSON_RPC_SERVER_ERROR_MESSAGE;
38049
+ }
38050
+ }
38051
+ return fallbackMessage;
38052
+ }
38053
+ function isValidCode(code) {
38054
+ return Number.isInteger(code);
38055
+ }
38056
+ function isJsonRpcServerError(code) {
38057
+ return code >= -32099 && code <= -32e3;
38058
+ }
38059
+ function serializeCause(error) {
38060
+ if (Array.isArray(error)) {
38061
+ return error.map((entry) => {
38062
+ if (isValidJson(entry)) {
38063
+ return entry;
38064
+ } else if (isObject2(entry)) {
38065
+ return serializeObject(entry);
38066
+ }
38067
+ return null;
38068
+ });
38069
+ } else if (isObject2(error)) {
38070
+ return serializeObject(error);
38071
+ }
38072
+ if (isValidJson(error)) {
38073
+ return error;
38074
+ }
38075
+ return null;
38076
+ }
38077
+ function serializeObject(object3) {
38078
+ return Object.getOwnPropertyNames(object3).reduce((acc, key) => {
38079
+ const value = object3[key];
38080
+ if (isValidJson(value)) {
38081
+ acc[key] = value;
38082
+ }
38083
+ return acc;
38084
+ }, {});
38085
+ }
38086
+ function dataHasCause(data) {
38087
+ return isObject2(data) && hasProperty(data, "cause") && isObject2(data.cause);
38088
+ }
38089
+
38090
+ // ../../node_modules/@metamask/rpc-errors/dist/classes.mjs
38091
+ function $importDefault(module) {
38092
+ if (module == null ? void 0 : module.__esModule) {
38093
+ return module.default;
38094
+ }
38095
+ return module;
38096
+ }
38097
+ var safeStringify = $importDefault(import_fast_safe_stringify.default);
38098
+ var JsonRpcError = class extends Error {
38099
+ constructor(code, message, data) {
38100
+ if (!Number.isInteger(code)) {
38101
+ throw new Error('"code" must be an integer.');
38102
+ }
38103
+ if (!message || typeof message !== "string") {
38104
+ throw new Error('"message" must be a non-empty string.');
38105
+ }
38106
+ if (dataHasCause(data)) {
38107
+ super(message, { cause: data.cause });
38108
+ if (!hasProperty(this, "cause")) {
38109
+ Object.assign(this, { cause: data.cause });
38110
+ }
38111
+ } else {
38112
+ super(message);
38113
+ }
38114
+ if (data !== void 0) {
38115
+ this.data = data;
38116
+ }
38117
+ this.code = code;
38118
+ }
38119
+ /**
38120
+ * Get the error as JSON-serializable object.
38121
+ *
38122
+ * @returns A plain object with all public class properties.
38123
+ */
38124
+ serialize() {
38125
+ const serialized = {
38126
+ code: this.code,
38127
+ message: this.message
38128
+ };
38129
+ if (this.data !== void 0) {
38130
+ serialized.data = this.data;
38131
+ if (isPlainObject(this.data)) {
38132
+ serialized.data.cause = serializeCause(this.data.cause);
38133
+ }
38134
+ }
38135
+ if (this.stack) {
38136
+ serialized.stack = this.stack;
38137
+ }
38138
+ return serialized;
38139
+ }
38140
+ /**
38141
+ * Get a string representation of the serialized error, omitting any circular
38142
+ * references.
38143
+ *
38144
+ * @returns A string representation of the serialized error.
38145
+ */
38146
+ toString() {
38147
+ return safeStringify(this.serialize(), stringifyReplacer, 2);
38148
+ }
38149
+ };
38150
+ var EthereumProviderError = class extends JsonRpcError {
38151
+ /**
38152
+ * Create an Ethereum Provider JSON-RPC error.
38153
+ *
38154
+ * @param code - The JSON-RPC error code. Must be an integer in the
38155
+ * `1000 <= n <= 4999` range.
38156
+ * @param message - The JSON-RPC error message.
38157
+ * @param data - Optional data to include in the error.
38158
+ */
38159
+ constructor(code, message, data) {
38160
+ if (!isValidEthProviderCode(code)) {
38161
+ throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');
38162
+ }
38163
+ super(code, message, data);
38164
+ }
38165
+ };
38166
+ function isValidEthProviderCode(code) {
38167
+ return Number.isInteger(code) && code >= 1e3 && code <= 4999;
38168
+ }
38169
+ function stringifyReplacer(_, value) {
38170
+ if (value === "[Circular]") {
38171
+ return void 0;
38172
+ }
38173
+ return value;
38174
+ }
38175
+
38176
+ // ../../node_modules/@metamask/rpc-errors/dist/errors.mjs
38177
+ var providerErrors = {
38178
+ /**
38179
+ * Get an Ethereum Provider User Rejected Request (4001) error.
38180
+ *
38181
+ * @param arg - The error message or options bag.
38182
+ * @returns An instance of the {@link EthereumProviderError} class.
38183
+ */
38184
+ userRejectedRequest: (arg) => {
38185
+ return getEthProviderError(errorCodes.provider.userRejectedRequest, arg);
38186
+ },
38187
+ /**
38188
+ * Get an Ethereum Provider Unauthorized (4100) error.
38189
+ *
38190
+ * @param arg - The error message or options bag.
38191
+ * @returns An instance of the {@link EthereumProviderError} class.
38192
+ */
38193
+ unauthorized: (arg) => {
38194
+ return getEthProviderError(errorCodes.provider.unauthorized, arg);
38195
+ },
38196
+ /**
38197
+ * Get an Ethereum Provider Unsupported Method (4200) error.
38198
+ *
38199
+ * @param arg - The error message or options bag.
38200
+ * @returns An instance of the {@link EthereumProviderError} class.
38201
+ */
38202
+ unsupportedMethod: (arg) => {
38203
+ return getEthProviderError(errorCodes.provider.unsupportedMethod, arg);
38204
+ },
38205
+ /**
38206
+ * Get an Ethereum Provider Not Connected (4900) error.
38207
+ *
38208
+ * @param arg - The error message or options bag.
38209
+ * @returns An instance of the {@link EthereumProviderError} class.
38210
+ */
38211
+ disconnected: (arg) => {
38212
+ return getEthProviderError(errorCodes.provider.disconnected, arg);
38213
+ },
38214
+ /**
38215
+ * Get an Ethereum Provider Chain Not Connected (4901) error.
38216
+ *
38217
+ * @param arg - The error message or options bag.
38218
+ * @returns An instance of the {@link EthereumProviderError} class.
38219
+ */
38220
+ chainDisconnected: (arg) => {
38221
+ return getEthProviderError(errorCodes.provider.chainDisconnected, arg);
38222
+ },
38223
+ /**
38224
+ * Get a custom Ethereum Provider error.
38225
+ *
38226
+ * @param opts - The error options bag.
38227
+ * @returns An instance of the {@link EthereumProviderError} class.
38228
+ */
38229
+ custom: (opts) => {
38230
+ if (!opts || typeof opts !== "object" || Array.isArray(opts)) {
38231
+ throw new Error("Ethereum Provider custom errors must provide single object argument.");
38232
+ }
38233
+ const { code, message, data } = opts;
38234
+ if (!message || typeof message !== "string") {
38235
+ throw new Error('"message" must be a nonempty string');
38236
+ }
38237
+ return new EthereumProviderError(code, message, data);
38238
+ }
38239
+ };
38240
+ function getEthProviderError(code, arg) {
38241
+ const [message, data] = parseOpts(arg);
38242
+ return new EthereumProviderError(code, message != null ? message : getMessageFromCode(code), data);
38243
+ }
38244
+ function parseOpts(arg) {
38245
+ if (arg) {
38246
+ if (typeof arg === "string") {
38247
+ return [arg];
38248
+ } else if (typeof arg === "object" && !Array.isArray(arg)) {
38249
+ const { message, data } = arg;
38250
+ if (message && typeof message !== "string") {
38251
+ throw new Error("Must specify string message.");
38252
+ }
38253
+ return [message != null ? message : void 0, data];
38254
+ }
38255
+ }
38256
+ return [];
38257
+ }
38258
+
38259
+ // src/multichain/transports/multichainApiClientWrapper/index.ts
38260
+ var MAX2 = 4294967295;
38261
+ var idCounter2 = Math.floor(Math.random() * MAX2);
38262
+ var getUniqueId2 = () => {
38263
+ idCounter2 = (idCounter2 + 1) % MAX2;
38264
+ return idCounter2;
38265
+ };
38266
+ var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
38267
+ var MultichainApiClientWrapperTransport = class {
38268
+ constructor(multichainSDK) {
38269
+ this.multichainSDK = multichainSDK;
38270
+ __privateAdd(this, _MultichainApiClientWrapperTransport_instances);
38271
+ this.requestId = getUniqueId2();
38272
+ this.notificationCallbacks = /* @__PURE__ */ new Set();
38273
+ }
38274
+ isTransportDefined() {
38275
+ try {
38276
+ return Boolean(this.multichainSDK.transport);
38277
+ } catch (error) {
38278
+ return false;
38279
+ }
38280
+ }
38281
+ clearNotificationCallbacks() {
38282
+ this.notificationCallbacks.clear();
38283
+ }
38284
+ notifyCallbacks(data) {
38285
+ this.notificationCallbacks.forEach((callback) => {
38286
+ callback(data);
38287
+ });
38288
+ }
38289
+ setupNotifcationListener() {
38290
+ this.multichainSDK.transport.onNotification(
38291
+ this.notifyCallbacks.bind(this)
38292
+ );
38293
+ }
38294
+ connect() {
38295
+ return __async(this, null, function* () {
38296
+ console.log("\u{1F4DA} connect");
38297
+ return Promise.resolve();
38298
+ });
38299
+ }
38300
+ disconnect() {
38301
+ return __async(this, null, function* () {
38302
+ return Promise.resolve();
38303
+ });
38304
+ }
38305
+ isConnected() {
38306
+ return true;
38307
+ }
38308
+ request(_0) {
38309
+ return __async(this, arguments, function* (params, _options = {}) {
38310
+ const id = this.requestId++;
38311
+ const requestPayload = __spreadValues({
38312
+ id,
38313
+ jsonrpc: "2.0"
38314
+ }, params);
38315
+ switch (requestPayload.method) {
38316
+ case "wallet_createSession":
38317
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
38318
+ case "wallet_getSession":
38319
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
38320
+ case "wallet_revokeSession":
38321
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
38322
+ case "wallet_invokeMethod":
38323
+ return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
38324
+ default:
38325
+ throw new Error(`Unsupported method: ${requestPayload.method}`);
38326
+ }
38327
+ throw new Error(`Unknown method: ${requestPayload.method}`);
38328
+ });
38329
+ }
38330
+ onNotification(callback) {
38331
+ if (!this.isTransportDefined()) {
38332
+ this.notificationCallbacks.add(callback);
38333
+ return () => {
38334
+ this.notificationCallbacks.delete(callback);
38335
+ };
38336
+ }
38337
+ return this.multichainSDK.transport.onNotification(callback);
38338
+ }
38339
+ };
38340
+ _MultichainApiClientWrapperTransport_instances = new WeakSet();
38341
+ walletCreateSession_fn = function(request2) {
38342
+ return __async(this, null, function* () {
38343
+ console.log("\u{1F4DA} #walletCreateSession", request2);
38344
+ const createSessionParams = request2.params;
38345
+ const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
38346
+ const scopeAccounts = [];
38347
+ scopes.forEach((scope) => {
38348
+ var _a3, _b, _c, _d;
38349
+ const requiredScope = (_a3 = createSessionParams.requiredScopes) == null ? void 0 : _a3[scope];
38350
+ const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
38351
+ if (requiredScope) {
38352
+ scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
38353
+ }
38354
+ if (optionalScope) {
38355
+ scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
38356
+ }
38357
+ });
38358
+ const accounts = [...new Set(scopeAccounts)];
38359
+ console.log("\u{1F4DA} SDK connect");
38360
+ yield this.multichainSDK.connect(
38361
+ scopes,
38362
+ accounts,
38363
+ createSessionParams.sessionProperties
38364
+ );
38365
+ console.log("\u{1F4DA} SDK connected");
38366
+ return this.multichainSDK.transport.request({
38367
+ method: "wallet_getSession"
38368
+ });
38369
+ });
38370
+ };
38371
+ walletGetSession_fn = function(request2) {
38372
+ return __async(this, null, function* () {
38373
+ if (!this.isTransportDefined()) {
38374
+ return {
38375
+ jsonrpc: "2.0",
38376
+ id: request2.id,
38377
+ result: {
38378
+ sessionScopes: {}
38379
+ }
38380
+ };
38381
+ }
38382
+ return this.multichainSDK.transport.request({
38383
+ method: "wallet_getSession"
38384
+ });
38385
+ });
38386
+ };
38387
+ walletRevokeSession_fn = function(request2) {
38388
+ return __async(this, null, function* () {
38389
+ if (!this.isTransportDefined()) {
38390
+ return { jsonrpc: "2.0", id: request2.id, result: true };
38391
+ }
38392
+ try {
38393
+ this.multichainSDK.disconnect();
38394
+ return { jsonrpc: "2.0", id: request2.id, result: true };
38395
+ } catch (error) {
38396
+ return { jsonrpc: "2.0", id: request2.id, result: false };
38397
+ }
38398
+ });
38399
+ };
38400
+ walletInvokeMethod_fn = function(request2) {
38401
+ return __async(this, null, function* () {
38402
+ if (!this.isTransportDefined()) {
38403
+ return { error: providerErrors.unauthorized() };
38404
+ }
38405
+ const result = this.multichainSDK.invokeMethod(
38406
+ request2.params
38407
+ );
38408
+ return {
38409
+ result
38410
+ };
38411
+ });
38412
+ };
38413
+
38414
+ // src/multichain/index.ts
37666
38415
  var logger2 = createLogger("metamask-sdk:core");
37667
- var _a2, _provider, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MultichainSDK_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
38416
+ var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MultichainSDK_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;
37668
38417
  var _MultichainSDK = class _MultichainSDK extends MultichainCore {
37669
38418
  constructor(options) {
37670
38419
  var _a3, _b, _c, _d, _e, _f;
@@ -37683,32 +38432,28 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37683
38432
  super(allOptions);
37684
38433
  __privateAdd(this, _MultichainSDK_instances);
37685
38434
  __privateAdd(this, _provider);
38435
+ __privateAdd(this, _providerTransportWrapper);
37686
38436
  __privateAdd(this, _transport2);
37687
38437
  __privateAdd(this, _dappClient);
37688
38438
  __privateAdd(this, _beforeUnloadListener);
37689
- this._state = "pending";
38439
+ this._status = "pending";
37690
38440
  __privateAdd(this, _listener);
37691
38441
  __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}`);
38442
+ __privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
38443
+ __privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _providerTransportWrapper) }));
37692
38444
  }
37693
- get state() {
37694
- return this._state;
38445
+ get status() {
38446
+ return this._status;
37695
38447
  }
37696
- set state(value) {
38448
+ set status(value) {
37697
38449
  var _a3, _b;
37698
- this._state = value;
38450
+ this._status = value;
37699
38451
  (_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, {
37700
38452
  method: "stateChanged",
37701
38453
  params: value
37702
38454
  });
37703
38455
  }
37704
38456
  get provider() {
37705
- if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
37706
- __privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _transport2) }));
37707
- return __privateGet(this, _provider);
37708
- }
37709
- if (!__privateGet(this, _provider)) {
37710
- throw new Error("Provider not initialized, establish connection first");
37711
- }
37712
38457
  return __privateGet(this, _provider);
37713
38458
  }
37714
38459
  get transport() {
@@ -37744,10 +38489,11 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37744
38489
  return instance2;
37745
38490
  });
37746
38491
  }
37747
- connect(scopes, caipAccountIds, forceRequest) {
38492
+ // TODO: make this into param object
38493
+ connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
37748
38494
  return __async(this, null, function* () {
37749
38495
  var _a3;
37750
- if (this.state !== "connected") {
38496
+ if (this.status !== "connected") {
37751
38497
  yield this.disconnect();
37752
38498
  }
37753
38499
  const { ui } = this.options;
@@ -37779,7 +38525,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37779
38525
  logger2("Error tracking connection_initiated event", error);
37780
38526
  }
37781
38527
  if (((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) && !secure) {
37782
- return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, forceRequest }).then(() => __async(this, null, function* () {
38528
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties, forceRequest }).then(() => __async(this, null, function* () {
37783
38529
  if (__privateGet(this, _transport2) instanceof MWPTransport) {
37784
38530
  return this.storage.setTransport("mwp" /* MWP */);
37785
38531
  }
@@ -37788,18 +38534,18 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37788
38534
  }
37789
38535
  if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
37790
38536
  const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
37791
- return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, forceRequest }), scopes, transportType);
38537
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
37792
38538
  }
37793
38539
  if (isWeb && hasExtensionInstalled && preferExtension) {
37794
38540
  const defaultTransport = yield __privateMethod(this, _MultichainSDK_instances, setupDefaultTransport_fn).call(this);
37795
- return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, forceRequest }), scopes, transportType);
38541
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
37796
38542
  }
37797
38543
  yield __privateMethod(this, _MultichainSDK_instances, setupMWP_fn).call(this);
37798
38544
  const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
37799
38545
  if (secure && !shouldShowInstallModal) {
37800
- return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds), scopes, transportType);
38546
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
37801
38547
  }
37802
- return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds), scopes, transportType);
38548
+ return __privateMethod(this, _MultichainSDK_instances, handleConnection_fn).call(this, __privateMethod(this, _MultichainSDK_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
37803
38549
  });
37804
38550
  }
37805
38551
  emit(event, args) {
@@ -37818,15 +38564,13 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37818
38564
  __privateSet(this, _listener, void 0);
37819
38565
  __privateSet(this, _beforeUnloadListener, void 0);
37820
38566
  __privateSet(this, _transport2, void 0);
37821
- __privateSet(this, _provider, void 0);
38567
+ __privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
37822
38568
  __privateSet(this, _dappClient, void 0);
37823
38569
  });
37824
38570
  }
37825
38571
  invokeMethod(request2) {
37826
38572
  return __async(this, null, function* () {
37827
- var _a3;
37828
38573
  const { transport, options } = this;
37829
- (_a3 = __privateGet(this, _provider)) != null ? _a3 : __privateSet(this, _provider, getMultichainClient({ transport }));
37830
38574
  const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
37831
38575
  const requestRouter = new RequestRouter(transport, rpcClient, options);
37832
38576
  return requestRouter.invokeMethod(request2);
@@ -37855,6 +38599,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37855
38599
  }
37856
38600
  };
37857
38601
  _provider = new WeakMap();
38602
+ _providerTransportWrapper = new WeakMap();
37858
38603
  _transport2 = new WeakMap();
37859
38604
  _dappClient = new WeakMap();
37860
38605
  _beforeUnloadListener = new WeakMap();
@@ -37901,6 +38646,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37901
38646
  if (hasExtensionInstalled) {
37902
38647
  const apiTransport = new DefaultTransport();
37903
38648
  __privateSet(this, _transport2, apiTransport);
38649
+ __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
37904
38650
  __privateSet(this, _listener, apiTransport.onNotification(
37905
38651
  __privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
37906
38652
  ));
@@ -37912,6 +38658,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37912
38658
  const apiTransport = new MWPTransport(dappClient, kvstore);
37913
38659
  __privateSet(this, _dappClient, dappClient);
37914
38660
  __privateSet(this, _transport2, apiTransport);
38661
+ __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
37915
38662
  __privateSet(this, _listener, apiTransport.onNotification(
37916
38663
  __privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
37917
38664
  ));
@@ -37927,17 +38674,17 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37927
38674
  const transport = yield __privateMethod(this, _MultichainSDK_instances, getStoredTransport_fn).call(this);
37928
38675
  if (transport) {
37929
38676
  if (!this.transport.isConnected()) {
37930
- this.state = "connecting";
38677
+ this.status = "connecting";
37931
38678
  yield this.transport.connect();
37932
38679
  }
37933
- this.state = "connected";
38680
+ this.status = "connected";
37934
38681
  if (this.transport instanceof MWPTransport) {
37935
38682
  yield this.storage.setTransport("mwp" /* MWP */);
37936
38683
  } else {
37937
38684
  yield this.storage.setTransport("browser" /* Browser */);
37938
38685
  }
37939
38686
  } else {
37940
- this.state = "loaded";
38687
+ this.status = "loaded";
37941
38688
  }
37942
38689
  });
37943
38690
  };
@@ -37965,7 +38712,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37965
38712
  }
37966
38713
  } catch (error) {
37967
38714
  yield this.storage.removeTransport();
37968
- this.state = "pending";
38715
+ this.status = "pending";
37969
38716
  logger2("MetaMaskSDK error during initialization", error);
37970
38717
  }
37971
38718
  });
@@ -37997,6 +38744,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
37997
38744
  __privateSet(this, _dappClient, dappClient);
37998
38745
  const apiTransport = new MWPTransport(dappClient, kvstore);
37999
38746
  __privateSet(this, _transport2, apiTransport);
38747
+ __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
38000
38748
  __privateSet(this, _listener, this.transport.onNotification(
38001
38749
  __privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
38002
38750
  ));
@@ -38024,7 +38772,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38024
38772
  }
38025
38773
  };
38026
38774
  };
38027
- renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds) {
38775
+ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
38028
38776
  return __async(this, null, function* () {
38029
38777
  return new Promise((resolve, reject) => {
38030
38778
  this.options.ui.factory.renderInstallModal(
@@ -38052,19 +38800,19 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38052
38800
  (() => __async(this, null, function* () {
38053
38801
  var _a3;
38054
38802
  try {
38055
- yield this.transport.connect({ scopes, caipAccountIds });
38803
+ yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
38056
38804
  yield this.options.ui.factory.unload();
38057
38805
  (_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
38058
- this.state = "connected";
38806
+ this.status = "connected";
38059
38807
  yield this.storage.setTransport("mwp" /* MWP */);
38060
38808
  } catch (error) {
38061
38809
  if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
38062
38810
  if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
38063
- this.state = "disconnected";
38811
+ this.status = "disconnected";
38064
38812
  reject(error);
38065
38813
  }
38066
38814
  } else {
38067
- this.state = "disconnected";
38815
+ this.status = "disconnected";
38068
38816
  reject(
38069
38817
  error instanceof Error ? error : new Error(String(error))
38070
38818
  );
@@ -38082,33 +38830,83 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38082
38830
  yield this.storage.setTransport("mwp" /* MWP */);
38083
38831
  resolve();
38084
38832
  }
38085
- })
38833
+ }),
38834
+ (uri) => {
38835
+ this.emit("display_uri", uri);
38836
+ }
38086
38837
  ).catch((error) => {
38087
38838
  reject(error instanceof Error ? error : new Error(String(error)));
38088
38839
  });
38089
38840
  });
38090
38841
  });
38091
38842
  };
38092
- showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds) {
38843
+ showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
38093
38844
  return __async(this, null, function* () {
38094
38845
  var _a3;
38095
38846
  (_a3 = __privateGet(this, _beforeUnloadListener)) != null ? _a3 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MultichainSDK_instances, createBeforeUnloadListener_fn).call(this));
38096
- yield __privateMethod(this, _MultichainSDK_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds);
38847
+ if (this.options.ui.headless) {
38848
+ yield __privateMethod(this, _MultichainSDK_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
38849
+ } else {
38850
+ yield __privateMethod(this, _MultichainSDK_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
38851
+ }
38852
+ });
38853
+ };
38854
+ headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
38855
+ return __async(this, null, function* () {
38856
+ return new Promise((resolve, reject) => {
38857
+ if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
38858
+ this.dappClient.disconnect().catch(() => {
38859
+ });
38860
+ }
38861
+ this.dappClient.on(
38862
+ "session_request",
38863
+ (sessionRequest) => {
38864
+ const connectionRequest = {
38865
+ sessionRequest,
38866
+ metadata: {
38867
+ dapp: this.options.dapp,
38868
+ sdk: {
38869
+ version: getVersion(),
38870
+ platform: getPlatformType()
38871
+ }
38872
+ }
38873
+ };
38874
+ const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
38875
+ this.emit("display_uri", deeplink);
38876
+ }
38877
+ );
38878
+ this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
38879
+ this.status = "connected";
38880
+ yield this.storage.setTransport("mwp" /* MWP */);
38881
+ resolve();
38882
+ })).catch((error) => __async(this, null, function* () {
38883
+ if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
38884
+ this.status = "disconnected";
38885
+ yield this.storage.removeTransport();
38886
+ reject(error);
38887
+ } else {
38888
+ this.status = "disconnected";
38889
+ yield this.storage.removeTransport();
38890
+ reject(error instanceof Error ? error : new Error(String(error)));
38891
+ }
38892
+ }));
38893
+ });
38097
38894
  });
38098
38895
  };
38099
38896
  setupDefaultTransport_fn = function() {
38100
38897
  return __async(this, null, function* () {
38101
- this.state = "connecting";
38898
+ this.status = "connecting";
38102
38899
  yield this.storage.setTransport("browser" /* Browser */);
38103
38900
  const transport = new DefaultTransport();
38104
38901
  __privateSet(this, _listener, transport.onNotification(
38105
38902
  __privateMethod(this, _MultichainSDK_instances, onTransportNotification_fn).bind(this)
38106
38903
  ));
38107
38904
  __privateSet(this, _transport2, transport);
38905
+ __privateGet(this, _providerTransportWrapper).setupNotifcationListener();
38108
38906
  return transport;
38109
38907
  });
38110
38908
  };
38111
- deeplinkConnect_fn = function(scopes, caipAccountIds) {
38909
+ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
38112
38910
  return __async(this, null, function* () {
38113
38911
  return new Promise((resolve, reject) => {
38114
38912
  const dappClientMessageHandler = (payload) => {
@@ -38151,6 +38949,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38151
38949
  const universalLink = this.options.ui.factory.createConnectionUniversalLink(
38152
38950
  connectionRequest
38153
38951
  );
38952
+ this.emit("display_uri", deeplink);
38154
38953
  if ((_a3 = this.options.mobile) == null ? void 0 : _a3.preferredOpenLink) {
38155
38954
  this.options.mobile.preferredOpenLink(deeplink, "_self");
38156
38955
  } else {
@@ -38159,7 +38958,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38159
38958
  }
38160
38959
  );
38161
38960
  }
38162
- return this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => __async(this, null, function* () {
38961
+ return this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
38163
38962
  yield this.storage.removeTransport();
38164
38963
  this.dappClient.off("message", dappClientMessageHandler);
38165
38964
  reject(error instanceof Error ? error : new Error(String(error)));
@@ -38173,9 +38972,9 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38173
38972
  };
38174
38973
  handleConnection_fn = function(promise, scopes, transportType) {
38175
38974
  return __async(this, null, function* () {
38176
- this.state = "connecting";
38975
+ this.status = "connecting";
38177
38976
  return promise.then(() => __async(this, null, function* () {
38178
- this.state = "connected";
38977
+ this.status = "connected";
38179
38978
  try {
38180
38979
  const baseProps = yield getBaseAnalyticsProperties(
38181
38980
  this.options,
@@ -38190,7 +38989,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38190
38989
  }
38191
38990
  return void 0;
38192
38991
  })).catch((error) => __async(this, null, function* () {
38193
- this.state = "disconnected";
38992
+ this.status = "disconnected";
38194
38993
  try {
38195
38994
  const baseProps = yield getBaseAnalyticsProperties(
38196
38995
  this.options,
@@ -38714,27 +39513,10 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38714
39513
  );
38715
39514
  var metamask_onboarding_es_default = Onboarding;
38716
39515
 
38717
- // src/ui/index.ts
39516
+ // src/ui/ModalFactory.ts
38718
39517
  init_domain();
38719
39518
  init_utils3();
38720
-
38721
- // src/ui/preload.web.ts
38722
- function preload() {
38723
- return __async(this, null, function* () {
38724
- if (typeof document === "undefined") {
38725
- return;
38726
- }
38727
- try {
38728
- const { defineCustomElements: defineCustomElements2 } = yield Promise.resolve().then(() => (init_loader2(), loader_exports));
38729
- yield defineCustomElements2();
38730
- } catch (error) {
38731
- console.error("Failed to load customElements:", error);
38732
- }
38733
- });
38734
- }
38735
-
38736
- // src/ui/index.ts
38737
- var ModalFactory = class {
39519
+ var BaseModalFactory = class {
38738
39520
  /**
38739
39521
  * Creates a new modal factory instance.
38740
39522
  *
@@ -38823,15 +39605,17 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38823
39605
  onStartDesktopOnboarding() {
38824
39606
  new metamask_onboarding_es_default().startOnboarding();
38825
39607
  }
38826
- renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
39608
+ renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
38827
39609
  return __async(this, null, function* () {
38828
- var _a3;
39610
+ var _a3, _b;
38829
39611
  (_a3 = this.modal) == null ? void 0 : _a3.unmount();
38830
- yield preload();
39612
+ yield this.preload();
38831
39613
  this.successCallback = successCallback;
39614
+ this.displayUriCallback = onDisplayUri;
38832
39615
  const parentElement = this.getMountedContainer();
38833
39616
  const connectionRequest = yield createConnectionRequest();
38834
39617
  const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
39618
+ (_b = this.displayUriCallback) == null ? void 0 : _b.call(this, qrCodeLink);
38835
39619
  const modal = new this.options.InstallModal({
38836
39620
  expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
38837
39621
  connectionRequest,
@@ -38840,11 +39624,15 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38840
39624
  link: qrCodeLink,
38841
39625
  sdkVersion: getVersion(),
38842
39626
  generateQRCode: (request2) => __async(this, null, function* () {
38843
- return this.createConnectionDeeplink(request2);
39627
+ var _a4;
39628
+ const newLink = this.createConnectionDeeplink(request2);
39629
+ (_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
39630
+ return newLink;
38844
39631
  }),
38845
39632
  onClose: this.onCloseModal.bind(this),
38846
39633
  startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
38847
- createConnectionRequest
39634
+ createConnectionRequest,
39635
+ onDisplayUri: this.displayUriCallback
38848
39636
  });
38849
39637
  this.modal = modal;
38850
39638
  modal.mount();
@@ -38854,7 +39642,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38854
39642
  return __async(this, null, function* () {
38855
39643
  var _a3;
38856
39644
  (_a3 = this.modal) == null ? void 0 : _a3.unmount();
38857
- yield preload();
39645
+ yield this.preload();
38858
39646
  this.successCallback = successCallback;
38859
39647
  const container = this.getMountedContainer();
38860
39648
  const otpCode = yield createOTPCode();
@@ -38872,9 +39660,31 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
38872
39660
  }
38873
39661
  };
38874
39662
 
39663
+ // src/ui/index.ts
39664
+ function preload() {
39665
+ return __async(this, null, function* () {
39666
+ if (typeof document === "undefined") {
39667
+ return;
39668
+ }
39669
+ try {
39670
+ const { defineCustomElements: defineCustomElements2 } = yield Promise.resolve().then(() => (init_loader2(), loader_exports));
39671
+ yield defineCustomElements2();
39672
+ } catch (error) {
39673
+ console.error("Failed to load customElements:", error);
39674
+ }
39675
+ });
39676
+ }
39677
+ var ModalFactory = class extends BaseModalFactory {
39678
+ preload() {
39679
+ return __async(this, null, function* () {
39680
+ return preload();
39681
+ });
39682
+ }
39683
+ };
39684
+
38875
39685
  // src/index.browser.ts
38876
39686
  init_domain();
38877
- var createMetamaskConnect = (options) => __async(null, null, function* () {
39687
+ var createMultichainClient = (options) => __async(null, null, function* () {
38878
39688
  const uiModules = yield Promise.resolve().then(() => (init_web(), web_exports));
38879
39689
  let storage;
38880
39690
  if (!options.storage) {