@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
|
|
|
@@ -1981,9 +2028,7 @@ var init_install = __esm({
|
|
|
1981
2028
|
mount() {
|
|
1982
2029
|
var _a3;
|
|
1983
2030
|
const { options } = this;
|
|
1984
|
-
const modal = document.createElement(
|
|
1985
|
-
"mm-install-modal"
|
|
1986
|
-
);
|
|
2031
|
+
const modal = document.createElement("mm-install-modal");
|
|
1987
2032
|
modal.showInstallModal = options.showInstallModal;
|
|
1988
2033
|
modal.addEventListener("close", (ev) => {
|
|
1989
2034
|
const { detail } = ev;
|
|
@@ -2179,6 +2224,7 @@ import { analytics as analytics2 } from "@metamask/analytics";
|
|
|
2179
2224
|
import {
|
|
2180
2225
|
getMultichainClient
|
|
2181
2226
|
} from "@metamask/multichain-api-client";
|
|
2227
|
+
import { createDeferredPromise as createDeferredPromise2 } from "@metamask/utils";
|
|
2182
2228
|
|
|
2183
2229
|
// src/config/index.ts
|
|
2184
2230
|
var MWP_RELAY_URL = "wss://mm-sdk-relay.api.cx.metamask.io/connection/websocket";
|
|
@@ -2332,6 +2378,9 @@ var RequestRouter = class {
|
|
|
2332
2378
|
invokeMethod(options) {
|
|
2333
2379
|
return __async(this, null, function* () {
|
|
2334
2380
|
const { method } = options.request;
|
|
2381
|
+
if (EIP1193_PASSTHROUGH_METHODS.has(method)) {
|
|
2382
|
+
return this.handleWithEip1193Passthrough(options);
|
|
2383
|
+
}
|
|
2335
2384
|
if (RPC_HANDLED_METHODS.has(method)) {
|
|
2336
2385
|
return this.handleWithRpcNode(options);
|
|
2337
2386
|
}
|
|
@@ -2341,6 +2390,29 @@ var RequestRouter = class {
|
|
|
2341
2390
|
return this.handleWithWallet(options);
|
|
2342
2391
|
});
|
|
2343
2392
|
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Forwards EIP-1193 / legacy provider methods (e.g. `wallet_addEthereumChain`,
|
|
2395
|
+
* `wallet_switchEthereumChain`, `eth_accounts`) directly to the underlying
|
|
2396
|
+
* transport's `sendEip1193Message`, bypassing the multichain
|
|
2397
|
+
* `wallet_invokeMethod` envelope. These methods are wallet-side concerns the
|
|
2398
|
+
* Multichain API does not model, so we forward the raw `{ method, params }`
|
|
2399
|
+
* payload and return the wallet's full JSON-RPC response envelope unchanged.
|
|
2400
|
+
*
|
|
2401
|
+
* Analytics tracking is intentionally skipped here: ecosystem clients
|
|
2402
|
+
* (e.g. `connect-evm`) emit their own `wallet_action_*` events around these
|
|
2403
|
+
* passthrough calls, and adding router-level tracking would double-count.
|
|
2404
|
+
*
|
|
2405
|
+
* @param options
|
|
2406
|
+
*/
|
|
2407
|
+
handleWithEip1193Passthrough(options) {
|
|
2408
|
+
return __async(this, null, function* () {
|
|
2409
|
+
const response = yield this.transport.sendEip1193Message({
|
|
2410
|
+
method: options.request.method,
|
|
2411
|
+
params: options.request.params
|
|
2412
|
+
});
|
|
2413
|
+
return response.result;
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2344
2416
|
/**
|
|
2345
2417
|
* Forwards the request directly to the wallet via the transport.
|
|
2346
2418
|
*
|
|
@@ -2372,14 +2444,6 @@ var RequestRouter = class {
|
|
|
2372
2444
|
}), 10);
|
|
2373
2445
|
}
|
|
2374
2446
|
const response = yield request;
|
|
2375
|
-
if (response.error) {
|
|
2376
|
-
const { error } = response;
|
|
2377
|
-
throw new RPCInvokeMethodErr(
|
|
2378
|
-
`RPC Request failed with code ${error.code}: ${error.message}`,
|
|
2379
|
-
error.code,
|
|
2380
|
-
error.message
|
|
2381
|
-
);
|
|
2382
|
-
}
|
|
2383
2447
|
return response.result;
|
|
2384
2448
|
}));
|
|
2385
2449
|
});
|
|
@@ -2494,7 +2558,7 @@ import {
|
|
|
2494
2558
|
getDefaultTransport
|
|
2495
2559
|
} from "@metamask/multichain-api-client";
|
|
2496
2560
|
var DEFAULT_REQUEST_TIMEOUT = 60 * 1e3;
|
|
2497
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
2561
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, parseWalletError_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
2498
2562
|
var DefaultTransport = class {
|
|
2499
2563
|
constructor() {
|
|
2500
2564
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -2630,7 +2694,11 @@ var DefaultTransport = class {
|
|
|
2630
2694
|
}
|
|
2631
2695
|
request(_0) {
|
|
2632
2696
|
return __async(this, arguments, function* (request, options = __privateGet(this, _defaultRequestOptions)) {
|
|
2633
|
-
|
|
2697
|
+
const response = yield __privateGet(this, _transport).request(request, options);
|
|
2698
|
+
if (response.error) {
|
|
2699
|
+
throw __privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error);
|
|
2700
|
+
}
|
|
2701
|
+
return response;
|
|
2634
2702
|
});
|
|
2635
2703
|
}
|
|
2636
2704
|
onNotification(callback) {
|
|
@@ -2674,6 +2742,16 @@ notifyCallbacks_fn = function(data) {
|
|
|
2674
2742
|
}
|
|
2675
2743
|
}
|
|
2676
2744
|
};
|
|
2745
|
+
parseWalletError_fn = function(errorPayload) {
|
|
2746
|
+
const errorData = errorPayload;
|
|
2747
|
+
const error = new Error(
|
|
2748
|
+
typeof errorData.message === "string" ? errorData.message : "Request failed"
|
|
2749
|
+
);
|
|
2750
|
+
if (typeof errorData.code === "number") {
|
|
2751
|
+
error.code = errorData.code;
|
|
2752
|
+
}
|
|
2753
|
+
return error;
|
|
2754
|
+
};
|
|
2677
2755
|
isMetamaskProviderEvent_fn = function(event) {
|
|
2678
2756
|
var _a3, _b;
|
|
2679
2757
|
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
|
|
@@ -2696,13 +2774,7 @@ handleResponse_fn = function(event) {
|
|
|
2696
2774
|
__privateGet(this, _pendingRequests).delete(responseId);
|
|
2697
2775
|
const response = responseData;
|
|
2698
2776
|
if ("error" in response && response.error) {
|
|
2699
|
-
|
|
2700
|
-
response.error.message || "Request failed"
|
|
2701
|
-
);
|
|
2702
|
-
if (typeof response.error.code === "number") {
|
|
2703
|
-
error.code = response.error.code;
|
|
2704
|
-
}
|
|
2705
|
-
pendingRequest.reject(error);
|
|
2777
|
+
pendingRequest.reject(__privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error));
|
|
2706
2778
|
} else {
|
|
2707
2779
|
pendingRequest.resolve(response);
|
|
2708
2780
|
}
|
|
@@ -2740,22 +2812,21 @@ init_fn = function() {
|
|
|
2740
2812
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2741
2813
|
init_utils2();
|
|
2742
2814
|
import { providerErrors } from "@metamask/rpc-errors";
|
|
2743
|
-
var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2815
|
+
var _notificationCallbacks2, _getTransport, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2744
2816
|
var MultichainApiClientWrapperTransport = class {
|
|
2745
|
-
constructor(metamaskConnectMultichain) {
|
|
2817
|
+
constructor(metamaskConnectMultichain, getTransport) {
|
|
2746
2818
|
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2747
2819
|
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2748
2820
|
__privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
|
|
2821
|
+
__privateAdd(this, _getTransport);
|
|
2822
|
+
__privateSet(this, _getTransport, getTransport);
|
|
2749
2823
|
}
|
|
2750
2824
|
isTransportDefined() {
|
|
2751
|
-
|
|
2752
|
-
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2753
|
-
} catch (_error) {
|
|
2754
|
-
return false;
|
|
2755
|
-
}
|
|
2825
|
+
return __privateGet(this, _getTransport).call(this) !== void 0;
|
|
2756
2826
|
}
|
|
2757
2827
|
isTransportConnected() {
|
|
2758
|
-
|
|
2828
|
+
var _a3, _b;
|
|
2829
|
+
return (_b = (_a3 = __privateGet(this, _getTransport).call(this)) == null ? void 0 : _a3.isConnected()) != null ? _b : false;
|
|
2759
2830
|
}
|
|
2760
2831
|
clearNotificationCallbacks() {
|
|
2761
2832
|
__privateGet(this, _notificationCallbacks2).clear();
|
|
@@ -2771,10 +2842,11 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
2771
2842
|
this.notificationListener = void 0;
|
|
2772
2843
|
}
|
|
2773
2844
|
setupTransportNotificationListener() {
|
|
2774
|
-
|
|
2845
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2846
|
+
if (!transport || this.notificationListener) {
|
|
2775
2847
|
return;
|
|
2776
2848
|
}
|
|
2777
|
-
this.notificationListener =
|
|
2849
|
+
this.notificationListener = transport.onNotification(
|
|
2778
2850
|
this.notifyCallbacks.bind(this)
|
|
2779
2851
|
);
|
|
2780
2852
|
}
|
|
@@ -2824,6 +2896,7 @@ var MultichainApiClientWrapperTransport = class {
|
|
|
2824
2896
|
}
|
|
2825
2897
|
};
|
|
2826
2898
|
_notificationCallbacks2 = new WeakMap();
|
|
2899
|
+
_getTransport = new WeakMap();
|
|
2827
2900
|
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2828
2901
|
walletCreateSession_fn = function(request) {
|
|
2829
2902
|
return __async(this, null, function* () {
|
|
@@ -2847,14 +2920,19 @@ walletCreateSession_fn = function(request) {
|
|
|
2847
2920
|
accounts,
|
|
2848
2921
|
createSessionParams.sessionProperties
|
|
2849
2922
|
);
|
|
2850
|
-
|
|
2923
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2924
|
+
if (!transport) {
|
|
2925
|
+
throw new Error("Transport not initialized after connect");
|
|
2926
|
+
}
|
|
2927
|
+
return transport.request({
|
|
2851
2928
|
method: "wallet_getSession"
|
|
2852
2929
|
});
|
|
2853
2930
|
});
|
|
2854
2931
|
};
|
|
2855
2932
|
walletGetSession_fn = function(request) {
|
|
2856
2933
|
return __async(this, null, function* () {
|
|
2857
|
-
|
|
2934
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
2935
|
+
if (!(transport == null ? void 0 : transport.isConnected())) {
|
|
2858
2936
|
return {
|
|
2859
2937
|
jsonrpc: "2.0",
|
|
2860
2938
|
id: request.id,
|
|
@@ -2863,7 +2941,7 @@ walletGetSession_fn = function(request) {
|
|
|
2863
2941
|
}
|
|
2864
2942
|
};
|
|
2865
2943
|
}
|
|
2866
|
-
return
|
|
2944
|
+
return transport.request({
|
|
2867
2945
|
method: "wallet_getSession"
|
|
2868
2946
|
});
|
|
2869
2947
|
});
|
|
@@ -2941,7 +3019,7 @@ function setupAnalyticsGlobals(options, storage, setAnonId) {
|
|
|
2941
3019
|
analytics2.enable();
|
|
2942
3020
|
});
|
|
2943
3021
|
}
|
|
2944
|
-
var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId,
|
|
3022
|
+
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;
|
|
2945
3023
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2946
3024
|
constructor(options) {
|
|
2947
3025
|
var _a3, _b, _c, _d;
|
|
@@ -2954,9 +3032,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2954
3032
|
}),
|
|
2955
3033
|
analytics: normalizeAnalyticsOptions(options.analytics),
|
|
2956
3034
|
versions: __spreadValues({
|
|
2957
|
-
|
|
2958
|
-
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
2959
|
-
"connect-multichain": false ? "unknown" : "0.15.0"
|
|
3035
|
+
"connect-multichain": getVersion()
|
|
2960
3036
|
}, (_d = options.versions) != null ? _d : {})
|
|
2961
3037
|
});
|
|
2962
3038
|
super(allOptions);
|
|
@@ -2972,7 +3048,8 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2972
3048
|
__privateAdd(this, _anonId);
|
|
2973
3049
|
__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}`);
|
|
2974
3050
|
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
2975
|
-
this
|
|
3051
|
+
this,
|
|
3052
|
+
() => __privateGet(this, _transport2)
|
|
2976
3053
|
));
|
|
2977
3054
|
__privateSet(this, _provider, getMultichainClient({
|
|
2978
3055
|
transport: __privateGet(this, _providerTransportWrapper)
|
|
@@ -2991,12 +3068,6 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
2991
3068
|
get provider() {
|
|
2992
3069
|
return __privateGet(this, _provider);
|
|
2993
3070
|
}
|
|
2994
|
-
get transport() {
|
|
2995
|
-
if (!__privateGet(this, _transport2)) {
|
|
2996
|
-
throw new Error("Transport not initialized, establish connection first");
|
|
2997
|
-
}
|
|
2998
|
-
return __privateGet(this, _transport2);
|
|
2999
|
-
}
|
|
3000
3071
|
get dappClient() {
|
|
3001
3072
|
if (!__privateGet(this, _dappClient)) {
|
|
3002
3073
|
throw new Error("DappClient not initialized, establish connection first");
|
|
@@ -3010,6 +3081,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3010
3081
|
get storage() {
|
|
3011
3082
|
return this.options.storage;
|
|
3012
3083
|
}
|
|
3084
|
+
get version() {
|
|
3085
|
+
return getVersion();
|
|
3086
|
+
}
|
|
3013
3087
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
3014
3088
|
// If the singleton already exists, it merges the incoming options with the
|
|
3015
3089
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
@@ -3024,6 +3098,11 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3024
3098
|
const existing = globalObject[SINGLETON_KEY];
|
|
3025
3099
|
if (existing) {
|
|
3026
3100
|
const instance = yield existing;
|
|
3101
|
+
if (instance.version !== getVersion()) {
|
|
3102
|
+
console.warn(
|
|
3103
|
+
`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.`
|
|
3104
|
+
);
|
|
3105
|
+
}
|
|
3027
3106
|
instance.mergeOptions(options);
|
|
3028
3107
|
if (instance instanceof _MetaMaskConnectMultichain) {
|
|
3029
3108
|
yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a3);
|
|
@@ -3047,12 +3126,12 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3047
3126
|
}
|
|
3048
3127
|
yield __privateMethod(_a4 = instance, _MetaMaskConnectMultichain_instances, init_fn2).call(_a4);
|
|
3049
3128
|
return instance;
|
|
3050
|
-
}))()
|
|
3051
|
-
globalObject[SINGLETON_KEY] = instancePromise;
|
|
3052
|
-
instancePromise.catch((error) => {
|
|
3129
|
+
}))().catch((error) => {
|
|
3053
3130
|
globalObject[SINGLETON_KEY] = void 0;
|
|
3054
3131
|
console.error("Error initializing MetaMaskConnectMultichain", error);
|
|
3132
|
+
throw error;
|
|
3055
3133
|
});
|
|
3134
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
3056
3135
|
return instancePromise;
|
|
3057
3136
|
});
|
|
3058
3137
|
}
|
|
@@ -3112,9 +3191,9 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3112
3191
|
forceRequest
|
|
3113
3192
|
}).then(() => __async(this, null, function* () {
|
|
3114
3193
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
3115
|
-
return this.storage.
|
|
3194
|
+
return this.storage.setTransportType("mwp" /* MWP */);
|
|
3116
3195
|
}
|
|
3117
|
-
return this.storage.
|
|
3196
|
+
return this.storage.setTransportType("browser" /* Browser */);
|
|
3118
3197
|
})), scopes, transportType);
|
|
3119
3198
|
}
|
|
3120
3199
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
@@ -3143,11 +3222,6 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3143
3222
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
3144
3223
|
});
|
|
3145
3224
|
}
|
|
3146
|
-
emit(event, args) {
|
|
3147
|
-
var _a3, _b;
|
|
3148
|
-
(_b = (_a3 = this.options.transport) == null ? void 0 : _a3.onNotification) == null ? void 0 : _b.call(_a3, { method: event, params: args });
|
|
3149
|
-
super.emit(event, args);
|
|
3150
|
-
}
|
|
3151
3225
|
disconnect() {
|
|
3152
3226
|
return __async(this, arguments, function* (scopes = []) {
|
|
3153
3227
|
var _a3, _b, _c;
|
|
@@ -3157,7 +3231,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3157
3231
|
);
|
|
3158
3232
|
yield (_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.disconnect(scopes);
|
|
3159
3233
|
if (remainingScopes.length === 0) {
|
|
3160
|
-
yield this.storage.
|
|
3234
|
+
yield this.storage.removeTransportType();
|
|
3161
3235
|
if (__privateGet(this, _transportType) !== "browser" /* Browser */) {
|
|
3162
3236
|
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
3163
3237
|
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
@@ -3175,7 +3249,8 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3175
3249
|
invokeMethod(request) {
|
|
3176
3250
|
return __async(this, null, function* () {
|
|
3177
3251
|
var _a3;
|
|
3178
|
-
const
|
|
3252
|
+
const transport = __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this);
|
|
3253
|
+
const { options } = this;
|
|
3179
3254
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
3180
3255
|
const requestRouter = new RequestRouter(
|
|
3181
3256
|
transport,
|
|
@@ -3194,7 +3269,7 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3194
3269
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
3195
3270
|
if (shouldOpenDeeplink) {
|
|
3196
3271
|
setTimeout(() => __async(this, null, function* () {
|
|
3197
|
-
const session = yield this.
|
|
3272
|
+
const session = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).getActiveSession();
|
|
3198
3273
|
if (!session) {
|
|
3199
3274
|
throw new Error("No active session found");
|
|
3200
3275
|
}
|
|
@@ -3218,10 +3293,13 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
|
|
|
3218
3293
|
this.emit("wallet_sessionChanged", emptySession);
|
|
3219
3294
|
return;
|
|
3220
3295
|
}
|
|
3221
|
-
const response = yield this.
|
|
3296
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
3222
3297
|
method: "wallet_getSession"
|
|
3223
3298
|
});
|
|
3224
|
-
this.emit(
|
|
3299
|
+
this.emit(
|
|
3300
|
+
"wallet_sessionChanged",
|
|
3301
|
+
(_b = response.result) != null ? _b : emptySession
|
|
3302
|
+
);
|
|
3225
3303
|
});
|
|
3226
3304
|
}
|
|
3227
3305
|
};
|
|
@@ -3233,8 +3311,14 @@ _beforeUnloadListener = new WeakMap();
|
|
|
3233
3311
|
_transportType = new WeakMap();
|
|
3234
3312
|
_listener = new WeakMap();
|
|
3235
3313
|
_anonId = new WeakMap();
|
|
3236
|
-
_sdkInfo = new WeakMap();
|
|
3237
3314
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
3315
|
+
transportOrThrow_fn = function() {
|
|
3316
|
+
if (!__privateGet(this, _transport2)) {
|
|
3317
|
+
throw new Error("Transport not initialized, establish connection first");
|
|
3318
|
+
}
|
|
3319
|
+
return __privateGet(this, _transport2);
|
|
3320
|
+
};
|
|
3321
|
+
_sdkInfo = new WeakMap();
|
|
3238
3322
|
setupAnalytics_fn = function() {
|
|
3239
3323
|
return __async(this, null, function* () {
|
|
3240
3324
|
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
@@ -3260,7 +3344,7 @@ onTransportNotification_fn = function(payload) {
|
|
|
3260
3344
|
};
|
|
3261
3345
|
getStoredTransport_fn = function() {
|
|
3262
3346
|
return __async(this, null, function* () {
|
|
3263
|
-
const transportType = yield this.storage.
|
|
3347
|
+
const transportType = yield this.storage.getTransportType();
|
|
3264
3348
|
const hasExtensionInstalled = yield hasExtension();
|
|
3265
3349
|
if (transportType) {
|
|
3266
3350
|
if (transportType === "browser" /* Browser */) {
|
|
@@ -3288,7 +3372,7 @@ getStoredTransport_fn = function() {
|
|
|
3288
3372
|
));
|
|
3289
3373
|
return apiTransport;
|
|
3290
3374
|
}
|
|
3291
|
-
yield this.storage.
|
|
3375
|
+
yield this.storage.removeTransportType();
|
|
3292
3376
|
}
|
|
3293
3377
|
return void 0;
|
|
3294
3378
|
});
|
|
@@ -3298,15 +3382,15 @@ setupTransport_fn = function() {
|
|
|
3298
3382
|
var _a3;
|
|
3299
3383
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
3300
3384
|
if (transport) {
|
|
3301
|
-
if (!
|
|
3385
|
+
if (!transport.isConnected()) {
|
|
3302
3386
|
this.status = "connecting";
|
|
3303
|
-
yield
|
|
3387
|
+
yield transport.connect();
|
|
3304
3388
|
}
|
|
3305
3389
|
this.status = "connected";
|
|
3306
3390
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
3307
|
-
yield this.storage.
|
|
3391
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3308
3392
|
} else {
|
|
3309
|
-
yield this.storage.
|
|
3393
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
3310
3394
|
}
|
|
3311
3395
|
} else {
|
|
3312
3396
|
this.status = "loaded";
|
|
@@ -3315,7 +3399,7 @@ setupTransport_fn = function() {
|
|
|
3315
3399
|
if (hasExtensionInstalled && preferExtension) {
|
|
3316
3400
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
3317
3401
|
try {
|
|
3318
|
-
yield this.
|
|
3402
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).init();
|
|
3319
3403
|
} catch (error) {
|
|
3320
3404
|
console.error("Passive init failed:", error);
|
|
3321
3405
|
}
|
|
@@ -3339,7 +3423,7 @@ init_fn2 = function() {
|
|
|
3339
3423
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
3340
3424
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
3341
3425
|
} catch (error) {
|
|
3342
|
-
yield this.storage.
|
|
3426
|
+
yield this.storage.removeTransportType();
|
|
3343
3427
|
this.status = "pending";
|
|
3344
3428
|
logger2("MetaMaskSDK error during initialization", error);
|
|
3345
3429
|
}
|
|
@@ -3385,17 +3469,17 @@ setupMWP_fn = function() {
|
|
|
3385
3469
|
__privateSet(this, _transport2, apiTransport);
|
|
3386
3470
|
__privateSet(this, _transportType, "mwp" /* MWP */);
|
|
3387
3471
|
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
3388
|
-
__privateSet(this, _listener,
|
|
3472
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
3389
3473
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
3390
3474
|
));
|
|
3391
|
-
yield this.storage.
|
|
3475
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3392
3476
|
});
|
|
3393
3477
|
};
|
|
3394
3478
|
onBeforeUnload_fn = function() {
|
|
3395
3479
|
return __async(this, null, function* () {
|
|
3396
3480
|
var _a3;
|
|
3397
3481
|
if ((_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.isMounted) {
|
|
3398
|
-
yield this.storage.
|
|
3482
|
+
yield this.storage.removeTransportType();
|
|
3399
3483
|
}
|
|
3400
3484
|
});
|
|
3401
3485
|
};
|
|
@@ -3412,70 +3496,65 @@ createBeforeUnloadListener_fn = function() {
|
|
|
3412
3496
|
};
|
|
3413
3497
|
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
3414
3498
|
return __async(this, null, function* () {
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
sessionRequest,
|
|
3428
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3429
|
-
});
|
|
3430
|
-
}
|
|
3431
|
-
);
|
|
3432
|
-
(() => __async(this, null, function* () {
|
|
3433
|
-
var _a3;
|
|
3434
|
-
try {
|
|
3435
|
-
yield this.transport.connect({
|
|
3436
|
-
scopes,
|
|
3437
|
-
caipAccountIds,
|
|
3438
|
-
sessionProperties
|
|
3439
|
-
});
|
|
3440
|
-
yield this.options.ui.factory.unload();
|
|
3441
|
-
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
3442
|
-
this.status = "connected";
|
|
3443
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
3444
|
-
} catch (error) {
|
|
3445
|
-
const { ProtocolError, ErrorCode } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3446
|
-
if (error instanceof ProtocolError) {
|
|
3447
|
-
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
3448
|
-
this.status = "disconnected";
|
|
3449
|
-
yield this.options.ui.factory.unload(error);
|
|
3450
|
-
reject(error);
|
|
3451
|
-
}
|
|
3452
|
-
} else {
|
|
3453
|
-
this.status = "disconnected";
|
|
3454
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3455
|
-
yield this.options.ui.factory.unload(normalizedError);
|
|
3456
|
-
reject(normalizedError);
|
|
3457
|
-
}
|
|
3458
|
-
}
|
|
3459
|
-
}))().catch(() => {
|
|
3460
|
-
});
|
|
3499
|
+
const completion = createDeferredPromise2();
|
|
3500
|
+
const createConnectionRequest = () => __async(this, null, function* () {
|
|
3501
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
3502
|
+
yield this.dappClient.disconnect();
|
|
3503
|
+
}
|
|
3504
|
+
const sessionRequestDeferred = createDeferredPromise2();
|
|
3505
|
+
this.dappClient.on(
|
|
3506
|
+
"session_request",
|
|
3507
|
+
(sessionRequest) => {
|
|
3508
|
+
sessionRequestDeferred.resolve({
|
|
3509
|
+
sessionRequest,
|
|
3510
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3461
3511
|
});
|
|
3462
|
-
}
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3512
|
+
}
|
|
3513
|
+
);
|
|
3514
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
3515
|
+
var _a3;
|
|
3516
|
+
yield this.options.ui.factory.unload();
|
|
3517
|
+
(_a3 = this.options.ui.factory.modal) == null ? void 0 : _a3.unmount();
|
|
3518
|
+
this.status = "connected";
|
|
3519
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3520
|
+
})).catch((error) => __async(this, null, function* () {
|
|
3521
|
+
const { ProtocolError, ErrorCode } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3522
|
+
if (error instanceof ProtocolError) {
|
|
3523
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
3524
|
+
this.status = "disconnected";
|
|
3525
|
+
yield this.options.ui.factory.unload(error);
|
|
3526
|
+
completion.reject(error);
|
|
3470
3527
|
}
|
|
3471
|
-
}
|
|
3472
|
-
|
|
3473
|
-
|
|
3528
|
+
} else {
|
|
3529
|
+
this.status = "disconnected";
|
|
3530
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
3531
|
+
yield this.options.ui.factory.unload(normalizedError);
|
|
3532
|
+
completion.reject(normalizedError);
|
|
3474
3533
|
}
|
|
3475
|
-
)
|
|
3476
|
-
|
|
3477
|
-
});
|
|
3534
|
+
}));
|
|
3535
|
+
return sessionRequestDeferred.promise;
|
|
3478
3536
|
});
|
|
3537
|
+
this.options.ui.factory.renderInstallModal(
|
|
3538
|
+
desktopPreferred,
|
|
3539
|
+
createConnectionRequest,
|
|
3540
|
+
(error) => __async(this, null, function* () {
|
|
3541
|
+
if (error) {
|
|
3542
|
+
yield this.storage.removeTransportType();
|
|
3543
|
+
completion.reject(error);
|
|
3544
|
+
} else {
|
|
3545
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3546
|
+
completion.resolve();
|
|
3547
|
+
}
|
|
3548
|
+
}),
|
|
3549
|
+
(uri) => {
|
|
3550
|
+
this.emit("display_uri", uri);
|
|
3551
|
+
}
|
|
3552
|
+
).catch((error) => {
|
|
3553
|
+
completion.reject(
|
|
3554
|
+
error instanceof Error ? error : new Error(String(error))
|
|
3555
|
+
);
|
|
3556
|
+
});
|
|
3557
|
+
return completion.promise;
|
|
3479
3558
|
});
|
|
3480
3559
|
};
|
|
3481
3560
|
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
@@ -3491,39 +3570,37 @@ showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, session
|
|
|
3491
3570
|
};
|
|
3492
3571
|
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
3493
3572
|
return __async(this, null, function* () {
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3573
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
3574
|
+
yield this.dappClient.disconnect().catch(() => void 0);
|
|
3575
|
+
}
|
|
3576
|
+
const onSessionRequest = (sessionRequest) => {
|
|
3577
|
+
const connectionRequest = {
|
|
3578
|
+
sessionRequest,
|
|
3579
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3580
|
+
};
|
|
3581
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3582
|
+
this.emit("display_uri", deeplink);
|
|
3583
|
+
};
|
|
3584
|
+
this.dappClient.on("session_request", onSessionRequest);
|
|
3585
|
+
try {
|
|
3586
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({
|
|
3587
|
+
scopes,
|
|
3588
|
+
caipAccountIds,
|
|
3589
|
+
sessionProperties
|
|
3590
|
+
});
|
|
3591
|
+
this.status = "connected";
|
|
3592
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
3593
|
+
} catch (error) {
|
|
3594
|
+
const { ProtocolError } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3595
|
+
this.status = "disconnected";
|
|
3596
|
+
yield this.storage.removeTransportType();
|
|
3597
|
+
if (error instanceof ProtocolError || error instanceof Error) {
|
|
3598
|
+
throw error;
|
|
3498
3599
|
}
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
sessionRequest,
|
|
3504
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
3505
|
-
};
|
|
3506
|
-
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
3507
|
-
this.emit("display_uri", deeplink);
|
|
3508
|
-
}
|
|
3509
|
-
);
|
|
3510
|
-
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
3511
|
-
this.status = "connected";
|
|
3512
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
3513
|
-
resolve();
|
|
3514
|
-
})).catch((error) => __async(this, null, function* () {
|
|
3515
|
-
const { ProtocolError } = yield import("@metamask/mobile-wallet-protocol-core");
|
|
3516
|
-
if (error instanceof ProtocolError) {
|
|
3517
|
-
this.status = "disconnected";
|
|
3518
|
-
yield this.storage.removeTransport();
|
|
3519
|
-
reject(error);
|
|
3520
|
-
} else {
|
|
3521
|
-
this.status = "disconnected";
|
|
3522
|
-
yield this.storage.removeTransport();
|
|
3523
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3524
|
-
}
|
|
3525
|
-
}));
|
|
3526
|
-
});
|
|
3600
|
+
throw new Error(String(error));
|
|
3601
|
+
} finally {
|
|
3602
|
+
this.dappClient.off("session_request", onSessionRequest);
|
|
3603
|
+
}
|
|
3527
3604
|
});
|
|
3528
3605
|
};
|
|
3529
3606
|
setupDefaultTransport_fn = function() {
|
|
@@ -3532,7 +3609,7 @@ setupDefaultTransport_fn = function() {
|
|
|
3532
3609
|
return __privateGet(this, _transport2);
|
|
3533
3610
|
}
|
|
3534
3611
|
if (options == null ? void 0 : options.persist) {
|
|
3535
|
-
yield this.storage.
|
|
3612
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
3536
3613
|
}
|
|
3537
3614
|
const transport = new DefaultTransport();
|
|
3538
3615
|
__privateSet(this, _listener, transport.onNotification(
|
|
@@ -3565,7 +3642,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3565
3642
|
};
|
|
3566
3643
|
this.dappClient.on("message", dappClientMessageHandler);
|
|
3567
3644
|
let timeout;
|
|
3568
|
-
if (this.
|
|
3645
|
+
if (__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).isConnected()) {
|
|
3569
3646
|
timeout = setTimeout(() => {
|
|
3570
3647
|
this.openSimpleDeeplinkIfNeeded();
|
|
3571
3648
|
}, 250);
|
|
@@ -3593,8 +3670,8 @@ deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
|
3593
3670
|
}
|
|
3594
3671
|
);
|
|
3595
3672
|
}
|
|
3596
|
-
return this.
|
|
3597
|
-
yield this.storage.
|
|
3673
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
3674
|
+
yield this.storage.removeTransportType();
|
|
3598
3675
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
3599
3676
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
3600
3677
|
})).finally(() => {
|
|
@@ -3660,7 +3737,7 @@ getCaipSession_fn = function() {
|
|
|
3660
3737
|
};
|
|
3661
3738
|
if ((_a3 = __privateGet(this, _transport2)) == null ? void 0 : _a3.isConnected()) {
|
|
3662
3739
|
try {
|
|
3663
|
-
const response = yield this.
|
|
3740
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
3664
3741
|
method: "wallet_getSession"
|
|
3665
3742
|
});
|
|
3666
3743
|
if (response.result) {
|
|
@@ -3754,14 +3831,14 @@ var Store = class extends StoreClient {
|
|
|
3754
3831
|
super();
|
|
3755
3832
|
this.adapter = adapter;
|
|
3756
3833
|
}
|
|
3757
|
-
|
|
3834
|
+
getTransportType() {
|
|
3758
3835
|
return __async(this, null, function* () {
|
|
3759
3836
|
try {
|
|
3760
|
-
const
|
|
3761
|
-
if (!
|
|
3837
|
+
const transportType = yield this.adapter.get("multichain-transport");
|
|
3838
|
+
if (!transportType) {
|
|
3762
3839
|
return null;
|
|
3763
3840
|
}
|
|
3764
|
-
return getTransportType(
|
|
3841
|
+
return getTransportType(transportType);
|
|
3765
3842
|
} catch (err) {
|
|
3766
3843
|
throw new StorageGetErr(
|
|
3767
3844
|
this.adapter.platform,
|
|
@@ -3771,10 +3848,10 @@ var Store = class extends StoreClient {
|
|
|
3771
3848
|
}
|
|
3772
3849
|
});
|
|
3773
3850
|
}
|
|
3774
|
-
|
|
3851
|
+
setTransportType(transportType) {
|
|
3775
3852
|
return __async(this, null, function* () {
|
|
3776
3853
|
try {
|
|
3777
|
-
yield this.adapter.set("multichain-transport",
|
|
3854
|
+
yield this.adapter.set("multichain-transport", transportType);
|
|
3778
3855
|
} catch (err) {
|
|
3779
3856
|
throw new StorageSetErr(
|
|
3780
3857
|
this.adapter.platform,
|
|
@@ -3784,7 +3861,7 @@ var Store = class extends StoreClient {
|
|
|
3784
3861
|
}
|
|
3785
3862
|
});
|
|
3786
3863
|
}
|
|
3787
|
-
|
|
3864
|
+
removeTransportType() {
|
|
3788
3865
|
return __async(this, null, function* () {
|
|
3789
3866
|
try {
|
|
3790
3867
|
yield this.adapter.delete("multichain-transport");
|
|
@@ -3998,7 +4075,11 @@ var BaseModalFactory = class {
|
|
|
3998
4075
|
(_a4 = this.displayUriCallback) == null ? void 0 : _a4.call(this, newLink);
|
|
3999
4076
|
return newLink;
|
|
4000
4077
|
}),
|
|
4001
|
-
onClose:
|
|
4078
|
+
onClose: (shouldTerminate) => {
|
|
4079
|
+
this.onCloseModal(shouldTerminate).catch((error) => {
|
|
4080
|
+
console.error("Failed to close modal:", error);
|
|
4081
|
+
});
|
|
4082
|
+
},
|
|
4002
4083
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
4003
4084
|
createConnectionRequest,
|
|
4004
4085
|
onDisplayUri: this.displayUriCallback
|
|
@@ -4036,7 +4117,7 @@ function preload() {
|
|
|
4036
4117
|
}
|
|
4037
4118
|
try {
|
|
4038
4119
|
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
4039
|
-
|
|
4120
|
+
defineCustomElements();
|
|
4040
4121
|
} catch (error) {
|
|
4041
4122
|
console.error("Failed to load customElements:", error);
|
|
4042
4123
|
}
|
|
@@ -4074,6 +4155,7 @@ var createMultichainClient = (options) => __async(null, null, function* () {
|
|
|
4074
4155
|
}));
|
|
4075
4156
|
});
|
|
4076
4157
|
export {
|
|
4158
|
+
EIP1193_PASSTHROUGH_METHODS,
|
|
4077
4159
|
EventEmitter,
|
|
4078
4160
|
Modal,
|
|
4079
4161
|
MultichainCore,
|
|
@@ -4101,6 +4183,7 @@ export {
|
|
|
4101
4183
|
isEnabled,
|
|
4102
4184
|
isMetamaskExtensionInstalled,
|
|
4103
4185
|
isRejectionError,
|
|
4104
|
-
isSecure
|
|
4186
|
+
isSecure,
|
|
4187
|
+
packageVersion
|
|
4105
4188
|
};
|
|
4106
4189
|
//# sourceMappingURL=connect-multichain.mjs.map
|