@metamask/connect-multichain 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -1
- package/README.md +9 -3
- package/dist/browser/es/connect-multichain.d.mts +27 -4
- package/dist/browser/es/connect-multichain.mjs +603 -333
- package/dist/browser/es/connect-multichain.mjs.map +1 -1
- package/dist/browser/es/metafile-esm.json +1 -1
- package/dist/browser/iife/connect-multichain.d.ts +27 -4
- package/dist/browser/iife/connect-multichain.js +3363 -2993
- package/dist/browser/iife/connect-multichain.js.map +1 -1
- package/dist/browser/iife/metafile-iife.json +1 -1
- package/dist/browser/umd/connect-multichain.d.ts +27 -4
- package/dist/browser/umd/connect-multichain.js +603 -333
- package/dist/browser/umd/connect-multichain.js.map +1 -1
- package/dist/browser/umd/metafile-cjs.json +1 -1
- package/dist/node/cjs/connect-multichain.d.ts +27 -4
- package/dist/node/cjs/connect-multichain.js +421 -151
- package/dist/node/cjs/connect-multichain.js.map +1 -1
- package/dist/node/cjs/metafile-cjs.json +1 -1
- package/dist/node/es/connect-multichain.d.mts +27 -4
- package/dist/node/es/connect-multichain.mjs +421 -151
- package/dist/node/es/connect-multichain.mjs.map +1 -1
- package/dist/node/es/metafile-esm.json +1 -1
- package/dist/react-native/es/connect-multichain.d.mts +27 -4
- package/dist/react-native/es/connect-multichain.mjs +596 -326
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/multichain/index.d.ts +15 -4
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js +14 -0
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +12 -0
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/multichain/index.d.ts +3 -2
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +158 -61
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +3 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +17 -11
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +3 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +28 -31
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +15 -2
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +155 -38
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/multichain/utils/index.d.ts +23 -0
- package/dist/src/multichain/utils/index.d.ts.map +1 -1
- package/dist/src/multichain/utils/index.js +57 -4
- package/dist/src/multichain/utils/index.js.map +1 -1
- package/dist/src/polyfills/buffer-shim.js +4 -14
- package/dist/src/polyfills/buffer-shim.js.map +1 -1
- package/dist/src/store/adapters/web.d.ts +1 -1
- package/dist/src/store/adapters/web.d.ts.map +1 -1
- package/dist/src/store/adapters/web.js +1 -1
- package/dist/src/store/adapters/web.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +27 -4
- package/package.json +1 -1
|
@@ -34,14 +34,6 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
34
34
|
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);
|
|
35
35
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
36
36
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
37
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
38
|
-
set _(value) {
|
|
39
|
-
__privateSet(obj, member, value, setter);
|
|
40
|
-
},
|
|
41
|
-
get _() {
|
|
42
|
-
return __privateGet(obj, member, getter);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
37
|
var __async = (__this, __arguments, generator) => {
|
|
46
38
|
return new Promise((resolve, reject) => {
|
|
47
39
|
var fulfilled = (value) => {
|
|
@@ -243,8 +235,8 @@ var init_logger = __esm({
|
|
|
243
235
|
debug.enable(namespace);
|
|
244
236
|
};
|
|
245
237
|
isEnabled = (namespace, storage) => __async(null, null, function* () {
|
|
246
|
-
var
|
|
247
|
-
if ("process" in globalThis && ((
|
|
238
|
+
var _a3;
|
|
239
|
+
if ("process" in globalThis && ((_a3 = process == null ? void 0 : process.env) == null ? void 0 : _a3.DEBUG)) {
|
|
248
240
|
const { DEBUG } = process.env;
|
|
249
241
|
return isNamespaceEnabled(DEBUG, namespace);
|
|
250
242
|
}
|
|
@@ -407,6 +399,34 @@ var init_multichain = __esm({
|
|
|
407
399
|
super();
|
|
408
400
|
this.options = options;
|
|
409
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Merges the given options into the current instance options.
|
|
404
|
+
* Only the mergeable keys are updated (api.supportedNetworks, ui.*, mobile.*, transport.extensionId, debug).
|
|
405
|
+
* The main thing to note is that the value for `dapp` is not merged as it does not make sense for
|
|
406
|
+
* subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
407
|
+
* Used when createMultichainClient is called with an existing singleton.
|
|
408
|
+
*
|
|
409
|
+
* @param partial - Options to merge/overwrite onto the current instance
|
|
410
|
+
*/
|
|
411
|
+
mergeOptions(partial) {
|
|
412
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
413
|
+
const opts = this.options;
|
|
414
|
+
this.options = __spreadProps(__spreadValues({}, opts), {
|
|
415
|
+
api: __spreadProps(__spreadValues({}, opts.api), {
|
|
416
|
+
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_b = (_a3 = partial.api) == null ? void 0 : _a3.supportedNetworks) != null ? _b : {})
|
|
417
|
+
}),
|
|
418
|
+
ui: __spreadProps(__spreadValues({}, opts.ui), {
|
|
419
|
+
headless: (_d = (_c = partial.ui) == null ? void 0 : _c.headless) != null ? _d : opts.ui.headless,
|
|
420
|
+
preferExtension: (_f = (_e = partial.ui) == null ? void 0 : _e.preferExtension) != null ? _f : opts.ui.preferExtension,
|
|
421
|
+
showInstallModal: (_h = (_g = partial.ui) == null ? void 0 : _g.showInstallModal) != null ? _h : opts.ui.showInstallModal
|
|
422
|
+
}),
|
|
423
|
+
mobile: __spreadValues(__spreadValues({}, opts.mobile), (_i = partial.mobile) != null ? _i : {}),
|
|
424
|
+
transport: __spreadProps(__spreadValues({}, (_j = opts.transport) != null ? _j : {}), {
|
|
425
|
+
extensionId: (_m = (_k = partial.transport) == null ? void 0 : _k.extensionId) != null ? _m : (_l = opts.transport) == null ? void 0 : _l.extensionId
|
|
426
|
+
}),
|
|
427
|
+
debug: (_n = partial.debug) != null ? _n : opts.debug
|
|
428
|
+
});
|
|
429
|
+
}
|
|
410
430
|
};
|
|
411
431
|
}
|
|
412
432
|
});
|
|
@@ -414,35 +434,35 @@ var init_multichain = __esm({
|
|
|
414
434
|
// src/domain/platform/index.ts
|
|
415
435
|
import Bowser from "bowser";
|
|
416
436
|
function isNotBrowser() {
|
|
417
|
-
var
|
|
437
|
+
var _a3;
|
|
418
438
|
if (typeof window === "undefined") {
|
|
419
439
|
return true;
|
|
420
440
|
}
|
|
421
441
|
if (!(window == null ? void 0 : window.navigator)) {
|
|
422
442
|
return true;
|
|
423
443
|
}
|
|
424
|
-
if (typeof global !== "undefined" && ((
|
|
444
|
+
if (typeof global !== "undefined" && ((_a3 = global == null ? void 0 : global.navigator) == null ? void 0 : _a3.product) === "ReactNative") {
|
|
425
445
|
return true;
|
|
426
446
|
}
|
|
427
447
|
return (navigator == null ? void 0 : navigator.product) === "ReactNative";
|
|
428
448
|
}
|
|
429
449
|
function isReactNative() {
|
|
430
|
-
var
|
|
450
|
+
var _a3;
|
|
431
451
|
const hasWindowNavigator = typeof window !== "undefined" && window.navigator !== void 0;
|
|
432
452
|
const nav = hasWindowNavigator ? window.navigator : void 0;
|
|
433
453
|
if (!nav) {
|
|
434
454
|
return false;
|
|
435
455
|
}
|
|
436
|
-
return hasWindowNavigator && ((
|
|
456
|
+
return hasWindowNavigator && ((_a3 = window.navigator) == null ? void 0 : _a3.product) === "ReactNative";
|
|
437
457
|
}
|
|
438
458
|
function isMetaMaskMobileWebView() {
|
|
439
459
|
return typeof window !== "undefined" && // @ts-expect-error ReactNativeWebView should be defined
|
|
440
460
|
Boolean(window.ReactNativeWebView) && Boolean(window.navigator.userAgent.endsWith("MetaMaskMobile"));
|
|
441
461
|
}
|
|
442
462
|
function isMobile() {
|
|
443
|
-
var
|
|
463
|
+
var _a3, _b;
|
|
444
464
|
const browser = Bowser.parse(window.navigator.userAgent);
|
|
445
|
-
return ((
|
|
465
|
+
return ((_a3 = browser == null ? void 0 : browser.platform) == null ? void 0 : _a3.type) === "mobile" || ((_b = browser == null ? void 0 : browser.platform) == null ? void 0 : _b.type) === "tablet";
|
|
446
466
|
}
|
|
447
467
|
function getPlatformType() {
|
|
448
468
|
if (isReactNative()) {
|
|
@@ -460,11 +480,11 @@ function getPlatformType() {
|
|
|
460
480
|
return "web-desktop" /* DesktopWeb */;
|
|
461
481
|
}
|
|
462
482
|
function isMetamaskExtensionInstalled() {
|
|
463
|
-
var
|
|
483
|
+
var _a3;
|
|
464
484
|
if (typeof window === "undefined") {
|
|
465
485
|
return false;
|
|
466
486
|
}
|
|
467
|
-
return Boolean((
|
|
487
|
+
return Boolean((_a3 = window.ethereum) == null ? void 0 : _a3.isMetaMask);
|
|
468
488
|
}
|
|
469
489
|
function isSecure() {
|
|
470
490
|
const platformType = getPlatformType();
|
|
@@ -495,8 +515,8 @@ var init_platform = __esm({
|
|
|
495
515
|
return new Promise((resolve) => {
|
|
496
516
|
const providers = [];
|
|
497
517
|
const handler = (event) => {
|
|
498
|
-
var
|
|
499
|
-
if ((_b = (
|
|
518
|
+
var _a3, _b;
|
|
519
|
+
if ((_b = (_a3 = event == null ? void 0 : event.detail) == null ? void 0 : _a3.info) == null ? void 0 : _b.rdns) {
|
|
500
520
|
providers.push(event.detail);
|
|
501
521
|
}
|
|
502
522
|
};
|
|
@@ -506,8 +526,8 @@ var init_platform = __esm({
|
|
|
506
526
|
window.removeEventListener("eip6963:announceProvider", handler);
|
|
507
527
|
const hasMetaMask = providers.some(
|
|
508
528
|
(provider) => {
|
|
509
|
-
var
|
|
510
|
-
return (_b = (
|
|
529
|
+
var _a3, _b;
|
|
530
|
+
return (_b = (_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
511
531
|
}
|
|
512
532
|
);
|
|
513
533
|
resolve(hasMetaMask);
|
|
@@ -591,12 +611,108 @@ var init_ui = __esm({
|
|
|
591
611
|
}
|
|
592
612
|
});
|
|
593
613
|
|
|
614
|
+
// src/multichain/utils/analytics.ts
|
|
615
|
+
function isRejectionError(error) {
|
|
616
|
+
var _a3, _b;
|
|
617
|
+
if (typeof error !== "object" || error === null) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
const errorObj = error;
|
|
621
|
+
const errorCode = errorObj.code;
|
|
622
|
+
const errorMessage = (_b = (_a3 = errorObj.message) == null ? void 0 : _a3.toLowerCase()) != null ? _b : "";
|
|
623
|
+
return errorCode === 4001 || // User rejected request (common EIP-1193 code)
|
|
624
|
+
errorCode === 4100 || // Unauthorized (common rejection code)
|
|
625
|
+
errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
|
|
626
|
+
}
|
|
627
|
+
function getBaseAnalyticsProperties(options, storage) {
|
|
628
|
+
return __async(this, null, function* () {
|
|
629
|
+
var _a3, _b;
|
|
630
|
+
const version = getVersion();
|
|
631
|
+
const dappId = getDappId(options.dapp);
|
|
632
|
+
const platform = getPlatformType();
|
|
633
|
+
const anonId = yield storage.getAnonId();
|
|
634
|
+
const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
635
|
+
return {
|
|
636
|
+
mmconnect_version: version,
|
|
637
|
+
dapp_id: dappId,
|
|
638
|
+
platform,
|
|
639
|
+
integration_type: integrationType,
|
|
640
|
+
anon_id: anonId
|
|
641
|
+
};
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
645
|
+
return __async(this, null, function* () {
|
|
646
|
+
var _a3, _b;
|
|
647
|
+
const version = getVersion();
|
|
648
|
+
const dappId = getDappId(options.dapp);
|
|
649
|
+
const anonId = yield storage.getAnonId();
|
|
650
|
+
const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown";
|
|
651
|
+
return {
|
|
652
|
+
mmconnect_version: version,
|
|
653
|
+
dapp_id: dappId,
|
|
654
|
+
method: invokeOptions.request.method,
|
|
655
|
+
integration_type: integrationType,
|
|
656
|
+
caip_chain_id: invokeOptions.scope,
|
|
657
|
+
anon_id: anonId
|
|
658
|
+
};
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
var init_analytics = __esm({
|
|
662
|
+
"src/multichain/utils/analytics.ts"() {
|
|
663
|
+
"use strict";
|
|
664
|
+
init_utils2();
|
|
665
|
+
init_domain();
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// src/domain/utils/index.ts
|
|
670
|
+
function getVersion() {
|
|
671
|
+
return "0.0.0";
|
|
672
|
+
}
|
|
673
|
+
var init_utils = __esm({
|
|
674
|
+
"src/domain/utils/index.ts"() {
|
|
675
|
+
"use strict";
|
|
676
|
+
init_analytics();
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
// src/domain/index.ts
|
|
681
|
+
var init_domain = __esm({
|
|
682
|
+
"src/domain/index.ts"() {
|
|
683
|
+
"use strict";
|
|
684
|
+
init_errors();
|
|
685
|
+
init_events();
|
|
686
|
+
init_logger();
|
|
687
|
+
init_multichain();
|
|
688
|
+
init_platform();
|
|
689
|
+
init_store();
|
|
690
|
+
init_ui();
|
|
691
|
+
init_utils();
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
|
|
594
695
|
// src/multichain/utils/index.ts
|
|
595
696
|
import {
|
|
596
697
|
parseCaipAccountId,
|
|
597
698
|
parseCaipChainId
|
|
598
699
|
} from "@metamask/utils";
|
|
599
700
|
import { deflate } from "pako";
|
|
701
|
+
function getGlobalObject() {
|
|
702
|
+
if (typeof globalThis !== "undefined") {
|
|
703
|
+
return globalThis;
|
|
704
|
+
}
|
|
705
|
+
if (typeof global !== "undefined") {
|
|
706
|
+
return global;
|
|
707
|
+
}
|
|
708
|
+
if (typeof self !== "undefined") {
|
|
709
|
+
return self;
|
|
710
|
+
}
|
|
711
|
+
if (typeof window !== "undefined") {
|
|
712
|
+
return window;
|
|
713
|
+
}
|
|
714
|
+
throw new Error("Unable to locate global object");
|
|
715
|
+
}
|
|
600
716
|
function base64Encode(str) {
|
|
601
717
|
if (typeof btoa !== "undefined") {
|
|
602
718
|
return btoa(str);
|
|
@@ -611,13 +727,13 @@ function compressString(str) {
|
|
|
611
727
|
return base64Encode(binaryString);
|
|
612
728
|
}
|
|
613
729
|
function getDappId(dapp) {
|
|
614
|
-
var
|
|
615
|
-
return (
|
|
730
|
+
var _a3;
|
|
731
|
+
return (_a3 = dapp.url) != null ? _a3 : dapp.name;
|
|
616
732
|
}
|
|
617
733
|
function openDeeplink(options, deeplink, universalLink) {
|
|
618
|
-
var
|
|
734
|
+
var _a3;
|
|
619
735
|
const { mobile } = options;
|
|
620
|
-
const useDeeplink = (
|
|
736
|
+
const useDeeplink = (_a3 = mobile == null ? void 0 : mobile.useDeeplink) != null ? _a3 : true;
|
|
621
737
|
if (useDeeplink) {
|
|
622
738
|
if (typeof window !== "undefined") {
|
|
623
739
|
window.location.href = deeplink;
|
|
@@ -630,6 +746,29 @@ function openDeeplink(options, deeplink, universalLink) {
|
|
|
630
746
|
link.click();
|
|
631
747
|
}
|
|
632
748
|
}
|
|
749
|
+
function mergeRequestedSessionWithExisting(sessionData, scopes, caipAccountIds, sessionProperties) {
|
|
750
|
+
const existingCaipChainIds = Object.keys(sessionData.sessionScopes);
|
|
751
|
+
const existingCaipAccountIds = [];
|
|
752
|
+
Object.values(sessionData.sessionScopes).forEach((scopeObject) => {
|
|
753
|
+
if ((scopeObject == null ? void 0 : scopeObject.accounts) && Array.isArray(scopeObject.accounts)) {
|
|
754
|
+
scopeObject.accounts.forEach((account) => {
|
|
755
|
+
existingCaipAccountIds.push(account);
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
const mergedScopes = Array.from(
|
|
760
|
+
/* @__PURE__ */ new Set([...existingCaipChainIds, ...scopes])
|
|
761
|
+
);
|
|
762
|
+
const mergedCaipAccountIds = Array.from(
|
|
763
|
+
/* @__PURE__ */ new Set([...existingCaipAccountIds, ...caipAccountIds])
|
|
764
|
+
);
|
|
765
|
+
const mergedSessionProperties = __spreadValues(__spreadValues({}, sessionData.sessionProperties), sessionProperties);
|
|
766
|
+
return {
|
|
767
|
+
mergedScopes,
|
|
768
|
+
mergedCaipAccountIds,
|
|
769
|
+
mergedSessionProperties
|
|
770
|
+
};
|
|
771
|
+
}
|
|
633
772
|
function getOptionalScopes(scopes) {
|
|
634
773
|
return scopes.reduce(
|
|
635
774
|
(prev, scope) => __spreadProps(__spreadValues({}, prev), {
|
|
@@ -643,10 +782,10 @@ function getOptionalScopes(scopes) {
|
|
|
643
782
|
);
|
|
644
783
|
}
|
|
645
784
|
function setupDappMetadata(options) {
|
|
646
|
-
var
|
|
785
|
+
var _a3, _b;
|
|
647
786
|
const platform = getPlatformType();
|
|
648
787
|
const isBrowser = platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */ || platform === "in-app-browser" /* MetaMaskMobileWebview */;
|
|
649
|
-
if (!((
|
|
788
|
+
if (!((_a3 = options.dapp) == null ? void 0 : _a3.name)) {
|
|
650
789
|
throw new Error("You must provide dapp name");
|
|
651
790
|
}
|
|
652
791
|
if (isBrowser) {
|
|
@@ -720,17 +859,17 @@ function getValidAccounts(caipAccountIds) {
|
|
|
720
859
|
);
|
|
721
860
|
}
|
|
722
861
|
function addValidAccounts(optionalScopes, validAccounts) {
|
|
723
|
-
var
|
|
862
|
+
var _a3;
|
|
724
863
|
if (!optionalScopes || !(validAccounts == null ? void 0 : validAccounts.length)) {
|
|
725
864
|
return optionalScopes;
|
|
726
865
|
}
|
|
727
866
|
const result = Object.fromEntries(
|
|
728
867
|
Object.entries(optionalScopes).map(([scope, scopeData]) => {
|
|
729
|
-
var
|
|
868
|
+
var _a4, _b, _c;
|
|
730
869
|
return [
|
|
731
870
|
scope,
|
|
732
871
|
{
|
|
733
|
-
methods: [...(
|
|
872
|
+
methods: [...(_a4 = scopeData == null ? void 0 : scopeData.methods) != null ? _a4 : []],
|
|
734
873
|
notifications: [...(_b = scopeData == null ? void 0 : scopeData.notifications) != null ? _b : []],
|
|
735
874
|
accounts: [...(_c = scopeData == null ? void 0 : scopeData.accounts) != null ? _c : []]
|
|
736
875
|
}
|
|
@@ -744,7 +883,7 @@ function addValidAccounts(optionalScopes, validAccounts) {
|
|
|
744
883
|
if (!accountsByChain.has(chainKey)) {
|
|
745
884
|
accountsByChain.set(chainKey, []);
|
|
746
885
|
}
|
|
747
|
-
(
|
|
886
|
+
(_a3 = accountsByChain.get(chainKey)) == null ? void 0 : _a3.push(accountId);
|
|
748
887
|
}
|
|
749
888
|
for (const [scopeKey, scopeData] of Object.entries(result)) {
|
|
750
889
|
if (!(scopeData == null ? void 0 : scopeData.accounts)) {
|
|
@@ -768,13 +907,13 @@ function addValidAccounts(optionalScopes, validAccounts) {
|
|
|
768
907
|
}
|
|
769
908
|
return result;
|
|
770
909
|
}
|
|
771
|
-
var extractFavicon;
|
|
772
|
-
var
|
|
910
|
+
var extractFavicon, MAX, idCounter, getUniqueRequestId;
|
|
911
|
+
var init_utils2 = __esm({
|
|
773
912
|
"src/multichain/utils/index.ts"() {
|
|
774
913
|
"use strict";
|
|
775
914
|
init_domain();
|
|
776
915
|
extractFavicon = () => {
|
|
777
|
-
var
|
|
916
|
+
var _a3;
|
|
778
917
|
if (typeof document === "undefined") {
|
|
779
918
|
return void 0;
|
|
780
919
|
}
|
|
@@ -782,92 +921,17 @@ var init_utils = __esm({
|
|
|
782
921
|
const nodeList = document.getElementsByTagName("link");
|
|
783
922
|
for (let i = 0; i < nodeList.length; i++) {
|
|
784
923
|
if (nodeList[i].getAttribute("rel") === "icon" || nodeList[i].getAttribute("rel") === "shortcut icon") {
|
|
785
|
-
favicon = (
|
|
924
|
+
favicon = (_a3 = nodeList[i].getAttribute("href")) != null ? _a3 : void 0;
|
|
786
925
|
}
|
|
787
926
|
}
|
|
788
927
|
return favicon;
|
|
789
928
|
};
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
var _a2, _b;
|
|
796
|
-
if (typeof error !== "object" || error === null) {
|
|
797
|
-
return false;
|
|
798
|
-
}
|
|
799
|
-
const errorObj = error;
|
|
800
|
-
const errorCode = errorObj.code;
|
|
801
|
-
const errorMessage = (_b = (_a2 = errorObj.message) == null ? void 0 : _a2.toLowerCase()) != null ? _b : "";
|
|
802
|
-
return errorCode === 4001 || // User rejected request (common EIP-1193 code)
|
|
803
|
-
errorCode === 4100 || // Unauthorized (common rejection code)
|
|
804
|
-
errorMessage.includes("reject") || errorMessage.includes("denied") || errorMessage.includes("cancel") || errorMessage.includes("user");
|
|
805
|
-
}
|
|
806
|
-
function getBaseAnalyticsProperties(options, storage) {
|
|
807
|
-
return __async(this, null, function* () {
|
|
808
|
-
var _a2, _b;
|
|
809
|
-
const version = getVersion();
|
|
810
|
-
const dappId = getDappId(options.dapp);
|
|
811
|
-
const platform = getPlatformType();
|
|
812
|
-
const anonId = yield storage.getAnonId();
|
|
813
|
-
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
814
|
-
return {
|
|
815
|
-
mmconnect_version: version,
|
|
816
|
-
dapp_id: dappId,
|
|
817
|
-
platform,
|
|
818
|
-
integration_type: integrationType,
|
|
819
|
-
anon_id: anonId
|
|
929
|
+
MAX = 4294967295;
|
|
930
|
+
idCounter = Math.floor(Math.random() * MAX);
|
|
931
|
+
getUniqueRequestId = () => {
|
|
932
|
+
idCounter = (idCounter + 1) % MAX;
|
|
933
|
+
return idCounter;
|
|
820
934
|
};
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
824
|
-
return __async(this, null, function* () {
|
|
825
|
-
var _a2, _b;
|
|
826
|
-
const version = getVersion();
|
|
827
|
-
const dappId = getDappId(options.dapp);
|
|
828
|
-
const anonId = yield storage.getAnonId();
|
|
829
|
-
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
|
|
830
|
-
return {
|
|
831
|
-
mmconnect_version: version,
|
|
832
|
-
dapp_id: dappId,
|
|
833
|
-
method: invokeOptions.request.method,
|
|
834
|
-
integration_type: integrationType,
|
|
835
|
-
caip_chain_id: invokeOptions.scope,
|
|
836
|
-
anon_id: anonId
|
|
837
|
-
};
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
var init_analytics = __esm({
|
|
841
|
-
"src/multichain/utils/analytics.ts"() {
|
|
842
|
-
"use strict";
|
|
843
|
-
init_utils();
|
|
844
|
-
init_domain();
|
|
845
|
-
}
|
|
846
|
-
});
|
|
847
|
-
|
|
848
|
-
// src/domain/utils/index.ts
|
|
849
|
-
function getVersion() {
|
|
850
|
-
return "0.0.0";
|
|
851
|
-
}
|
|
852
|
-
var init_utils2 = __esm({
|
|
853
|
-
"src/domain/utils/index.ts"() {
|
|
854
|
-
"use strict";
|
|
855
|
-
init_analytics();
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
|
|
859
|
-
// src/domain/index.ts
|
|
860
|
-
var init_domain = __esm({
|
|
861
|
-
"src/domain/index.ts"() {
|
|
862
|
-
"use strict";
|
|
863
|
-
init_errors();
|
|
864
|
-
init_events();
|
|
865
|
-
init_logger();
|
|
866
|
-
init_multichain();
|
|
867
|
-
init_platform();
|
|
868
|
-
init_store();
|
|
869
|
-
init_ui();
|
|
870
|
-
init_utils2();
|
|
871
935
|
}
|
|
872
936
|
});
|
|
873
937
|
|
|
@@ -996,7 +1060,7 @@ var init_install = __esm({
|
|
|
996
1060
|
renderQRCode() {
|
|
997
1061
|
}
|
|
998
1062
|
mount() {
|
|
999
|
-
var
|
|
1063
|
+
var _a3;
|
|
1000
1064
|
const { options } = this;
|
|
1001
1065
|
const modal = document.createElement(
|
|
1002
1066
|
"mm-install-modal"
|
|
@@ -1013,14 +1077,14 @@ var init_install = __esm({
|
|
|
1013
1077
|
);
|
|
1014
1078
|
modal.link = options.link;
|
|
1015
1079
|
this.instance = modal;
|
|
1016
|
-
(
|
|
1080
|
+
(_a3 = options.parentElement) == null ? void 0 : _a3.appendChild(modal);
|
|
1017
1081
|
this.startExpirationCheck(options.connectionRequest);
|
|
1018
1082
|
}
|
|
1019
1083
|
unmount() {
|
|
1020
|
-
var
|
|
1084
|
+
var _a3;
|
|
1021
1085
|
const { options, instance: modal } = this;
|
|
1022
1086
|
this.stopExpirationCheck();
|
|
1023
|
-
if (modal && ((
|
|
1087
|
+
if (modal && ((_a3 = options.parentElement) == null ? void 0 : _a3.contains(modal))) {
|
|
1024
1088
|
options.parentElement.removeChild(modal);
|
|
1025
1089
|
this.instance = void 0;
|
|
1026
1090
|
}
|
|
@@ -1132,8 +1196,8 @@ var init_web2 = __esm({
|
|
|
1132
1196
|
const request = store.get(key);
|
|
1133
1197
|
request.onerror = () => reject(new Error("Failed to get value from IndexedDB."));
|
|
1134
1198
|
request.onsuccess = () => {
|
|
1135
|
-
var
|
|
1136
|
-
return resolve((
|
|
1199
|
+
var _a3;
|
|
1200
|
+
return resolve((_a3 = request.result) != null ? _a3 : null);
|
|
1137
1201
|
};
|
|
1138
1202
|
} catch (error) {
|
|
1139
1203
|
reject(error);
|
|
@@ -1177,17 +1241,17 @@ var init_web2 = __esm({
|
|
|
1177
1241
|
}
|
|
1178
1242
|
};
|
|
1179
1243
|
_StoreAdapterWeb.stores = ["sdk-kv-store", "key-value-pairs"];
|
|
1180
|
-
_StoreAdapterWeb.DB_NAME = "
|
|
1244
|
+
_StoreAdapterWeb.DB_NAME = "mmconnect";
|
|
1181
1245
|
StoreAdapterWeb = _StoreAdapterWeb;
|
|
1182
1246
|
}
|
|
1183
1247
|
});
|
|
1184
1248
|
|
|
1185
1249
|
// src/polyfills/buffer-shim.ts
|
|
1250
|
+
init_utils2();
|
|
1186
1251
|
import { Buffer as Buffer2 } from "buffer";
|
|
1187
|
-
var globalObj =
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
}
|
|
1252
|
+
var globalObj = getGlobalObject();
|
|
1253
|
+
var _a;
|
|
1254
|
+
(_a = globalObj.Buffer) != null ? _a : globalObj.Buffer = Buffer2;
|
|
1191
1255
|
|
|
1192
1256
|
// src/index.browser.ts
|
|
1193
1257
|
init_domain();
|
|
@@ -1260,8 +1324,8 @@ var RpcClient = class {
|
|
|
1260
1324
|
});
|
|
1261
1325
|
}
|
|
1262
1326
|
getRpcEndpoint(scope) {
|
|
1263
|
-
var
|
|
1264
|
-
const supportedNetworks = (_c = (_b = (
|
|
1327
|
+
var _a3, _b, _c;
|
|
1328
|
+
const supportedNetworks = (_c = (_b = (_a3 = this.config) == null ? void 0 : _a3.api) == null ? void 0 : _b.supportedNetworks) != null ? _c : {};
|
|
1265
1329
|
const rpcEndpoint = supportedNetworks[scope];
|
|
1266
1330
|
if (!rpcEndpoint) {
|
|
1267
1331
|
throw new MissingRpcEndpointErr(
|
|
@@ -1325,7 +1389,7 @@ var RpcClient = class {
|
|
|
1325
1389
|
// src/multichain/rpc/requestRouter.ts
|
|
1326
1390
|
import { analytics } from "@metamask/analytics";
|
|
1327
1391
|
init_domain();
|
|
1328
|
-
|
|
1392
|
+
init_utils2();
|
|
1329
1393
|
init_analytics();
|
|
1330
1394
|
var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
|
|
1331
1395
|
var RequestRouter = class {
|
|
@@ -1492,12 +1556,12 @@ trackWalletActionRejected_fn = function(options) {
|
|
|
1492
1556
|
};
|
|
1493
1557
|
|
|
1494
1558
|
// src/multichain/transports/default/index.ts
|
|
1495
|
-
|
|
1559
|
+
init_utils2();
|
|
1496
1560
|
import {
|
|
1497
1561
|
getDefaultTransport
|
|
1498
1562
|
} from "@metamask/multichain-api-client";
|
|
1499
1563
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
1500
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions,
|
|
1564
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
|
|
1501
1565
|
var DefaultTransport = class {
|
|
1502
1566
|
constructor() {
|
|
1503
1567
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -1506,8 +1570,6 @@ var DefaultTransport = class {
|
|
|
1506
1570
|
__privateAdd(this, _defaultRequestOptions, {
|
|
1507
1571
|
timeout: DEFAULT_REQUEST_TIMEOUT
|
|
1508
1572
|
});
|
|
1509
|
-
// Use timestamp-based ID to avoid conflicts across disconnect/reconnect cycles
|
|
1510
|
-
__privateAdd(this, _reqId, Date.now());
|
|
1511
1573
|
__privateAdd(this, _pendingRequests, /* @__PURE__ */ new Map());
|
|
1512
1574
|
__privateAdd(this, _handleResponseListener);
|
|
1513
1575
|
__privateAdd(this, _handleNotificationListener);
|
|
@@ -1515,18 +1577,17 @@ var DefaultTransport = class {
|
|
|
1515
1577
|
sendEip1193Message(payload, options) {
|
|
1516
1578
|
return __async(this, null, function* () {
|
|
1517
1579
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1518
|
-
|
|
1519
|
-
const requestId = `${__privateGet(this, _reqId)}`;
|
|
1580
|
+
const requestId = String(getUniqueRequestId());
|
|
1520
1581
|
const request = __spreadValues({
|
|
1521
1582
|
jsonrpc: "2.0",
|
|
1522
1583
|
id: requestId
|
|
1523
1584
|
}, payload);
|
|
1524
1585
|
return new Promise((resolve, reject) => {
|
|
1525
|
-
var
|
|
1586
|
+
var _a3;
|
|
1526
1587
|
const timeout = setTimeout(() => {
|
|
1527
1588
|
__privateGet(this, _pendingRequests).delete(requestId);
|
|
1528
1589
|
reject(new Error("Request timeout"));
|
|
1529
|
-
}, (
|
|
1590
|
+
}, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : __privateGet(this, _defaultRequestOptions).timeout);
|
|
1530
1591
|
__privateGet(this, _pendingRequests).set(requestId, {
|
|
1531
1592
|
resolve: (response) => {
|
|
1532
1593
|
resolve(response);
|
|
@@ -1550,7 +1611,7 @@ var DefaultTransport = class {
|
|
|
1550
1611
|
}
|
|
1551
1612
|
connect(options) {
|
|
1552
1613
|
return __async(this, null, function* () {
|
|
1553
|
-
var
|
|
1614
|
+
var _a3, _b, _c, _d, _e;
|
|
1554
1615
|
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1555
1616
|
yield __privateGet(this, _transport).connect();
|
|
1556
1617
|
const sessionRequest = yield this.request(
|
|
@@ -1563,7 +1624,7 @@ var DefaultTransport = class {
|
|
|
1563
1624
|
let walletSession = sessionRequest.result;
|
|
1564
1625
|
const createSessionParams = {
|
|
1565
1626
|
optionalScopes: addValidAccounts(
|
|
1566
|
-
getOptionalScopes((
|
|
1627
|
+
getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
|
|
1567
1628
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1568
1629
|
),
|
|
1569
1630
|
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
@@ -1581,10 +1642,6 @@ var DefaultTransport = class {
|
|
|
1581
1642
|
proposedCaipAccountIds
|
|
1582
1643
|
);
|
|
1583
1644
|
if (!hasSameScopesAndAccounts) {
|
|
1584
|
-
yield this.request(
|
|
1585
|
-
{ method: "wallet_revokeSession", params: walletSession },
|
|
1586
|
-
__privateGet(this, _defaultRequestOptions)
|
|
1587
|
-
);
|
|
1588
1645
|
const response = yield this.request(
|
|
1589
1646
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
1590
1647
|
__privateGet(this, _defaultRequestOptions)
|
|
@@ -1611,9 +1668,14 @@ var DefaultTransport = class {
|
|
|
1611
1668
|
});
|
|
1612
1669
|
}
|
|
1613
1670
|
disconnect() {
|
|
1614
|
-
return __async(this,
|
|
1671
|
+
return __async(this, arguments, function* (scopes = []) {
|
|
1672
|
+
yield this.request({ method: "wallet_revokeSession", params: { scopes } });
|
|
1673
|
+
const response = yield this.request({ method: "wallet_getSession" });
|
|
1674
|
+
const { sessionScopes } = response.result;
|
|
1675
|
+
if (Object.keys(sessionScopes).length > 0) {
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1615
1678
|
__privateGet(this, _notificationCallbacks).clear();
|
|
1616
|
-
yield this.request({ method: "wallet_revokeSession", params: {} });
|
|
1617
1679
|
if (__privateGet(this, _handleResponseListener)) {
|
|
1618
1680
|
window.removeEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1619
1681
|
__privateSet(this, _handleResponseListener, void 0);
|
|
@@ -1627,7 +1689,7 @@ var DefaultTransport = class {
|
|
|
1627
1689
|
request.reject(new Error("Transport disconnected"));
|
|
1628
1690
|
}
|
|
1629
1691
|
__privateGet(this, _pendingRequests).clear();
|
|
1630
|
-
|
|
1692
|
+
yield __privateGet(this, _transport).disconnect();
|
|
1631
1693
|
});
|
|
1632
1694
|
}
|
|
1633
1695
|
isConnected() {
|
|
@@ -1652,11 +1714,17 @@ var DefaultTransport = class {
|
|
|
1652
1714
|
);
|
|
1653
1715
|
});
|
|
1654
1716
|
}
|
|
1717
|
+
getStoredPendingSessionRequest() {
|
|
1718
|
+
return __async(this, null, function* () {
|
|
1719
|
+
throw new Error(
|
|
1720
|
+
"getStoredPendingSessionRequest is purposely not implemented for the DefaultTransport"
|
|
1721
|
+
);
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1655
1724
|
};
|
|
1656
1725
|
_notificationCallbacks = new WeakMap();
|
|
1657
1726
|
_transport = new WeakMap();
|
|
1658
1727
|
_defaultRequestOptions = new WeakMap();
|
|
1659
|
-
_reqId = new WeakMap();
|
|
1660
1728
|
_pendingRequests = new WeakMap();
|
|
1661
1729
|
_handleResponseListener = new WeakMap();
|
|
1662
1730
|
_handleNotificationListener = new WeakMap();
|
|
@@ -1674,16 +1742,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
1674
1742
|
}
|
|
1675
1743
|
};
|
|
1676
1744
|
isMetamaskProviderEvent_fn = function(event) {
|
|
1677
|
-
var
|
|
1678
|
-
return ((_b = (
|
|
1745
|
+
var _a3, _b;
|
|
1746
|
+
return ((_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
|
|
1679
1747
|
event.origin === location.origin;
|
|
1680
1748
|
};
|
|
1681
1749
|
handleResponse_fn = function(event) {
|
|
1682
|
-
var
|
|
1750
|
+
var _a3, _b;
|
|
1683
1751
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1684
1752
|
return;
|
|
1685
1753
|
}
|
|
1686
|
-
const responseData = (_b = (
|
|
1754
|
+
const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
|
|
1687
1755
|
if (typeof responseData === "object" && responseData !== null && "method" in responseData) {
|
|
1688
1756
|
return;
|
|
1689
1757
|
}
|
|
@@ -1705,11 +1773,11 @@ handleResponse_fn = function(event) {
|
|
|
1705
1773
|
}
|
|
1706
1774
|
};
|
|
1707
1775
|
handleNotification_fn = function(event) {
|
|
1708
|
-
var
|
|
1776
|
+
var _a3, _b;
|
|
1709
1777
|
if (!__privateMethod(this, _DefaultTransport_instances, isMetamaskProviderEvent_fn).call(this, event)) {
|
|
1710
1778
|
return;
|
|
1711
1779
|
}
|
|
1712
|
-
const responseData = (_b = (
|
|
1780
|
+
const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
|
|
1713
1781
|
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1714
1782
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1715
1783
|
}
|
|
@@ -1725,19 +1793,13 @@ setupMessageListener_fn = function() {
|
|
|
1725
1793
|
};
|
|
1726
1794
|
|
|
1727
1795
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
1796
|
+
init_utils2();
|
|
1728
1797
|
import { providerErrors } from "@metamask/rpc-errors";
|
|
1729
|
-
var
|
|
1730
|
-
var idCounter = Math.floor(Math.random() * MAX);
|
|
1731
|
-
var getUniqueId = () => {
|
|
1732
|
-
idCounter = (idCounter + 1) % MAX;
|
|
1733
|
-
return idCounter;
|
|
1734
|
-
};
|
|
1735
|
-
var _requestId, _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
1798
|
+
var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
1736
1799
|
var MultichainApiClientWrapperTransport = class {
|
|
1737
1800
|
constructor(metamaskConnectMultichain) {
|
|
1738
1801
|
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
1739
1802
|
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
1740
|
-
__privateAdd(this, _requestId, getUniqueId());
|
|
1741
1803
|
__privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
|
|
1742
1804
|
}
|
|
1743
1805
|
isTransportDefined() {
|
|
@@ -1755,15 +1817,23 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
1755
1817
|
callback(data);
|
|
1756
1818
|
});
|
|
1757
1819
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1820
|
+
clearTransportNotificationListener() {
|
|
1821
|
+
var _a3;
|
|
1822
|
+
(_a3 = this.notificationListener) == null ? void 0 : _a3.call(this);
|
|
1823
|
+
this.notificationListener = void 0;
|
|
1824
|
+
}
|
|
1825
|
+
setupTransportNotificationListener() {
|
|
1826
|
+
if (!this.isTransportDefined() || this.notificationListener) {
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
this.notificationListener = this.metamaskConnectMultichain.transport.onNotification(
|
|
1760
1830
|
this.notifyCallbacks.bind(this)
|
|
1761
1831
|
);
|
|
1762
1832
|
}
|
|
1763
1833
|
connect() {
|
|
1764
1834
|
return __async(this, null, function* () {
|
|
1765
1835
|
console.log("\u{1F4DA} connect");
|
|
1766
|
-
|
|
1836
|
+
yield this.metamaskConnectMultichain.emitSessionChanged();
|
|
1767
1837
|
});
|
|
1768
1838
|
}
|
|
1769
1839
|
disconnect() {
|
|
@@ -1776,7 +1846,7 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
1776
1846
|
}
|
|
1777
1847
|
request(_0) {
|
|
1778
1848
|
return __async(this, arguments, function* (params, _options = {}) {
|
|
1779
|
-
const id =
|
|
1849
|
+
const id = getUniqueRequestId();
|
|
1780
1850
|
const requestPayload = __spreadValues({
|
|
1781
1851
|
id,
|
|
1782
1852
|
jsonrpc: "2.0"
|
|
@@ -1797,16 +1867,13 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
1797
1867
|
});
|
|
1798
1868
|
}
|
|
1799
1869
|
onNotification(callback) {
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
}
|
|
1806
|
-
return this.metamaskConnectMultichain.transport.onNotification(callback);
|
|
1870
|
+
this.setupTransportNotificationListener();
|
|
1871
|
+
__privateGet(this, _notificationCallbacks2).add(callback);
|
|
1872
|
+
return () => {
|
|
1873
|
+
__privateGet(this, _notificationCallbacks2).delete(callback);
|
|
1874
|
+
};
|
|
1807
1875
|
}
|
|
1808
1876
|
};
|
|
1809
|
-
_requestId = new WeakMap();
|
|
1810
1877
|
_notificationCallbacks2 = new WeakMap();
|
|
1811
1878
|
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
1812
1879
|
walletCreateSession_fn = function(request) {
|
|
@@ -1816,8 +1883,8 @@ walletCreateSession_fn = function(request) {
|
|
|
1816
1883
|
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
1817
1884
|
const scopeAccounts = [];
|
|
1818
1885
|
scopes.forEach((scope) => {
|
|
1819
|
-
var
|
|
1820
|
-
const requiredScope = (
|
|
1886
|
+
var _a3, _b, _c, _d;
|
|
1887
|
+
const requiredScope = (_a3 = createSessionParams.requiredScopes) == null ? void 0 : _a3[scope];
|
|
1821
1888
|
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
1822
1889
|
if (requiredScope) {
|
|
1823
1890
|
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
@@ -1857,11 +1924,14 @@ walletGetSession_fn = function(request) {
|
|
|
1857
1924
|
};
|
|
1858
1925
|
walletRevokeSession_fn = function(request) {
|
|
1859
1926
|
return __async(this, null, function* () {
|
|
1927
|
+
var _a3;
|
|
1860
1928
|
if (!this.isTransportDefined()) {
|
|
1861
1929
|
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
1862
1930
|
}
|
|
1931
|
+
const revokeSessionParams = request.params;
|
|
1932
|
+
const scopes = (_a3 = revokeSessionParams == null ? void 0 : revokeSessionParams.scopes) != null ? _a3 : [];
|
|
1863
1933
|
try {
|
|
1864
|
-
this.metamaskConnectMultichain.disconnect();
|
|
1934
|
+
yield this.metamaskConnectMultichain.disconnect(scopes);
|
|
1865
1935
|
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
1866
1936
|
} catch (_error) {
|
|
1867
1937
|
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
@@ -1884,11 +1954,12 @@ walletInvokeMethod_fn = function(request) {
|
|
|
1884
1954
|
|
|
1885
1955
|
// src/multichain/transports/mwp/index.ts
|
|
1886
1956
|
init_domain();
|
|
1887
|
-
|
|
1957
|
+
init_utils2();
|
|
1888
1958
|
import { SessionStore } from "@metamask/mobile-wallet-protocol-core";
|
|
1889
1959
|
import {
|
|
1890
1960
|
TransportTimeoutError
|
|
1891
1961
|
} from "@metamask/multichain-api-client";
|
|
1962
|
+
import { providerErrors as providerErrors2, rpcErrors } from "@metamask/rpc-errors";
|
|
1892
1963
|
|
|
1893
1964
|
// src/multichain/transports/constants.ts
|
|
1894
1965
|
var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
|
|
@@ -1901,6 +1972,7 @@ var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
|
|
|
1901
1972
|
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1902
1973
|
var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
|
|
1903
1974
|
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
1975
|
+
var PENDING_SESSION_REQUEST_KEY = "pending_session_request";
|
|
1904
1976
|
var CACHED_METHOD_LIST = [
|
|
1905
1977
|
"wallet_getSession",
|
|
1906
1978
|
"wallet_createSession",
|
|
@@ -1920,10 +1992,15 @@ var MWPTransport = class {
|
|
|
1920
1992
|
this.dappClient = dappClient;
|
|
1921
1993
|
this.kvstore = kvstore;
|
|
1922
1994
|
this.options = options;
|
|
1923
|
-
this.__reqId = 0;
|
|
1924
1995
|
this.__pendingRequests = /* @__PURE__ */ new Map();
|
|
1925
1996
|
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
1926
1997
|
this.dappClient.on("message", this.handleMessage.bind(this));
|
|
1998
|
+
this.dappClient.on("session_request", (sessionRequest) => {
|
|
1999
|
+
this.currentSessionRequest = sessionRequest;
|
|
2000
|
+
this.kvstore.set(PENDING_SESSION_REQUEST_KEY, JSON.stringify(sessionRequest)).catch((err) => {
|
|
2001
|
+
logger("Failed to store pending session request", err);
|
|
2002
|
+
});
|
|
2003
|
+
});
|
|
1927
2004
|
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
1928
2005
|
this.windowFocusHandler = this.onWindowFocus.bind(this);
|
|
1929
2006
|
window.addEventListener("focus", this.windowFocusHandler);
|
|
@@ -1938,6 +2015,34 @@ var MWPTransport = class {
|
|
|
1938
2015
|
get sessionRequest() {
|
|
1939
2016
|
return this.currentSessionRequest;
|
|
1940
2017
|
}
|
|
2018
|
+
/**
|
|
2019
|
+
* Returns the stored pending session request from the dappClient session_request event, if any.
|
|
2020
|
+
*
|
|
2021
|
+
* @returns The stored SessionRequest, or null if none or invalid.
|
|
2022
|
+
*/
|
|
2023
|
+
getStoredPendingSessionRequest() {
|
|
2024
|
+
return __async(this, null, function* () {
|
|
2025
|
+
try {
|
|
2026
|
+
const raw = yield this.kvstore.get(PENDING_SESSION_REQUEST_KEY);
|
|
2027
|
+
if (!raw) {
|
|
2028
|
+
return null;
|
|
2029
|
+
}
|
|
2030
|
+
return JSON.parse(raw);
|
|
2031
|
+
} catch (e) {
|
|
2032
|
+
return null;
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Removes the stored pending session request from the KVStore.
|
|
2038
|
+
* This is necessary to ensure that ConnectMultichain is able to correctly
|
|
2039
|
+
* infer the MWP Transport connection attempt status.
|
|
2040
|
+
*/
|
|
2041
|
+
removeStoredPendingSessionRequest() {
|
|
2042
|
+
return __async(this, null, function* () {
|
|
2043
|
+
yield this.kvstore.delete(PENDING_SESSION_REQUEST_KEY);
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
1941
2046
|
onWindowFocus() {
|
|
1942
2047
|
if (!this.isConnected()) {
|
|
1943
2048
|
this.dappClient.reconnect();
|
|
@@ -1954,6 +2059,17 @@ var MWPTransport = class {
|
|
|
1954
2059
|
request.reject(error);
|
|
1955
2060
|
}
|
|
1956
2061
|
}
|
|
2062
|
+
parseWalletError(errorPayload) {
|
|
2063
|
+
const errorData = errorPayload;
|
|
2064
|
+
if (typeof errorData.code === "number" && typeof errorData.message === "string") {
|
|
2065
|
+
return providerErrors2.custom({
|
|
2066
|
+
code: errorData.code,
|
|
2067
|
+
message: errorData.message
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
|
|
2071
|
+
return rpcErrors.internal({ message });
|
|
2072
|
+
}
|
|
1957
2073
|
handleMessage(message) {
|
|
1958
2074
|
if (typeof message === "object" && message !== null) {
|
|
1959
2075
|
if ("data" in message) {
|
|
@@ -1961,6 +2077,12 @@ var MWPTransport = class {
|
|
|
1961
2077
|
if ("id" in messagePayload && typeof messagePayload.id === "string") {
|
|
1962
2078
|
const request = this.pendingRequests.get(messagePayload.id);
|
|
1963
2079
|
if (request) {
|
|
2080
|
+
clearTimeout(request.timeout);
|
|
2081
|
+
if ("error" in messagePayload && messagePayload.error) {
|
|
2082
|
+
this.pendingRequests.delete(messagePayload.id);
|
|
2083
|
+
request.reject(this.parseWalletError(messagePayload.error));
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
1964
2086
|
const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
|
|
1965
2087
|
method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method
|
|
1966
2088
|
});
|
|
@@ -1968,7 +2090,6 @@ var MWPTransport = class {
|
|
|
1968
2090
|
method: request.method === "wallet_getSession" || request.method === "wallet_createSession" ? "wallet_sessionChanged" : request.method,
|
|
1969
2091
|
params: requestWithName.result
|
|
1970
2092
|
});
|
|
1971
|
-
clearTimeout(request.timeout);
|
|
1972
2093
|
this.notifyCallbacks(notification);
|
|
1973
2094
|
request.resolve(requestWithName);
|
|
1974
2095
|
this.pendingRequests.delete(messagePayload.id);
|
|
@@ -2004,7 +2125,7 @@ var MWPTransport = class {
|
|
|
2004
2125
|
}
|
|
2005
2126
|
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
2006
2127
|
return __async(this, null, function* () {
|
|
2007
|
-
var
|
|
2128
|
+
var _a3, _b, _c, _d, _e, _f, _g;
|
|
2008
2129
|
try {
|
|
2009
2130
|
yield this.waitForWalletSessionIfNotCached();
|
|
2010
2131
|
const sessionRequest = yield this.request({
|
|
@@ -2016,7 +2137,7 @@ var MWPTransport = class {
|
|
|
2016
2137
|
let walletSession = sessionRequest.result;
|
|
2017
2138
|
if (walletSession && options) {
|
|
2018
2139
|
const currentScopes = Object.keys(
|
|
2019
|
-
(
|
|
2140
|
+
(_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
|
|
2020
2141
|
);
|
|
2021
2142
|
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
2022
2143
|
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
@@ -2058,6 +2179,7 @@ var MWPTransport = class {
|
|
|
2058
2179
|
}
|
|
2059
2180
|
walletSession = response.result;
|
|
2060
2181
|
}
|
|
2182
|
+
yield this.removeStoredPendingSessionRequest();
|
|
2061
2183
|
this.notifyCallbacks({
|
|
2062
2184
|
method: "wallet_sessionChanged",
|
|
2063
2185
|
params: walletSession
|
|
@@ -2073,7 +2195,7 @@ var MWPTransport = class {
|
|
|
2073
2195
|
return __async(this, null, function* () {
|
|
2074
2196
|
const request = __spreadValues({
|
|
2075
2197
|
jsonrpc: "2.0",
|
|
2076
|
-
id:
|
|
2198
|
+
id: String(getUniqueRequestId())
|
|
2077
2199
|
}, payload);
|
|
2078
2200
|
const cachedWalletSession = yield this.getCachedResponse(request);
|
|
2079
2201
|
if (cachedWalletSession) {
|
|
@@ -2081,10 +2203,10 @@ var MWPTransport = class {
|
|
|
2081
2203
|
return cachedWalletSession;
|
|
2082
2204
|
}
|
|
2083
2205
|
return new Promise((resolve, reject) => {
|
|
2084
|
-
var
|
|
2206
|
+
var _a3;
|
|
2085
2207
|
const timeout = setTimeout(() => {
|
|
2086
2208
|
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
2087
|
-
}, (
|
|
2209
|
+
}, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : this.options.requestTimeout);
|
|
2088
2210
|
this.pendingRequests.set(request.id, {
|
|
2089
2211
|
request,
|
|
2090
2212
|
method: request.method,
|
|
@@ -2109,28 +2231,29 @@ var MWPTransport = class {
|
|
|
2109
2231
|
if (session) {
|
|
2110
2232
|
logger("active session found", session);
|
|
2111
2233
|
}
|
|
2234
|
+
const storedSessionRequestBeforeConnectionAttempt = yield this.getStoredPendingSessionRequest();
|
|
2112
2235
|
let timeout;
|
|
2113
2236
|
let initialConnectionMessageHandler;
|
|
2114
2237
|
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2115
2238
|
let connection;
|
|
2116
2239
|
if (session) {
|
|
2117
2240
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
2118
|
-
var
|
|
2241
|
+
var _a3;
|
|
2119
2242
|
if (this.dappClient.state === "CONNECTED") {
|
|
2120
2243
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
2121
2244
|
} else {
|
|
2122
2245
|
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
2123
2246
|
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
2124
2247
|
}));
|
|
2125
|
-
dappClient.resume((
|
|
2248
|
+
dappClient.resume((_a3 = session == null ? void 0 : session.id) != null ? _a3 : "");
|
|
2126
2249
|
}
|
|
2127
2250
|
});
|
|
2128
2251
|
} else {
|
|
2129
2252
|
connection = new Promise(
|
|
2130
2253
|
(resolveConnection, rejectConnection) => {
|
|
2131
|
-
var
|
|
2254
|
+
var _a3, _b;
|
|
2132
2255
|
const optionalScopes = addValidAccounts(
|
|
2133
|
-
getOptionalScopes((
|
|
2256
|
+
getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
|
|
2134
2257
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
2135
2258
|
);
|
|
2136
2259
|
const sessionRequest = {
|
|
@@ -2139,33 +2262,35 @@ var MWPTransport = class {
|
|
|
2139
2262
|
};
|
|
2140
2263
|
const request = {
|
|
2141
2264
|
jsonrpc: "2.0",
|
|
2142
|
-
id:
|
|
2265
|
+
id: String(getUniqueRequestId()),
|
|
2143
2266
|
method: "wallet_createSession",
|
|
2144
2267
|
params: sessionRequest
|
|
2145
2268
|
};
|
|
2146
2269
|
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
2147
|
-
if (typeof message
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
if (initialConnectionMessageHandler) {
|
|
2153
|
-
this.dappClient.off(
|
|
2154
|
-
"message",
|
|
2155
|
-
initialConnectionMessageHandler
|
|
2156
|
-
);
|
|
2157
|
-
}
|
|
2158
|
-
return rejectConnection(messagePayload.error);
|
|
2159
|
-
}
|
|
2160
|
-
yield this.storeWalletSession(
|
|
2161
|
-
request,
|
|
2162
|
-
messagePayload
|
|
2163
|
-
);
|
|
2164
|
-
this.notifyCallbacks(messagePayload);
|
|
2165
|
-
return resolveConnection();
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2270
|
+
if (typeof message !== "object" || message === null) {
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
if (!("data" in message)) {
|
|
2274
|
+
return;
|
|
2168
2275
|
}
|
|
2276
|
+
const messagePayload = message.data;
|
|
2277
|
+
const isMatchingId = messagePayload.id === request.id;
|
|
2278
|
+
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
2279
|
+
if (!isMatchingId && !isMatchingMethod) {
|
|
2280
|
+
return;
|
|
2281
|
+
}
|
|
2282
|
+
if (messagePayload.error) {
|
|
2283
|
+
return rejectConnection(
|
|
2284
|
+
this.parseWalletError(messagePayload.error)
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
2287
|
+
yield this.storeWalletSession(
|
|
2288
|
+
request,
|
|
2289
|
+
messagePayload
|
|
2290
|
+
);
|
|
2291
|
+
yield this.removeStoredPendingSessionRequest();
|
|
2292
|
+
this.notifyCallbacks(messagePayload);
|
|
2293
|
+
return resolveConnection();
|
|
2169
2294
|
});
|
|
2170
2295
|
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
2171
2296
|
dappClient.connect({
|
|
@@ -2186,14 +2311,18 @@ var MWPTransport = class {
|
|
|
2186
2311
|
}
|
|
2187
2312
|
);
|
|
2188
2313
|
}
|
|
2189
|
-
timeout = setTimeout(
|
|
2190
|
-
|
|
2191
|
-
|
|
2314
|
+
timeout = setTimeout(
|
|
2315
|
+
() => {
|
|
2316
|
+
reject(new TransportTimeoutError());
|
|
2317
|
+
},
|
|
2318
|
+
storedSessionRequestBeforeConnectionAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
2319
|
+
);
|
|
2192
2320
|
connection.then(resolve).catch(reject);
|
|
2193
2321
|
}));
|
|
2194
|
-
return connectionPromise.catch((error) => {
|
|
2322
|
+
return connectionPromise.catch((error) => __async(this, null, function* () {
|
|
2323
|
+
yield this.dappClient.disconnect();
|
|
2195
2324
|
throw error;
|
|
2196
|
-
}).finally(() => {
|
|
2325
|
+
})).finally(() => {
|
|
2197
2326
|
if (timeout) {
|
|
2198
2327
|
clearTimeout(timeout);
|
|
2199
2328
|
}
|
|
@@ -2201,24 +2330,68 @@ var MWPTransport = class {
|
|
|
2201
2330
|
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
2202
2331
|
initialConnectionMessageHandler = void 0;
|
|
2203
2332
|
}
|
|
2333
|
+
this.removeStoredPendingSessionRequest();
|
|
2204
2334
|
});
|
|
2205
2335
|
});
|
|
2206
2336
|
}
|
|
2207
2337
|
/**
|
|
2208
2338
|
* Disconnects from the Mobile Wallet Protocol
|
|
2209
2339
|
*
|
|
2340
|
+
* @param [scopes] - The scopes to revoke. If not provided or empty, all scopes will be revoked.
|
|
2210
2341
|
* @returns Nothing
|
|
2211
2342
|
*/
|
|
2212
2343
|
disconnect() {
|
|
2213
|
-
return __async(this,
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2344
|
+
return __async(this, arguments, function* (scopes = []) {
|
|
2345
|
+
var _a3, _b;
|
|
2346
|
+
const cachedSession = yield this.getCachedResponse({
|
|
2347
|
+
jsonrpc: "2.0",
|
|
2348
|
+
id: "0",
|
|
2349
|
+
method: "wallet_getSession"
|
|
2350
|
+
});
|
|
2351
|
+
const cachedSessionScopes = (_b = (_a3 = cachedSession == null ? void 0 : cachedSession.result) == null ? void 0 : _a3.sessionScopes) != null ? _b : {};
|
|
2352
|
+
const remainingScopes = scopes.length === 0 ? [] : Object.keys(cachedSessionScopes).filter(
|
|
2353
|
+
(scope) => !scopes.includes(scope)
|
|
2354
|
+
);
|
|
2355
|
+
const newSessionScopes = Object.fromEntries(
|
|
2356
|
+
Object.entries(cachedSessionScopes).filter(
|
|
2357
|
+
([key]) => remainingScopes.includes(key)
|
|
2358
|
+
)
|
|
2359
|
+
);
|
|
2360
|
+
this.request({ method: "wallet_revokeSession", params: { scopes } }).catch(
|
|
2361
|
+
(err) => {
|
|
2362
|
+
console.error("error revoking session", err);
|
|
2363
|
+
}
|
|
2364
|
+
);
|
|
2365
|
+
const remainingScopesIncludeEip155 = remainingScopes.some(
|
|
2366
|
+
(scope) => scope.includes("eip155")
|
|
2367
|
+
);
|
|
2368
|
+
if (!remainingScopesIncludeEip155) {
|
|
2369
|
+
this.kvstore.delete(ACCOUNTS_STORE_KEY);
|
|
2370
|
+
this.kvstore.delete(CHAIN_STORE_KEY);
|
|
2371
|
+
}
|
|
2372
|
+
if (remainingScopes.length > 0) {
|
|
2373
|
+
this.kvstore.set(
|
|
2374
|
+
SESSION_STORE_KEY,
|
|
2375
|
+
JSON.stringify({
|
|
2376
|
+
result: {
|
|
2377
|
+
sessionScopes: newSessionScopes
|
|
2378
|
+
}
|
|
2379
|
+
})
|
|
2380
|
+
);
|
|
2381
|
+
} else {
|
|
2382
|
+
this.kvstore.delete(SESSION_STORE_KEY);
|
|
2383
|
+
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined" && this.windowFocusHandler) {
|
|
2384
|
+
window.removeEventListener("focus", this.windowFocusHandler);
|
|
2385
|
+
this.windowFocusHandler = void 0;
|
|
2386
|
+
}
|
|
2387
|
+
yield this.dappClient.disconnect();
|
|
2388
|
+
}
|
|
2389
|
+
this.notifyCallbacks({
|
|
2390
|
+
method: "wallet_sessionChanged",
|
|
2391
|
+
params: {
|
|
2392
|
+
sessionScopes: newSessionScopes
|
|
2393
|
+
}
|
|
2394
|
+
});
|
|
2222
2395
|
});
|
|
2223
2396
|
}
|
|
2224
2397
|
/**
|
|
@@ -2263,7 +2436,7 @@ var MWPTransport = class {
|
|
|
2263
2436
|
}
|
|
2264
2437
|
getCachedResponse(request) {
|
|
2265
2438
|
return __async(this, null, function* () {
|
|
2266
|
-
var
|
|
2439
|
+
var _a3;
|
|
2267
2440
|
if (request.method === "wallet_getSession") {
|
|
2268
2441
|
const walletGetSession = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2269
2442
|
if (walletGetSession) {
|
|
@@ -2271,7 +2444,7 @@ var MWPTransport = class {
|
|
|
2271
2444
|
return {
|
|
2272
2445
|
id: request.id,
|
|
2273
2446
|
jsonrpc: "2.0",
|
|
2274
|
-
result: (
|
|
2447
|
+
result: (_a3 = walletSession.params) != null ? _a3 : walletSession.result,
|
|
2275
2448
|
// "what?... why walletSession.params?.."
|
|
2276
2449
|
method: request.method
|
|
2277
2450
|
};
|
|
@@ -2324,7 +2497,7 @@ var MWPTransport = class {
|
|
|
2324
2497
|
return __async(this, null, function* () {
|
|
2325
2498
|
const request = __spreadValues({
|
|
2326
2499
|
jsonrpc: "2.0",
|
|
2327
|
-
id:
|
|
2500
|
+
id: String(getUniqueRequestId())
|
|
2328
2501
|
}, payload);
|
|
2329
2502
|
const cachedWalletSession = yield this.getCachedResponse(request);
|
|
2330
2503
|
if (cachedWalletSession) {
|
|
@@ -2335,10 +2508,10 @@ var MWPTransport = class {
|
|
|
2335
2508
|
yield this.attemptResumeSession();
|
|
2336
2509
|
}
|
|
2337
2510
|
return new Promise((resolve, reject) => {
|
|
2338
|
-
var
|
|
2511
|
+
var _a3;
|
|
2339
2512
|
const timeout = setTimeout(() => {
|
|
2340
2513
|
this.rejectRequest(request.id, new TransportTimeoutError());
|
|
2341
|
-
}, (
|
|
2514
|
+
}, (_a3 = options == null ? void 0 : options.timeout) != null ? _a3 : this.options.requestTimeout);
|
|
2342
2515
|
this.pendingRequests.set(request.id, {
|
|
2343
2516
|
request,
|
|
2344
2517
|
method: request.method,
|
|
@@ -2406,6 +2579,7 @@ var MWPTransport = class {
|
|
|
2406
2579
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
2407
2580
|
setTimeout(() => {
|
|
2408
2581
|
unsubscribe();
|
|
2582
|
+
this.removeStoredPendingSessionRequest();
|
|
2409
2583
|
reject(new TransportTimeoutError());
|
|
2410
2584
|
}, this.options.resumeTimeout);
|
|
2411
2585
|
});
|
|
@@ -2442,14 +2616,15 @@ var KeyManager = class {
|
|
|
2442
2616
|
var keymanager = new KeyManager();
|
|
2443
2617
|
|
|
2444
2618
|
// src/multichain/index.ts
|
|
2445
|
-
|
|
2619
|
+
init_utils2();
|
|
2446
2620
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2447
|
-
var
|
|
2621
|
+
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
2622
|
+
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
|
|
2448
2623
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2449
2624
|
constructor(options) {
|
|
2450
|
-
var
|
|
2625
|
+
var _a3, _b, _c, _d, _e, _f;
|
|
2451
2626
|
const withDappMetadata = setupDappMetadata(options);
|
|
2452
|
-
const integrationType = (_b = (
|
|
2627
|
+
const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "direct";
|
|
2453
2628
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
2454
2629
|
ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
|
|
2455
2630
|
preferExtension: (_c = withDappMetadata.ui.preferExtension) != null ? _c : true,
|
|
@@ -2469,7 +2644,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2469
2644
|
__privateAdd(this, _beforeUnloadListener);
|
|
2470
2645
|
this._status = "pending";
|
|
2471
2646
|
__privateAdd(this, _listener);
|
|
2472
|
-
__privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(
|
|
2647
|
+
__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}`);
|
|
2473
2648
|
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
2474
2649
|
this
|
|
2475
2650
|
));
|
|
@@ -2481,9 +2656,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2481
2656
|
return this._status;
|
|
2482
2657
|
}
|
|
2483
2658
|
set status(value) {
|
|
2484
|
-
var
|
|
2659
|
+
var _a3, _b;
|
|
2485
2660
|
this._status = value;
|
|
2486
|
-
(_b = (
|
|
2661
|
+
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, {
|
|
2487
2662
|
method: "stateChanged",
|
|
2488
2663
|
params: value
|
|
2489
2664
|
});
|
|
@@ -2509,27 +2684,54 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2509
2684
|
get transportType() {
|
|
2510
2685
|
return __privateGet(this, _transport2) instanceof MWPTransport ? "mwp" /* MWP */ : "browser" /* Browser */;
|
|
2511
2686
|
}
|
|
2687
|
+
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
2688
|
+
// If the singleton already exists, it merges the incoming options with the
|
|
2689
|
+
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
2690
|
+
// `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note that the
|
|
2691
|
+
// value for `dapp` is not merged as it does not make sense for subsequent calls to
|
|
2692
|
+
// `createMultichainClient` to have a different `dapp` value.
|
|
2512
2693
|
static create(options) {
|
|
2513
2694
|
return __async(this, null, function* () {
|
|
2514
|
-
|
|
2515
|
-
const
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
instance.options
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2695
|
+
const globalObject = getGlobalObject();
|
|
2696
|
+
const existing = globalObject[SINGLETON_KEY];
|
|
2697
|
+
if (existing) {
|
|
2698
|
+
const instance = yield existing;
|
|
2699
|
+
instance.mergeOptions(options);
|
|
2700
|
+
if (options.debug) {
|
|
2701
|
+
enableDebug("metamask-sdk:*");
|
|
2702
|
+
}
|
|
2703
|
+
return instance;
|
|
2704
|
+
}
|
|
2705
|
+
const instancePromise = (() => __async(null, null, function* () {
|
|
2706
|
+
var _a3;
|
|
2707
|
+
const instance = new _MetaMaskConnectMultichain(options);
|
|
2708
|
+
const isEnabled2 = yield isEnabled(
|
|
2709
|
+
"metamask-sdk:core",
|
|
2710
|
+
instance.options.storage
|
|
2711
|
+
);
|
|
2712
|
+
if (isEnabled2) {
|
|
2713
|
+
enableDebug("metamask-sdk:core");
|
|
2714
|
+
}
|
|
2715
|
+
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a3);
|
|
2716
|
+
return instance;
|
|
2717
|
+
}))();
|
|
2718
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
2719
|
+
instancePromise.catch((error) => {
|
|
2720
|
+
globalObject[SINGLETON_KEY] = void 0;
|
|
2721
|
+
console.error("Error initializing MetaMaskConnectMultichain", error);
|
|
2722
|
+
});
|
|
2723
|
+
return instancePromise;
|
|
2525
2724
|
});
|
|
2526
2725
|
}
|
|
2527
2726
|
// TODO: make this into param object
|
|
2528
2727
|
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
2529
2728
|
return __async(this, null, function* () {
|
|
2530
|
-
var
|
|
2531
|
-
if (this.status
|
|
2532
|
-
yield this.
|
|
2729
|
+
var _a3;
|
|
2730
|
+
if (this.status === "connecting" && this.transportType === "mwp" /* MWP */) {
|
|
2731
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, openConnectDeeplinkIfNeeded_fn).call(this);
|
|
2732
|
+
throw new Error(
|
|
2733
|
+
"Existing connection is pending. Please check your MetaMask Mobile app to continue."
|
|
2734
|
+
);
|
|
2533
2735
|
}
|
|
2534
2736
|
const { ui } = this.options;
|
|
2535
2737
|
const platformType = getPlatformType();
|
|
@@ -2559,12 +2761,19 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2559
2761
|
} catch (error) {
|
|
2560
2762
|
logger2("Error tracking connection_initiated event", error);
|
|
2561
2763
|
}
|
|
2562
|
-
const
|
|
2563
|
-
|
|
2764
|
+
const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
|
|
2765
|
+
const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
|
|
2766
|
+
sessionData,
|
|
2767
|
+
scopes,
|
|
2768
|
+
caipAccountIds,
|
|
2769
|
+
sessionProperties
|
|
2770
|
+
);
|
|
2771
|
+
const nonEmptySessionProperties = Object.keys(mergedSessionProperties != null ? mergedSessionProperties : {}).length > 0 ? mergedSessionProperties : void 0;
|
|
2772
|
+
if (((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) && !secure) {
|
|
2564
2773
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({
|
|
2565
|
-
scopes,
|
|
2566
|
-
caipAccountIds,
|
|
2567
|
-
sessionProperties:
|
|
2774
|
+
scopes: mergedScopes,
|
|
2775
|
+
caipAccountIds: mergedCaipAccountIds,
|
|
2776
|
+
sessionProperties: nonEmptySessionProperties,
|
|
2568
2777
|
forceRequest
|
|
2569
2778
|
}).then(() => __async(this, null, function* () {
|
|
2570
2779
|
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
@@ -2576,47 +2785,53 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2576
2785
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2577
2786
|
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2578
2787
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
|
|
2579
|
-
scopes,
|
|
2580
|
-
caipAccountIds,
|
|
2581
|
-
sessionProperties:
|
|
2788
|
+
scopes: mergedScopes,
|
|
2789
|
+
caipAccountIds: mergedCaipAccountIds,
|
|
2790
|
+
sessionProperties: nonEmptySessionProperties,
|
|
2582
2791
|
forceRequest
|
|
2583
2792
|
}), scopes, transportType);
|
|
2584
2793
|
}
|
|
2585
2794
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2586
2795
|
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2587
2796
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({
|
|
2588
|
-
scopes,
|
|
2589
|
-
caipAccountIds,
|
|
2590
|
-
sessionProperties:
|
|
2797
|
+
scopes: mergedScopes,
|
|
2798
|
+
caipAccountIds: mergedCaipAccountIds,
|
|
2799
|
+
sessionProperties: nonEmptySessionProperties,
|
|
2591
2800
|
forceRequest
|
|
2592
2801
|
}), scopes, transportType);
|
|
2593
2802
|
}
|
|
2594
2803
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
|
|
2595
2804
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2596
2805
|
if (secure && !shouldShowInstallModal) {
|
|
2597
|
-
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this,
|
|
2806
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
2598
2807
|
}
|
|
2599
|
-
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal,
|
|
2808
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
2600
2809
|
});
|
|
2601
2810
|
}
|
|
2602
2811
|
emit(event, args) {
|
|
2603
|
-
var
|
|
2604
|
-
(_b = (
|
|
2812
|
+
var _a3, _b;
|
|
2813
|
+
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, { method: event, params: args });
|
|
2605
2814
|
super.emit(event, args);
|
|
2606
2815
|
}
|
|
2607
2816
|
disconnect() {
|
|
2608
|
-
return __async(this,
|
|
2609
|
-
var
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
this
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2817
|
+
return __async(this, arguments, function* (scopes = []) {
|
|
2818
|
+
var _a3, _b, _c;
|
|
2819
|
+
const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
|
|
2820
|
+
const remainingScopes = scopes.length === 0 ? [] : Object.keys(sessionData.sessionScopes).filter(
|
|
2821
|
+
(scope) => !scopes.includes(scope)
|
|
2822
|
+
);
|
|
2823
|
+
yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
|
|
2824
|
+
if (remainingScopes.length === 0) {
|
|
2825
|
+
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2826
|
+
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2827
|
+
yield this.storage.removeTransport();
|
|
2828
|
+
__privateSet(this, _listener, void 0);
|
|
2829
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2830
|
+
__privateSet(this, _transport2, void 0);
|
|
2831
|
+
__privateGet(this, _providerTransportWrapper).clearTransportNotificationListener();
|
|
2832
|
+
__privateSet(this, _dappClient, void 0);
|
|
2833
|
+
this.status = "disconnected";
|
|
2834
|
+
}
|
|
2620
2835
|
});
|
|
2621
2836
|
}
|
|
2622
2837
|
invokeMethod(request) {
|
|
@@ -2628,7 +2843,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2628
2843
|
});
|
|
2629
2844
|
}
|
|
2630
2845
|
// DRY THIS WITH REQUEST ROUTER
|
|
2631
|
-
|
|
2846
|
+
openSimpleDeeplinkIfNeeded() {
|
|
2632
2847
|
const { ui, mobile } = this.options;
|
|
2633
2848
|
const { showInstallModal = false } = ui != null ? ui : {};
|
|
2634
2849
|
const secure = isSecure();
|
|
@@ -2648,6 +2863,23 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2648
2863
|
}), 10);
|
|
2649
2864
|
}
|
|
2650
2865
|
}
|
|
2866
|
+
// Provides a way for ecosystem clients (EVM, Solana, etc.) to get the current CAIP session data
|
|
2867
|
+
// when instantiating themselves (as they would have already missed any initial sessionChanged events emitted by ConnectMultichain)
|
|
2868
|
+
// without having to concern themselves with the current transport connection status.
|
|
2869
|
+
emitSessionChanged() {
|
|
2870
|
+
return __async(this, null, function* () {
|
|
2871
|
+
var _a3;
|
|
2872
|
+
const emptySession = { sessionScopes: {} };
|
|
2873
|
+
if (this.status !== "connected" && this.status !== "connecting") {
|
|
2874
|
+
this.emit("wallet_sessionChanged", emptySession);
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
const response = yield this.transport.request({
|
|
2878
|
+
method: "wallet_getSession"
|
|
2879
|
+
});
|
|
2880
|
+
this.emit("wallet_sessionChanged", (_a3 = response.result) != null ? _a3 : emptySession);
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2651
2883
|
};
|
|
2652
2884
|
_provider = new WeakMap();
|
|
2653
2885
|
_providerTransportWrapper = new WeakMap();
|
|
@@ -2659,7 +2891,7 @@ _sdkInfo = new WeakMap();
|
|
|
2659
2891
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2660
2892
|
setupAnalytics_fn = function() {
|
|
2661
2893
|
return __async(this, null, function* () {
|
|
2662
|
-
var
|
|
2894
|
+
var _a3;
|
|
2663
2895
|
const platform = getPlatformType();
|
|
2664
2896
|
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2665
2897
|
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
@@ -2669,7 +2901,7 @@ setupAnalytics_fn = function() {
|
|
|
2669
2901
|
const version = getVersion();
|
|
2670
2902
|
const dappId = getDappId(this.options.dapp);
|
|
2671
2903
|
const anonId = yield this.storage.getAnonId();
|
|
2672
|
-
const { integrationType } = (
|
|
2904
|
+
const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
|
|
2673
2905
|
integrationType: ""
|
|
2674
2906
|
};
|
|
2675
2907
|
analytics2.setGlobalProperty("mmconnect_version", version);
|
|
@@ -2682,9 +2914,9 @@ setupAnalytics_fn = function() {
|
|
|
2682
2914
|
};
|
|
2683
2915
|
onTransportNotification_fn = function(payload) {
|
|
2684
2916
|
return __async(this, null, function* () {
|
|
2685
|
-
var
|
|
2917
|
+
var _a3;
|
|
2686
2918
|
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2687
|
-
this.emit(payload.method, (
|
|
2919
|
+
this.emit(payload.method, (_a3 = payload.params) != null ? _a3 : payload.result);
|
|
2688
2920
|
}
|
|
2689
2921
|
});
|
|
2690
2922
|
};
|
|
@@ -2697,7 +2929,7 @@ getStoredTransport_fn = function() {
|
|
|
2697
2929
|
if (hasExtensionInstalled) {
|
|
2698
2930
|
const apiTransport = new DefaultTransport();
|
|
2699
2931
|
__privateSet(this, _transport2, apiTransport);
|
|
2700
|
-
__privateGet(this, _providerTransportWrapper).
|
|
2932
|
+
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
2701
2933
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2702
2934
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2703
2935
|
));
|
|
@@ -2709,7 +2941,7 @@ getStoredTransport_fn = function() {
|
|
|
2709
2941
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2710
2942
|
__privateSet(this, _dappClient, dappClient);
|
|
2711
2943
|
__privateSet(this, _transport2, apiTransport);
|
|
2712
|
-
__privateGet(this, _providerTransportWrapper).
|
|
2944
|
+
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
2713
2945
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2714
2946
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2715
2947
|
));
|
|
@@ -2741,25 +2973,17 @@ setupTransport_fn = function() {
|
|
|
2741
2973
|
};
|
|
2742
2974
|
init_fn = function() {
|
|
2743
2975
|
return __async(this, null, function* () {
|
|
2744
|
-
var _a2;
|
|
2745
2976
|
try {
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
analytics2.track("mmconnect_initialized", baseProps);
|
|
2757
|
-
} catch (error) {
|
|
2758
|
-
logger2("Error tracking initialized event", error);
|
|
2759
|
-
}
|
|
2760
|
-
if (typeof window !== "undefined") {
|
|
2761
|
-
window.mmsdk = this;
|
|
2762
|
-
}
|
|
2977
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
2978
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
2979
|
+
try {
|
|
2980
|
+
const baseProps = yield getBaseAnalyticsProperties(
|
|
2981
|
+
this.options,
|
|
2982
|
+
this.storage
|
|
2983
|
+
);
|
|
2984
|
+
analytics2.track("mmconnect_initialized", baseProps);
|
|
2985
|
+
} catch (error) {
|
|
2986
|
+
logger2("Error tracking initialized event", error);
|
|
2763
2987
|
}
|
|
2764
2988
|
} catch (error) {
|
|
2765
2989
|
yield this.storage.removeTransport();
|
|
@@ -2795,7 +3019,7 @@ setupMWP_fn = function() {
|
|
|
2795
3019
|
__privateSet(this, _dappClient, dappClient);
|
|
2796
3020
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2797
3021
|
__privateSet(this, _transport2, apiTransport);
|
|
2798
|
-
__privateGet(this, _providerTransportWrapper).
|
|
3022
|
+
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
2799
3023
|
__privateSet(this, _listener, this.transport.onNotification(
|
|
2800
3024
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2801
3025
|
));
|
|
@@ -2804,22 +3028,20 @@ setupMWP_fn = function() {
|
|
|
2804
3028
|
};
|
|
2805
3029
|
onBeforeUnload_fn = function() {
|
|
2806
3030
|
return __async(this, null, function* () {
|
|
2807
|
-
var
|
|
2808
|
-
if ((
|
|
3031
|
+
var _a3;
|
|
3032
|
+
if ((_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.isMounted) {
|
|
2809
3033
|
yield this.storage.removeTransport();
|
|
2810
3034
|
}
|
|
2811
3035
|
});
|
|
2812
3036
|
};
|
|
2813
3037
|
createBeforeUnloadListener_fn = function() {
|
|
3038
|
+
const handler = __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this);
|
|
2814
3039
|
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2815
|
-
window.addEventListener("beforeunload",
|
|
3040
|
+
window.addEventListener("beforeunload", handler);
|
|
2816
3041
|
}
|
|
2817
3042
|
return () => {
|
|
2818
3043
|
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2819
|
-
window.removeEventListener(
|
|
2820
|
-
"beforeunload",
|
|
2821
|
-
__privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this)
|
|
2822
|
-
);
|
|
3044
|
+
window.removeEventListener("beforeunload", handler);
|
|
2823
3045
|
}
|
|
2824
3046
|
};
|
|
2825
3047
|
};
|
|
@@ -2849,7 +3071,7 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
|
|
|
2849
3071
|
}
|
|
2850
3072
|
);
|
|
2851
3073
|
(() => __async(this, null, function* () {
|
|
2852
|
-
var
|
|
3074
|
+
var _a3;
|
|
2853
3075
|
try {
|
|
2854
3076
|
yield this.transport.connect({
|
|
2855
3077
|
scopes,
|
|
@@ -2857,20 +3079,21 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
|
|
|
2857
3079
|
sessionProperties
|
|
2858
3080
|
});
|
|
2859
3081
|
yield this.options.ui.factory.unload();
|
|
2860
|
-
(
|
|
3082
|
+
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
2861
3083
|
this.status = "connected";
|
|
2862
3084
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2863
3085
|
} catch (error) {
|
|
2864
3086
|
if (error instanceof ProtocolError) {
|
|
2865
3087
|
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2866
3088
|
this.status = "disconnected";
|
|
3089
|
+
yield this.options.ui.factory.unload(error);
|
|
2867
3090
|
reject(error);
|
|
2868
3091
|
}
|
|
2869
3092
|
} else {
|
|
2870
3093
|
this.status = "disconnected";
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
);
|
|
3094
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3095
|
+
yield this.options.ui.factory.unload(normalizedError);
|
|
3096
|
+
reject(normalizedError);
|
|
2874
3097
|
}
|
|
2875
3098
|
}
|
|
2876
3099
|
}))().catch(() => {
|
|
@@ -2897,8 +3120,8 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds,
|
|
|
2897
3120
|
};
|
|
2898
3121
|
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2899
3122
|
return __async(this, null, function* () {
|
|
2900
|
-
var
|
|
2901
|
-
(
|
|
3123
|
+
var _a3;
|
|
3124
|
+
(_a3 = __privateGet(this, _beforeUnloadListener)) != null ? _a3 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
|
|
2902
3125
|
if (this.options.ui.headless) {
|
|
2903
3126
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
|
|
2904
3127
|
} else {
|
|
@@ -2957,7 +3180,7 @@ setupDefaultTransport_fn = function() {
|
|
|
2957
3180
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2958
3181
|
));
|
|
2959
3182
|
__privateSet(this, _transport2, transport);
|
|
2960
|
-
__privateGet(this, _providerTransportWrapper).
|
|
3183
|
+
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
2961
3184
|
return transport;
|
|
2962
3185
|
});
|
|
2963
3186
|
};
|
|
@@ -2965,7 +3188,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
2965
3188
|
return __async(this, null, function* () {
|
|
2966
3189
|
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
2967
3190
|
const dappClientMessageHandler = (payload) => {
|
|
2968
|
-
var
|
|
3191
|
+
var _a3;
|
|
2969
3192
|
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
2970
3193
|
return;
|
|
2971
3194
|
}
|
|
@@ -2975,7 +3198,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
2975
3198
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
2976
3199
|
reject(data.error);
|
|
2977
3200
|
}
|
|
2978
|
-
if ((
|
|
3201
|
+
if ((_a3 = data == null ? void 0 : data.result) == null ? void 0 : _a3.sessionScopes) {
|
|
2979
3202
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
2980
3203
|
}
|
|
2981
3204
|
}
|
|
@@ -2984,13 +3207,13 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
2984
3207
|
let timeout;
|
|
2985
3208
|
if (this.transport.isConnected()) {
|
|
2986
3209
|
timeout = setTimeout(() => {
|
|
2987
|
-
this.
|
|
3210
|
+
this.openSimpleDeeplinkIfNeeded();
|
|
2988
3211
|
}, 250);
|
|
2989
3212
|
} else {
|
|
2990
3213
|
this.dappClient.once(
|
|
2991
3214
|
"session_request",
|
|
2992
3215
|
(sessionRequest) => {
|
|
2993
|
-
var
|
|
3216
|
+
var _a3;
|
|
2994
3217
|
const connectionRequest = {
|
|
2995
3218
|
sessionRequest,
|
|
2996
3219
|
metadata: {
|
|
@@ -3005,7 +3228,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3005
3228
|
connectionRequest
|
|
3006
3229
|
);
|
|
3007
3230
|
this.emit("display_uri", deeplink);
|
|
3008
|
-
if ((
|
|
3231
|
+
if ((_a3 = this.options.mobile) == null ? void 0 : _a3.preferredOpenLink) {
|
|
3009
3232
|
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
3010
3233
|
} else {
|
|
3011
3234
|
openDeeplink(this.options, deeplink, universalLink);
|
|
@@ -3067,6 +3290,53 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
3067
3290
|
}));
|
|
3068
3291
|
});
|
|
3069
3292
|
};
|
|
3293
|
+
getCaipSession_fn = function() {
|
|
3294
|
+
return __async(this, null, function* () {
|
|
3295
|
+
let sessionData = {
|
|
3296
|
+
sessionScopes: {},
|
|
3297
|
+
sessionProperties: {}
|
|
3298
|
+
};
|
|
3299
|
+
if (this.status === "connected") {
|
|
3300
|
+
const response = yield this.transport.request({
|
|
3301
|
+
method: "wallet_getSession"
|
|
3302
|
+
});
|
|
3303
|
+
if (response.result) {
|
|
3304
|
+
sessionData = response.result;
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
return sessionData;
|
|
3308
|
+
});
|
|
3309
|
+
};
|
|
3310
|
+
openConnectDeeplinkIfNeeded_fn = function() {
|
|
3311
|
+
return __async(this, null, function* () {
|
|
3312
|
+
var _a3, _b;
|
|
3313
|
+
const { ui } = this.options;
|
|
3314
|
+
const { showInstallModal = false } = ui != null ? ui : {};
|
|
3315
|
+
const secure = isSecure();
|
|
3316
|
+
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
3317
|
+
if (!shouldOpenDeeplink) {
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
const storedSessionRequest = yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.getStoredPendingSessionRequest();
|
|
3321
|
+
if (!storedSessionRequest) {
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
const connectionRequest = {
|
|
3325
|
+
sessionRequest: storedSessionRequest,
|
|
3326
|
+
metadata: {
|
|
3327
|
+
dapp: this.options.dapp,
|
|
3328
|
+
sdk: { version: getVersion(), platform: getPlatformType() }
|
|
3329
|
+
}
|
|
3330
|
+
};
|
|
3331
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3332
|
+
const universalLink = this.options.ui.factory.createConnectionUniversalLink(connectionRequest);
|
|
3333
|
+
if ((_b = this.options.mobile) == null ? void 0 : _b.preferredOpenLink) {
|
|
3334
|
+
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
3335
|
+
} else {
|
|
3336
|
+
openDeeplink(this.options, deeplink, universalLink);
|
|
3337
|
+
}
|
|
3338
|
+
});
|
|
3339
|
+
};
|
|
3070
3340
|
var MetaMaskConnectMultichain = _MetaMaskConnectMultichain;
|
|
3071
3341
|
|
|
3072
3342
|
// src/store/index.ts
|
|
@@ -3251,7 +3521,7 @@ var Store = class extends StoreClient {
|
|
|
3251
3521
|
// src/ui/ModalFactory.ts
|
|
3252
3522
|
import MetaMaskOnboarding from "@metamask/onboarding";
|
|
3253
3523
|
init_domain();
|
|
3254
|
-
|
|
3524
|
+
init_utils2();
|
|
3255
3525
|
var BaseModalFactory = class {
|
|
3256
3526
|
/**
|
|
3257
3527
|
* Creates a new modal factory instance.
|
|
@@ -3274,8 +3544,8 @@ var BaseModalFactory = class {
|
|
|
3274
3544
|
}
|
|
3275
3545
|
unload(error) {
|
|
3276
3546
|
return __async(this, null, function* () {
|
|
3277
|
-
var
|
|
3278
|
-
(
|
|
3547
|
+
var _a3, _b;
|
|
3548
|
+
(_a3 = this.modal) == null ? void 0 : _a3.unmount();
|
|
3279
3549
|
yield (_b = this.successCallback) == null ? void 0 : _b.call(this, error);
|
|
3280
3550
|
});
|
|
3281
3551
|
}
|
|
@@ -3345,8 +3615,8 @@ var BaseModalFactory = class {
|
|
|
3345
3615
|
}
|
|
3346
3616
|
renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
|
|
3347
3617
|
return __async(this, null, function* () {
|
|
3348
|
-
var
|
|
3349
|
-
(
|
|
3618
|
+
var _a3, _b;
|
|
3619
|
+
(_a3 = this.modal) == null ? void 0 : _a3.unmount();
|
|
3350
3620
|
yield this.preload();
|
|
3351
3621
|
this.successCallback = successCallback;
|
|
3352
3622
|
this.displayUriCallback = onDisplayUri;
|
|
@@ -3362,9 +3632,9 @@ var BaseModalFactory = class {
|
|
|
3362
3632
|
link: qrCodeLink,
|
|
3363
3633
|
sdkVersion: getVersion(),
|
|
3364
3634
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3365
|
-
var
|
|
3635
|
+
var _a4;
|
|
3366
3636
|
const newLink = this.createConnectionDeeplink(request);
|
|
3367
|
-
(
|
|
3637
|
+
(_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
|
|
3368
3638
|
return newLink;
|
|
3369
3639
|
}),
|
|
3370
3640
|
onClose: this.onCloseModal.bind(this),
|
|
@@ -3378,8 +3648,8 @@ var BaseModalFactory = class {
|
|
|
3378
3648
|
}
|
|
3379
3649
|
renderOTPCodeModal(createOTPCode, successCallback, updateOTPCode) {
|
|
3380
3650
|
return __async(this, null, function* () {
|
|
3381
|
-
var
|
|
3382
|
-
(
|
|
3651
|
+
var _a3;
|
|
3652
|
+
(_a3 = this.modal) == null ? void 0 : _a3.unmount();
|
|
3383
3653
|
yield this.preload();
|
|
3384
3654
|
this.successCallback = successCallback;
|
|
3385
3655
|
const container = this.getMountedContainer();
|