@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
|
@@ -422,7 +422,7 @@ var init_multichain = __esm({
|
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
424
|
* Merges the given options into the current instance options.
|
|
425
|
-
* Only the mergeable keys are updated (api.supportedNetworks, ui.*, mobile.*, transport.extensionId, debug).
|
|
425
|
+
* Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
|
|
426
426
|
* The main thing to note is that the value for `dapp` is not merged as it does not make sense for
|
|
427
427
|
* subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
428
428
|
* Used when createMultichainClient is called with an existing singleton.
|
|
@@ -430,22 +430,23 @@ var init_multichain = __esm({
|
|
|
430
430
|
* @param partial - Options to merge/overwrite onto the current instance
|
|
431
431
|
*/
|
|
432
432
|
mergeOptions(partial) {
|
|
433
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
433
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
434
434
|
const opts = this.options;
|
|
435
435
|
this.options = __spreadProps(__spreadValues({}, opts), {
|
|
436
436
|
api: __spreadProps(__spreadValues({}, opts.api), {
|
|
437
437
|
supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_b = (_a2 = partial.api) == null ? void 0 : _a2.supportedNetworks) != null ? _b : {})
|
|
438
438
|
}),
|
|
439
|
+
versions: __spreadValues(__spreadValues({}, opts.versions), (_c = partial.versions) != null ? _c : {}),
|
|
439
440
|
ui: __spreadProps(__spreadValues({}, opts.ui), {
|
|
440
|
-
headless: (
|
|
441
|
-
preferExtension: (
|
|
442
|
-
showInstallModal: (
|
|
441
|
+
headless: (_e = (_d = partial.ui) == null ? void 0 : _d.headless) != null ? _e : opts.ui.headless,
|
|
442
|
+
preferExtension: (_g = (_f = partial.ui) == null ? void 0 : _f.preferExtension) != null ? _g : opts.ui.preferExtension,
|
|
443
|
+
showInstallModal: (_i = (_h = partial.ui) == null ? void 0 : _h.showInstallModal) != null ? _i : opts.ui.showInstallModal
|
|
443
444
|
}),
|
|
444
|
-
mobile: __spreadValues(__spreadValues({}, opts.mobile), (
|
|
445
|
-
transport: __spreadProps(__spreadValues({}, (
|
|
446
|
-
extensionId: (
|
|
445
|
+
mobile: __spreadValues(__spreadValues({}, opts.mobile), (_j = partial.mobile) != null ? _j : {}),
|
|
446
|
+
transport: __spreadProps(__spreadValues({}, (_k = opts.transport) != null ? _k : {}), {
|
|
447
|
+
extensionId: (_n = (_l = partial.transport) == null ? void 0 : _l.extensionId) != null ? _n : (_m = opts.transport) == null ? void 0 : _m.extensionId
|
|
447
448
|
}),
|
|
448
|
-
debug: (
|
|
449
|
+
debug: (_o = partial.debug) != null ? _o : opts.debug
|
|
449
450
|
});
|
|
450
451
|
}
|
|
451
452
|
};
|
|
@@ -914,14 +915,13 @@ function isRejectionError(error) {
|
|
|
914
915
|
}
|
|
915
916
|
function getBaseAnalyticsProperties(options, storage) {
|
|
916
917
|
return __async(this, null, function* () {
|
|
917
|
-
var _a2, _b;
|
|
918
|
-
const version = getVersion();
|
|
918
|
+
var _a2, _b, _c;
|
|
919
919
|
const dappId = getDappId(options.dapp);
|
|
920
920
|
const platform = getPlatformType();
|
|
921
921
|
const anonId = yield storage.getAnonId();
|
|
922
922
|
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown" /* UNKNOWN */;
|
|
923
923
|
return {
|
|
924
|
-
|
|
924
|
+
mmconnect_versions: (_c = options.versions) != null ? _c : {},
|
|
925
925
|
dapp_id: dappId,
|
|
926
926
|
platform,
|
|
927
927
|
integration_type: integrationType,
|
|
@@ -929,20 +929,20 @@ function getBaseAnalyticsProperties(options, storage) {
|
|
|
929
929
|
};
|
|
930
930
|
});
|
|
931
931
|
}
|
|
932
|
-
function getWalletActionAnalyticsProperties(options, storage, invokeOptions) {
|
|
932
|
+
function getWalletActionAnalyticsProperties(options, storage, invokeOptions, transportType) {
|
|
933
933
|
return __async(this, null, function* () {
|
|
934
|
-
var _a2, _b;
|
|
935
|
-
const version = getVersion();
|
|
934
|
+
var _a2, _b, _c;
|
|
936
935
|
const dappId = getDappId(options.dapp);
|
|
937
936
|
const anonId = yield storage.getAnonId();
|
|
938
937
|
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "unknown";
|
|
939
938
|
return {
|
|
940
|
-
|
|
939
|
+
mmconnect_versions: (_c = options.versions) != null ? _c : {},
|
|
941
940
|
dapp_id: dappId,
|
|
942
941
|
method: invokeOptions.request.method,
|
|
943
942
|
integration_type: integrationType,
|
|
944
943
|
caip_chain_id: invokeOptions.scope,
|
|
945
|
-
anon_id: anonId
|
|
944
|
+
anon_id: anonId,
|
|
945
|
+
transport_type: transportType
|
|
946
946
|
};
|
|
947
947
|
});
|
|
948
948
|
}
|
|
@@ -1400,10 +1400,11 @@ init_utils();
|
|
|
1400
1400
|
init_analytics();
|
|
1401
1401
|
var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
|
|
1402
1402
|
var RequestRouter = class {
|
|
1403
|
-
constructor(transport, rpcClient, config) {
|
|
1403
|
+
constructor(transport, rpcClient, config, transportType) {
|
|
1404
1404
|
this.transport = transport;
|
|
1405
1405
|
this.rpcClient = rpcClient;
|
|
1406
1406
|
this.config = config;
|
|
1407
|
+
this.transportType = transportType;
|
|
1407
1408
|
__privateAdd(this, _RequestRouter_instances);
|
|
1408
1409
|
}
|
|
1409
1410
|
/**
|
|
@@ -1473,16 +1474,14 @@ var RequestRouter = class {
|
|
|
1473
1474
|
*/
|
|
1474
1475
|
handleWithRpcNode(options) {
|
|
1475
1476
|
return __async(this, null, function* () {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
return this.handleWithWallet(options);
|
|
1482
|
-
}
|
|
1483
|
-
throw error;
|
|
1477
|
+
try {
|
|
1478
|
+
return yield this.rpcClient.request(options);
|
|
1479
|
+
} catch (error) {
|
|
1480
|
+
if (error instanceof MissingRpcEndpointErr) {
|
|
1481
|
+
return this.handleWithWallet(options);
|
|
1484
1482
|
}
|
|
1485
|
-
|
|
1483
|
+
throw error;
|
|
1484
|
+
}
|
|
1486
1485
|
});
|
|
1487
1486
|
}
|
|
1488
1487
|
/**
|
|
@@ -1526,7 +1525,8 @@ trackWalletActionRequested_fn = function(options) {
|
|
|
1526
1525
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1527
1526
|
this.config,
|
|
1528
1527
|
this.config.storage,
|
|
1529
|
-
options
|
|
1528
|
+
options,
|
|
1529
|
+
this.transportType
|
|
1530
1530
|
);
|
|
1531
1531
|
import_analytics2.analytics.track("mmconnect_wallet_action_requested", props);
|
|
1532
1532
|
});
|
|
@@ -1536,7 +1536,8 @@ trackWalletActionSucceeded_fn = function(options) {
|
|
|
1536
1536
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1537
1537
|
this.config,
|
|
1538
1538
|
this.config.storage,
|
|
1539
|
-
options
|
|
1539
|
+
options,
|
|
1540
|
+
this.transportType
|
|
1540
1541
|
);
|
|
1541
1542
|
import_analytics2.analytics.track("mmconnect_wallet_action_succeeded", props);
|
|
1542
1543
|
});
|
|
@@ -1546,7 +1547,8 @@ trackWalletActionFailed_fn = function(options) {
|
|
|
1546
1547
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1547
1548
|
this.config,
|
|
1548
1549
|
this.config.storage,
|
|
1549
|
-
options
|
|
1550
|
+
options,
|
|
1551
|
+
this.transportType
|
|
1550
1552
|
);
|
|
1551
1553
|
import_analytics2.analytics.track("mmconnect_wallet_action_failed", props);
|
|
1552
1554
|
});
|
|
@@ -1556,7 +1558,8 @@ trackWalletActionRejected_fn = function(options) {
|
|
|
1556
1558
|
const props = yield getWalletActionAnalyticsProperties(
|
|
1557
1559
|
this.config,
|
|
1558
1560
|
this.config.storage,
|
|
1559
|
-
options
|
|
1561
|
+
options,
|
|
1562
|
+
this.transportType
|
|
1560
1563
|
);
|
|
1561
1564
|
import_analytics2.analytics.track("mmconnect_wallet_action_rejected", props);
|
|
1562
1565
|
});
|
|
@@ -1566,7 +1569,7 @@ trackWalletActionRejected_fn = function(options) {
|
|
|
1566
1569
|
var import_multichain_api_client = require("@metamask/multichain-api-client");
|
|
1567
1570
|
init_utils();
|
|
1568
1571
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
1569
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
|
|
1572
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
1570
1573
|
var DefaultTransport = class {
|
|
1571
1574
|
constructor() {
|
|
1572
1575
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -1614,11 +1617,31 @@ var DefaultTransport = class {
|
|
|
1614
1617
|
});
|
|
1615
1618
|
});
|
|
1616
1619
|
}
|
|
1620
|
+
init() {
|
|
1621
|
+
return __async(this, null, function* () {
|
|
1622
|
+
yield __privateMethod(this, _DefaultTransport_instances, init_fn).call(this);
|
|
1623
|
+
let walletSession = { sessionScopes: {} };
|
|
1624
|
+
try {
|
|
1625
|
+
const sessionRequest = yield this.request(
|
|
1626
|
+
{ method: "wallet_getSession" },
|
|
1627
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1628
|
+
);
|
|
1629
|
+
walletSession = sessionRequest.result;
|
|
1630
|
+
} catch (e) {
|
|
1631
|
+
console.error(
|
|
1632
|
+
"Failed to get wallet session during DefaultTransport init"
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, {
|
|
1636
|
+
method: "wallet_sessionChanged",
|
|
1637
|
+
params: walletSession
|
|
1638
|
+
});
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1617
1641
|
connect(options) {
|
|
1618
1642
|
return __async(this, null, function* () {
|
|
1619
1643
|
var _a2, _b, _c, _d, _e;
|
|
1620
|
-
__privateMethod(this, _DefaultTransport_instances,
|
|
1621
|
-
yield __privateGet(this, _transport).connect();
|
|
1644
|
+
yield __privateMethod(this, _DefaultTransport_instances, init_fn).call(this);
|
|
1622
1645
|
const sessionRequest = yield this.request(
|
|
1623
1646
|
{ method: "wallet_getSession" },
|
|
1624
1647
|
__privateGet(this, _defaultRequestOptions)
|
|
@@ -1675,26 +1698,6 @@ var DefaultTransport = class {
|
|
|
1675
1698
|
disconnect() {
|
|
1676
1699
|
return __async(this, arguments, function* (scopes = []) {
|
|
1677
1700
|
yield this.request({ method: "wallet_revokeSession", params: { scopes } });
|
|
1678
|
-
const response = yield this.request({ method: "wallet_getSession" });
|
|
1679
|
-
const { sessionScopes } = response.result;
|
|
1680
|
-
if (Object.keys(sessionScopes).length > 0) {
|
|
1681
|
-
return;
|
|
1682
|
-
}
|
|
1683
|
-
__privateGet(this, _notificationCallbacks).clear();
|
|
1684
|
-
if (__privateGet(this, _handleResponseListener)) {
|
|
1685
|
-
window.removeEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1686
|
-
__privateSet(this, _handleResponseListener, void 0);
|
|
1687
|
-
}
|
|
1688
|
-
if (__privateGet(this, _handleNotificationListener)) {
|
|
1689
|
-
window.removeEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1690
|
-
__privateSet(this, _handleNotificationListener, void 0);
|
|
1691
|
-
}
|
|
1692
|
-
for (const [, request] of __privateGet(this, _pendingRequests)) {
|
|
1693
|
-
clearTimeout(request.timeout);
|
|
1694
|
-
request.reject(new Error("Transport disconnected"));
|
|
1695
|
-
}
|
|
1696
|
-
__privateGet(this, _pendingRequests).clear();
|
|
1697
|
-
yield __privateGet(this, _transport).disconnect();
|
|
1698
1701
|
});
|
|
1699
1702
|
}
|
|
1700
1703
|
isConnected() {
|
|
@@ -1783,7 +1786,7 @@ handleNotification_fn = function(event) {
|
|
|
1783
1786
|
return;
|
|
1784
1787
|
}
|
|
1785
1788
|
const responseData = (_b = (_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.data;
|
|
1786
|
-
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1789
|
+
if (typeof responseData === "object" && responseData !== null && (responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged")) {
|
|
1787
1790
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1788
1791
|
}
|
|
1789
1792
|
};
|
|
@@ -1796,6 +1799,14 @@ setupMessageListener_fn = function() {
|
|
|
1796
1799
|
window.addEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1797
1800
|
window.addEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1798
1801
|
};
|
|
1802
|
+
init_fn = function() {
|
|
1803
|
+
return __async(this, null, function* () {
|
|
1804
|
+
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1805
|
+
if (!__privateGet(this, _transport).isConnected()) {
|
|
1806
|
+
yield __privateGet(this, _transport).connect();
|
|
1807
|
+
}
|
|
1808
|
+
});
|
|
1809
|
+
};
|
|
1799
1810
|
|
|
1800
1811
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
1801
1812
|
var import_rpc_errors = require("@metamask/rpc-errors");
|
|
@@ -2193,6 +2204,10 @@ var MWPTransport = class {
|
|
|
2193
2204
|
}
|
|
2194
2205
|
});
|
|
2195
2206
|
}
|
|
2207
|
+
init() {
|
|
2208
|
+
return __async(this, null, function* () {
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2196
2211
|
// TODO: Rename this
|
|
2197
2212
|
sendEip1193Message(payload, options) {
|
|
2198
2213
|
return __async(this, null, function* () {
|
|
@@ -2545,7 +2560,7 @@ var MWPTransport = class {
|
|
|
2545
2560
|
getActiveSession() {
|
|
2546
2561
|
return __async(this, null, function* () {
|
|
2547
2562
|
const { kvstore } = this;
|
|
2548
|
-
const sessionStore =
|
|
2563
|
+
const sessionStore = yield import_mobile_wallet_protocol_core.SessionStore.create(kvstore);
|
|
2549
2564
|
try {
|
|
2550
2565
|
const [activeSession] = yield sessionStore.list();
|
|
2551
2566
|
return activeSession;
|
|
@@ -2619,6 +2634,9 @@ var KeyManager = class {
|
|
|
2619
2634
|
return Buffer.from(decryptedBuffer).toString("utf8");
|
|
2620
2635
|
});
|
|
2621
2636
|
}
|
|
2637
|
+
validatePeerKey(key) {
|
|
2638
|
+
import_eciesjs.PublicKey.fromHex(Buffer.from(key).toString("hex"));
|
|
2639
|
+
}
|
|
2622
2640
|
};
|
|
2623
2641
|
var keymanager = new KeyManager();
|
|
2624
2642
|
|
|
@@ -2626,10 +2644,10 @@ var keymanager = new KeyManager();
|
|
|
2626
2644
|
init_utils();
|
|
2627
2645
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2628
2646
|
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
2629
|
-
var _a, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn,
|
|
2647
|
+
var _a, _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;
|
|
2630
2648
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2631
2649
|
constructor(options) {
|
|
2632
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
2650
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
2633
2651
|
const withDappMetadata = setupDappMetadata(options);
|
|
2634
2652
|
const integrationType = (_b = (_a2 = options.analytics) == null ? void 0 : _a2.integrationType) != null ? _b : "direct";
|
|
2635
2653
|
const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
|
|
@@ -2640,7 +2658,10 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2640
2658
|
}),
|
|
2641
2659
|
analytics: __spreadProps(__spreadValues({}, (_f = options.analytics) != null ? _f : {}), {
|
|
2642
2660
|
integrationType
|
|
2643
|
-
})
|
|
2661
|
+
}),
|
|
2662
|
+
versions: __spreadValues({
|
|
2663
|
+
"connect-multichain": "0.9.0"
|
|
2664
|
+
}, (_g = options.versions) != null ? _g : {})
|
|
2644
2665
|
});
|
|
2645
2666
|
super(allOptions);
|
|
2646
2667
|
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
@@ -2664,6 +2685,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2664
2685
|
}
|
|
2665
2686
|
set status(value) {
|
|
2666
2687
|
var _a2, _b;
|
|
2688
|
+
if (this._status === value) {
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2667
2691
|
this._status = value;
|
|
2668
2692
|
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2669
2693
|
method: "stateChanged",
|
|
@@ -2694,23 +2718,28 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2694
2718
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
2695
2719
|
// If the singleton already exists, it merges the incoming options with the
|
|
2696
2720
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
2697
|
-
// `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note
|
|
2698
|
-
// value for `dapp` is not merged as it does not make sense for
|
|
2699
|
-
// `createMultichainClient` to have a different `dapp` value.
|
|
2721
|
+
// `versions`, `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note
|
|
2722
|
+
// that the value for `dapp` is not merged as it does not make sense for
|
|
2723
|
+
// subsequent calls to `createMultichainClient` to have a different `dapp` value.
|
|
2700
2724
|
static create(options) {
|
|
2701
2725
|
return __async(this, null, function* () {
|
|
2726
|
+
var _a2;
|
|
2702
2727
|
const globalObject = getGlobalObject();
|
|
2703
2728
|
const existing = globalObject[SINGLETON_KEY];
|
|
2704
2729
|
if (existing) {
|
|
2705
2730
|
const instance = yield existing;
|
|
2706
2731
|
instance.mergeOptions(options);
|
|
2732
|
+
import_analytics4.analytics.setGlobalProperty(
|
|
2733
|
+
"mmconnect_versions",
|
|
2734
|
+
(_a2 = instance.options.versions) != null ? _a2 : {}
|
|
2735
|
+
);
|
|
2707
2736
|
if (options.debug) {
|
|
2708
2737
|
enableDebug("metamask-sdk:*");
|
|
2709
2738
|
}
|
|
2710
2739
|
return instance;
|
|
2711
2740
|
}
|
|
2712
2741
|
const instancePromise = (() => __async(null, null, function* () {
|
|
2713
|
-
var
|
|
2742
|
+
var _a3;
|
|
2714
2743
|
const instance = new _MetaMaskConnectMultichain(options);
|
|
2715
2744
|
const isEnabled2 = yield isEnabled(
|
|
2716
2745
|
"metamask-sdk:core",
|
|
@@ -2719,7 +2748,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2719
2748
|
if (isEnabled2) {
|
|
2720
2749
|
enableDebug("metamask-sdk:core");
|
|
2721
2750
|
}
|
|
2722
|
-
yield __privateMethod(
|
|
2751
|
+
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, init_fn2).call(_a3);
|
|
2723
2752
|
return instance;
|
|
2724
2753
|
}))();
|
|
2725
2754
|
globalObject[SINGLETON_KEY] = instancePromise;
|
|
@@ -2829,14 +2858,16 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2829
2858
|
);
|
|
2830
2859
|
yield (_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.disconnect(scopes);
|
|
2831
2860
|
if (remainingScopes.length === 0) {
|
|
2832
|
-
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2833
|
-
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2834
2861
|
yield this.storage.removeTransport();
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2862
|
+
if (this.transportType !== "browser" /* Browser */) {
|
|
2863
|
+
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2864
|
+
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2865
|
+
__privateSet(this, _listener, void 0);
|
|
2866
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2867
|
+
__privateSet(this, _transport2, void 0);
|
|
2868
|
+
__privateGet(this, _providerTransportWrapper).clearTransportNotificationListener();
|
|
2869
|
+
__privateSet(this, _dappClient, void 0);
|
|
2870
|
+
}
|
|
2840
2871
|
this.status = "disconnected";
|
|
2841
2872
|
}
|
|
2842
2873
|
});
|
|
@@ -2845,7 +2876,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2845
2876
|
return __async(this, null, function* () {
|
|
2846
2877
|
const { transport, options } = this;
|
|
2847
2878
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2848
|
-
const requestRouter = new RequestRouter(
|
|
2879
|
+
const requestRouter = new RequestRouter(
|
|
2880
|
+
transport,
|
|
2881
|
+
rpcClient,
|
|
2882
|
+
options,
|
|
2883
|
+
this.transportType
|
|
2884
|
+
);
|
|
2849
2885
|
return requestRouter.invokeMethod(request);
|
|
2850
2886
|
});
|
|
2851
2887
|
}
|
|
@@ -2875,16 +2911,16 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2875
2911
|
// without having to concern themselves with the current transport connection status.
|
|
2876
2912
|
emitSessionChanged() {
|
|
2877
2913
|
return __async(this, null, function* () {
|
|
2878
|
-
var _a2;
|
|
2914
|
+
var _a2, _b;
|
|
2879
2915
|
const emptySession = { sessionScopes: {} };
|
|
2880
|
-
if (this
|
|
2916
|
+
if (!((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected())) {
|
|
2881
2917
|
this.emit("wallet_sessionChanged", emptySession);
|
|
2882
2918
|
return;
|
|
2883
2919
|
}
|
|
2884
2920
|
const response = yield this.transport.request({
|
|
2885
2921
|
method: "wallet_getSession"
|
|
2886
2922
|
});
|
|
2887
|
-
this.emit("wallet_sessionChanged", (
|
|
2923
|
+
this.emit("wallet_sessionChanged", (_b = response.result) != null ? _b : emptySession);
|
|
2888
2924
|
});
|
|
2889
2925
|
}
|
|
2890
2926
|
};
|
|
@@ -2898,20 +2934,22 @@ _sdkInfo = new WeakMap();
|
|
|
2898
2934
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2899
2935
|
setupAnalytics_fn = function() {
|
|
2900
2936
|
return __async(this, null, function* () {
|
|
2901
|
-
var _a2;
|
|
2937
|
+
var _a2, _b;
|
|
2902
2938
|
const platform = getPlatformType();
|
|
2903
2939
|
const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
|
|
2904
2940
|
const isReactNative2 = platform === "react-native" /* ReactNative */;
|
|
2905
2941
|
if (!isBrowser && !isReactNative2) {
|
|
2906
2942
|
return;
|
|
2907
2943
|
}
|
|
2908
|
-
const version = getVersion();
|
|
2909
2944
|
const dappId = getDappId(this.options.dapp);
|
|
2910
2945
|
const anonId = yield this.storage.getAnonId();
|
|
2911
2946
|
const { integrationType } = (_a2 = this.options.analytics) != null ? _a2 : {
|
|
2912
2947
|
integrationType: ""
|
|
2913
2948
|
};
|
|
2914
|
-
import_analytics4.analytics.setGlobalProperty(
|
|
2949
|
+
import_analytics4.analytics.setGlobalProperty(
|
|
2950
|
+
"mmconnect_versions",
|
|
2951
|
+
(_b = this.options.versions) != null ? _b : {}
|
|
2952
|
+
);
|
|
2915
2953
|
import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
|
|
2916
2954
|
import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
|
|
2917
2955
|
import_analytics4.analytics.setGlobalProperty("platform", platform);
|
|
@@ -2921,9 +2959,17 @@ setupAnalytics_fn = function() {
|
|
|
2921
2959
|
};
|
|
2922
2960
|
onTransportNotification_fn = function(payload) {
|
|
2923
2961
|
return __async(this, null, function* () {
|
|
2924
|
-
var _a2;
|
|
2962
|
+
var _a2, _b, _c;
|
|
2925
2963
|
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2926
|
-
|
|
2964
|
+
if (payload.method === "wallet_sessionChanged") {
|
|
2965
|
+
const sessionScopes = (_b = (_a2 = payload.params) == null ? void 0 : _a2.sessionScopes) != null ? _b : {};
|
|
2966
|
+
const hasScopes = Object.keys(sessionScopes).length > 0;
|
|
2967
|
+
if (this.status === "loaded" && !hasScopes) {
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
this.status = hasScopes ? "connected" : "disconnected";
|
|
2971
|
+
}
|
|
2972
|
+
this.emit(payload.method, (_c = payload.params) != null ? _c : payload.result);
|
|
2927
2973
|
}
|
|
2928
2974
|
});
|
|
2929
2975
|
};
|
|
@@ -2961,6 +3007,7 @@ getStoredTransport_fn = function() {
|
|
|
2961
3007
|
};
|
|
2962
3008
|
setupTransport_fn = function() {
|
|
2963
3009
|
return __async(this, null, function* () {
|
|
3010
|
+
var _a2;
|
|
2964
3011
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
2965
3012
|
if (transport) {
|
|
2966
3013
|
if (!this.transport.isConnected()) {
|
|
@@ -2975,23 +3022,24 @@ setupTransport_fn = function() {
|
|
|
2975
3022
|
}
|
|
2976
3023
|
} else {
|
|
2977
3024
|
this.status = "loaded";
|
|
3025
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
3026
|
+
const preferExtension = (_a2 = this.options.ui.preferExtension) != null ? _a2 : true;
|
|
3027
|
+
if (hasExtensionInstalled && preferExtension) {
|
|
3028
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
3029
|
+
try {
|
|
3030
|
+
yield this.transport.init();
|
|
3031
|
+
} catch (error) {
|
|
3032
|
+
console.error("Passive init failed:", error);
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
2978
3035
|
}
|
|
2979
3036
|
});
|
|
2980
3037
|
};
|
|
2981
|
-
|
|
3038
|
+
init_fn2 = function() {
|
|
2982
3039
|
return __async(this, null, function* () {
|
|
2983
3040
|
try {
|
|
2984
3041
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
2985
3042
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
2986
|
-
try {
|
|
2987
|
-
const baseProps = yield getBaseAnalyticsProperties(
|
|
2988
|
-
this.options,
|
|
2989
|
-
this.storage
|
|
2990
|
-
);
|
|
2991
|
-
import_analytics4.analytics.track("mmconnect_initialized", baseProps);
|
|
2992
|
-
} catch (error) {
|
|
2993
|
-
logger2("Error tracking initialized event", error);
|
|
2994
|
-
}
|
|
2995
3043
|
} catch (error) {
|
|
2996
3044
|
yield this.storage.removeTransport();
|
|
2997
3045
|
this.status = "pending";
|
|
@@ -3002,7 +3050,7 @@ init_fn = function() {
|
|
|
3002
3050
|
createDappClient_fn = function() {
|
|
3003
3051
|
return __async(this, null, function* () {
|
|
3004
3052
|
const { adapter: kvstore } = this.options.storage;
|
|
3005
|
-
const sessionstore =
|
|
3053
|
+
const sessionstore = yield import_mobile_wallet_protocol_core2.SessionStore.create(kvstore);
|
|
3006
3054
|
const websocket = (
|
|
3007
3055
|
// eslint-disable-next-line no-negated-condition
|
|
3008
3056
|
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
@@ -3179,9 +3227,13 @@ headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3179
3227
|
});
|
|
3180
3228
|
};
|
|
3181
3229
|
setupDefaultTransport_fn = function() {
|
|
3182
|
-
return __async(this,
|
|
3183
|
-
this
|
|
3184
|
-
|
|
3230
|
+
return __async(this, arguments, function* (options = { persist: true }) {
|
|
3231
|
+
if (__privateGet(this, _transport2) instanceof DefaultTransport) {
|
|
3232
|
+
return __privateGet(this, _transport2);
|
|
3233
|
+
}
|
|
3234
|
+
if (options == null ? void 0 : options.persist) {
|
|
3235
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
3236
|
+
}
|
|
3185
3237
|
const transport = new DefaultTransport();
|
|
3186
3238
|
__privateSet(this, _listener, transport.onNotification(
|
|
3187
3239
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
@@ -3299,16 +3351,20 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
3299
3351
|
};
|
|
3300
3352
|
getCaipSession_fn = function() {
|
|
3301
3353
|
return __async(this, null, function* () {
|
|
3354
|
+
var _a2;
|
|
3302
3355
|
let sessionData = {
|
|
3303
3356
|
sessionScopes: {},
|
|
3304
3357
|
sessionProperties: {}
|
|
3305
3358
|
};
|
|
3306
|
-
if (this
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3359
|
+
if ((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) {
|
|
3360
|
+
try {
|
|
3361
|
+
const response = yield this.transport.request({
|
|
3362
|
+
method: "wallet_getSession"
|
|
3363
|
+
});
|
|
3364
|
+
if (response.result) {
|
|
3365
|
+
sessionData = response.result;
|
|
3366
|
+
}
|
|
3367
|
+
} catch (e) {
|
|
3312
3368
|
}
|
|
3313
3369
|
}
|
|
3314
3370
|
return sessionData;
|
|
@@ -3637,7 +3693,6 @@ var BaseModalFactory = class {
|
|
|
3637
3693
|
parentElement,
|
|
3638
3694
|
showInstallModal,
|
|
3639
3695
|
link: qrCodeLink,
|
|
3640
|
-
sdkVersion: getVersion(),
|
|
3641
3696
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3642
3697
|
var _a3;
|
|
3643
3698
|
const newLink = this.createConnectionDeeplink(request);
|
|
@@ -3663,7 +3718,6 @@ var BaseModalFactory = class {
|
|
|
3663
3718
|
const otpCode = yield createOTPCode();
|
|
3664
3719
|
const modal = new this.options.OTPCodeModal({
|
|
3665
3720
|
parentElement: container,
|
|
3666
|
-
sdkVersion: getVersion(),
|
|
3667
3721
|
otpCode,
|
|
3668
3722
|
onClose: this.onCloseModal.bind(this),
|
|
3669
3723
|
createOTPCode,
|