@metamask/connect-multichain 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -1
- package/README.md +20 -19
- package/dist/browser/es/connect-multichain.d.mts +19 -5
- package/dist/browser/es/connect-multichain.mjs +157 -104
- 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 +19 -5
- package/dist/browser/iife/connect-multichain.js +2717 -5028
- 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 +19 -5
- package/dist/browser/umd/connect-multichain.js +156 -103
- 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 +19 -5
- package/dist/node/cjs/connect-multichain.js +156 -102
- 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 +19 -5
- package/dist/node/es/connect-multichain.mjs +157 -103
- 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 +19 -5
- package/dist/react-native/es/connect-multichain.mjs +157 -103
- 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 +1 -1
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js +3 -3
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +13 -1
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +76 -39
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts +3 -2
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +14 -15
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +1 -0
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +34 -32
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/KeyManager.d.ts +1 -0
- package/dist/src/multichain/transports/mwp/KeyManager.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/KeyManager.js +4 -1
- package/dist/src/multichain/transports/mwp/KeyManager.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +1 -0
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +6 -1
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/multichain/utils/analytics.d.ts +6 -3
- package/dist/src/multichain/utils/analytics.d.ts.map +1 -1
- package/dist/src/multichain/utils/analytics.js +8 -8
- package/dist/src/multichain/utils/analytics.js.map +1 -1
- package/dist/src/ui/ModalFactory.d.ts.map +1 -1
- package/dist/src/ui/ModalFactory.js +1 -3
- package/dist/src/ui/ModalFactory.js.map +1 -1
- package/dist/src/ui/modals/web/install.d.ts.map +1 -1
- package/dist/src/ui/modals/web/install.js +0 -1
- package/dist/src/ui/modals/web/install.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +19 -5
- package/package.json +5 -5
|
@@ -401,7 +401,7 @@ var init_multichain = __esm({
|
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* Merges the given options into the current instance options.
|
|
404
|
-
* Only the mergeable keys are updated (api.supportedNetworks, ui.*, mobile.*, transport.extensionId, debug).
|
|
404
|
+
* Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
405
405
|
* The main thing to note is that the value for `dapp` is not merged as it does not make sense for
|
|
406
406
|
* subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
407
407
|
* Used when createMultichainClient is called with an existing singleton.
|
|
@@ -409,22 +409,23 @@ var init_multichain = __esm({
|
|
|
409
409
|
* @param partial - Options to merge/overwrite onto the current instance
|
|
410
410
|
*/
|
|
411
411
|
mergeOptions(partial) {
|
|
412
|
-
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
412
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
413
413
|
const opts = this.options;
|
|
414
414
|
this.options = __spreadProps(__spreadValues({}, opts), {
|
|
415
415
|
api: __spreadProps(__spreadValues({}, opts.api), {
|
|
416
416
|
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_b = (_a3 = partial.api) == null ? void 0 : _a3.supportedNetworks) != null ? _b : {})
|
|
417
417
|
}),
|
|
418
|
+
versions: __spreadValues(__spreadValues({}, opts.versions), (_c = partial.versions) != null ? _c : {}),
|
|
418
419
|
ui: __spreadProps(__spreadValues({}, opts.ui), {
|
|
419
|
-
headless: (
|
|
420
|
-
preferExtension: (
|
|
421
|
-
showInstallModal: (
|
|
420
|
+
headless: (_e = (_d = partial.ui) == null ? void 0 : _d.headless) != null ? _e : opts.ui.headless,
|
|
421
|
+
preferExtension: (_g = (_f = partial.ui) == null ? void 0 : _f.preferExtension) != null ? _g : opts.ui.preferExtension,
|
|
422
|
+
showInstallModal: (_i = (_h = partial.ui) == null ? void 0 : _h.showInstallModal) != null ? _i : opts.ui.showInstallModal
|
|
422
423
|
}),
|
|
423
|
-
mobile: __spreadValues(__spreadValues({}, opts.mobile), (
|
|
424
|
-
transport: __spreadProps(__spreadValues({}, (
|
|
425
|
-
extensionId: (
|
|
424
|
+
mobile: __spreadValues(__spreadValues({}, opts.mobile), (_j = partial.mobile) != null ? _j : {}),
|
|
425
|
+
transport: __spreadProps(__spreadValues({}, (_k = opts.transport) != null ? _k : {}), {
|
|
426
|
+
extensionId: (_n = (_l = partial.transport) == null ? void 0 : _l.extensionId) != null ? _n : (_m = opts.transport) == null ? void 0 : _m.extensionId
|
|
426
427
|
}),
|
|
427
|
-
debug: (
|
|
428
|
+
debug: (_o = partial.debug) != null ? _o : opts.debug
|
|
428
429
|
});
|
|
429
430
|
}
|
|
430
431
|
};
|
|
@@ -626,14 +627,13 @@ function isRejectionError(error) {
|
|
|
626
627
|
}
|
|
627
628
|
function getBaseAnalyticsProperties(options, storage) {
|
|
628
629
|
return __async(this, null, function* () {
|
|
629
|
-
var _a3, _b;
|
|
630
|
-
const version = getVersion();
|
|
630
|
+
var _a3, _b, _c;
|
|
631
631
|
const dappId = getDappId(options.dapp);
|
|
632
632
|
const platform = getPlatformType();
|
|
633
633
|
const anonId = yield storage.getAnonId();
|
|
634
634
|
const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
635
635
|
return {
|
|
636
|
-
|
|
636
|
+
mmconnect_versions: (_c = options.versions) != null ? _c : {},
|
|
637
637
|
dapp_id: dappId,
|
|
638
638
|
platform,
|
|
639
639
|
integration_type: integrationType,
|
|
@@ -641,20 +641,20 @@ function getBaseAnalyticsProperties(options, storage) {
|
|
|
641
641
|
};
|
|
642
642
|
});
|
|
643
643
|
}
|
|
644
|
-
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
644
|
+
function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType) {
|
|
645
645
|
return __async(this, null, function* () {
|
|
646
|
-
var _a3, _b;
|
|
647
|
-
const version = getVersion();
|
|
646
|
+
var _a3, _b, _c;
|
|
648
647
|
const dappId = getDappId(options.dapp);
|
|
649
648
|
const anonId = yield storage.getAnonId();
|
|
650
649
|
const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "unknown";
|
|
651
650
|
return {
|
|
652
|
-
|
|
651
|
+
mmconnect_versions: (_c = options.versions) != null ? _c : {},
|
|
653
652
|
dapp_id: dappId,
|
|
654
653
|
method: invokeOptions.request.method,
|
|
655
654
|
integration_type: integrationType,
|
|
656
655
|
caip_chain_id: invokeOptions.scope,
|
|
657
|
-
anon_id: anonId
|
|
656
|
+
anon_id: anonId,
|
|
657
|
+
transport_type: transportType
|
|
658
658
|
};
|
|
659
659
|
});
|
|
660
660
|
}
|
|
@@ -1093,7 +1093,6 @@ var init_install = __esm({
|
|
|
1093
1093
|
"mm-install-modal"
|
|
1094
1094
|
);
|
|
1095
1095
|
modal.showInstallModal = options.showInstallModal;
|
|
1096
|
-
modal.sdkVersion = options.sdkVersion;
|
|
1097
1096
|
modal.addEventListener("close", (ev) => {
|
|
1098
1097
|
const { detail } = ev;
|
|
1099
1098
|
options.onClose(detail == null ? void 0 : detail.shouldTerminate);
|
|
@@ -1420,10 +1419,11 @@ init_utils2();
|
|
|
1420
1419
|
init_analytics();
|
|
1421
1420
|
var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
|
|
1422
1421
|
var RequestRouter = class {
|
|
1423
|
-
constructor(transport, rpcClient, config) {
|
|
1422
|
+
constructor(transport, rpcClient, config, transportType) {
|
|
1424
1423
|
this.transport = transport;
|
|
1425
1424
|
this.rpcClient = rpcClient;
|
|
1426
1425
|
this.config = config;
|
|
1426
|
+
this.transportType = transportType;
|
|
1427
1427
|
__privateAdd(this, _RequestRouter_instances);
|
|
1428
1428
|
}
|
|
1429
1429
|
/**
|
|
@@ -1493,16 +1493,14 @@ var RequestRouter = class {
|
|
|
1493
1493
|
*/
|
|
1494
1494
|
handleWithRpcNode(options) {
|
|
1495
1495
|
return __async(this, null, function* () {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
return this.handleWithWallet(options);
|
|
1502
|
-
}
|
|
1503
|
-
throw error;
|
|
1496
|
+
try {
|
|
1497
|
+
return yield this.rpcClient.request(options);
|
|
1498
|
+
} catch (error) {
|
|
1499
|
+
if (error instanceof MissingRpcEndpointErr) {
|
|
1500
|
+
return this.handleWithWallet(options);
|
|
1504
1501
|
}
|
|
1505
|
-
|
|
1502
|
+
throw error;
|
|
1503
|
+
}
|
|
1506
1504
|
});
|
|
1507
1505
|
}
|
|
1508
1506
|
/**
|
|
@@ -1546,7 +1544,8 @@ trackWalletActionRequested_fn = function(options) {
|
|
|
1546
1544
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1547
1545
|
this.config,
|
|
1548
1546
|
this.config.storage,
|
|
1549
|
-
options
|
|
1547
|
+
options,
|
|
1548
|
+
this.transportType
|
|
1550
1549
|
);
|
|
1551
1550
|
analytics.track("mmconnect_wallet_action_requested", props);
|
|
1552
1551
|
});
|
|
@@ -1556,7 +1555,8 @@ trackWalletActionSucceeded_fn = function(options) {
|
|
|
1556
1555
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1557
1556
|
this.config,
|
|
1558
1557
|
this.config.storage,
|
|
1559
|
-
options
|
|
1558
|
+
options,
|
|
1559
|
+
this.transportType
|
|
1560
1560
|
);
|
|
1561
1561
|
analytics.track("mmconnect_wallet_action_succeeded", props);
|
|
1562
1562
|
});
|
|
@@ -1566,7 +1566,8 @@ trackWalletActionFailed_fn = function(options) {
|
|
|
1566
1566
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1567
1567
|
this.config,
|
|
1568
1568
|
this.config.storage,
|
|
1569
|
-
options
|
|
1569
|
+
options,
|
|
1570
|
+
this.transportType
|
|
1570
1571
|
);
|
|
1571
1572
|
analytics.track("mmconnect_wallet_action_failed", props);
|
|
1572
1573
|
});
|
|
@@ -1576,7 +1577,8 @@ trackWalletActionRejected_fn = function(options) {
|
|
|
1576
1577
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1577
1578
|
this.config,
|
|
1578
1579
|
this.config.storage,
|
|
1579
|
-
options
|
|
1580
|
+
options,
|
|
1581
|
+
this.transportType
|
|
1580
1582
|
);
|
|
1581
1583
|
analytics.track("mmconnect_wallet_action_rejected", props);
|
|
1582
1584
|
});
|
|
@@ -1588,7 +1590,7 @@ import {
|
|
|
1588
1590
|
getDefaultTransport
|
|
1589
1591
|
} from "@metamask/multichain-api-client";
|
|
1590
1592
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
1591
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
|
|
1593
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
1592
1594
|
var DefaultTransport = class {
|
|
1593
1595
|
constructor() {
|
|
1594
1596
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -1636,11 +1638,31 @@ var DefaultTransport = class {
|
|
|
1636
1638
|
});
|
|
1637
1639
|
});
|
|
1638
1640
|
}
|
|
1641
|
+
init() {
|
|
1642
|
+
return __async(this, null, function* () {
|
|
1643
|
+
yield __privateMethod(this, _DefaultTransport_instances, init_fn).call(this);
|
|
1644
|
+
let walletSession = { sessionScopes: {} };
|
|
1645
|
+
try {
|
|
1646
|
+
const sessionRequest = yield this.request(
|
|
1647
|
+
{ method: "wallet_getSession" },
|
|
1648
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1649
|
+
);
|
|
1650
|
+
walletSession = sessionRequest.result;
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
console.error(
|
|
1653
|
+
"Failed to get wallet session during DefaultTransport init"
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, {
|
|
1657
|
+
method: "wallet_sessionChanged",
|
|
1658
|
+
params: walletSession
|
|
1659
|
+
});
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1639
1662
|
connect(options) {
|
|
1640
1663
|
return __async(this, null, function* () {
|
|
1641
1664
|
var _a3, _b, _c, _d, _e;
|
|
1642
|
-
__privateMethod(this, _DefaultTransport_instances,
|
|
1643
|
-
yield __privateGet(this, _transport).connect();
|
|
1665
|
+
yield __privateMethod(this, _DefaultTransport_instances, init_fn).call(this);
|
|
1644
1666
|
const sessionRequest = yield this.request(
|
|
1645
1667
|
{ method: "wallet_getSession" },
|
|
1646
1668
|
__privateGet(this, _defaultRequestOptions)
|
|
@@ -1697,26 +1719,6 @@ var DefaultTransport = class {
|
|
|
1697
1719
|
disconnect() {
|
|
1698
1720
|
return __async(this, arguments, function* (scopes = []) {
|
|
1699
1721
|
yield this.request({ method: "wallet_revokeSession", params: { scopes } });
|
|
1700
|
-
const response = yield this.request({ method: "wallet_getSession" });
|
|
1701
|
-
const { sessionScopes } = response.result;
|
|
1702
|
-
if (Object.keys(sessionScopes).length > 0) {
|
|
1703
|
-
return;
|
|
1704
|
-
}
|
|
1705
|
-
__privateGet(this, _notificationCallbacks).clear();
|
|
1706
|
-
if (__privateGet(this, _handleResponseListener)) {
|
|
1707
|
-
window.removeEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1708
|
-
__privateSet(this, _handleResponseListener, void 0);
|
|
1709
|
-
}
|
|
1710
|
-
if (__privateGet(this, _handleNotificationListener)) {
|
|
1711
|
-
window.removeEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1712
|
-
__privateSet(this, _handleNotificationListener, void 0);
|
|
1713
|
-
}
|
|
1714
|
-
for (const [, request] of __privateGet(this, _pendingRequests)) {
|
|
1715
|
-
clearTimeout(request.timeout);
|
|
1716
|
-
request.reject(new Error("Transport disconnected"));
|
|
1717
|
-
}
|
|
1718
|
-
__privateGet(this, _pendingRequests).clear();
|
|
1719
|
-
yield __privateGet(this, _transport).disconnect();
|
|
1720
1722
|
});
|
|
1721
1723
|
}
|
|
1722
1724
|
isConnected() {
|
|
@@ -1805,7 +1807,7 @@ handleNotification_fn = function(event) {
|
|
|
1805
1807
|
return;
|
|
1806
1808
|
}
|
|
1807
1809
|
const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
|
|
1808
|
-
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1810
|
+
if (typeof responseData === "object" && responseData !== null && (responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged")) {
|
|
1809
1811
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1810
1812
|
}
|
|
1811
1813
|
};
|
|
@@ -1818,6 +1820,14 @@ setupMessageListener_fn = function() {
|
|
|
1818
1820
|
window.addEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1819
1821
|
window.addEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1820
1822
|
};
|
|
1823
|
+
init_fn = function() {
|
|
1824
|
+
return __async(this, null, function* () {
|
|
1825
|
+
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1826
|
+
if (!__privateGet(this, _transport).isConnected()) {
|
|
1827
|
+
yield __privateGet(this, _transport).connect();
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
};
|
|
1821
1831
|
|
|
1822
1832
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
1823
1833
|
init_utils2();
|
|
@@ -2217,6 +2227,10 @@ var MWPTransport = class {
|
|
|
2217
2227
|
}
|
|
2218
2228
|
});
|
|
2219
2229
|
}
|
|
2230
|
+
init() {
|
|
2231
|
+
return __async(this, null, function* () {
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2220
2234
|
// TODO: Rename this
|
|
2221
2235
|
sendEip1193Message(payload, options) {
|
|
2222
2236
|
return __async(this, null, function* () {
|
|
@@ -2569,7 +2583,7 @@ var MWPTransport = class {
|
|
|
2569
2583
|
getActiveSession() {
|
|
2570
2584
|
return __async(this, null, function* () {
|
|
2571
2585
|
const { kvstore } = this;
|
|
2572
|
-
const sessionStore =
|
|
2586
|
+
const sessionStore = yield SessionStore.create(kvstore);
|
|
2573
2587
|
try {
|
|
2574
2588
|
const [activeSession] = yield sessionStore.list();
|
|
2575
2589
|
return activeSession;
|
|
@@ -2620,7 +2634,7 @@ var MWPTransport = class {
|
|
|
2620
2634
|
};
|
|
2621
2635
|
|
|
2622
2636
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
2623
|
-
import { decrypt, encrypt, PrivateKey } from "eciesjs";
|
|
2637
|
+
import { decrypt, encrypt, PrivateKey, PublicKey } from "eciesjs";
|
|
2624
2638
|
var KeyManager = class {
|
|
2625
2639
|
generateKeyPair() {
|
|
2626
2640
|
const privateKey = new PrivateKey();
|
|
@@ -2643,6 +2657,9 @@ var KeyManager = class {
|
|
|
2643
2657
|
return Buffer.from(decryptedBuffer).toString("utf8");
|
|
2644
2658
|
});
|
|
2645
2659
|
}
|
|
2660
|
+
validatePeerKey(key) {
|
|
2661
|
+
PublicKey.fromHex(Buffer.from(key).toString("hex"));
|
|
2662
|
+
}
|
|
2646
2663
|
};
|
|
2647
2664
|
var keymanager = new KeyManager();
|
|
2648
2665
|
|
|
@@ -2650,10 +2667,10 @@ var keymanager = new KeyManager();
|
|
|
2650
2667
|
init_utils2();
|
|
2651
2668
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2652
2669
|
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
2653
|
-
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn,
|
|
2670
|
+
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn2, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
|
|
2654
2671
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2655
2672
|
constructor(options) {
|
|
2656
|
-
var _a3, _b, _c, _d, _e, _f;
|
|
2673
|
+
var _a3, _b, _c, _d, _e, _f, _g;
|
|
2657
2674
|
const withDappMetadata = setupDappMetadata(options);
|
|
2658
2675
|
const integrationType = (_b = (_a3 = options.analytics) == null ? void 0 : _a3.integrationType) != null ? _b : "direct";
|
|
2659
2676
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
@@ -2664,7 +2681,10 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2664
2681
|
}),
|
|
2665
2682
|
analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
|
|
2666
2683
|
integrationType
|
|
2667
|
-
})
|
|
2684
|
+
}),
|
|
2685
|
+
versions: __spreadValues({
|
|
2686
|
+
"connect-multichain": "0.9.0"
|
|
2687
|
+
}, (_g = options.versions) != null ? _g : {})
|
|
2668
2688
|
});
|
|
2669
2689
|
super(allOptions);
|
|
2670
2690
|
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
@@ -2688,6 +2708,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2688
2708
|
}
|
|
2689
2709
|
set status(value) {
|
|
2690
2710
|
var _a3, _b;
|
|
2711
|
+
if (this._status === value) {
|
|
2712
|
+
return;
|
|
2713
|
+
}
|
|
2691
2714
|
this._status = value;
|
|
2692
2715
|
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, {
|
|
2693
2716
|
method: "stateChanged",
|
|
@@ -2718,23 +2741,28 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2718
2741
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
2719
2742
|
// If the singleton already exists, it merges the incoming options with the
|
|
2720
2743
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
2721
|
-
// `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note
|
|
2722
|
-
// value for `dapp` is not merged as it does not make sense for
|
|
2723
|
-
// `createMultichainClient` to have a different `dapp` value.
|
|
2744
|
+
// `versions`, `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note
|
|
2745
|
+
// that the value for `dapp` is not merged as it does not make sense for
|
|
2746
|
+
// subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
2724
2747
|
static create(options) {
|
|
2725
2748
|
return __async(this, null, function* () {
|
|
2749
|
+
var _a3;
|
|
2726
2750
|
const globalObject = getGlobalObject();
|
|
2727
2751
|
const existing = globalObject[SINGLETON_KEY];
|
|
2728
2752
|
if (existing) {
|
|
2729
2753
|
const instance = yield existing;
|
|
2730
2754
|
instance.mergeOptions(options);
|
|
2755
|
+
analytics2.setGlobalProperty(
|
|
2756
|
+
"mmconnect_versions",
|
|
2757
|
+
(_a3 = instance.options.versions) != null ? _a3 : {}
|
|
2758
|
+
);
|
|
2731
2759
|
if (options.debug) {
|
|
2732
2760
|
enableDebug("metamask-sdk:*");
|
|
2733
2761
|
}
|
|
2734
2762
|
return instance;
|
|
2735
2763
|
}
|
|
2736
2764
|
const instancePromise = (() => __async(null, null, function* () {
|
|
2737
|
-
var
|
|
2765
|
+
var _a4;
|
|
2738
2766
|
const instance = new _MetaMaskConnectMultichain(options);
|
|
2739
2767
|
const isEnabled2 = yield isEnabled(
|
|
2740
2768
|
"metamask-sdk:core",
|
|
@@ -2743,7 +2771,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2743
2771
|
if (isEnabled2) {
|
|
2744
2772
|
enableDebug("metamask-sdk:core");
|
|
2745
2773
|
}
|
|
2746
|
-
yield __privateMethod(
|
|
2774
|
+
yield __privateMethod(_a4 = instance, _MetaMaskConnectMultichain_instances, init_fn2).call(_a4);
|
|
2747
2775
|
return instance;
|
|
2748
2776
|
}))();
|
|
2749
2777
|
globalObject[SINGLETON_KEY] = instancePromise;
|
|
@@ -2853,14 +2881,16 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2853
2881
|
);
|
|
2854
2882
|
yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
|
|
2855
2883
|
if (remainingScopes.length === 0) {
|
|
2856
|
-
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2857
|
-
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2858
2884
|
yield this.storage.removeTransport();
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2885
|
+
if (this.transportType !== "browser" /* Browser */) {
|
|
2886
|
+
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2887
|
+
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2888
|
+
__privateSet(this, _listener, void 0);
|
|
2889
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2890
|
+
__privateSet(this, _transport2, void 0);
|
|
2891
|
+
__privateGet(this, _providerTransportWrapper).clearTransportNotificationListener();
|
|
2892
|
+
__privateSet(this, _dappClient, void 0);
|
|
2893
|
+
}
|
|
2864
2894
|
this.status = "disconnected";
|
|
2865
2895
|
}
|
|
2866
2896
|
});
|
|
@@ -2869,7 +2899,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2869
2899
|
return __async(this, null, function* () {
|
|
2870
2900
|
const { transport, options } = this;
|
|
2871
2901
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2872
|
-
const requestRouter = new RequestRouter(
|
|
2902
|
+
const requestRouter = new RequestRouter(
|
|
2903
|
+
transport,
|
|
2904
|
+
rpcClient,
|
|
2905
|
+
options,
|
|
2906
|
+
this.transportType
|
|
2907
|
+
);
|
|
2873
2908
|
return requestRouter.invokeMethod(request);
|
|
2874
2909
|
});
|
|
2875
2910
|
}
|
|
@@ -2899,16 +2934,16 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2899
2934
|
// without having to concern themselves with the current transport connection status.
|
|
2900
2935
|
emitSessionChanged() {
|
|
2901
2936
|
return __async(this, null, function* () {
|
|
2902
|
-
var _a3;
|
|
2937
|
+
var _a3, _b;
|
|
2903
2938
|
const emptySession = { sessionScopes: {} };
|
|
2904
|
-
if (this
|
|
2939
|
+
if (!((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected())) {
|
|
2905
2940
|
this.emit("wallet_sessionChanged", emptySession);
|
|
2906
2941
|
return;
|
|
2907
2942
|
}
|
|
2908
2943
|
const response = yield this.transport.request({
|
|
2909
2944
|
method: "wallet_getSession"
|
|
2910
2945
|
});
|
|
2911
|
-
this.emit("wallet_sessionChanged", (
|
|
2946
|
+
this.emit("wallet_sessionChanged", (_b = response.result) != null ? _b : emptySession);
|
|
2912
2947
|
});
|
|
2913
2948
|
}
|
|
2914
2949
|
};
|
|
@@ -2922,20 +2957,22 @@ _sdkInfo = new WeakMap();
|
|
|
2922
2957
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2923
2958
|
setupAnalytics_fn = function() {
|
|
2924
2959
|
return __async(this, null, function* () {
|
|
2925
|
-
var _a3;
|
|
2960
|
+
var _a3, _b;
|
|
2926
2961
|
const platform = getPlatformType();
|
|
2927
2962
|
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2928
2963
|
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2929
2964
|
if (!isBrowser && !isReactNative2) {
|
|
2930
2965
|
return;
|
|
2931
2966
|
}
|
|
2932
|
-
const version = getVersion();
|
|
2933
2967
|
const dappId = getDappId(this.options.dapp);
|
|
2934
2968
|
const anonId = yield this.storage.getAnonId();
|
|
2935
2969
|
const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
|
|
2936
2970
|
integrationType: ""
|
|
2937
2971
|
};
|
|
2938
|
-
analytics2.setGlobalProperty(
|
|
2972
|
+
analytics2.setGlobalProperty(
|
|
2973
|
+
"mmconnect_versions",
|
|
2974
|
+
(_b = this.options.versions) != null ? _b : {}
|
|
2975
|
+
);
|
|
2939
2976
|
analytics2.setGlobalProperty("dapp_id", dappId);
|
|
2940
2977
|
analytics2.setGlobalProperty("anon_id", anonId);
|
|
2941
2978
|
analytics2.setGlobalProperty("platform", platform);
|
|
@@ -2945,9 +2982,17 @@ setupAnalytics_fn = function() {
|
|
|
2945
2982
|
};
|
|
2946
2983
|
onTransportNotification_fn = function(payload) {
|
|
2947
2984
|
return __async(this, null, function* () {
|
|
2948
|
-
var _a3;
|
|
2985
|
+
var _a3, _b, _c;
|
|
2949
2986
|
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2950
|
-
|
|
2987
|
+
if (payload.method === "wallet_sessionChanged") {
|
|
2988
|
+
const sessionScopes = (_b = (_a3 = payload.params) == null ? void 0 : _a3.sessionScopes) != null ? _b : {};
|
|
2989
|
+
const hasScopes = Object.keys(sessionScopes).length > 0;
|
|
2990
|
+
if (this.status === "loaded" && !hasScopes) {
|
|
2991
|
+
return;
|
|
2992
|
+
}
|
|
2993
|
+
this.status = hasScopes ? "connected" : "disconnected";
|
|
2994
|
+
}
|
|
2995
|
+
this.emit(payload.method, (_c = payload.params) != null ? _c : payload.result);
|
|
2951
2996
|
}
|
|
2952
2997
|
});
|
|
2953
2998
|
};
|
|
@@ -2985,6 +3030,7 @@ getStoredTransport_fn = function() {
|
|
|
2985
3030
|
};
|
|
2986
3031
|
setupTransport_fn = function() {
|
|
2987
3032
|
return __async(this, null, function* () {
|
|
3033
|
+
var _a3;
|
|
2988
3034
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
2989
3035
|
if (transport) {
|
|
2990
3036
|
if (!this.transport.isConnected()) {
|
|
@@ -2999,23 +3045,24 @@ setupTransport_fn = function() {
|
|
|
2999
3045
|
}
|
|
3000
3046
|
} else {
|
|
3001
3047
|
this.status = "loaded";
|
|
3048
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
3049
|
+
const preferExtension = (_a3 = this.options.ui.preferExtension) != null ? _a3 : true;
|
|
3050
|
+
if (hasExtensionInstalled && preferExtension) {
|
|
3051
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
3052
|
+
try {
|
|
3053
|
+
yield this.transport.init();
|
|
3054
|
+
} catch (error) {
|
|
3055
|
+
console.error("Passive init failed:", error);
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3002
3058
|
}
|
|
3003
3059
|
});
|
|
3004
3060
|
};
|
|
3005
|
-
|
|
3061
|
+
init_fn2 = function() {
|
|
3006
3062
|
return __async(this, null, function* () {
|
|
3007
3063
|
try {
|
|
3008
3064
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
3009
3065
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
3010
|
-
try {
|
|
3011
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
3012
|
-
this.options,
|
|
3013
|
-
this.storage
|
|
3014
|
-
);
|
|
3015
|
-
analytics2.track("mmconnect_initialized", baseProps);
|
|
3016
|
-
} catch (error) {
|
|
3017
|
-
logger2("Error tracking initialized event", error);
|
|
3018
|
-
}
|
|
3019
3066
|
} catch (error) {
|
|
3020
3067
|
yield this.storage.removeTransport();
|
|
3021
3068
|
this.status = "pending";
|
|
@@ -3026,7 +3073,7 @@ init_fn = function() {
|
|
|
3026
3073
|
createDappClient_fn = function() {
|
|
3027
3074
|
return __async(this, null, function* () {
|
|
3028
3075
|
const { adapter: kvstore } = this.options.storage;
|
|
3029
|
-
const sessionstore =
|
|
3076
|
+
const sessionstore = yield SessionStore2.create(kvstore);
|
|
3030
3077
|
const websocket = (
|
|
3031
3078
|
// eslint-disable-next-line no-negated-condition
|
|
3032
3079
|
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
@@ -3203,9 +3250,13 @@ headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3203
3250
|
});
|
|
3204
3251
|
};
|
|
3205
3252
|
setupDefaultTransport_fn = function() {
|
|
3206
|
-
return __async(this,
|
|
3207
|
-
this
|
|
3208
|
-
|
|
3253
|
+
return __async(this, arguments, function* (options = { persist: true }) {
|
|
3254
|
+
if (__privateGet(this, _transport2) instanceof DefaultTransport) {
|
|
3255
|
+
return __privateGet(this, _transport2);
|
|
3256
|
+
}
|
|
3257
|
+
if (options == null ? void 0 : options.persist) {
|
|
3258
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
3259
|
+
}
|
|
3209
3260
|
const transport = new DefaultTransport();
|
|
3210
3261
|
__privateSet(this, _listener, transport.onNotification(
|
|
3211
3262
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
@@ -3323,16 +3374,20 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
3323
3374
|
};
|
|
3324
3375
|
getCaipSession_fn = function() {
|
|
3325
3376
|
return __async(this, null, function* () {
|
|
3377
|
+
var _a3;
|
|
3326
3378
|
let sessionData = {
|
|
3327
3379
|
sessionScopes: {},
|
|
3328
3380
|
sessionProperties: {}
|
|
3329
3381
|
};
|
|
3330
|
-
if (this
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3382
|
+
if ((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) {
|
|
3383
|
+
try {
|
|
3384
|
+
const response = yield this.transport.request({
|
|
3385
|
+
method: "wallet_getSession"
|
|
3386
|
+
});
|
|
3387
|
+
if (response.result) {
|
|
3388
|
+
sessionData = response.result;
|
|
3389
|
+
}
|
|
3390
|
+
} catch (e) {
|
|
3336
3391
|
}
|
|
3337
3392
|
}
|
|
3338
3393
|
return sessionData;
|
|
@@ -3661,7 +3716,6 @@ var BaseModalFactory = class {
|
|
|
3661
3716
|
parentElement,
|
|
3662
3717
|
showInstallModal,
|
|
3663
3718
|
link: qrCodeLink,
|
|
3664
|
-
sdkVersion: getVersion(),
|
|
3665
3719
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3666
3720
|
var _a4;
|
|
3667
3721
|
const newLink = this.createConnectionDeeplink(request);
|
|
@@ -3687,7 +3741,6 @@ var BaseModalFactory = class {
|
|
|
3687
3741
|
const otpCode = yield createOTPCode();
|
|
3688
3742
|
const modal = new this.options.OTPCodeModal({
|
|
3689
3743
|
parentElement: container,
|
|
3690
|
-
sdkVersion: getVersion(),
|
|
3691
3744
|
otpCode,
|
|
3692
3745
|
onClose: this.onCloseModal.bind(this),
|
|
3693
3746
|
createOTPCode,
|