@metamask/connect-multichain 0.6.0 → 0.8.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 +21 -19
- package/dist/browser/es/connect-multichain.d.mts +3 -0
- package/dist/browser/es/connect-multichain.mjs +134 -58
- 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 +3 -0
- package/dist/browser/iife/connect-multichain.js +2737 -5000
- 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 +3 -0
- package/dist/browser/umd/connect-multichain.js +132 -56
- 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 +3 -0
- package/dist/node/cjs/connect-multichain.js +132 -56
- 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 +3 -0
- package/dist/node/es/connect-multichain.mjs +134 -58
- 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 +3 -0
- package/dist/react-native/es/connect-multichain.mjs +134 -58
- 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/types.d.ts +3 -0
- 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 +65 -22
- package/dist/src/multichain/index.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 +28 -32
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +0 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/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 +17 -7
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/multichain/utils/index.d.ts.map +1 -1
- package/dist/src/multichain/utils/index.js +37 -0
- package/dist/src/multichain/utils/index.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +3 -0
- package/package.json +4 -4
|
@@ -369,6 +369,8 @@ declare function hasExtension(): Promise<boolean>;
|
|
|
369
369
|
type DappSettings = {
|
|
370
370
|
name: string;
|
|
371
371
|
url?: string;
|
|
372
|
+
/** The original non-http(s) URL before normalization on React Native platforms */
|
|
373
|
+
nativeScheme?: string;
|
|
372
374
|
} & ({
|
|
373
375
|
iconUrl?: string;
|
|
374
376
|
} | {
|
|
@@ -453,6 +455,7 @@ type MergeableMultichainOptions = Omit<MultichainOptions, 'dapp' | 'analytics' |
|
|
|
453
455
|
*/
|
|
454
456
|
type CreateMultichainFN = (options: MultiChainFNOptions) => Promise<MultichainCore>;
|
|
455
457
|
type ExtendedTransport = Omit<Transport, 'connect'> & {
|
|
458
|
+
init: () => Promise<void>;
|
|
456
459
|
connect: (props?: {
|
|
457
460
|
scopes: Scope[];
|
|
458
461
|
caipAccountIds: CaipAccountId[];
|
|
@@ -797,6 +797,21 @@ function getOptionalScopes(scopes) {
|
|
|
797
797
|
{}
|
|
798
798
|
);
|
|
799
799
|
}
|
|
800
|
+
function normalizeNativeUrl(url) {
|
|
801
|
+
var _a3;
|
|
802
|
+
const httpPattern = /^https?:\/\//u;
|
|
803
|
+
if (httpPattern.test(url)) {
|
|
804
|
+
return void 0;
|
|
805
|
+
}
|
|
806
|
+
const schemeMatch = url.match(/^([^:]*):\/\//u);
|
|
807
|
+
const rawScheme = (_a3 = schemeMatch == null ? void 0 : schemeMatch[1]) != null ? _a3 : url;
|
|
808
|
+
const sanitized = rawScheme.toLowerCase().replace(/[^a-z0-9-]/gu, "-").replace(/^-+|-+$/gu, "");
|
|
809
|
+
const subdomain = (sanitized || "unknown").slice(0, 63).replace(/-+$/u, "");
|
|
810
|
+
return {
|
|
811
|
+
url: `https://${subdomain}.rn.dapp.local`,
|
|
812
|
+
nativeScheme: url
|
|
813
|
+
};
|
|
814
|
+
}
|
|
800
815
|
function setupDappMetadata(options) {
|
|
801
816
|
var _a3, _b;
|
|
802
817
|
const platform = getPlatformType();
|
|
@@ -812,6 +827,18 @@ function setupDappMetadata(options) {
|
|
|
812
827
|
if (!((_b = options.dapp) == null ? void 0 : _b.url)) {
|
|
813
828
|
throw new Error("You must provide dapp url");
|
|
814
829
|
}
|
|
830
|
+
if (platform === "react-native" /* ReactNative */ && options.dapp.url) {
|
|
831
|
+
const normalized = normalizeNativeUrl(options.dapp.url);
|
|
832
|
+
if (normalized) {
|
|
833
|
+
console.info(
|
|
834
|
+
`Normalizing dapp URL for React Native: "${options.dapp.url}" -> "${normalized.url}"`
|
|
835
|
+
);
|
|
836
|
+
options.dapp = __spreadProps(__spreadValues({}, options.dapp), {
|
|
837
|
+
url: normalized.url,
|
|
838
|
+
nativeScheme: normalized.nativeScheme
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
}
|
|
815
842
|
const BASE_64_ICON_MAX_LENGTH = 163400;
|
|
816
843
|
const urlPattern = /^(http|https):\/\/[^\s]*$/u;
|
|
817
844
|
if (options.dapp) {
|
|
@@ -1603,7 +1630,7 @@ trackWalletActionRejected_fn = function(options) {
|
|
|
1603
1630
|
var import_multichain_api_client = require("@metamask/multichain-api-client");
|
|
1604
1631
|
init_utils2();
|
|
1605
1632
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
1606
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn;
|
|
1633
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
1607
1634
|
var DefaultTransport = class {
|
|
1608
1635
|
constructor() {
|
|
1609
1636
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -1651,11 +1678,31 @@ var DefaultTransport = class {
|
|
|
1651
1678
|
});
|
|
1652
1679
|
});
|
|
1653
1680
|
}
|
|
1681
|
+
init() {
|
|
1682
|
+
return __async(this, null, function* () {
|
|
1683
|
+
yield __privateMethod(this, _DefaultTransport_instances, init_fn).call(this);
|
|
1684
|
+
let walletSession = { sessionScopes: {} };
|
|
1685
|
+
try {
|
|
1686
|
+
const sessionRequest = yield this.request(
|
|
1687
|
+
{ method: "wallet_getSession" },
|
|
1688
|
+
__privateGet(this, _defaultRequestOptions)
|
|
1689
|
+
);
|
|
1690
|
+
walletSession = sessionRequest.result;
|
|
1691
|
+
} catch (e) {
|
|
1692
|
+
console.error(
|
|
1693
|
+
"Failed to get wallet session during DefaultTransport init"
|
|
1694
|
+
);
|
|
1695
|
+
}
|
|
1696
|
+
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, {
|
|
1697
|
+
method: "wallet_sessionChanged",
|
|
1698
|
+
params: walletSession
|
|
1699
|
+
});
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1654
1702
|
connect(options) {
|
|
1655
1703
|
return __async(this, null, function* () {
|
|
1656
1704
|
var _a3, _b, _c, _d, _e;
|
|
1657
|
-
__privateMethod(this, _DefaultTransport_instances,
|
|
1658
|
-
yield __privateGet(this, _transport).connect();
|
|
1705
|
+
yield __privateMethod(this, _DefaultTransport_instances, init_fn).call(this);
|
|
1659
1706
|
const sessionRequest = yield this.request(
|
|
1660
1707
|
{ method: "wallet_getSession" },
|
|
1661
1708
|
__privateGet(this, _defaultRequestOptions)
|
|
@@ -1712,26 +1759,6 @@ var DefaultTransport = class {
|
|
|
1712
1759
|
disconnect() {
|
|
1713
1760
|
return __async(this, arguments, function* (scopes = []) {
|
|
1714
1761
|
yield this.request({ method: "wallet_revokeSession", params: { scopes } });
|
|
1715
|
-
const response = yield this.request({ method: "wallet_getSession" });
|
|
1716
|
-
const { sessionScopes } = response.result;
|
|
1717
|
-
if (Object.keys(sessionScopes).length > 0) {
|
|
1718
|
-
return;
|
|
1719
|
-
}
|
|
1720
|
-
__privateGet(this, _notificationCallbacks).clear();
|
|
1721
|
-
if (__privateGet(this, _handleResponseListener)) {
|
|
1722
|
-
window.removeEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1723
|
-
__privateSet(this, _handleResponseListener, void 0);
|
|
1724
|
-
}
|
|
1725
|
-
if (__privateGet(this, _handleNotificationListener)) {
|
|
1726
|
-
window.removeEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1727
|
-
__privateSet(this, _handleNotificationListener, void 0);
|
|
1728
|
-
}
|
|
1729
|
-
for (const [, request] of __privateGet(this, _pendingRequests)) {
|
|
1730
|
-
clearTimeout(request.timeout);
|
|
1731
|
-
request.reject(new Error("Transport disconnected"));
|
|
1732
|
-
}
|
|
1733
|
-
__privateGet(this, _pendingRequests).clear();
|
|
1734
|
-
yield __privateGet(this, _transport).disconnect();
|
|
1735
1762
|
});
|
|
1736
1763
|
}
|
|
1737
1764
|
isConnected() {
|
|
@@ -1820,7 +1847,7 @@ handleNotification_fn = function(event) {
|
|
|
1820
1847
|
return;
|
|
1821
1848
|
}
|
|
1822
1849
|
const responseData = (_b = (_a3 = event == null ? void 0 : event.data) == null ? void 0 : _a3.data) == null ? void 0 : _b.data;
|
|
1823
|
-
if (typeof responseData === "object" && responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged") {
|
|
1850
|
+
if (typeof responseData === "object" && responseData !== null && (responseData.method === "metamask_chainChanged" || responseData.method === "metamask_accountsChanged")) {
|
|
1824
1851
|
__privateMethod(this, _DefaultTransport_instances, notifyCallbacks_fn).call(this, responseData);
|
|
1825
1852
|
}
|
|
1826
1853
|
};
|
|
@@ -1833,6 +1860,12 @@ setupMessageListener_fn = function() {
|
|
|
1833
1860
|
window.addEventListener("message", __privateGet(this, _handleResponseListener));
|
|
1834
1861
|
window.addEventListener("message", __privateGet(this, _handleNotificationListener));
|
|
1835
1862
|
};
|
|
1863
|
+
init_fn = function() {
|
|
1864
|
+
return __async(this, null, function* () {
|
|
1865
|
+
__privateMethod(this, _DefaultTransport_instances, setupMessageListener_fn).call(this);
|
|
1866
|
+
yield __privateGet(this, _transport).connect();
|
|
1867
|
+
});
|
|
1868
|
+
};
|
|
1836
1869
|
|
|
1837
1870
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
1838
1871
|
var import_rpc_errors = require("@metamask/rpc-errors");
|
|
@@ -1920,7 +1953,6 @@ _notificationCallbacks2 = new WeakMap();
|
|
|
1920
1953
|
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
1921
1954
|
walletCreateSession_fn = function(request) {
|
|
1922
1955
|
return __async(this, null, function* () {
|
|
1923
|
-
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
1924
1956
|
const createSessionParams = request.params;
|
|
1925
1957
|
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
1926
1958
|
const scopeAccounts = [];
|
|
@@ -2102,10 +2134,11 @@ var MWPTransport = class {
|
|
|
2102
2134
|
parseWalletError(errorPayload) {
|
|
2103
2135
|
const errorData = errorPayload;
|
|
2104
2136
|
if (typeof errorData.code === "number" && typeof errorData.message === "string") {
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
message:
|
|
2108
|
-
}
|
|
2137
|
+
const { code, message: message2 } = errorData;
|
|
2138
|
+
if (code >= 1e3 && code <= 4999) {
|
|
2139
|
+
return import_rpc_errors2.providerErrors.custom({ code, message: message2 });
|
|
2140
|
+
}
|
|
2141
|
+
return new import_rpc_errors2.JsonRpcError(code, message2);
|
|
2109
2142
|
}
|
|
2110
2143
|
const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
|
|
2111
2144
|
return import_rpc_errors2.rpcErrors.internal({ message });
|
|
@@ -2230,6 +2263,10 @@ var MWPTransport = class {
|
|
|
2230
2263
|
}
|
|
2231
2264
|
});
|
|
2232
2265
|
}
|
|
2266
|
+
init() {
|
|
2267
|
+
return __async(this, null, function* () {
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2233
2270
|
// TODO: Rename this
|
|
2234
2271
|
sendEip1193Message(payload, options) {
|
|
2235
2272
|
return __async(this, null, function* () {
|
|
@@ -2269,7 +2306,11 @@ var MWPTransport = class {
|
|
|
2269
2306
|
const { dappClient } = this;
|
|
2270
2307
|
const session = yield this.getActiveSession();
|
|
2271
2308
|
if (session) {
|
|
2272
|
-
logger("active session found",
|
|
2309
|
+
logger("active session found", {
|
|
2310
|
+
id: session.id,
|
|
2311
|
+
channel: session.channel,
|
|
2312
|
+
expiresAt: session.expiresAt
|
|
2313
|
+
});
|
|
2273
2314
|
}
|
|
2274
2315
|
const storedSessionRequestBeforeConnectionAttempt = yield this.getStoredPendingSessionRequest();
|
|
2275
2316
|
let timeout;
|
|
@@ -2578,7 +2619,7 @@ var MWPTransport = class {
|
|
|
2578
2619
|
getActiveSession() {
|
|
2579
2620
|
return __async(this, null, function* () {
|
|
2580
2621
|
const { kvstore } = this;
|
|
2581
|
-
const sessionStore =
|
|
2622
|
+
const sessionStore = yield import_mobile_wallet_protocol_core.SessionStore.create(kvstore);
|
|
2582
2623
|
try {
|
|
2583
2624
|
const [activeSession] = yield sessionStore.list();
|
|
2584
2625
|
return activeSession;
|
|
@@ -2652,6 +2693,9 @@ var KeyManager = class {
|
|
|
2652
2693
|
return Buffer.from(decryptedBuffer).toString("utf8");
|
|
2653
2694
|
});
|
|
2654
2695
|
}
|
|
2696
|
+
validatePeerKey(key) {
|
|
2697
|
+
import_eciesjs.PublicKey.fromHex(Buffer.from(key).toString("hex"));
|
|
2698
|
+
}
|
|
2655
2699
|
};
|
|
2656
2700
|
var keymanager = new KeyManager();
|
|
2657
2701
|
|
|
@@ -2659,7 +2703,7 @@ var keymanager = new KeyManager();
|
|
|
2659
2703
|
init_utils2();
|
|
2660
2704
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2661
2705
|
var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
|
|
2662
|
-
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn,
|
|
2706
|
+
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;
|
|
2663
2707
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2664
2708
|
constructor(options) {
|
|
2665
2709
|
var _a3, _b, _c, _d, _e, _f;
|
|
@@ -2697,6 +2741,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2697
2741
|
}
|
|
2698
2742
|
set status(value) {
|
|
2699
2743
|
var _a3, _b;
|
|
2744
|
+
if (this._status === value) {
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2700
2747
|
this._status = value;
|
|
2701
2748
|
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, {
|
|
2702
2749
|
method: "stateChanged",
|
|
@@ -2752,7 +2799,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2752
2799
|
if (isEnabled2) {
|
|
2753
2800
|
enableDebug("metamask-sdk:core");
|
|
2754
2801
|
}
|
|
2755
|
-
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances,
|
|
2802
|
+
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, init_fn2).call(_a3);
|
|
2756
2803
|
return instance;
|
|
2757
2804
|
}))();
|
|
2758
2805
|
globalObject[SINGLETON_KEY] = instancePromise;
|
|
@@ -2862,14 +2909,16 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2862
2909
|
);
|
|
2863
2910
|
yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
|
|
2864
2911
|
if (remainingScopes.length === 0) {
|
|
2865
|
-
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2866
|
-
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2867
2912
|
yield this.storage.removeTransport();
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2913
|
+
if (this.transportType !== "browser" /* Browser */) {
|
|
2914
|
+
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
2915
|
+
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
2916
|
+
__privateSet(this, _listener, void 0);
|
|
2917
|
+
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2918
|
+
__privateSet(this, _transport2, void 0);
|
|
2919
|
+
__privateGet(this, _providerTransportWrapper).clearTransportNotificationListener();
|
|
2920
|
+
__privateSet(this, _dappClient, void 0);
|
|
2921
|
+
}
|
|
2873
2922
|
this.status = "disconnected";
|
|
2874
2923
|
}
|
|
2875
2924
|
});
|
|
@@ -2908,16 +2957,16 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2908
2957
|
// without having to concern themselves with the current transport connection status.
|
|
2909
2958
|
emitSessionChanged() {
|
|
2910
2959
|
return __async(this, null, function* () {
|
|
2911
|
-
var _a3;
|
|
2960
|
+
var _a3, _b;
|
|
2912
2961
|
const emptySession = { sessionScopes: {} };
|
|
2913
|
-
if (this
|
|
2962
|
+
if (!((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected())) {
|
|
2914
2963
|
this.emit("wallet_sessionChanged", emptySession);
|
|
2915
2964
|
return;
|
|
2916
2965
|
}
|
|
2917
2966
|
const response = yield this.transport.request({
|
|
2918
2967
|
method: "wallet_getSession"
|
|
2919
2968
|
});
|
|
2920
|
-
this.emit("wallet_sessionChanged", (
|
|
2969
|
+
this.emit("wallet_sessionChanged", (_b = response.result) != null ? _b : emptySession);
|
|
2921
2970
|
});
|
|
2922
2971
|
}
|
|
2923
2972
|
};
|
|
@@ -2954,9 +3003,17 @@ setupAnalytics_fn = function() {
|
|
|
2954
3003
|
};
|
|
2955
3004
|
onTransportNotification_fn = function(payload) {
|
|
2956
3005
|
return __async(this, null, function* () {
|
|
2957
|
-
var _a3;
|
|
3006
|
+
var _a3, _b, _c;
|
|
2958
3007
|
if (typeof payload === "object" && payload !== null && "method" in payload) {
|
|
2959
|
-
|
|
3008
|
+
if (payload.method === "wallet_sessionChanged") {
|
|
3009
|
+
const sessionScopes = (_b = (_a3 = payload.params) == null ? void 0 : _a3.sessionScopes) != null ? _b : {};
|
|
3010
|
+
const hasScopes = Object.keys(sessionScopes).length > 0;
|
|
3011
|
+
if (this.status === "loaded" && !hasScopes) {
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
this.status = hasScopes ? "connected" : "disconnected";
|
|
3015
|
+
}
|
|
3016
|
+
this.emit(payload.method, (_c = payload.params) != null ? _c : payload.result);
|
|
2960
3017
|
}
|
|
2961
3018
|
});
|
|
2962
3019
|
};
|
|
@@ -2994,6 +3051,7 @@ getStoredTransport_fn = function() {
|
|
|
2994
3051
|
};
|
|
2995
3052
|
setupTransport_fn = function() {
|
|
2996
3053
|
return __async(this, null, function* () {
|
|
3054
|
+
var _a3;
|
|
2997
3055
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
2998
3056
|
if (transport) {
|
|
2999
3057
|
if (!this.transport.isConnected()) {
|
|
@@ -3008,10 +3066,20 @@ setupTransport_fn = function() {
|
|
|
3008
3066
|
}
|
|
3009
3067
|
} else {
|
|
3010
3068
|
this.status = "loaded";
|
|
3069
|
+
const hasExtensionInstalled = yield hasExtension();
|
|
3070
|
+
const preferExtension = (_a3 = this.options.ui.preferExtension) != null ? _a3 : true;
|
|
3071
|
+
if (hasExtensionInstalled && preferExtension) {
|
|
3072
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
3073
|
+
try {
|
|
3074
|
+
yield this.transport.init();
|
|
3075
|
+
} catch (error) {
|
|
3076
|
+
console.error("Passive init failed:", error);
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3011
3079
|
}
|
|
3012
3080
|
});
|
|
3013
3081
|
};
|
|
3014
|
-
|
|
3082
|
+
init_fn2 = function() {
|
|
3015
3083
|
return __async(this, null, function* () {
|
|
3016
3084
|
try {
|
|
3017
3085
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
@@ -3035,7 +3103,7 @@ init_fn = function() {
|
|
|
3035
3103
|
createDappClient_fn = function() {
|
|
3036
3104
|
return __async(this, null, function* () {
|
|
3037
3105
|
const { adapter: kvstore } = this.options.storage;
|
|
3038
|
-
const sessionstore =
|
|
3106
|
+
const sessionstore = yield import_mobile_wallet_protocol_core2.SessionStore.create(kvstore);
|
|
3039
3107
|
const websocket = (
|
|
3040
3108
|
// eslint-disable-next-line no-negated-condition
|
|
3041
3109
|
typeof window !== "undefined" ? WebSocket : (yield import("ws")).WebSocket
|
|
@@ -3212,9 +3280,13 @@ headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3212
3280
|
});
|
|
3213
3281
|
};
|
|
3214
3282
|
setupDefaultTransport_fn = function() {
|
|
3215
|
-
return __async(this,
|
|
3216
|
-
this
|
|
3217
|
-
|
|
3283
|
+
return __async(this, arguments, function* (options = { persist: true }) {
|
|
3284
|
+
if (__privateGet(this, _transport2) instanceof DefaultTransport) {
|
|
3285
|
+
return __privateGet(this, _transport2);
|
|
3286
|
+
}
|
|
3287
|
+
if (options == null ? void 0 : options.persist) {
|
|
3288
|
+
yield this.storage.setTransport("browser" /* Browser */);
|
|
3289
|
+
}
|
|
3218
3290
|
const transport = new DefaultTransport();
|
|
3219
3291
|
__privateSet(this, _listener, transport.onNotification(
|
|
3220
3292
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
@@ -3332,16 +3404,20 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
3332
3404
|
};
|
|
3333
3405
|
getCaipSession_fn = function() {
|
|
3334
3406
|
return __async(this, null, function* () {
|
|
3407
|
+
var _a3;
|
|
3335
3408
|
let sessionData = {
|
|
3336
3409
|
sessionScopes: {},
|
|
3337
3410
|
sessionProperties: {}
|
|
3338
3411
|
};
|
|
3339
|
-
if (this
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3412
|
+
if ((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) {
|
|
3413
|
+
try {
|
|
3414
|
+
const response = yield this.transport.request({
|
|
3415
|
+
method: "wallet_getSession"
|
|
3416
|
+
});
|
|
3417
|
+
if (response.result) {
|
|
3418
|
+
sessionData = response.result;
|
|
3419
|
+
}
|
|
3420
|
+
} catch (e) {
|
|
3345
3421
|
}
|
|
3346
3422
|
}
|
|
3347
3423
|
return sessionData;
|