@metamask/connect-multichain 0.15.0 → 1.0.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 +28 -1
- package/README.md +0 -1
- package/dist/browser/es/connect-multichain.d.mts +7 -6
- package/dist/browser/es/connect-multichain.mjs +451 -368
- 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 +7 -6
- package/dist/browser/iife/connect-multichain.js +464 -368
- 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 +7 -6
- package/dist/browser/umd/connect-multichain.js +451 -368
- 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 +7 -6
- package/dist/node/cjs/connect-multichain.js +453 -366
- 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 +7 -6
- package/dist/node/es/connect-multichain.mjs +450 -365
- 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 +7 -6
- package/dist/react-native/es/connect-multichain.mjs +449 -364
- 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/api/constants.d.ts +1 -0
- package/dist/src/domain/multichain/api/constants.d.ts.map +1 -1
- package/dist/src/domain/multichain/api/constants.js +13 -0
- package/dist/src/domain/multichain/api/constants.js.map +1 -1
- package/dist/src/domain/multichain/index.d.ts +2 -2
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +0 -1
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/platform/index.d.ts.map +1 -1
- package/dist/src/domain/platform/index.js +27 -5
- package/dist/src/domain/platform/index.js.map +1 -1
- package/dist/src/domain/store/client.d.ts +3 -3
- package/dist/src/domain/store/client.d.ts.map +1 -1
- package/dist/src/domain/utils/index.d.ts +1 -0
- package/dist/src/domain/utils/index.d.ts.map +1 -1
- package/dist/src/domain/utils/index.js +5 -1
- package/dist/src/domain/utils/index.js.map +1 -1
- package/dist/src/multichain/index.d.ts +2 -3
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +142 -147
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts +15 -0
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +31 -5
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +16 -10
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +2 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +25 -17
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +3 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +227 -170
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/store/index.d.ts +3 -3
- package/dist/src/store/index.d.ts.map +1 -1
- package/dist/src/store/index.js +8 -8
- package/dist/src/store/index.js.map +1 -1
- package/dist/src/ui/ModalFactory.d.ts.map +1 -1
- package/dist/src/ui/ModalFactory.js +5 -1
- package/dist/src/ui/ModalFactory.js.map +1 -1
- package/dist/src/ui/index.js +1 -1
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/modals/web/install.d.ts.map +1 -1
- package/dist/src/ui/modals/web/install.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +7 -6
- package/package.json +2 -2
|
@@ -252,7 +252,7 @@ var init_logger = __esm({
|
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
// src/domain/multichain/api/constants.ts
|
|
255
|
-
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS;
|
|
255
|
+
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS, EIP1193_PASSTHROUGH_METHODS;
|
|
256
256
|
var init_constants = __esm({
|
|
257
257
|
"src/domain/multichain/api/constants.ts"() {
|
|
258
258
|
"use strict";
|
|
@@ -417,6 +417,11 @@ var init_constants = __esm({
|
|
|
417
417
|
"eth_uninstallFilter"
|
|
418
418
|
]);
|
|
419
419
|
SDK_HANDLED_METHODS = /* @__PURE__ */ new Set(["eth_accounts", "eth_chainId"]);
|
|
420
|
+
EIP1193_PASSTHROUGH_METHODS = /* @__PURE__ */ new Set([
|
|
421
|
+
"wallet_addEthereumChain",
|
|
422
|
+
"wallet_switchEthereumChain",
|
|
423
|
+
"eth_accounts"
|
|
424
|
+
]);
|
|
420
425
|
}
|
|
421
426
|
});
|
|
422
427
|
|
|
@@ -567,7 +572,7 @@ function hasExtension() {
|
|
|
567
572
|
return detectionPromise;
|
|
568
573
|
});
|
|
569
574
|
}
|
|
570
|
-
var PlatformType, detectionPromise;
|
|
575
|
+
var PlatformType, NATIVE_METAMASK_EIP6963_RDNS, detectionPromise;
|
|
571
576
|
var init_platform = __esm({
|
|
572
577
|
"src/domain/platform/index.ts"() {
|
|
573
578
|
"use strict";
|
|
@@ -579,6 +584,10 @@ var init_platform = __esm({
|
|
|
579
584
|
PlatformType2["ReactNative"] = "react-native";
|
|
580
585
|
return PlatformType2;
|
|
581
586
|
})(PlatformType || {});
|
|
587
|
+
NATIVE_METAMASK_EIP6963_RDNS = /* @__PURE__ */ new Set([
|
|
588
|
+
"io.metamask",
|
|
589
|
+
"io.metamask.mobile"
|
|
590
|
+
]);
|
|
582
591
|
detectionPromise = (() => __async(null, null, function* () {
|
|
583
592
|
const pt = getPlatformType();
|
|
584
593
|
if (pt === "nodejs" /* NonBrowser */ || pt === "react-native" /* ReactNative */) {
|
|
@@ -586,23 +595,30 @@ var init_platform = __esm({
|
|
|
586
595
|
}
|
|
587
596
|
return new Promise((resolve) => {
|
|
588
597
|
const providers = [];
|
|
598
|
+
const targetWindow = window;
|
|
589
599
|
const handler = (event) => {
|
|
590
600
|
var _a3, _b;
|
|
591
601
|
if ((_b = (_a3 = event == null ? void 0 : event.detail) == null ? void 0 : _a3.info) == null ? void 0 : _b.rdns) {
|
|
592
602
|
providers.push(event.detail);
|
|
593
603
|
}
|
|
594
604
|
};
|
|
595
|
-
|
|
596
|
-
|
|
605
|
+
targetWindow.addEventListener("eip6963:announceProvider", handler);
|
|
606
|
+
targetWindow.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
597
607
|
setTimeout(() => {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
var _a3, _b;
|
|
602
|
-
return (_b = (_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
608
|
+
try {
|
|
609
|
+
if (typeof (targetWindow == null ? void 0 : targetWindow.removeEventListener) === "function") {
|
|
610
|
+
targetWindow.removeEventListener("eip6963:announceProvider", handler);
|
|
603
611
|
}
|
|
604
|
-
|
|
605
|
-
|
|
612
|
+
const hasMetaMask = providers.some(
|
|
613
|
+
(provider) => {
|
|
614
|
+
var _a3;
|
|
615
|
+
return typeof ((_a3 = provider == null ? void 0 : provider.info) == null ? void 0 : _a3.rdns) === "string" && NATIVE_METAMASK_EIP6963_RDNS.has(provider.info.rdns);
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
resolve(hasMetaMask);
|
|
619
|
+
} catch (e) {
|
|
620
|
+
resolve(false);
|
|
621
|
+
}
|
|
606
622
|
}, 300);
|
|
607
623
|
});
|
|
608
624
|
}))();
|
|
@@ -847,12 +863,14 @@ var init_analytics = __esm({
|
|
|
847
863
|
|
|
848
864
|
// src/domain/utils/index.ts
|
|
849
865
|
function getVersion() {
|
|
850
|
-
return
|
|
866
|
+
return packageVersion;
|
|
851
867
|
}
|
|
868
|
+
var packageVersion;
|
|
852
869
|
var init_utils = __esm({
|
|
853
870
|
"src/domain/utils/index.ts"() {
|
|
854
871
|
"use strict";
|
|
855
872
|
init_analytics();
|
|
873
|
+
packageVersion = false ? "unknown" : "1.0.0";
|
|
856
874
|
}
|
|
857
875
|
});
|
|
858
876
|
|
|
@@ -1159,7 +1177,8 @@ import {
|
|
|
1159
1177
|
TransportTimeoutError
|
|
1160
1178
|
} from "@metamask/multichain-api-client";
|
|
1161
1179
|
import { JsonRpcError, providerErrors as providerErrors2, rpcErrors } from "@metamask/rpc-errors";
|
|
1162
|
-
|
|
1180
|
+
import { createDeferredPromise } from "@metamask/utils";
|
|
1181
|
+
var DEFAULT_REQUEST_TIMEOUT2, CONNECTION_GRACE_PERIOD, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_RESUME_TIMEOUT, SESSION_STORE_KEY, ACCOUNTS_STORE_KEY, CHAIN_STORE_KEY, PENDING_SESSION_REQUEST_KEY, CACHED_METHOD_LIST, CACHED_RESET_METHOD_LIST, logger, _MWPTransport_instances, onResumeHandler_fn, resumeSession_fn, startSession_fn, MWPTransport;
|
|
1163
1182
|
var init_mwp = __esm({
|
|
1164
1183
|
"src/multichain/transports/mwp/index.ts"() {
|
|
1165
1184
|
"use strict";
|
|
@@ -1193,6 +1212,7 @@ var init_mwp = __esm({
|
|
|
1193
1212
|
this.dappClient = dappClient;
|
|
1194
1213
|
this.kvstore = kvstore;
|
|
1195
1214
|
this.options = options;
|
|
1215
|
+
__privateAdd(this, _MWPTransport_instances);
|
|
1196
1216
|
this.__pendingRequests = /* @__PURE__ */ new Map();
|
|
1197
1217
|
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
1198
1218
|
this.dappClient.on("message", this.handleMessage.bind(this));
|
|
@@ -1272,6 +1292,23 @@ var init_mwp = __esm({
|
|
|
1272
1292
|
const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
|
|
1273
1293
|
return rpcErrors.internal({ message });
|
|
1274
1294
|
}
|
|
1295
|
+
getResponseError(messagePayload) {
|
|
1296
|
+
if ("error" in messagePayload && messagePayload.error) {
|
|
1297
|
+
return messagePayload.error;
|
|
1298
|
+
}
|
|
1299
|
+
const { result } = messagePayload;
|
|
1300
|
+
if (typeof result === "object" && result !== null && "error" in result && result.error && this.isErrorPayload(result.error)) {
|
|
1301
|
+
return result.error;
|
|
1302
|
+
}
|
|
1303
|
+
return void 0;
|
|
1304
|
+
}
|
|
1305
|
+
isErrorPayload(errorPayload) {
|
|
1306
|
+
if (errorPayload instanceof Error) {
|
|
1307
|
+
return true;
|
|
1308
|
+
}
|
|
1309
|
+
const errorData = errorPayload;
|
|
1310
|
+
return typeof (errorData == null ? void 0 : errorData.code) === "number" && typeof (errorData == null ? void 0 : errorData.message) === "string";
|
|
1311
|
+
}
|
|
1275
1312
|
handleMessage(message) {
|
|
1276
1313
|
if (typeof message === "object" && message !== null) {
|
|
1277
1314
|
if ("data" in message) {
|
|
@@ -1280,9 +1317,10 @@ var init_mwp = __esm({
|
|
|
1280
1317
|
const request = this.pendingRequests.get(messagePayload.id);
|
|
1281
1318
|
if (request) {
|
|
1282
1319
|
clearTimeout(request.timeout);
|
|
1283
|
-
|
|
1320
|
+
const responseError = this.getResponseError(messagePayload);
|
|
1321
|
+
if (responseError) {
|
|
1284
1322
|
this.pendingRequests.delete(messagePayload.id);
|
|
1285
|
-
request.reject(this.parseWalletError(
|
|
1323
|
+
request.reject(this.parseWalletError(responseError));
|
|
1286
1324
|
return;
|
|
1287
1325
|
}
|
|
1288
1326
|
const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
|
|
@@ -1325,73 +1363,6 @@ var init_mwp = __esm({
|
|
|
1325
1363
|
}
|
|
1326
1364
|
}
|
|
1327
1365
|
}
|
|
1328
|
-
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
1329
|
-
return __async(this, null, function* () {
|
|
1330
|
-
var _a3, _b, _c, _d, _e, _f, _g;
|
|
1331
|
-
try {
|
|
1332
|
-
yield this.waitForWalletSessionIfNotCached();
|
|
1333
|
-
const sessionRequest = yield this.request({
|
|
1334
|
-
method: "wallet_getSession"
|
|
1335
|
-
});
|
|
1336
|
-
if (sessionRequest.error) {
|
|
1337
|
-
return resumeReject(new Error(sessionRequest.error.message));
|
|
1338
|
-
}
|
|
1339
|
-
let walletSession = sessionRequest.result;
|
|
1340
|
-
if (walletSession && options) {
|
|
1341
|
-
const currentScopes = Object.keys(
|
|
1342
|
-
(_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
|
|
1343
|
-
);
|
|
1344
|
-
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1345
|
-
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
1346
|
-
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1347
|
-
currentScopes,
|
|
1348
|
-
proposedScopes,
|
|
1349
|
-
walletSession,
|
|
1350
|
-
proposedCaipAccountIds
|
|
1351
|
-
);
|
|
1352
|
-
if (options.forceRequest || !hasSameScopesAndAccounts) {
|
|
1353
|
-
const optionalScopes = addValidAccounts(
|
|
1354
|
-
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1355
|
-
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1356
|
-
);
|
|
1357
|
-
const sessionRequest2 = {
|
|
1358
|
-
optionalScopes
|
|
1359
|
-
};
|
|
1360
|
-
const response = yield this.request({
|
|
1361
|
-
method: "wallet_createSession",
|
|
1362
|
-
params: sessionRequest2
|
|
1363
|
-
});
|
|
1364
|
-
if (response.error) {
|
|
1365
|
-
return resumeReject(new Error(response.error.message));
|
|
1366
|
-
}
|
|
1367
|
-
walletSession = response.result;
|
|
1368
|
-
}
|
|
1369
|
-
} else if (!walletSession) {
|
|
1370
|
-
const optionalScopes = addValidAccounts(
|
|
1371
|
-
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1372
|
-
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1373
|
-
);
|
|
1374
|
-
const sessionRequest2 = { optionalScopes };
|
|
1375
|
-
const response = yield this.request({
|
|
1376
|
-
method: "wallet_createSession",
|
|
1377
|
-
params: sessionRequest2
|
|
1378
|
-
});
|
|
1379
|
-
if (response.error) {
|
|
1380
|
-
return resumeReject(new Error(response.error.message));
|
|
1381
|
-
}
|
|
1382
|
-
walletSession = response.result;
|
|
1383
|
-
}
|
|
1384
|
-
yield this.removeStoredPendingSessionRequest();
|
|
1385
|
-
this.notifyCallbacks({
|
|
1386
|
-
method: "wallet_sessionChanged",
|
|
1387
|
-
params: walletSession
|
|
1388
|
-
});
|
|
1389
|
-
return resumeResolve();
|
|
1390
|
-
} catch (err) {
|
|
1391
|
-
return resumeReject(err);
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
1366
|
init() {
|
|
1396
1367
|
return __async(this, null, function* () {
|
|
1397
1368
|
});
|
|
@@ -1432,7 +1403,6 @@ var init_mwp = __esm({
|
|
|
1432
1403
|
}
|
|
1433
1404
|
connect(options) {
|
|
1434
1405
|
return __async(this, null, function* () {
|
|
1435
|
-
const { dappClient } = this;
|
|
1436
1406
|
const session = yield this.getActiveSession();
|
|
1437
1407
|
if (session) {
|
|
1438
1408
|
logger("active session found", {
|
|
@@ -1441,116 +1411,11 @@ var init_mwp = __esm({
|
|
|
1441
1411
|
expiresAt: session.expiresAt
|
|
1442
1412
|
});
|
|
1443
1413
|
}
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
let initialConnectionMessageHandler;
|
|
1447
|
-
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1448
|
-
let connection;
|
|
1449
|
-
if (session) {
|
|
1450
|
-
connection = new Promise((resumeResolve, resumeReject) => {
|
|
1451
|
-
var _a3;
|
|
1452
|
-
if (this.dappClient.state === "CONNECTED") {
|
|
1453
|
-
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1454
|
-
} else {
|
|
1455
|
-
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
1456
|
-
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
1457
|
-
}));
|
|
1458
|
-
dappClient.resume((_a3 = session == null ? void 0 : session.id) != null ? _a3 : "");
|
|
1459
|
-
}
|
|
1460
|
-
});
|
|
1461
|
-
} else {
|
|
1462
|
-
connection = new Promise(
|
|
1463
|
-
(resolveConnection, rejectConnection) => {
|
|
1464
|
-
var _a3, _b;
|
|
1465
|
-
const optionalScopes = addValidAccounts(
|
|
1466
|
-
getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
|
|
1467
|
-
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1468
|
-
);
|
|
1469
|
-
const sessionRequest = {
|
|
1470
|
-
optionalScopes,
|
|
1471
|
-
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1472
|
-
};
|
|
1473
|
-
const request = {
|
|
1474
|
-
jsonrpc: "2.0",
|
|
1475
|
-
id: String(getUniqueRequestId()),
|
|
1476
|
-
method: "wallet_createSession",
|
|
1477
|
-
params: sessionRequest
|
|
1478
|
-
};
|
|
1479
|
-
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
1480
|
-
if (typeof message !== "object" || message === null) {
|
|
1481
|
-
return;
|
|
1482
|
-
}
|
|
1483
|
-
if (!("data" in message)) {
|
|
1484
|
-
return;
|
|
1485
|
-
}
|
|
1486
|
-
const messagePayload = message.data;
|
|
1487
|
-
const isMatchingId = messagePayload.id === request.id;
|
|
1488
|
-
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
1489
|
-
if (!isMatchingId && !isMatchingMethod) {
|
|
1490
|
-
return;
|
|
1491
|
-
}
|
|
1492
|
-
if (messagePayload.error) {
|
|
1493
|
-
return rejectConnection(
|
|
1494
|
-
this.parseWalletError(messagePayload.error)
|
|
1495
|
-
);
|
|
1496
|
-
}
|
|
1497
|
-
yield this.storeWalletSession(
|
|
1498
|
-
request,
|
|
1499
|
-
messagePayload
|
|
1500
|
-
);
|
|
1501
|
-
yield this.removeStoredPendingSessionRequest();
|
|
1502
|
-
this.notifyCallbacks(messagePayload);
|
|
1503
|
-
return resolveConnection();
|
|
1504
|
-
});
|
|
1505
|
-
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
1506
|
-
const platformType = getPlatformType();
|
|
1507
|
-
const isQRCodeFlow = [
|
|
1508
|
-
"web-desktop" /* DesktopWeb */,
|
|
1509
|
-
"nodejs" /* NonBrowser */
|
|
1510
|
-
].includes(platformType);
|
|
1511
|
-
const initialPayload = {
|
|
1512
|
-
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1513
|
-
data: request
|
|
1514
|
-
};
|
|
1515
|
-
dappClient.connect({
|
|
1516
|
-
mode: "trusted",
|
|
1517
|
-
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
1518
|
-
}).then(() => __async(this, null, function* () {
|
|
1519
|
-
if (isQRCodeFlow) {
|
|
1520
|
-
return dappClient.sendRequest(initialPayload);
|
|
1521
|
-
}
|
|
1522
|
-
return void 0;
|
|
1523
|
-
})).catch((error) => {
|
|
1524
|
-
if (initialConnectionMessageHandler) {
|
|
1525
|
-
this.dappClient.off(
|
|
1526
|
-
"message",
|
|
1527
|
-
initialConnectionMessageHandler
|
|
1528
|
-
);
|
|
1529
|
-
}
|
|
1530
|
-
rejectConnection(error);
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
timeout = setTimeout(
|
|
1536
|
-
() => {
|
|
1537
|
-
reject(new TransportTimeoutError());
|
|
1538
|
-
},
|
|
1539
|
-
storedSessionRequestBeforeConnectionAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
1540
|
-
);
|
|
1541
|
-
connection.then(resolve).catch(reject);
|
|
1542
|
-
}));
|
|
1543
|
-
return connectionPromise.catch((error) => __async(this, null, function* () {
|
|
1414
|
+
const connection = session ? __privateMethod(this, _MWPTransport_instances, resumeSession_fn).call(this, session, options) : __privateMethod(this, _MWPTransport_instances, startSession_fn).call(this, options);
|
|
1415
|
+
return connection.catch((error) => __async(this, null, function* () {
|
|
1544
1416
|
yield this.dappClient.disconnect();
|
|
1545
1417
|
throw error;
|
|
1546
1418
|
})).finally(() => {
|
|
1547
|
-
if (timeout) {
|
|
1548
|
-
clearTimeout(timeout);
|
|
1549
|
-
}
|
|
1550
|
-
if (initialConnectionMessageHandler) {
|
|
1551
|
-
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
1552
|
-
initialConnectionMessageHandler = void 0;
|
|
1553
|
-
}
|
|
1554
1419
|
this.removeStoredPendingSessionRequest();
|
|
1555
1420
|
});
|
|
1556
1421
|
});
|
|
@@ -1809,6 +1674,188 @@ var init_mwp = __esm({
|
|
|
1809
1674
|
});
|
|
1810
1675
|
}
|
|
1811
1676
|
};
|
|
1677
|
+
_MWPTransport_instances = new WeakSet();
|
|
1678
|
+
onResumeHandler_fn = function(options) {
|
|
1679
|
+
return __async(this, null, function* () {
|
|
1680
|
+
var _a3, _b, _c, _d, _e, _f, _g;
|
|
1681
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1682
|
+
const sessionResponse = yield this.request({ method: "wallet_getSession" });
|
|
1683
|
+
if (sessionResponse.error) {
|
|
1684
|
+
throw new Error(sessionResponse.error.message);
|
|
1685
|
+
}
|
|
1686
|
+
let walletSession = sessionResponse.result;
|
|
1687
|
+
if (walletSession && options) {
|
|
1688
|
+
const currentScopes = Object.keys(
|
|
1689
|
+
(_a3 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a3 : {}
|
|
1690
|
+
);
|
|
1691
|
+
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
1692
|
+
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
1693
|
+
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
1694
|
+
currentScopes,
|
|
1695
|
+
proposedScopes,
|
|
1696
|
+
walletSession,
|
|
1697
|
+
proposedCaipAccountIds
|
|
1698
|
+
);
|
|
1699
|
+
if (options.forceRequest || !hasSameScopesAndAccounts) {
|
|
1700
|
+
const optionalScopes = addValidAccounts(
|
|
1701
|
+
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
1702
|
+
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
1703
|
+
);
|
|
1704
|
+
const sessionRequest = {
|
|
1705
|
+
optionalScopes
|
|
1706
|
+
};
|
|
1707
|
+
const response = yield this.request({
|
|
1708
|
+
method: "wallet_createSession",
|
|
1709
|
+
params: sessionRequest
|
|
1710
|
+
});
|
|
1711
|
+
if (response.error) {
|
|
1712
|
+
throw new Error(response.error.message);
|
|
1713
|
+
}
|
|
1714
|
+
walletSession = response.result;
|
|
1715
|
+
}
|
|
1716
|
+
} else if (!walletSession) {
|
|
1717
|
+
const optionalScopes = addValidAccounts(
|
|
1718
|
+
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
1719
|
+
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1720
|
+
);
|
|
1721
|
+
const sessionRequest = {
|
|
1722
|
+
optionalScopes
|
|
1723
|
+
};
|
|
1724
|
+
const response = yield this.request({
|
|
1725
|
+
method: "wallet_createSession",
|
|
1726
|
+
params: sessionRequest
|
|
1727
|
+
});
|
|
1728
|
+
if (response.error) {
|
|
1729
|
+
throw new Error(response.error.message);
|
|
1730
|
+
}
|
|
1731
|
+
walletSession = response.result;
|
|
1732
|
+
}
|
|
1733
|
+
yield this.removeStoredPendingSessionRequest();
|
|
1734
|
+
this.notifyCallbacks({
|
|
1735
|
+
method: "wallet_sessionChanged",
|
|
1736
|
+
params: walletSession
|
|
1737
|
+
});
|
|
1738
|
+
});
|
|
1739
|
+
};
|
|
1740
|
+
resumeSession_fn = function(session, options) {
|
|
1741
|
+
return __async(this, null, function* () {
|
|
1742
|
+
var _a3;
|
|
1743
|
+
const isContinuingPriorAttempt = (yield this.getStoredPendingSessionRequest()) !== null;
|
|
1744
|
+
const resumeDeferred = createDeferredPromise();
|
|
1745
|
+
const runOnResumeHandler = () => __async(this, null, function* () {
|
|
1746
|
+
try {
|
|
1747
|
+
resumeDeferred.resolve(yield __privateMethod(this, _MWPTransport_instances, onResumeHandler_fn).call(this, options));
|
|
1748
|
+
} catch (err) {
|
|
1749
|
+
resumeDeferred.reject(err);
|
|
1750
|
+
}
|
|
1751
|
+
});
|
|
1752
|
+
if (this.dappClient.state === "CONNECTED") {
|
|
1753
|
+
runOnResumeHandler();
|
|
1754
|
+
} else {
|
|
1755
|
+
this.dappClient.once("connected", runOnResumeHandler);
|
|
1756
|
+
this.dappClient.resume((_a3 = session.id) != null ? _a3 : "").catch((err) => resumeDeferred.reject(err));
|
|
1757
|
+
}
|
|
1758
|
+
const timeoutDeferred = createDeferredPromise();
|
|
1759
|
+
const timeout = setTimeout(
|
|
1760
|
+
() => timeoutDeferred.reject(new TransportTimeoutError()),
|
|
1761
|
+
isContinuingPriorAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
1762
|
+
);
|
|
1763
|
+
const cleanup = () => this.dappClient.off("connected", runOnResumeHandler);
|
|
1764
|
+
return Promise.race([
|
|
1765
|
+
resumeDeferred.promise,
|
|
1766
|
+
timeoutDeferred.promise
|
|
1767
|
+
]).finally(() => {
|
|
1768
|
+
clearTimeout(timeout);
|
|
1769
|
+
cleanup();
|
|
1770
|
+
});
|
|
1771
|
+
});
|
|
1772
|
+
};
|
|
1773
|
+
startSession_fn = function(options) {
|
|
1774
|
+
return __async(this, null, function* () {
|
|
1775
|
+
var _a3, _b;
|
|
1776
|
+
const { dappClient } = this;
|
|
1777
|
+
const isContinuingPriorAttempt = (yield this.getStoredPendingSessionRequest()) !== null;
|
|
1778
|
+
const connDeferred = createDeferredPromise();
|
|
1779
|
+
const optionalScopes = addValidAccounts(
|
|
1780
|
+
getOptionalScopes((_a3 = options == null ? void 0 : options.scopes) != null ? _a3 : []),
|
|
1781
|
+
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1782
|
+
);
|
|
1783
|
+
const sessionRequest = {
|
|
1784
|
+
optionalScopes,
|
|
1785
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1786
|
+
};
|
|
1787
|
+
const request = {
|
|
1788
|
+
jsonrpc: "2.0",
|
|
1789
|
+
id: String(getUniqueRequestId()),
|
|
1790
|
+
method: "wallet_createSession",
|
|
1791
|
+
params: sessionRequest
|
|
1792
|
+
};
|
|
1793
|
+
let handler;
|
|
1794
|
+
const removeHandler = () => {
|
|
1795
|
+
if (handler) {
|
|
1796
|
+
this.dappClient.off("message", handler);
|
|
1797
|
+
handler = void 0;
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
handler = (message) => __async(this, null, function* () {
|
|
1801
|
+
if (typeof message !== "object" || message === null) {
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
if (!("data" in message)) {
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
const messagePayload = message.data;
|
|
1808
|
+
const isMatchingId = messagePayload.id === request.id;
|
|
1809
|
+
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
1810
|
+
if (!isMatchingId && !isMatchingMethod) {
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const responseError = this.getResponseError(messagePayload);
|
|
1814
|
+
if (responseError) {
|
|
1815
|
+
connDeferred.reject(this.parseWalletError(responseError));
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
yield this.storeWalletSession(
|
|
1819
|
+
request,
|
|
1820
|
+
messagePayload
|
|
1821
|
+
);
|
|
1822
|
+
yield this.removeStoredPendingSessionRequest();
|
|
1823
|
+
this.notifyCallbacks(messagePayload);
|
|
1824
|
+
connDeferred.resolve();
|
|
1825
|
+
});
|
|
1826
|
+
this.dappClient.on("message", handler);
|
|
1827
|
+
const platformType = getPlatformType();
|
|
1828
|
+
const isQRCodeFlow = [
|
|
1829
|
+
"web-desktop" /* DesktopWeb */,
|
|
1830
|
+
"nodejs" /* NonBrowser */
|
|
1831
|
+
].includes(platformType);
|
|
1832
|
+
const initialPayload = {
|
|
1833
|
+
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
1834
|
+
data: request
|
|
1835
|
+
};
|
|
1836
|
+
dappClient.connect({
|
|
1837
|
+
mode: "trusted",
|
|
1838
|
+
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
1839
|
+
}).then(() => __async(this, null, function* () {
|
|
1840
|
+
if (isQRCodeFlow) {
|
|
1841
|
+
return dappClient.sendRequest(initialPayload);
|
|
1842
|
+
}
|
|
1843
|
+
return void 0;
|
|
1844
|
+
})).catch((error) => connDeferred.reject(error));
|
|
1845
|
+
const timeoutDeferred = createDeferredPromise();
|
|
1846
|
+
const timeout = setTimeout(
|
|
1847
|
+
() => timeoutDeferred.reject(new TransportTimeoutError()),
|
|
1848
|
+
isContinuingPriorAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
1849
|
+
);
|
|
1850
|
+
return Promise.race([
|
|
1851
|
+
connDeferred.promise,
|
|
1852
|
+
timeoutDeferred.promise
|
|
1853
|
+
]).finally(() => {
|
|
1854
|
+
clearTimeout(timeout);
|
|
1855
|
+
removeHandler();
|
|
1856
|
+
});
|
|
1857
|
+
});
|
|
1858
|
+
};
|
|
1812
1859
|
}
|
|
1813
1860
|
});
|
|
1814
1861
|
|
|
@@ -2088,6 +2135,7 @@ import { analytics as analytics2 } from "@metamask/analytics";
|
|
|
2088
2135
|
import {
|
|
2089
2136
|
getMultichainClient
|
|
2090
2137
|
} from "@metamask/multichain-api-client";
|
|
2138
|
+
import { createDeferredPromise as createDeferredPromise2 } from "@metamask/utils";
|
|
2091
2139
|
|
|
2092
2140
|
// src/config/index.ts
|
|
2093
2141
|
var MWP_RELAY_URL = "wss://mm-sdk-relay.api.cx.metamask.io/connection/websocket";
|
|
@@ -2241,6 +2289,9 @@ var RequestRouter = class {
|
|
|
2241
2289
|
invokeMethod(options) {
|
|
2242
2290
|
return __async(this, null, function* () {
|
|
2243
2291
|
const { method } = options.request;
|
|
2292
|
+
if (EIP1193_PASSTHROUGH_METHODS.has(method)) {
|
|
2293
|
+
return this.handleWithEip1193Passthrough(options);
|
|
2294
|
+
}
|
|
2244
2295
|
if (RPC_HANDLED_METHODS.has(method)) {
|
|
2245
2296
|
return this.handleWithRpcNode(options);
|
|
2246
2297
|
}
|
|
@@ -2250,6 +2301,29 @@ var RequestRouter = class {
|
|
|
2250
2301
|
return this.handleWithWallet(options);
|
|
2251
2302
|
});
|
|
2252
2303
|
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Forwards EIP-1193 / legacy provider methods (e.g. `wallet_addEthereumChain`,
|
|
2306
|
+
* `wallet_switchEthereumChain`, `eth_accounts`) directly to the underlying
|
|
2307
|
+
* transport's `sendEip1193Message`, bypassing the multichain
|
|
2308
|
+
* `wallet_invokeMethod` envelope. These methods are wallet-side concerns the
|
|
2309
|
+
* Multichain API does not model, so we forward the raw `{ method, params }`
|
|
2310
|
+
* payload and return the wallet's full JSON-RPC response envelope unchanged.
|
|
2311
|
+
*
|
|
2312
|
+
* Analytics tracking is intentionally skipped here: ecosystem clients
|
|
2313
|
+
* (e.g. `connect-evm`) emit their own `wallet_action_*` events around these
|
|
2314
|
+
* passthrough calls, and adding router-level tracking would double-count.
|
|
2315
|
+
*
|
|
2316
|
+
* @param options
|
|
2317
|
+
*/
|
|
2318
|
+
handleWithEip1193Passthrough(options) {
|
|
2319
|
+
return __async(this, null, function* () {
|
|
2320
|
+
const response = yield this.transport.sendEip1193Message({
|
|
2321
|
+
method: options.request.method,
|
|
2322
|
+
params: options.request.params
|
|
2323
|
+
});
|
|
2324
|
+
return response.result;
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2253
2327
|
/**
|
|
2254
2328
|
* Forwards the request directly to the wallet via the transport.
|
|
2255
2329
|
*
|
|
@@ -2281,14 +2355,6 @@ var RequestRouter = class {
|
|
|
2281
2355
|
}), 10);
|
|
2282
2356
|
}
|
|
2283
2357
|
const response = yield request;
|
|
2284
|
-
if (response.error) {
|
|
2285
|
-
const { error } = response;
|
|
2286
|
-
throw new RPCInvokeMethodErr(
|
|
2287
|
-
`RPC Request failed with code ${error.code}: ${error.message}`,
|
|
2288
|
-
error.code,
|
|
2289
|
-
error.message
|
|
2290
|
-
);
|
|
2291
|
-
}
|
|
2292
2358
|
return response.result;
|
|
2293
2359
|
}));
|
|
2294
2360
|
});
|
|
@@ -2403,7 +2469,7 @@ import {
|
|
|
2403
2469
|
getDefaultTransport
|
|
2404
2470
|
} from "@metamask/multichain-api-client";
|
|
2405
2471
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
2406
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
2472
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, parseWalletError_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
2407
2473
|
var DefaultTransport = class {
|
|
2408
2474
|
constructor() {
|
|
2409
2475
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -2539,7 +2605,11 @@ var DefaultTransport = class {
|
|
|
2539
2605
|
}
|
|
2540
2606
|
request(_0) {
|
|
2541
2607
|
return __async(this, arguments, function* (request, options = __privateGet(this, _defaultRequestOptions)) {
|
|
2542
|
-
|
|
2608
|
+
const response = yield __privateGet(this, _transport).request(request, options);
|
|
2609
|
+
if (response.error) {
|
|
2610
|
+
throw __privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error);
|
|
2611
|
+
}
|
|
2612
|
+
return response;
|
|
2543
2613
|
});
|
|
2544
2614
|
}
|
|
2545
2615
|
onNotification(callback) {
|
|
@@ -2583,6 +2653,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
2583
2653
|
}
|
|
2584
2654
|
}
|
|
2585
2655
|
};
|
|
2656
|
+
parseWalletError_fn = function(errorPayload) {
|
|
2657
|
+
const errorData = errorPayload;
|
|
2658
|
+
const error = new Error(
|
|
2659
|
+
typeof errorData.message === "string" ? errorData.message : "Request failed"
|
|
2660
|
+
);
|
|
2661
|
+
if (typeof errorData.code === "number") {
|
|
2662
|
+
error.code = errorData.code;
|
|
2663
|
+
}
|
|
2664
|
+
return error;
|
|
2665
|
+
};
|
|
2586
2666
|
isMetamaskProviderEvent_fn = function(event) {
|
|
2587
2667
|
var _a3, _b;
|
|
2588
2668
|
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
|
|
@@ -2605,13 +2685,7 @@ handleResponse_fn = function(event) {
|
|
|
2605
2685
|
__privateGet(this, _pendingRequests).delete(responseId);
|
|
2606
2686
|
const response = responseData;
|
|
2607
2687
|
if ("error" in response && response.error) {
|
|
2608
|
-
|
|
2609
|
-
response.error.message || "Request failed"
|
|
2610
|
-
);
|
|
2611
|
-
if (typeof response.error.code === "number") {
|
|
2612
|
-
error.code = response.error.code;
|
|
2613
|
-
}
|
|
2614
|
-
pendingRequest.reject(error);
|
|
2688
|
+
pendingRequest.reject(__privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error));
|
|
2615
2689
|
} else {
|
|
2616
2690
|
pendingRequest.resolve(response);
|
|
2617
2691
|
}
|
|
@@ -2649,22 +2723,21 @@ init_fn = function() {
|
|
|
2649
2723
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2650
2724
|
init_utils2();
|
|
2651
2725
|
import { providerErrors } from "@metamask/rpc-errors";
|
|
2652
|
-
var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2726
|
+
var _notificationCallbacks2, _getTransport, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2653
2727
|
var MultichainApiClientWrapperTransport = class {
|
|
2654
|
-
constructor(metamaskConnectMultichain) {
|
|
2728
|
+
constructor(metamaskConnectMultichain, getTransport) {
|
|
2655
2729
|
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2656
2730
|
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2657
2731
|
__privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
|
|
2732
|
+
__privateAdd(this, _getTransport);
|
|
2733
|
+
__privateSet(this, _getTransport, getTransport);
|
|
2658
2734
|
}
|
|
2659
2735
|
isTransportDefined() {
|
|
2660
|
-
|
|
2661
|
-
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2662
|
-
} catch (_error) {
|
|
2663
|
-
return false;
|
|
2664
|
-
}
|
|
2736
|
+
return __privateGet(this, _getTransport).call(this) !== void 0;
|
|
2665
2737
|
}
|
|
2666
2738
|
isTransportConnected() {
|
|
2667
|
-
|
|
2739
|
+
var _a3, _b;
|
|
2740
|
+
return (_b = (_a3 = __privateGet(this, _getTransport).call(this)) == null ? void 0 : _a3.isConnected()) != null ? _b : false;
|
|
2668
2741
|
}
|
|
2669
2742
|
clearNotificationCallbacks() {
|
|
2670
2743
|
__privateGet(this, _notificationCallbacks2).clear();
|
|
@@ -2680,10 +2753,11 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
2680
2753
|
this.notificationListener = void 0;
|
|
2681
2754
|
}
|
|
2682
2755
|
setupTransportNotificationListener() {
|
|
2683
|
-
|
|
2756
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2757
|
+
if (!transport || this.notificationListener) {
|
|
2684
2758
|
return;
|
|
2685
2759
|
}
|
|
2686
|
-
this.notificationListener =
|
|
2760
|
+
this.notificationListener = transport.onNotification(
|
|
2687
2761
|
this.notifyCallbacks.bind(this)
|
|
2688
2762
|
);
|
|
2689
2763
|
}
|
|
@@ -2733,6 +2807,7 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
2733
2807
|
}
|
|
2734
2808
|
};
|
|
2735
2809
|
_notificationCallbacks2 = new WeakMap();
|
|
2810
|
+
_getTransport = new WeakMap();
|
|
2736
2811
|
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2737
2812
|
walletCreateSession_fn = function(request) {
|
|
2738
2813
|
return __async(this, null, function* () {
|
|
@@ -2756,14 +2831,19 @@ walletCreateSession_fn = function(request) {
|
|
|
2756
2831
|
accounts,
|
|
2757
2832
|
createSessionParams.sessionProperties
|
|
2758
2833
|
);
|
|
2759
|
-
|
|
2834
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2835
|
+
if (!transport) {
|
|
2836
|
+
throw new Error("Transport not initialized after connect");
|
|
2837
|
+
}
|
|
2838
|
+
return transport.request({
|
|
2760
2839
|
method: "wallet_getSession"
|
|
2761
2840
|
});
|
|
2762
2841
|
});
|
|
2763
2842
|
};
|
|
2764
2843
|
walletGetSession_fn = function(request) {
|
|
2765
2844
|
return __async(this, null, function* () {
|
|
2766
|
-
|
|
2845
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2846
|
+
if (!(transport == null ? void 0 : transport.isConnected())) {
|
|
2767
2847
|
return {
|
|
2768
2848
|
jsonrpc: "2.0",
|
|
2769
2849
|
id: request.id,
|
|
@@ -2772,7 +2852,7 @@ walletGetSession_fn = function(request) {
|
|
|
2772
2852
|
}
|
|
2773
2853
|
};
|
|
2774
2854
|
}
|
|
2775
|
-
return
|
|
2855
|
+
return transport.request({
|
|
2776
2856
|
method: "wallet_getSession"
|
|
2777
2857
|
});
|
|
2778
2858
|
});
|
|
@@ -2850,7 +2930,7 @@ function setupAnalyticsGlobals(options, storage, setAnonId) {
|
|
|
2850
2930
|
analytics2.enable();
|
|
2851
2931
|
});
|
|
2852
2932
|
}
|
|
2853
|
-
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId,
|
|
2933
|
+
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId, _MetaMaskConnectMultichain_instances, transportOrThrow_fn, _sdkInfo, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, buildConnectionMetadata_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;
|
|
2854
2934
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2855
2935
|
constructor(options) {
|
|
2856
2936
|
var _a3, _b, _c, _d;
|
|
@@ -2863,9 +2943,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2863
2943
|
}),
|
|
2864
2944
|
analytics: normalizeAnalyticsOptions(options.analytics),
|
|
2865
2945
|
versions: __spreadValues({
|
|
2866
|
-
|
|
2867
|
-
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
2868
|
-
"connect-multichain": false ? "unknown" : "0.15.0"
|
|
2946
|
+
"connect-multichain": getVersion()
|
|
2869
2947
|
}, (_d = options.versions) != null ? _d : {})
|
|
2870
2948
|
});
|
|
2871
2949
|
super(allOptions);
|
|
@@ -2881,7 +2959,8 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2881
2959
|
__privateAdd(this, _anonId);
|
|
2882
2960
|
__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}`);
|
|
2883
2961
|
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
2884
|
-
this
|
|
2962
|
+
this,
|
|
2963
|
+
() => __privateGet(this, _transport2)
|
|
2885
2964
|
));
|
|
2886
2965
|
__privateSet(this, _provider, getMultichainClient({
|
|
2887
2966
|
transport: __privateGet(this, _providerTransportWrapper)
|
|
@@ -2900,12 +2979,6 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2900
2979
|
get provider() {
|
|
2901
2980
|
return __privateGet(this, _provider);
|
|
2902
2981
|
}
|
|
2903
|
-
get transport() {
|
|
2904
|
-
if (!__privateGet(this, _transport2)) {
|
|
2905
|
-
throw new Error("Transport not initialized, establish connection first");
|
|
2906
|
-
}
|
|
2907
|
-
return __privateGet(this, _transport2);
|
|
2908
|
-
}
|
|
2909
2982
|
get dappClient() {
|
|
2910
2983
|
if (!__privateGet(this, _dappClient)) {
|
|
2911
2984
|
throw new Error("DappClient not initialized, establish connection first");
|
|
@@ -2919,6 +2992,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2919
2992
|
get storage() {
|
|
2920
2993
|
return this.options.storage;
|
|
2921
2994
|
}
|
|
2995
|
+
get version() {
|
|
2996
|
+
return getVersion();
|
|
2997
|
+
}
|
|
2922
2998
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
2923
2999
|
// If the singleton already exists, it merges the incoming options with the
|
|
2924
3000
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
@@ -2933,6 +3009,11 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2933
3009
|
const existing = globalObject[SINGLETON_KEY];
|
|
2934
3010
|
if (existing) {
|
|
2935
3011
|
const instance = yield existing;
|
|
3012
|
+
if (instance.version !== getVersion()) {
|
|
3013
|
+
console.warn(
|
|
3014
|
+
`MetaMask Connect does not support using multiple versions of @metamask/connect-multichain. Attempted to create a new instance with version ${getVersion()}, but an existing ${instance.version} singleton was already initialized. Using the existing ${instance.version} singleton. This is NOT supported and may lead to unexpected behavior. Please ensure there is only one version of @metamask/connect-multichain package resolved in your application.`
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
2936
3017
|
instance.mergeOptions(options);
|
|
2937
3018
|
if (instance instanceof _MetaMaskConnectMultichain) {
|
|
2938
3019
|
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a3);
|
|
@@ -2956,12 +3037,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2956
3037
|
}
|
|
2957
3038
|
yield __privateMethod(_a4 = instance, _MetaMaskConnectMultichain_instances, init_fn2).call(_a4);
|
|
2958
3039
|
return instance;
|
|
2959
|
-
}))()
|
|
2960
|
-
globalObject[SINGLETON_KEY] = instancePromise;
|
|
2961
|
-
instancePromise.catch((error) => {
|
|
3040
|
+
}))().catch((error) => {
|
|
2962
3041
|
globalObject[SINGLETON_KEY] = void 0;
|
|
2963
3042
|
console.error("Error initializing MetaMaskConnectMultichain", error);
|
|
3043
|
+
throw error;
|
|
2964
3044
|
});
|
|
3045
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
2965
3046
|
return instancePromise;
|
|
2966
3047
|
});
|
|
2967
3048
|
}
|
|
@@ -3021,9 +3102,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3021
3102
|
forceRequest
|
|
3022
3103
|
}).then(() => __async(this, null, function* () {
|
|
3023
3104
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
3024
|
-
return this.storage.
|
|
3105
|
+
return this.storage.setTransportType("mwp" /* MWP */);
|
|
3025
3106
|
}
|
|
3026
|
-
return this.storage.
|
|
3107
|
+
return this.storage.setTransportType("browser" /* Browser */);
|
|
3027
3108
|
})), scopes, transportType);
|
|
3028
3109
|
}
|
|
3029
3110
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
@@ -3052,11 +3133,6 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3052
3133
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
3053
3134
|
});
|
|
3054
3135
|
}
|
|
3055
|
-
emit(event, args) {
|
|
3056
|
-
var _a3, _b;
|
|
3057
|
-
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, { method: event, params: args });
|
|
3058
|
-
super.emit(event, args);
|
|
3059
|
-
}
|
|
3060
3136
|
disconnect() {
|
|
3061
3137
|
return __async(this, arguments, function* (scopes = []) {
|
|
3062
3138
|
var _a3, _b, _c;
|
|
@@ -3066,7 +3142,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3066
3142
|
);
|
|
3067
3143
|
yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
|
|
3068
3144
|
if (remainingScopes.length === 0) {
|
|
3069
|
-
yield this.storage.
|
|
3145
|
+
yield this.storage.removeTransportType();
|
|
3070
3146
|
if (__privateGet(this, _transportType) !== "browser" /* Browser */) {
|
|
3071
3147
|
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
3072
3148
|
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
@@ -3084,7 +3160,8 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3084
3160
|
invokeMethod(request) {
|
|
3085
3161
|
return __async(this, null, function* () {
|
|
3086
3162
|
var _a3;
|
|
3087
|
-
const
|
|
3163
|
+
const transport = __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this);
|
|
3164
|
+
const { options } = this;
|
|
3088
3165
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
3089
3166
|
const requestRouter = new RequestRouter(
|
|
3090
3167
|
transport,
|
|
@@ -3103,7 +3180,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3103
3180
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
3104
3181
|
if (shouldOpenDeeplink) {
|
|
3105
3182
|
setTimeout(() => __async(this, null, function* () {
|
|
3106
|
-
const session = yield this.
|
|
3183
|
+
const session = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).getActiveSession();
|
|
3107
3184
|
if (!session) {
|
|
3108
3185
|
throw new Error("No active session found");
|
|
3109
3186
|
}
|
|
@@ -3127,10 +3204,13 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3127
3204
|
this.emit("wallet_sessionChanged", emptySession);
|
|
3128
3205
|
return;
|
|
3129
3206
|
}
|
|
3130
|
-
const response = yield this.
|
|
3207
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
3131
3208
|
method: "wallet_getSession"
|
|
3132
3209
|
});
|
|
3133
|
-
this.emit(
|
|
3210
|
+
this.emit(
|
|
3211
|
+
"wallet_sessionChanged",
|
|
3212
|
+
(_b = response.result) != null ? _b : emptySession
|
|
3213
|
+
);
|
|
3134
3214
|
});
|
|
3135
3215
|
}
|
|
3136
3216
|
};
|
|
@@ -3142,8 +3222,14 @@ _beforeUnloadListener = new WeakMap();
|
|
|
3142
3222
|
_transportType = new WeakMap();
|
|
3143
3223
|
_listener = new WeakMap();
|
|
3144
3224
|
_anonId = new WeakMap();
|
|
3145
|
-
_sdkInfo = new WeakMap();
|
|
3146
3225
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
3226
|
+
transportOrThrow_fn = function() {
|
|
3227
|
+
if (!__privateGet(this, _transport2)) {
|
|
3228
|
+
throw new Error("Transport not initialized, establish connection first");
|
|
3229
|
+
}
|
|
3230
|
+
return __privateGet(this, _transport2);
|
|
3231
|
+
};
|
|
3232
|
+
_sdkInfo = new WeakMap();
|
|
3147
3233
|
setupAnalytics_fn = function() {
|
|
3148
3234
|
return __async(this, null, function* () {
|
|
3149
3235
|
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
@@ -3169,7 +3255,7 @@ onTransportNotification_fn = function(payload) {
|
|
|
3169
3255
|
};
|
|
3170
3256
|
getStoredTransport_fn = function() {
|
|
3171
3257
|
return __async(this, null, function* () {
|
|
3172
|
-
const transportType = yield this.storage.
|
|
3258
|
+
const transportType = yield this.storage.getTransportType();
|
|
3173
3259
|
const hasExtensionInstalled = yield hasExtension();
|
|
3174
3260
|
if (transportType) {
|
|
3175
3261
|
if (transportType === "browser" /* Browser */) {
|
|
@@ -3197,7 +3283,7 @@ getStoredTransport_fn = function() {
|
|
|
3197
3283
|
));
|
|
3198
3284
|
return apiTransport;
|
|
3199
3285
|
}
|
|
3200
|
-
yield this.storage.
|
|
3286
|
+
yield this.storage.removeTransportType();
|
|
3201
3287
|
}
|
|
3202
3288
|
return void 0;
|
|
3203
3289
|
});
|
|
@@ -3207,15 +3293,15 @@ setupTransport_fn = function() {
|
|
|
3207
3293
|
var _a3;
|
|
3208
3294
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
3209
3295
|
if (transport) {
|
|
3210
|
-
if (!
|
|
3296
|
+
if (!transport.isConnected()) {
|
|
3211
3297
|
this.status = "connecting";
|
|
3212
|
-
yield
|
|
3298
|
+
yield transport.connect();
|
|
3213
3299
|
}
|
|
3214
3300
|
this.status = "connected";
|
|
3215
3301
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
3216
|
-
yield this.storage.
|
|
3302
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3217
3303
|
} else {
|
|
3218
|
-
yield this.storage.
|
|
3304
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
3219
3305
|
}
|
|
3220
3306
|
} else {
|
|
3221
3307
|
this.status = "loaded";
|
|
@@ -3224,7 +3310,7 @@ setupTransport_fn = function() {
|
|
|
3224
3310
|
if (hasExtensionInstalled && preferExtension) {
|
|
3225
3311
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
3226
3312
|
try {
|
|
3227
|
-
yield this.
|
|
3313
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).init();
|
|
3228
3314
|
} catch (error) {
|
|
3229
3315
|
console.error("Passive init failed:", error);
|
|
3230
3316
|
}
|
|
@@ -3248,7 +3334,7 @@ init_fn2 = function() {
|
|
|
3248
3334
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
3249
3335
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
3250
3336
|
} catch (error) {
|
|
3251
|
-
yield this.storage.
|
|
3337
|
+
yield this.storage.removeTransportType();
|
|
3252
3338
|
this.status = "pending";
|
|
3253
3339
|
logger2("MetaMaskSDK error during initialization", error);
|
|
3254
3340
|
}
|
|
@@ -3294,17 +3380,17 @@ setupMWP_fn = function() {
|
|
|
3294
3380
|
__privateSet(this, _transport2, apiTransport);
|
|
3295
3381
|
__privateSet(this, _transportType, "mwp" /* MWP */);
|
|
3296
3382
|
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
3297
|
-
__privateSet(this, _listener,
|
|
3383
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
3298
3384
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
3299
3385
|
));
|
|
3300
|
-
yield this.storage.
|
|
3386
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3301
3387
|
});
|
|
3302
3388
|
};
|
|
3303
3389
|
onBeforeUnload_fn = function() {
|
|
3304
3390
|
return __async(this, null, function* () {
|
|
3305
3391
|
var _a3;
|
|
3306
3392
|
if ((_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.isMounted) {
|
|
3307
|
-
yield this.storage.
|
|
3393
|
+
yield this.storage.removeTransportType();
|
|
3308
3394
|
}
|
|
3309
3395
|
});
|
|
3310
3396
|
};
|
|
@@ -3321,70 +3407,65 @@ createBeforeUnloadListener_fn = function() {
|
|
|
3321
3407
|
};
|
|
3322
3408
|
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
3323
3409
|
return __async(this, null, function* () {
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
sessionRequest,
|
|
3337
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3338
|
-
});
|
|
3339
|
-
}
|
|
3340
|
-
);
|
|
3341
|
-
(() => __async(this, null, function* () {
|
|
3342
|
-
var _a3;
|
|
3343
|
-
try {
|
|
3344
|
-
yield this.transport.connect({
|
|
3345
|
-
scopes,
|
|
3346
|
-
caipAccountIds,
|
|
3347
|
-
sessionProperties
|
|
3348
|
-
});
|
|
3349
|
-
yield this.options.ui.factory.unload();
|
|
3350
|
-
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
3351
|
-
this.status = "connected";
|
|
3352
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
3353
|
-
} catch (error) {
|
|
3354
|
-
const { ProtocolError, ErrorCode } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3355
|
-
if (error instanceof ProtocolError) {
|
|
3356
|
-
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
3357
|
-
this.status = "disconnected";
|
|
3358
|
-
yield this.options.ui.factory.unload(error);
|
|
3359
|
-
reject(error);
|
|
3360
|
-
}
|
|
3361
|
-
} else {
|
|
3362
|
-
this.status = "disconnected";
|
|
3363
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3364
|
-
yield this.options.ui.factory.unload(normalizedError);
|
|
3365
|
-
reject(normalizedError);
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
}))().catch(() => {
|
|
3369
|
-
});
|
|
3410
|
+
const completion = createDeferredPromise2();
|
|
3411
|
+
const createConnectionRequest = () => __async(this, null, function* () {
|
|
3412
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
3413
|
+
yield this.dappClient.disconnect();
|
|
3414
|
+
}
|
|
3415
|
+
const sessionRequestDeferred = createDeferredPromise2();
|
|
3416
|
+
this.dappClient.on(
|
|
3417
|
+
"session_request",
|
|
3418
|
+
(sessionRequest) => {
|
|
3419
|
+
sessionRequestDeferred.resolve({
|
|
3420
|
+
sessionRequest,
|
|
3421
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3370
3422
|
});
|
|
3371
|
-
}
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3423
|
+
}
|
|
3424
|
+
);
|
|
3425
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
3426
|
+
var _a3;
|
|
3427
|
+
yield this.options.ui.factory.unload();
|
|
3428
|
+
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
3429
|
+
this.status = "connected";
|
|
3430
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3431
|
+
})).catch((error) => __async(this, null, function* () {
|
|
3432
|
+
const { ProtocolError, ErrorCode } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3433
|
+
if (error instanceof ProtocolError) {
|
|
3434
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
3435
|
+
this.status = "disconnected";
|
|
3436
|
+
yield this.options.ui.factory.unload(error);
|
|
3437
|
+
completion.reject(error);
|
|
3379
3438
|
}
|
|
3380
|
-
}
|
|
3381
|
-
|
|
3382
|
-
|
|
3439
|
+
} else {
|
|
3440
|
+
this.status = "disconnected";
|
|
3441
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3442
|
+
yield this.options.ui.factory.unload(normalizedError);
|
|
3443
|
+
completion.reject(normalizedError);
|
|
3383
3444
|
}
|
|
3384
|
-
)
|
|
3385
|
-
|
|
3386
|
-
});
|
|
3445
|
+
}));
|
|
3446
|
+
return sessionRequestDeferred.promise;
|
|
3387
3447
|
});
|
|
3448
|
+
this.options.ui.factory.renderInstallModal(
|
|
3449
|
+
desktopPreferred,
|
|
3450
|
+
createConnectionRequest,
|
|
3451
|
+
(error) => __async(this, null, function* () {
|
|
3452
|
+
if (error) {
|
|
3453
|
+
yield this.storage.removeTransportType();
|
|
3454
|
+
completion.reject(error);
|
|
3455
|
+
} else {
|
|
3456
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3457
|
+
completion.resolve();
|
|
3458
|
+
}
|
|
3459
|
+
}),
|
|
3460
|
+
(uri) => {
|
|
3461
|
+
this.emit("display_uri", uri);
|
|
3462
|
+
}
|
|
3463
|
+
).catch((error) => {
|
|
3464
|
+
completion.reject(
|
|
3465
|
+
error instanceof Error ? error : new Error(String(error))
|
|
3466
|
+
);
|
|
3467
|
+
});
|
|
3468
|
+
return completion.promise;
|
|
3388
3469
|
});
|
|
3389
3470
|
};
|
|
3390
3471
|
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
@@ -3400,39 +3481,37 @@ showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, session
|
|
|
3400
3481
|
};
|
|
3401
3482
|
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
3402
3483
|
return __async(this, null, function* () {
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3484
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
3485
|
+
yield this.dappClient.disconnect().catch(() => void 0);
|
|
3486
|
+
}
|
|
3487
|
+
const onSessionRequest = (sessionRequest) => {
|
|
3488
|
+
const connectionRequest = {
|
|
3489
|
+
sessionRequest,
|
|
3490
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3491
|
+
};
|
|
3492
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3493
|
+
this.emit("display_uri", deeplink);
|
|
3494
|
+
};
|
|
3495
|
+
this.dappClient.on("session_request", onSessionRequest);
|
|
3496
|
+
try {
|
|
3497
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({
|
|
3498
|
+
scopes,
|
|
3499
|
+
caipAccountIds,
|
|
3500
|
+
sessionProperties
|
|
3501
|
+
});
|
|
3502
|
+
this.status = "connected";
|
|
3503
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3504
|
+
} catch (error) {
|
|
3505
|
+
const { ProtocolError } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3506
|
+
this.status = "disconnected";
|
|
3507
|
+
yield this.storage.removeTransportType();
|
|
3508
|
+
if (error instanceof ProtocolError || error instanceof Error) {
|
|
3509
|
+
throw error;
|
|
3407
3510
|
}
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
sessionRequest,
|
|
3413
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3414
|
-
};
|
|
3415
|
-
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3416
|
-
this.emit("display_uri", deeplink);
|
|
3417
|
-
}
|
|
3418
|
-
);
|
|
3419
|
-
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
3420
|
-
this.status = "connected";
|
|
3421
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
3422
|
-
resolve();
|
|
3423
|
-
})).catch((error) => __async(this, null, function* () {
|
|
3424
|
-
const { ProtocolError } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3425
|
-
if (error instanceof ProtocolError) {
|
|
3426
|
-
this.status = "disconnected";
|
|
3427
|
-
yield this.storage.removeTransport();
|
|
3428
|
-
reject(error);
|
|
3429
|
-
} else {
|
|
3430
|
-
this.status = "disconnected";
|
|
3431
|
-
yield this.storage.removeTransport();
|
|
3432
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3433
|
-
}
|
|
3434
|
-
}));
|
|
3435
|
-
});
|
|
3511
|
+
throw new Error(String(error));
|
|
3512
|
+
} finally {
|
|
3513
|
+
this.dappClient.off("session_request", onSessionRequest);
|
|
3514
|
+
}
|
|
3436
3515
|
});
|
|
3437
3516
|
};
|
|
3438
3517
|
setupDefaultTransport_fn = function() {
|
|
@@ -3441,7 +3520,7 @@ setupDefaultTransport_fn = function() {
|
|
|
3441
3520
|
return __privateGet(this, _transport2);
|
|
3442
3521
|
}
|
|
3443
3522
|
if (options == null ? void 0 : options.persist) {
|
|
3444
|
-
yield this.storage.
|
|
3523
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
3445
3524
|
}
|
|
3446
3525
|
const transport = new DefaultTransport();
|
|
3447
3526
|
__privateSet(this, _listener, transport.onNotification(
|
|
@@ -3474,7 +3553,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3474
3553
|
};
|
|
3475
3554
|
this.dappClient.on("message", dappClientMessageHandler);
|
|
3476
3555
|
let timeout;
|
|
3477
|
-
if (this.
|
|
3556
|
+
if (__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).isConnected()) {
|
|
3478
3557
|
timeout = setTimeout(() => {
|
|
3479
3558
|
this.openSimpleDeeplinkIfNeeded();
|
|
3480
3559
|
}, 250);
|
|
@@ -3502,8 +3581,8 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3502
3581
|
}
|
|
3503
3582
|
);
|
|
3504
3583
|
}
|
|
3505
|
-
return this.
|
|
3506
|
-
yield this.storage.
|
|
3584
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
3585
|
+
yield this.storage.removeTransportType();
|
|
3507
3586
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
3508
3587
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3509
3588
|
})).finally(() => {
|
|
@@ -3569,7 +3648,7 @@ getCaipSession_fn = function() {
|
|
|
3569
3648
|
};
|
|
3570
3649
|
if ((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) {
|
|
3571
3650
|
try {
|
|
3572
|
-
const response = yield this.
|
|
3651
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
3573
3652
|
method: "wallet_getSession"
|
|
3574
3653
|
});
|
|
3575
3654
|
if (response.result) {
|
|
@@ -3663,14 +3742,14 @@ var Store = class extends StoreClient {
|
|
|
3663
3742
|
super();
|
|
3664
3743
|
this.adapter = adapter;
|
|
3665
3744
|
}
|
|
3666
|
-
|
|
3745
|
+
getTransportType() {
|
|
3667
3746
|
return __async(this, null, function* () {
|
|
3668
3747
|
try {
|
|
3669
|
-
const
|
|
3670
|
-
if (!
|
|
3748
|
+
const transportType = yield this.adapter.get("multichain-transport");
|
|
3749
|
+
if (!transportType) {
|
|
3671
3750
|
return null;
|
|
3672
3751
|
}
|
|
3673
|
-
return getTransportType(
|
|
3752
|
+
return getTransportType(transportType);
|
|
3674
3753
|
} catch (err) {
|
|
3675
3754
|
throw new StorageGetErr(
|
|
3676
3755
|
this.adapter.platform,
|
|
@@ -3680,10 +3759,10 @@ var Store = class extends StoreClient {
|
|
|
3680
3759
|
}
|
|
3681
3760
|
});
|
|
3682
3761
|
}
|
|
3683
|
-
|
|
3762
|
+
setTransportType(transportType) {
|
|
3684
3763
|
return __async(this, null, function* () {
|
|
3685
3764
|
try {
|
|
3686
|
-
yield this.adapter.set("multichain-transport",
|
|
3765
|
+
yield this.adapter.set("multichain-transport", transportType);
|
|
3687
3766
|
} catch (err) {
|
|
3688
3767
|
throw new StorageSetErr(
|
|
3689
3768
|
this.adapter.platform,
|
|
@@ -3693,7 +3772,7 @@ var Store = class extends StoreClient {
|
|
|
3693
3772
|
}
|
|
3694
3773
|
});
|
|
3695
3774
|
}
|
|
3696
|
-
|
|
3775
|
+
removeTransportType() {
|
|
3697
3776
|
return __async(this, null, function* () {
|
|
3698
3777
|
try {
|
|
3699
3778
|
yield this.adapter.delete("multichain-transport");
|
|
@@ -3907,7 +3986,11 @@ var BaseModalFactory = class {
|
|
|
3907
3986
|
(_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
|
|
3908
3987
|
return newLink;
|
|
3909
3988
|
}),
|
|
3910
|
-
onClose:
|
|
3989
|
+
onClose: (shouldTerminate) => {
|
|
3990
|
+
this.onCloseModal(shouldTerminate).catch((error) => {
|
|
3991
|
+
console.error("Failed to close modal:", error);
|
|
3992
|
+
});
|
|
3993
|
+
},
|
|
3911
3994
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
3912
3995
|
createConnectionRequest,
|
|
3913
3996
|
onDisplayUri: this.displayUriCallback
|
|
@@ -3978,6 +4061,7 @@ Original error: ${error instanceof Error ? error.message : error}`
|
|
|
3978
4061
|
}));
|
|
3979
4062
|
});
|
|
3980
4063
|
export {
|
|
4064
|
+
EIP1193_PASSTHROUGH_METHODS,
|
|
3981
4065
|
EventEmitter,
|
|
3982
4066
|
Modal,
|
|
3983
4067
|
MultichainCore,
|
|
@@ -4005,6 +4089,7 @@ export {
|
|
|
4005
4089
|
isEnabled,
|
|
4006
4090
|
isMetamaskExtensionInstalled,
|
|
4007
4091
|
isRejectionError,
|
|
4008
|
-
isSecure
|
|
4092
|
+
isSecure,
|
|
4093
|
+
packageVersion
|
|
4009
4094
|
};
|
|
4010
4095
|
//# sourceMappingURL=connect-multichain.mjs.map
|