@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
|
@@ -9518,6 +9518,19 @@ var MetaMaskSDK = (() => {
|
|
|
9518
9518
|
});
|
|
9519
9519
|
|
|
9520
9520
|
// ../../node_modules/@metamask/utils/dist/promise.mjs
|
|
9521
|
+
function createDeferredPromise({ suppressUnhandledRejection = false } = {}) {
|
|
9522
|
+
let resolve;
|
|
9523
|
+
let reject;
|
|
9524
|
+
const promise = new Promise((innerResolve, innerReject) => {
|
|
9525
|
+
resolve = innerResolve;
|
|
9526
|
+
reject = innerReject;
|
|
9527
|
+
});
|
|
9528
|
+
if (suppressUnhandledRejection) {
|
|
9529
|
+
promise.catch((_error) => {
|
|
9530
|
+
});
|
|
9531
|
+
}
|
|
9532
|
+
return { promise, resolve, reject };
|
|
9533
|
+
}
|
|
9521
9534
|
var init_promise = __esm({
|
|
9522
9535
|
"../../node_modules/@metamask/utils/dist/promise.mjs"() {
|
|
9523
9536
|
"use strict";
|
|
@@ -16066,7 +16079,7 @@ var MetaMaskSDK = (() => {
|
|
|
16066
16079
|
});
|
|
16067
16080
|
|
|
16068
16081
|
// src/domain/multichain/api/constants.ts
|
|
16069
|
-
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS;
|
|
16082
|
+
var infuraRpcUrls, RPC_HANDLED_METHODS, SDK_HANDLED_METHODS, EIP1193_PASSTHROUGH_METHODS;
|
|
16070
16083
|
var init_constants = __esm({
|
|
16071
16084
|
"src/domain/multichain/api/constants.ts"() {
|
|
16072
16085
|
"use strict";
|
|
@@ -16231,6 +16244,11 @@ var MetaMaskSDK = (() => {
|
|
|
16231
16244
|
"eth_uninstallFilter"
|
|
16232
16245
|
]);
|
|
16233
16246
|
SDK_HANDLED_METHODS = /* @__PURE__ */ new Set(["eth_accounts", "eth_chainId"]);
|
|
16247
|
+
EIP1193_PASSTHROUGH_METHODS = /* @__PURE__ */ new Set([
|
|
16248
|
+
"wallet_addEthereumChain",
|
|
16249
|
+
"wallet_switchEthereumChain",
|
|
16250
|
+
"eth_accounts"
|
|
16251
|
+
]);
|
|
16234
16252
|
}
|
|
16235
16253
|
});
|
|
16236
16254
|
|
|
@@ -17016,7 +17034,7 @@ var MetaMaskSDK = (() => {
|
|
|
17016
17034
|
return detectionPromise;
|
|
17017
17035
|
});
|
|
17018
17036
|
}
|
|
17019
|
-
var import_bowser, PlatformType, detectionPromise;
|
|
17037
|
+
var import_bowser, PlatformType, NATIVE_METAMASK_EIP6963_RDNS, detectionPromise;
|
|
17020
17038
|
var init_platform = __esm({
|
|
17021
17039
|
"src/domain/platform/index.ts"() {
|
|
17022
17040
|
"use strict";
|
|
@@ -17029,6 +17047,10 @@ var MetaMaskSDK = (() => {
|
|
|
17029
17047
|
PlatformType2["ReactNative"] = "react-native";
|
|
17030
17048
|
return PlatformType2;
|
|
17031
17049
|
})(PlatformType || {});
|
|
17050
|
+
NATIVE_METAMASK_EIP6963_RDNS = /* @__PURE__ */ new Set([
|
|
17051
|
+
"io.metamask",
|
|
17052
|
+
"io.metamask.mobile"
|
|
17053
|
+
]);
|
|
17032
17054
|
detectionPromise = (() => __async(null, null, function* () {
|
|
17033
17055
|
const pt = getPlatformType();
|
|
17034
17056
|
if (pt === "nodejs" /* NonBrowser */ || pt === "react-native" /* ReactNative */) {
|
|
@@ -17036,23 +17058,30 @@ var MetaMaskSDK = (() => {
|
|
|
17036
17058
|
}
|
|
17037
17059
|
return new Promise((resolve) => {
|
|
17038
17060
|
const providers = [];
|
|
17061
|
+
const targetWindow = window;
|
|
17039
17062
|
const handler = (event) => {
|
|
17040
17063
|
var _a4, _b;
|
|
17041
17064
|
if ((_b = (_a4 = event == null ? void 0 : event.detail) == null ? void 0 : _a4.info) == null ? void 0 : _b.rdns) {
|
|
17042
17065
|
providers.push(event.detail);
|
|
17043
17066
|
}
|
|
17044
17067
|
};
|
|
17045
|
-
|
|
17046
|
-
|
|
17068
|
+
targetWindow.addEventListener("eip6963:announceProvider", handler);
|
|
17069
|
+
targetWindow.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
17047
17070
|
setTimeout(() => {
|
|
17048
|
-
|
|
17049
|
-
|
|
17050
|
-
|
|
17051
|
-
var _a4, _b;
|
|
17052
|
-
return (_b = (_a4 = provider == null ? void 0 : provider.info) == null ? void 0 : _a4.rdns) == null ? void 0 : _b.startsWith("io.metamask");
|
|
17071
|
+
try {
|
|
17072
|
+
if (typeof (targetWindow == null ? void 0 : targetWindow.removeEventListener) === "function") {
|
|
17073
|
+
targetWindow.removeEventListener("eip6963:announceProvider", handler);
|
|
17053
17074
|
}
|
|
17054
|
-
|
|
17055
|
-
|
|
17075
|
+
const hasMetaMask = providers.some(
|
|
17076
|
+
(provider) => {
|
|
17077
|
+
var _a4;
|
|
17078
|
+
return typeof ((_a4 = provider == null ? void 0 : provider.info) == null ? void 0 : _a4.rdns) === "string" && NATIVE_METAMASK_EIP6963_RDNS.has(provider.info.rdns);
|
|
17079
|
+
}
|
|
17080
|
+
);
|
|
17081
|
+
resolve(hasMetaMask);
|
|
17082
|
+
} catch (e) {
|
|
17083
|
+
resolve(false);
|
|
17084
|
+
}
|
|
17056
17085
|
}, 300);
|
|
17057
17086
|
});
|
|
17058
17087
|
}))();
|
|
@@ -17297,12 +17326,14 @@ var MetaMaskSDK = (() => {
|
|
|
17297
17326
|
|
|
17298
17327
|
// src/domain/utils/index.ts
|
|
17299
17328
|
function getVersion() {
|
|
17300
|
-
return
|
|
17329
|
+
return packageVersion;
|
|
17301
17330
|
}
|
|
17331
|
+
var packageVersion;
|
|
17302
17332
|
var init_utils3 = __esm({
|
|
17303
17333
|
"src/domain/utils/index.ts"() {
|
|
17304
17334
|
"use strict";
|
|
17305
17335
|
init_analytics();
|
|
17336
|
+
packageVersion = false ? "unknown" : "1.0.0";
|
|
17306
17337
|
}
|
|
17307
17338
|
});
|
|
17308
17339
|
|
|
@@ -25748,12 +25779,13 @@ var MetaMaskSDK = (() => {
|
|
|
25748
25779
|
__export(mwp_exports, {
|
|
25749
25780
|
MWPTransport: () => MWPTransport
|
|
25750
25781
|
});
|
|
25751
|
-
var DEFAULT_REQUEST_TIMEOUT3, 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;
|
|
25782
|
+
var DEFAULT_REQUEST_TIMEOUT3, 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;
|
|
25752
25783
|
var init_mwp = __esm({
|
|
25753
25784
|
"src/multichain/transports/mwp/index.ts"() {
|
|
25754
25785
|
"use strict";
|
|
25755
25786
|
init_dist3();
|
|
25756
25787
|
init_dist4();
|
|
25788
|
+
init_dist2();
|
|
25757
25789
|
init_domain();
|
|
25758
25790
|
init_utils4();
|
|
25759
25791
|
init_constants3();
|
|
@@ -25784,6 +25816,7 @@ var MetaMaskSDK = (() => {
|
|
|
25784
25816
|
this.dappClient = dappClient;
|
|
25785
25817
|
this.kvstore = kvstore;
|
|
25786
25818
|
this.options = options;
|
|
25819
|
+
__privateAdd(this, _MWPTransport_instances);
|
|
25787
25820
|
this.__pendingRequests = /* @__PURE__ */ new Map();
|
|
25788
25821
|
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
25789
25822
|
this.dappClient.on("message", this.handleMessage.bind(this));
|
|
@@ -25863,6 +25896,23 @@ var MetaMaskSDK = (() => {
|
|
|
25863
25896
|
const message = errorPayload instanceof Error ? errorPayload.message : JSON.stringify(errorPayload);
|
|
25864
25897
|
return rpcErrors.internal({ message });
|
|
25865
25898
|
}
|
|
25899
|
+
getResponseError(messagePayload) {
|
|
25900
|
+
if ("error" in messagePayload && messagePayload.error) {
|
|
25901
|
+
return messagePayload.error;
|
|
25902
|
+
}
|
|
25903
|
+
const { result } = messagePayload;
|
|
25904
|
+
if (typeof result === "object" && result !== null && "error" in result && result.error && this.isErrorPayload(result.error)) {
|
|
25905
|
+
return result.error;
|
|
25906
|
+
}
|
|
25907
|
+
return void 0;
|
|
25908
|
+
}
|
|
25909
|
+
isErrorPayload(errorPayload) {
|
|
25910
|
+
if (errorPayload instanceof Error) {
|
|
25911
|
+
return true;
|
|
25912
|
+
}
|
|
25913
|
+
const errorData = errorPayload;
|
|
25914
|
+
return typeof (errorData == null ? void 0 : errorData.code) === "number" && typeof (errorData == null ? void 0 : errorData.message) === "string";
|
|
25915
|
+
}
|
|
25866
25916
|
handleMessage(message) {
|
|
25867
25917
|
if (typeof message === "object" && message !== null) {
|
|
25868
25918
|
if ("data" in message) {
|
|
@@ -25871,9 +25921,10 @@ var MetaMaskSDK = (() => {
|
|
|
25871
25921
|
const request2 = this.pendingRequests.get(messagePayload.id);
|
|
25872
25922
|
if (request2) {
|
|
25873
25923
|
clearTimeout(request2.timeout);
|
|
25874
|
-
|
|
25924
|
+
const responseError = this.getResponseError(messagePayload);
|
|
25925
|
+
if (responseError) {
|
|
25875
25926
|
this.pendingRequests.delete(messagePayload.id);
|
|
25876
|
-
request2.reject(this.parseWalletError(
|
|
25927
|
+
request2.reject(this.parseWalletError(responseError));
|
|
25877
25928
|
return;
|
|
25878
25929
|
}
|
|
25879
25930
|
const requestWithName = __spreadProps(__spreadValues({}, messagePayload), {
|
|
@@ -25916,73 +25967,6 @@ var MetaMaskSDK = (() => {
|
|
|
25916
25967
|
}
|
|
25917
25968
|
}
|
|
25918
25969
|
}
|
|
25919
|
-
onResumeSuccess(resumeResolve, resumeReject, options) {
|
|
25920
|
-
return __async(this, null, function* () {
|
|
25921
|
-
var _a4, _b, _c, _d, _e, _f, _g;
|
|
25922
|
-
try {
|
|
25923
|
-
yield this.waitForWalletSessionIfNotCached();
|
|
25924
|
-
const sessionRequest = yield this.request({
|
|
25925
|
-
method: "wallet_getSession"
|
|
25926
|
-
});
|
|
25927
|
-
if (sessionRequest.error) {
|
|
25928
|
-
return resumeReject(new Error(sessionRequest.error.message));
|
|
25929
|
-
}
|
|
25930
|
-
let walletSession = sessionRequest.result;
|
|
25931
|
-
if (walletSession && options) {
|
|
25932
|
-
const currentScopes = Object.keys(
|
|
25933
|
-
(_a4 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a4 : {}
|
|
25934
|
-
);
|
|
25935
|
-
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
25936
|
-
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
25937
|
-
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
25938
|
-
currentScopes,
|
|
25939
|
-
proposedScopes,
|
|
25940
|
-
walletSession,
|
|
25941
|
-
proposedCaipAccountIds
|
|
25942
|
-
);
|
|
25943
|
-
if (options.forceRequest || !hasSameScopesAndAccounts) {
|
|
25944
|
-
const optionalScopes = addValidAccounts(
|
|
25945
|
-
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
25946
|
-
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
25947
|
-
);
|
|
25948
|
-
const sessionRequest2 = {
|
|
25949
|
-
optionalScopes
|
|
25950
|
-
};
|
|
25951
|
-
const response = yield this.request({
|
|
25952
|
-
method: "wallet_createSession",
|
|
25953
|
-
params: sessionRequest2
|
|
25954
|
-
});
|
|
25955
|
-
if (response.error) {
|
|
25956
|
-
return resumeReject(new Error(response.error.message));
|
|
25957
|
-
}
|
|
25958
|
-
walletSession = response.result;
|
|
25959
|
-
}
|
|
25960
|
-
} else if (!walletSession) {
|
|
25961
|
-
const optionalScopes = addValidAccounts(
|
|
25962
|
-
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
25963
|
-
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
25964
|
-
);
|
|
25965
|
-
const sessionRequest2 = { optionalScopes };
|
|
25966
|
-
const response = yield this.request({
|
|
25967
|
-
method: "wallet_createSession",
|
|
25968
|
-
params: sessionRequest2
|
|
25969
|
-
});
|
|
25970
|
-
if (response.error) {
|
|
25971
|
-
return resumeReject(new Error(response.error.message));
|
|
25972
|
-
}
|
|
25973
|
-
walletSession = response.result;
|
|
25974
|
-
}
|
|
25975
|
-
yield this.removeStoredPendingSessionRequest();
|
|
25976
|
-
this.notifyCallbacks({
|
|
25977
|
-
method: "wallet_sessionChanged",
|
|
25978
|
-
params: walletSession
|
|
25979
|
-
});
|
|
25980
|
-
return resumeResolve();
|
|
25981
|
-
} catch (err3) {
|
|
25982
|
-
return resumeReject(err3);
|
|
25983
|
-
}
|
|
25984
|
-
});
|
|
25985
|
-
}
|
|
25986
25970
|
init() {
|
|
25987
25971
|
return __async(this, null, function* () {
|
|
25988
25972
|
});
|
|
@@ -26023,7 +26007,6 @@ var MetaMaskSDK = (() => {
|
|
|
26023
26007
|
}
|
|
26024
26008
|
connect(options) {
|
|
26025
26009
|
return __async(this, null, function* () {
|
|
26026
|
-
const { dappClient } = this;
|
|
26027
26010
|
const session = yield this.getActiveSession();
|
|
26028
26011
|
if (session) {
|
|
26029
26012
|
logger("active session found", {
|
|
@@ -26032,116 +26015,11 @@ var MetaMaskSDK = (() => {
|
|
|
26032
26015
|
expiresAt: session.expiresAt
|
|
26033
26016
|
});
|
|
26034
26017
|
}
|
|
26035
|
-
const
|
|
26036
|
-
|
|
26037
|
-
let initialConnectionMessageHandler;
|
|
26038
|
-
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
26039
|
-
let connection;
|
|
26040
|
-
if (session) {
|
|
26041
|
-
connection = new Promise((resumeResolve, resumeReject) => {
|
|
26042
|
-
var _a4;
|
|
26043
|
-
if (this.dappClient.state === "CONNECTED") {
|
|
26044
|
-
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
26045
|
-
} else {
|
|
26046
|
-
this.dappClient.once("connected", () => __async(this, null, function* () {
|
|
26047
|
-
this.onResumeSuccess(resumeResolve, resumeReject, options);
|
|
26048
|
-
}));
|
|
26049
|
-
dappClient.resume((_a4 = session == null ? void 0 : session.id) != null ? _a4 : "");
|
|
26050
|
-
}
|
|
26051
|
-
});
|
|
26052
|
-
} else {
|
|
26053
|
-
connection = new Promise(
|
|
26054
|
-
(resolveConnection, rejectConnection) => {
|
|
26055
|
-
var _a4, _b;
|
|
26056
|
-
const optionalScopes = addValidAccounts(
|
|
26057
|
-
getOptionalScopes((_a4 = options == null ? void 0 : options.scopes) != null ? _a4 : []),
|
|
26058
|
-
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
26059
|
-
);
|
|
26060
|
-
const sessionRequest = {
|
|
26061
|
-
optionalScopes,
|
|
26062
|
-
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
26063
|
-
};
|
|
26064
|
-
const request2 = {
|
|
26065
|
-
jsonrpc: "2.0",
|
|
26066
|
-
id: String(getUniqueRequestId()),
|
|
26067
|
-
method: "wallet_createSession",
|
|
26068
|
-
params: sessionRequest
|
|
26069
|
-
};
|
|
26070
|
-
initialConnectionMessageHandler = (message) => __async(this, null, function* () {
|
|
26071
|
-
if (typeof message !== "object" || message === null) {
|
|
26072
|
-
return;
|
|
26073
|
-
}
|
|
26074
|
-
if (!("data" in message)) {
|
|
26075
|
-
return;
|
|
26076
|
-
}
|
|
26077
|
-
const messagePayload = message.data;
|
|
26078
|
-
const isMatchingId = messagePayload.id === request2.id;
|
|
26079
|
-
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
26080
|
-
if (!isMatchingId && !isMatchingMethod) {
|
|
26081
|
-
return;
|
|
26082
|
-
}
|
|
26083
|
-
if (messagePayload.error) {
|
|
26084
|
-
return rejectConnection(
|
|
26085
|
-
this.parseWalletError(messagePayload.error)
|
|
26086
|
-
);
|
|
26087
|
-
}
|
|
26088
|
-
yield this.storeWalletSession(
|
|
26089
|
-
request2,
|
|
26090
|
-
messagePayload
|
|
26091
|
-
);
|
|
26092
|
-
yield this.removeStoredPendingSessionRequest();
|
|
26093
|
-
this.notifyCallbacks(messagePayload);
|
|
26094
|
-
return resolveConnection();
|
|
26095
|
-
});
|
|
26096
|
-
this.dappClient.on("message", initialConnectionMessageHandler);
|
|
26097
|
-
const platformType = getPlatformType();
|
|
26098
|
-
const isQRCodeFlow = [
|
|
26099
|
-
"web-desktop" /* DesktopWeb */,
|
|
26100
|
-
"nodejs" /* NonBrowser */
|
|
26101
|
-
].includes(platformType);
|
|
26102
|
-
const initialPayload = {
|
|
26103
|
-
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
26104
|
-
data: request2
|
|
26105
|
-
};
|
|
26106
|
-
dappClient.connect({
|
|
26107
|
-
mode: "trusted",
|
|
26108
|
-
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
26109
|
-
}).then(() => __async(this, null, function* () {
|
|
26110
|
-
if (isQRCodeFlow) {
|
|
26111
|
-
return dappClient.sendRequest(initialPayload);
|
|
26112
|
-
}
|
|
26113
|
-
return void 0;
|
|
26114
|
-
})).catch((error) => {
|
|
26115
|
-
if (initialConnectionMessageHandler) {
|
|
26116
|
-
this.dappClient.off(
|
|
26117
|
-
"message",
|
|
26118
|
-
initialConnectionMessageHandler
|
|
26119
|
-
);
|
|
26120
|
-
}
|
|
26121
|
-
rejectConnection(error);
|
|
26122
|
-
});
|
|
26123
|
-
}
|
|
26124
|
-
);
|
|
26125
|
-
}
|
|
26126
|
-
timeout = setTimeout(
|
|
26127
|
-
() => {
|
|
26128
|
-
reject(new TransportTimeoutError());
|
|
26129
|
-
},
|
|
26130
|
-
storedSessionRequestBeforeConnectionAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
26131
|
-
);
|
|
26132
|
-
connection.then(resolve).catch(reject);
|
|
26133
|
-
}));
|
|
26134
|
-
return connectionPromise.catch((error) => __async(this, null, function* () {
|
|
26018
|
+
const connection = session ? __privateMethod(this, _MWPTransport_instances, resumeSession_fn).call(this, session, options) : __privateMethod(this, _MWPTransport_instances, startSession_fn).call(this, options);
|
|
26019
|
+
return connection.catch((error) => __async(this, null, function* () {
|
|
26135
26020
|
yield this.dappClient.disconnect();
|
|
26136
26021
|
throw error;
|
|
26137
26022
|
})).finally(() => {
|
|
26138
|
-
if (timeout) {
|
|
26139
|
-
clearTimeout(timeout);
|
|
26140
|
-
}
|
|
26141
|
-
if (initialConnectionMessageHandler) {
|
|
26142
|
-
this.dappClient.off("message", initialConnectionMessageHandler);
|
|
26143
|
-
initialConnectionMessageHandler = void 0;
|
|
26144
|
-
}
|
|
26145
26023
|
this.removeStoredPendingSessionRequest();
|
|
26146
26024
|
});
|
|
26147
26025
|
});
|
|
@@ -26400,6 +26278,188 @@ var MetaMaskSDK = (() => {
|
|
|
26400
26278
|
});
|
|
26401
26279
|
}
|
|
26402
26280
|
};
|
|
26281
|
+
_MWPTransport_instances = new WeakSet();
|
|
26282
|
+
onResumeHandler_fn = function(options) {
|
|
26283
|
+
return __async(this, null, function* () {
|
|
26284
|
+
var _a4, _b, _c, _d, _e, _f, _g;
|
|
26285
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
26286
|
+
const sessionResponse = yield this.request({ method: "wallet_getSession" });
|
|
26287
|
+
if (sessionResponse.error) {
|
|
26288
|
+
throw new Error(sessionResponse.error.message);
|
|
26289
|
+
}
|
|
26290
|
+
let walletSession = sessionResponse.result;
|
|
26291
|
+
if (walletSession && options) {
|
|
26292
|
+
const currentScopes = Object.keys(
|
|
26293
|
+
(_a4 = walletSession == null ? void 0 : walletSession.sessionScopes) != null ? _a4 : {}
|
|
26294
|
+
);
|
|
26295
|
+
const proposedScopes = (_b = options == null ? void 0 : options.scopes) != null ? _b : [];
|
|
26296
|
+
const proposedCaipAccountIds = (_c = options == null ? void 0 : options.caipAccountIds) != null ? _c : [];
|
|
26297
|
+
const hasSameScopesAndAccounts = isSameScopesAndAccounts(
|
|
26298
|
+
currentScopes,
|
|
26299
|
+
proposedScopes,
|
|
26300
|
+
walletSession,
|
|
26301
|
+
proposedCaipAccountIds
|
|
26302
|
+
);
|
|
26303
|
+
if (options.forceRequest || !hasSameScopesAndAccounts) {
|
|
26304
|
+
const optionalScopes = addValidAccounts(
|
|
26305
|
+
getOptionalScopes((_d = options == null ? void 0 : options.scopes) != null ? _d : []),
|
|
26306
|
+
getValidAccounts((_e = options == null ? void 0 : options.caipAccountIds) != null ? _e : [])
|
|
26307
|
+
);
|
|
26308
|
+
const sessionRequest = {
|
|
26309
|
+
optionalScopes
|
|
26310
|
+
};
|
|
26311
|
+
const response = yield this.request({
|
|
26312
|
+
method: "wallet_createSession",
|
|
26313
|
+
params: sessionRequest
|
|
26314
|
+
});
|
|
26315
|
+
if (response.error) {
|
|
26316
|
+
throw new Error(response.error.message);
|
|
26317
|
+
}
|
|
26318
|
+
walletSession = response.result;
|
|
26319
|
+
}
|
|
26320
|
+
} else if (!walletSession) {
|
|
26321
|
+
const optionalScopes = addValidAccounts(
|
|
26322
|
+
getOptionalScopes((_f = options == null ? void 0 : options.scopes) != null ? _f : []),
|
|
26323
|
+
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
26324
|
+
);
|
|
26325
|
+
const sessionRequest = {
|
|
26326
|
+
optionalScopes
|
|
26327
|
+
};
|
|
26328
|
+
const response = yield this.request({
|
|
26329
|
+
method: "wallet_createSession",
|
|
26330
|
+
params: sessionRequest
|
|
26331
|
+
});
|
|
26332
|
+
if (response.error) {
|
|
26333
|
+
throw new Error(response.error.message);
|
|
26334
|
+
}
|
|
26335
|
+
walletSession = response.result;
|
|
26336
|
+
}
|
|
26337
|
+
yield this.removeStoredPendingSessionRequest();
|
|
26338
|
+
this.notifyCallbacks({
|
|
26339
|
+
method: "wallet_sessionChanged",
|
|
26340
|
+
params: walletSession
|
|
26341
|
+
});
|
|
26342
|
+
});
|
|
26343
|
+
};
|
|
26344
|
+
resumeSession_fn = function(session, options) {
|
|
26345
|
+
return __async(this, null, function* () {
|
|
26346
|
+
var _a4;
|
|
26347
|
+
const isContinuingPriorAttempt = (yield this.getStoredPendingSessionRequest()) !== null;
|
|
26348
|
+
const resumeDeferred = createDeferredPromise();
|
|
26349
|
+
const runOnResumeHandler = () => __async(this, null, function* () {
|
|
26350
|
+
try {
|
|
26351
|
+
resumeDeferred.resolve(yield __privateMethod(this, _MWPTransport_instances, onResumeHandler_fn).call(this, options));
|
|
26352
|
+
} catch (err3) {
|
|
26353
|
+
resumeDeferred.reject(err3);
|
|
26354
|
+
}
|
|
26355
|
+
});
|
|
26356
|
+
if (this.dappClient.state === "CONNECTED") {
|
|
26357
|
+
runOnResumeHandler();
|
|
26358
|
+
} else {
|
|
26359
|
+
this.dappClient.once("connected", runOnResumeHandler);
|
|
26360
|
+
this.dappClient.resume((_a4 = session.id) != null ? _a4 : "").catch((err3) => resumeDeferred.reject(err3));
|
|
26361
|
+
}
|
|
26362
|
+
const timeoutDeferred = createDeferredPromise();
|
|
26363
|
+
const timeout = setTimeout(
|
|
26364
|
+
() => timeoutDeferred.reject(new TransportTimeoutError()),
|
|
26365
|
+
isContinuingPriorAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
26366
|
+
);
|
|
26367
|
+
const cleanup = () => this.dappClient.off("connected", runOnResumeHandler);
|
|
26368
|
+
return Promise.race([
|
|
26369
|
+
resumeDeferred.promise,
|
|
26370
|
+
timeoutDeferred.promise
|
|
26371
|
+
]).finally(() => {
|
|
26372
|
+
clearTimeout(timeout);
|
|
26373
|
+
cleanup();
|
|
26374
|
+
});
|
|
26375
|
+
});
|
|
26376
|
+
};
|
|
26377
|
+
startSession_fn = function(options) {
|
|
26378
|
+
return __async(this, null, function* () {
|
|
26379
|
+
var _a4, _b;
|
|
26380
|
+
const { dappClient } = this;
|
|
26381
|
+
const isContinuingPriorAttempt = (yield this.getStoredPendingSessionRequest()) !== null;
|
|
26382
|
+
const connDeferred = createDeferredPromise();
|
|
26383
|
+
const optionalScopes = addValidAccounts(
|
|
26384
|
+
getOptionalScopes((_a4 = options == null ? void 0 : options.scopes) != null ? _a4 : []),
|
|
26385
|
+
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
26386
|
+
);
|
|
26387
|
+
const sessionRequest = {
|
|
26388
|
+
optionalScopes,
|
|
26389
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
26390
|
+
};
|
|
26391
|
+
const request2 = {
|
|
26392
|
+
jsonrpc: "2.0",
|
|
26393
|
+
id: String(getUniqueRequestId()),
|
|
26394
|
+
method: "wallet_createSession",
|
|
26395
|
+
params: sessionRequest
|
|
26396
|
+
};
|
|
26397
|
+
let handler;
|
|
26398
|
+
const removeHandler = () => {
|
|
26399
|
+
if (handler) {
|
|
26400
|
+
this.dappClient.off("message", handler);
|
|
26401
|
+
handler = void 0;
|
|
26402
|
+
}
|
|
26403
|
+
};
|
|
26404
|
+
handler = (message) => __async(this, null, function* () {
|
|
26405
|
+
if (typeof message !== "object" || message === null) {
|
|
26406
|
+
return;
|
|
26407
|
+
}
|
|
26408
|
+
if (!("data" in message)) {
|
|
26409
|
+
return;
|
|
26410
|
+
}
|
|
26411
|
+
const messagePayload = message.data;
|
|
26412
|
+
const isMatchingId = messagePayload.id === request2.id;
|
|
26413
|
+
const isMatchingMethod = messagePayload.method === "wallet_createSession" || messagePayload.method === "wallet_sessionChanged";
|
|
26414
|
+
if (!isMatchingId && !isMatchingMethod) {
|
|
26415
|
+
return;
|
|
26416
|
+
}
|
|
26417
|
+
const responseError = this.getResponseError(messagePayload);
|
|
26418
|
+
if (responseError) {
|
|
26419
|
+
connDeferred.reject(this.parseWalletError(responseError));
|
|
26420
|
+
return;
|
|
26421
|
+
}
|
|
26422
|
+
yield this.storeWalletSession(
|
|
26423
|
+
request2,
|
|
26424
|
+
messagePayload
|
|
26425
|
+
);
|
|
26426
|
+
yield this.removeStoredPendingSessionRequest();
|
|
26427
|
+
this.notifyCallbacks(messagePayload);
|
|
26428
|
+
connDeferred.resolve();
|
|
26429
|
+
});
|
|
26430
|
+
this.dappClient.on("message", handler);
|
|
26431
|
+
const platformType = getPlatformType();
|
|
26432
|
+
const isQRCodeFlow = [
|
|
26433
|
+
"web-desktop" /* DesktopWeb */,
|
|
26434
|
+
"nodejs" /* NonBrowser */
|
|
26435
|
+
].includes(platformType);
|
|
26436
|
+
const initialPayload = {
|
|
26437
|
+
name: MULTICHAIN_PROVIDER_STREAM_NAME,
|
|
26438
|
+
data: request2
|
|
26439
|
+
};
|
|
26440
|
+
dappClient.connect({
|
|
26441
|
+
mode: "trusted",
|
|
26442
|
+
initialPayload: isQRCodeFlow ? void 0 : initialPayload
|
|
26443
|
+
}).then(() => __async(this, null, function* () {
|
|
26444
|
+
if (isQRCodeFlow) {
|
|
26445
|
+
return dappClient.sendRequest(initialPayload);
|
|
26446
|
+
}
|
|
26447
|
+
return void 0;
|
|
26448
|
+
})).catch((error) => connDeferred.reject(error));
|
|
26449
|
+
const timeoutDeferred = createDeferredPromise();
|
|
26450
|
+
const timeout = setTimeout(
|
|
26451
|
+
() => timeoutDeferred.reject(new TransportTimeoutError()),
|
|
26452
|
+
isContinuingPriorAttempt ? this.options.resumeTimeout : this.options.connectionTimeout
|
|
26453
|
+
);
|
|
26454
|
+
return Promise.race([
|
|
26455
|
+
connDeferred.promise,
|
|
26456
|
+
timeoutDeferred.promise
|
|
26457
|
+
]).finally(() => {
|
|
26458
|
+
clearTimeout(timeout);
|
|
26459
|
+
removeHandler();
|
|
26460
|
+
});
|
|
26461
|
+
});
|
|
26462
|
+
};
|
|
26403
26463
|
}
|
|
26404
26464
|
});
|
|
26405
26465
|
|
|
@@ -37700,9 +37760,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
37700
37760
|
mount() {
|
|
37701
37761
|
var _a4;
|
|
37702
37762
|
const { options } = this;
|
|
37703
|
-
const modal = document.createElement(
|
|
37704
|
-
"mm-install-modal"
|
|
37705
|
-
);
|
|
37763
|
+
const modal = document.createElement("mm-install-modal");
|
|
37706
37764
|
modal.showInstallModal = options.showInstallModal;
|
|
37707
37765
|
modal.addEventListener("close", (ev) => {
|
|
37708
37766
|
const { detail } = ev;
|
|
@@ -37886,6 +37944,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
37886
37944
|
// src/index.browser.ts
|
|
37887
37945
|
var index_browser_exports = {};
|
|
37888
37946
|
__export(index_browser_exports, {
|
|
37947
|
+
EIP1193_PASSTHROUGH_METHODS: () => EIP1193_PASSTHROUGH_METHODS,
|
|
37889
37948
|
EventEmitter: () => EventEmitter2,
|
|
37890
37949
|
Modal: () => Modal,
|
|
37891
37950
|
MultichainCore: () => MultichainCore,
|
|
@@ -37913,7 +37972,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
37913
37972
|
isEnabled: () => isEnabled,
|
|
37914
37973
|
isMetamaskExtensionInstalled: () => isMetamaskExtensionInstalled,
|
|
37915
37974
|
isRejectionError: () => isRejectionError,
|
|
37916
|
-
isSecure: () => isSecure
|
|
37975
|
+
isSecure: () => isSecure,
|
|
37976
|
+
packageVersion: () => packageVersion
|
|
37917
37977
|
});
|
|
37918
37978
|
|
|
37919
37979
|
// src/polyfills/buffer-shim.ts
|
|
@@ -38531,6 +38591,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38531
38591
|
|
|
38532
38592
|
// src/multichain/index.ts
|
|
38533
38593
|
init_dist3();
|
|
38594
|
+
init_dist2();
|
|
38534
38595
|
|
|
38535
38596
|
// src/config/index.ts
|
|
38536
38597
|
var MWP_RELAY_URL = "wss://mm-sdk-relay.api.cx.metamask.io/connection/websocket";
|
|
@@ -38683,6 +38744,9 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38683
38744
|
invokeMethod(options) {
|
|
38684
38745
|
return __async(this, null, function* () {
|
|
38685
38746
|
const { method } = options.request;
|
|
38747
|
+
if (EIP1193_PASSTHROUGH_METHODS.has(method)) {
|
|
38748
|
+
return this.handleWithEip1193Passthrough(options);
|
|
38749
|
+
}
|
|
38686
38750
|
if (RPC_HANDLED_METHODS.has(method)) {
|
|
38687
38751
|
return this.handleWithRpcNode(options);
|
|
38688
38752
|
}
|
|
@@ -38692,6 +38756,29 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38692
38756
|
return this.handleWithWallet(options);
|
|
38693
38757
|
});
|
|
38694
38758
|
}
|
|
38759
|
+
/**
|
|
38760
|
+
* Forwards EIP-1193 / legacy provider methods (e.g. `wallet_addEthereumChain`,
|
|
38761
|
+
* `wallet_switchEthereumChain`, `eth_accounts`) directly to the underlying
|
|
38762
|
+
* transport's `sendEip1193Message`, bypassing the multichain
|
|
38763
|
+
* `wallet_invokeMethod` envelope. These methods are wallet-side concerns the
|
|
38764
|
+
* Multichain API does not model, so we forward the raw `{ method, params }`
|
|
38765
|
+
* payload and return the wallet's full JSON-RPC response envelope unchanged.
|
|
38766
|
+
*
|
|
38767
|
+
* Analytics tracking is intentionally skipped here: ecosystem clients
|
|
38768
|
+
* (e.g. `connect-evm`) emit their own `wallet_action_*` events around these
|
|
38769
|
+
* passthrough calls, and adding router-level tracking would double-count.
|
|
38770
|
+
*
|
|
38771
|
+
* @param options
|
|
38772
|
+
*/
|
|
38773
|
+
handleWithEip1193Passthrough(options) {
|
|
38774
|
+
return __async(this, null, function* () {
|
|
38775
|
+
const response = yield this.transport.sendEip1193Message({
|
|
38776
|
+
method: options.request.method,
|
|
38777
|
+
params: options.request.params
|
|
38778
|
+
});
|
|
38779
|
+
return response.result;
|
|
38780
|
+
});
|
|
38781
|
+
}
|
|
38695
38782
|
/**
|
|
38696
38783
|
* Forwards the request directly to the wallet via the transport.
|
|
38697
38784
|
*
|
|
@@ -38723,14 +38810,6 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38723
38810
|
}), 10);
|
|
38724
38811
|
}
|
|
38725
38812
|
const response = yield request2;
|
|
38726
|
-
if (response.error) {
|
|
38727
|
-
const { error } = response;
|
|
38728
|
-
throw new RPCInvokeMethodErr(
|
|
38729
|
-
`RPC Request failed with code ${error.code}: ${error.message}`,
|
|
38730
|
-
error.code,
|
|
38731
|
-
error.message
|
|
38732
|
-
);
|
|
38733
|
-
}
|
|
38734
38813
|
return response.result;
|
|
38735
38814
|
}));
|
|
38736
38815
|
});
|
|
@@ -38843,7 +38922,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38843
38922
|
init_dist3();
|
|
38844
38923
|
init_utils4();
|
|
38845
38924
|
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
38846
|
-
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
38925
|
+
var _notificationCallbacks, _transport, _defaultRequestOptions, _pendingRequests, _handleResponseListener, _handleNotificationListener, _DefaultTransport_instances, notifyCallbacks_fn, parseWalletError_fn, isMetamaskProviderEvent_fn, handleResponse_fn, handleNotification_fn, setupMessageListener_fn, init_fn;
|
|
38847
38926
|
var DefaultTransport = class {
|
|
38848
38927
|
constructor() {
|
|
38849
38928
|
__privateAdd(this, _DefaultTransport_instances);
|
|
@@ -38979,7 +39058,11 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
38979
39058
|
}
|
|
38980
39059
|
request(_0) {
|
|
38981
39060
|
return __async(this, arguments, function* (request2, options = __privateGet(this, _defaultRequestOptions)) {
|
|
38982
|
-
|
|
39061
|
+
const response = yield __privateGet(this, _transport).request(request2, options);
|
|
39062
|
+
if (response.error) {
|
|
39063
|
+
throw __privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error);
|
|
39064
|
+
}
|
|
39065
|
+
return response;
|
|
38983
39066
|
});
|
|
38984
39067
|
}
|
|
38985
39068
|
onNotification(callback) {
|
|
@@ -39023,6 +39106,16 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39023
39106
|
}
|
|
39024
39107
|
}
|
|
39025
39108
|
};
|
|
39109
|
+
parseWalletError_fn = function(errorPayload) {
|
|
39110
|
+
const errorData = errorPayload;
|
|
39111
|
+
const error = new Error(
|
|
39112
|
+
typeof errorData.message === "string" ? errorData.message : "Request failed"
|
|
39113
|
+
);
|
|
39114
|
+
if (typeof errorData.code === "number") {
|
|
39115
|
+
error.code = errorData.code;
|
|
39116
|
+
}
|
|
39117
|
+
return error;
|
|
39118
|
+
};
|
|
39026
39119
|
isMetamaskProviderEvent_fn = function(event) {
|
|
39027
39120
|
var _a4, _b;
|
|
39028
39121
|
return ((_b = (_a4 = event == null ? void 0 : event.data) == null ? void 0 : _a4.data) == null ? void 0 : _b.name) === "metamask-provider" && // eslint-disable-next-line no-restricted-globals
|
|
@@ -39045,13 +39138,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39045
39138
|
__privateGet(this, _pendingRequests).delete(responseId);
|
|
39046
39139
|
const response = responseData;
|
|
39047
39140
|
if ("error" in response && response.error) {
|
|
39048
|
-
|
|
39049
|
-
response.error.message || "Request failed"
|
|
39050
|
-
);
|
|
39051
|
-
if (typeof response.error.code === "number") {
|
|
39052
|
-
error.code = response.error.code;
|
|
39053
|
-
}
|
|
39054
|
-
pendingRequest.reject(error);
|
|
39141
|
+
pendingRequest.reject(__privateMethod(this, _DefaultTransport_instances, parseWalletError_fn).call(this, response.error));
|
|
39055
39142
|
} else {
|
|
39056
39143
|
pendingRequest.resolve(response);
|
|
39057
39144
|
}
|
|
@@ -39089,22 +39176,21 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39089
39176
|
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
39090
39177
|
init_dist4();
|
|
39091
39178
|
init_utils4();
|
|
39092
|
-
var _notificationCallbacks2, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
39179
|
+
var _notificationCallbacks2, _getTransport, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
39093
39180
|
var MultichainApiClientWrapperTransport = class {
|
|
39094
|
-
constructor(metamaskConnectMultichain) {
|
|
39181
|
+
constructor(metamaskConnectMultichain, getTransport) {
|
|
39095
39182
|
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
39096
39183
|
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
39097
39184
|
__privateAdd(this, _notificationCallbacks2, /* @__PURE__ */ new Set());
|
|
39185
|
+
__privateAdd(this, _getTransport);
|
|
39186
|
+
__privateSet(this, _getTransport, getTransport);
|
|
39098
39187
|
}
|
|
39099
39188
|
isTransportDefined() {
|
|
39100
|
-
|
|
39101
|
-
return Boolean(this.metamaskConnectMultichain.transport);
|
|
39102
|
-
} catch (_error) {
|
|
39103
|
-
return false;
|
|
39104
|
-
}
|
|
39189
|
+
return __privateGet(this, _getTransport).call(this) !== void 0;
|
|
39105
39190
|
}
|
|
39106
39191
|
isTransportConnected() {
|
|
39107
|
-
|
|
39192
|
+
var _a4, _b;
|
|
39193
|
+
return (_b = (_a4 = __privateGet(this, _getTransport).call(this)) == null ? void 0 : _a4.isConnected()) != null ? _b : false;
|
|
39108
39194
|
}
|
|
39109
39195
|
clearNotificationCallbacks() {
|
|
39110
39196
|
__privateGet(this, _notificationCallbacks2).clear();
|
|
@@ -39120,10 +39206,11 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39120
39206
|
this.notificationListener = void 0;
|
|
39121
39207
|
}
|
|
39122
39208
|
setupTransportNotificationListener() {
|
|
39123
|
-
|
|
39209
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
39210
|
+
if (!transport || this.notificationListener) {
|
|
39124
39211
|
return;
|
|
39125
39212
|
}
|
|
39126
|
-
this.notificationListener =
|
|
39213
|
+
this.notificationListener = transport.onNotification(
|
|
39127
39214
|
this.notifyCallbacks.bind(this)
|
|
39128
39215
|
);
|
|
39129
39216
|
}
|
|
@@ -39173,6 +39260,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39173
39260
|
}
|
|
39174
39261
|
};
|
|
39175
39262
|
_notificationCallbacks2 = new WeakMap();
|
|
39263
|
+
_getTransport = new WeakMap();
|
|
39176
39264
|
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
39177
39265
|
walletCreateSession_fn = function(request2) {
|
|
39178
39266
|
return __async(this, null, function* () {
|
|
@@ -39196,14 +39284,19 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39196
39284
|
accounts,
|
|
39197
39285
|
createSessionParams.sessionProperties
|
|
39198
39286
|
);
|
|
39199
|
-
|
|
39287
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
39288
|
+
if (!transport) {
|
|
39289
|
+
throw new Error("Transport not initialized after connect");
|
|
39290
|
+
}
|
|
39291
|
+
return transport.request({
|
|
39200
39292
|
method: "wallet_getSession"
|
|
39201
39293
|
});
|
|
39202
39294
|
});
|
|
39203
39295
|
};
|
|
39204
39296
|
walletGetSession_fn = function(request2) {
|
|
39205
39297
|
return __async(this, null, function* () {
|
|
39206
|
-
|
|
39298
|
+
const transport = __privateGet(this, _getTransport).call(this);
|
|
39299
|
+
if (!(transport == null ? void 0 : transport.isConnected())) {
|
|
39207
39300
|
return {
|
|
39208
39301
|
jsonrpc: "2.0",
|
|
39209
39302
|
id: request2.id,
|
|
@@ -39212,7 +39305,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39212
39305
|
}
|
|
39213
39306
|
};
|
|
39214
39307
|
}
|
|
39215
|
-
return
|
|
39308
|
+
return transport.request({
|
|
39216
39309
|
method: "wallet_getSession"
|
|
39217
39310
|
});
|
|
39218
39311
|
});
|
|
@@ -39290,7 +39383,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39290
39383
|
analytics.enable();
|
|
39291
39384
|
});
|
|
39292
39385
|
}
|
|
39293
|
-
var _a3, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId,
|
|
39386
|
+
var _a3, _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;
|
|
39294
39387
|
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
39295
39388
|
constructor(options) {
|
|
39296
39389
|
var _a4, _b, _c, _d;
|
|
@@ -39303,9 +39396,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39303
39396
|
}),
|
|
39304
39397
|
analytics: normalizeAnalyticsOptions(options.analytics),
|
|
39305
39398
|
versions: __spreadValues({
|
|
39306
|
-
|
|
39307
|
-
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
39308
|
-
"connect-multichain": false ? "unknown" : "0.15.0"
|
|
39399
|
+
"connect-multichain": getVersion()
|
|
39309
39400
|
}, (_d = options.versions) != null ? _d : {})
|
|
39310
39401
|
});
|
|
39311
39402
|
super(allOptions);
|
|
@@ -39321,7 +39412,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39321
39412
|
__privateAdd(this, _anonId);
|
|
39322
39413
|
__privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a3 = this.options.dapp.url) != null ? _a3 : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
39323
39414
|
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(
|
|
39324
|
-
this
|
|
39415
|
+
this,
|
|
39416
|
+
() => __privateGet(this, _transport2)
|
|
39325
39417
|
));
|
|
39326
39418
|
__privateSet(this, _provider, getMultichainClient({
|
|
39327
39419
|
transport: __privateGet(this, _providerTransportWrapper)
|
|
@@ -39340,12 +39432,6 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39340
39432
|
get provider() {
|
|
39341
39433
|
return __privateGet(this, _provider);
|
|
39342
39434
|
}
|
|
39343
|
-
get transport() {
|
|
39344
|
-
if (!__privateGet(this, _transport2)) {
|
|
39345
|
-
throw new Error("Transport not initialized, establish connection first");
|
|
39346
|
-
}
|
|
39347
|
-
return __privateGet(this, _transport2);
|
|
39348
|
-
}
|
|
39349
39435
|
get dappClient() {
|
|
39350
39436
|
if (!__privateGet(this, _dappClient)) {
|
|
39351
39437
|
throw new Error("DappClient not initialized, establish connection first");
|
|
@@ -39359,6 +39445,9 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39359
39445
|
get storage() {
|
|
39360
39446
|
return this.options.storage;
|
|
39361
39447
|
}
|
|
39448
|
+
get version() {
|
|
39449
|
+
return getVersion();
|
|
39450
|
+
}
|
|
39362
39451
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
39363
39452
|
// If the singleton already exists, it merges the incoming options with the
|
|
39364
39453
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
@@ -39373,6 +39462,11 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39373
39462
|
const existing = globalObject[SINGLETON_KEY];
|
|
39374
39463
|
if (existing) {
|
|
39375
39464
|
const instance2 = yield existing;
|
|
39465
|
+
if (instance2.version !== getVersion()) {
|
|
39466
|
+
console.warn(
|
|
39467
|
+
`MetaMask Connect does not support using multiple versions of @metamask/connect-multichain. Attempted to create a new instance with version ${getVersion()}, but an existing ${instance2.version} singleton was already initialized. Using the existing ${instance2.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.`
|
|
39468
|
+
);
|
|
39469
|
+
}
|
|
39376
39470
|
instance2.mergeOptions(options);
|
|
39377
39471
|
if (instance2 instanceof _MetaMaskConnectMultichain) {
|
|
39378
39472
|
yield __privateMethod(_a4 = instance2, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a4);
|
|
@@ -39396,12 +39490,12 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39396
39490
|
}
|
|
39397
39491
|
yield __privateMethod(_a5 = instance2, _MetaMaskConnectMultichain_instances, init_fn2).call(_a5);
|
|
39398
39492
|
return instance2;
|
|
39399
|
-
}))()
|
|
39400
|
-
globalObject[SINGLETON_KEY] = instancePromise;
|
|
39401
|
-
instancePromise.catch((error) => {
|
|
39493
|
+
}))().catch((error) => {
|
|
39402
39494
|
globalObject[SINGLETON_KEY] = void 0;
|
|
39403
39495
|
console.error("Error initializing MetaMaskConnectMultichain", error);
|
|
39496
|
+
throw error;
|
|
39404
39497
|
});
|
|
39498
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
39405
39499
|
return instancePromise;
|
|
39406
39500
|
});
|
|
39407
39501
|
}
|
|
@@ -39461,9 +39555,9 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39461
39555
|
forceRequest
|
|
39462
39556
|
}).then(() => __async(this, null, function* () {
|
|
39463
39557
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
39464
|
-
return this.storage.
|
|
39558
|
+
return this.storage.setTransportType("mwp" /* MWP */);
|
|
39465
39559
|
}
|
|
39466
|
-
return this.storage.
|
|
39560
|
+
return this.storage.setTransportType("browser" /* Browser */);
|
|
39467
39561
|
})), scopes, transportType);
|
|
39468
39562
|
}
|
|
39469
39563
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
@@ -39492,11 +39586,6 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39492
39586
|
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
39493
39587
|
});
|
|
39494
39588
|
}
|
|
39495
|
-
emit(event, args) {
|
|
39496
|
-
var _a4, _b;
|
|
39497
|
-
(_b = (_a4 = this.options.transport) == null ? void 0 : _a4.onNotification) == null ? void 0 : _b.call(_a4, { method: event, params: args });
|
|
39498
|
-
super.emit(event, args);
|
|
39499
|
-
}
|
|
39500
39589
|
disconnect() {
|
|
39501
39590
|
return __async(this, arguments, function* (scopes = []) {
|
|
39502
39591
|
var _a4, _b, _c;
|
|
@@ -39506,7 +39595,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39506
39595
|
);
|
|
39507
39596
|
yield (_a4 = __privateGet(this, _transport2)) == null ? void 0 : _a4.disconnect(scopes);
|
|
39508
39597
|
if (remainingScopes.length === 0) {
|
|
39509
|
-
yield this.storage.
|
|
39598
|
+
yield this.storage.removeTransportType();
|
|
39510
39599
|
if (__privateGet(this, _transportType) !== "browser" /* Browser */) {
|
|
39511
39600
|
yield (_b = __privateGet(this, _listener)) == null ? void 0 : _b.call(this);
|
|
39512
39601
|
(_c = __privateGet(this, _beforeUnloadListener)) == null ? void 0 : _c.call(this);
|
|
@@ -39524,7 +39613,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39524
39613
|
invokeMethod(request2) {
|
|
39525
39614
|
return __async(this, null, function* () {
|
|
39526
39615
|
var _a4;
|
|
39527
|
-
const
|
|
39616
|
+
const transport = __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this);
|
|
39617
|
+
const { options } = this;
|
|
39528
39618
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
39529
39619
|
const requestRouter = new RequestRouter(
|
|
39530
39620
|
transport,
|
|
@@ -39543,7 +39633,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39543
39633
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
39544
39634
|
if (shouldOpenDeeplink) {
|
|
39545
39635
|
setTimeout(() => __async(this, null, function* () {
|
|
39546
|
-
const session = yield this.
|
|
39636
|
+
const session = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).getActiveSession();
|
|
39547
39637
|
if (!session) {
|
|
39548
39638
|
throw new Error("No active session found");
|
|
39549
39639
|
}
|
|
@@ -39567,10 +39657,13 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39567
39657
|
this.emit("wallet_sessionChanged", emptySession);
|
|
39568
39658
|
return;
|
|
39569
39659
|
}
|
|
39570
|
-
const response = yield this.
|
|
39660
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
39571
39661
|
method: "wallet_getSession"
|
|
39572
39662
|
});
|
|
39573
|
-
this.emit(
|
|
39663
|
+
this.emit(
|
|
39664
|
+
"wallet_sessionChanged",
|
|
39665
|
+
(_b = response.result) != null ? _b : emptySession
|
|
39666
|
+
);
|
|
39574
39667
|
});
|
|
39575
39668
|
}
|
|
39576
39669
|
};
|
|
@@ -39582,8 +39675,14 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39582
39675
|
_transportType = new WeakMap();
|
|
39583
39676
|
_listener = new WeakMap();
|
|
39584
39677
|
_anonId = new WeakMap();
|
|
39585
|
-
_sdkInfo = new WeakMap();
|
|
39586
39678
|
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
39679
|
+
transportOrThrow_fn = function() {
|
|
39680
|
+
if (!__privateGet(this, _transport2)) {
|
|
39681
|
+
throw new Error("Transport not initialized, establish connection first");
|
|
39682
|
+
}
|
|
39683
|
+
return __privateGet(this, _transport2);
|
|
39684
|
+
};
|
|
39685
|
+
_sdkInfo = new WeakMap();
|
|
39587
39686
|
setupAnalytics_fn = function() {
|
|
39588
39687
|
return __async(this, null, function* () {
|
|
39589
39688
|
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
@@ -39609,7 +39708,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39609
39708
|
};
|
|
39610
39709
|
getStoredTransport_fn = function() {
|
|
39611
39710
|
return __async(this, null, function* () {
|
|
39612
|
-
const transportType = yield this.storage.
|
|
39711
|
+
const transportType = yield this.storage.getTransportType();
|
|
39613
39712
|
const hasExtensionInstalled = yield hasExtension();
|
|
39614
39713
|
if (transportType) {
|
|
39615
39714
|
if (transportType === "browser" /* Browser */) {
|
|
@@ -39637,7 +39736,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39637
39736
|
));
|
|
39638
39737
|
return apiTransport;
|
|
39639
39738
|
}
|
|
39640
|
-
yield this.storage.
|
|
39739
|
+
yield this.storage.removeTransportType();
|
|
39641
39740
|
}
|
|
39642
39741
|
return void 0;
|
|
39643
39742
|
});
|
|
@@ -39647,15 +39746,15 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39647
39746
|
var _a4;
|
|
39648
39747
|
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
39649
39748
|
if (transport) {
|
|
39650
|
-
if (!
|
|
39749
|
+
if (!transport.isConnected()) {
|
|
39651
39750
|
this.status = "connecting";
|
|
39652
|
-
yield
|
|
39751
|
+
yield transport.connect();
|
|
39653
39752
|
}
|
|
39654
39753
|
this.status = "connected";
|
|
39655
39754
|
if (__privateGet(this, _transportType) === "mwp" /* MWP */) {
|
|
39656
|
-
yield this.storage.
|
|
39755
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
39657
39756
|
} else {
|
|
39658
|
-
yield this.storage.
|
|
39757
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
39659
39758
|
}
|
|
39660
39759
|
} else {
|
|
39661
39760
|
this.status = "loaded";
|
|
@@ -39664,7 +39763,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39664
39763
|
if (hasExtensionInstalled && preferExtension) {
|
|
39665
39764
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this, { persist: false });
|
|
39666
39765
|
try {
|
|
39667
|
-
yield this.
|
|
39766
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).init();
|
|
39668
39767
|
} catch (error) {
|
|
39669
39768
|
console.error("Passive init failed:", error);
|
|
39670
39769
|
}
|
|
@@ -39688,7 +39787,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39688
39787
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
39689
39788
|
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
39690
39789
|
} catch (error) {
|
|
39691
|
-
yield this.storage.
|
|
39790
|
+
yield this.storage.removeTransportType();
|
|
39692
39791
|
this.status = "pending";
|
|
39693
39792
|
logger2("MetaMaskSDK error during initialization", error);
|
|
39694
39793
|
}
|
|
@@ -39734,17 +39833,17 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39734
39833
|
__privateSet(this, _transport2, apiTransport);
|
|
39735
39834
|
__privateSet(this, _transportType, "mwp" /* MWP */);
|
|
39736
39835
|
__privateGet(this, _providerTransportWrapper).setupTransportNotificationListener();
|
|
39737
|
-
__privateSet(this, _listener,
|
|
39836
|
+
__privateSet(this, _listener, apiTransport.onNotification(
|
|
39738
39837
|
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
39739
39838
|
));
|
|
39740
|
-
yield this.storage.
|
|
39839
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
39741
39840
|
});
|
|
39742
39841
|
};
|
|
39743
39842
|
onBeforeUnload_fn = function() {
|
|
39744
39843
|
return __async(this, null, function* () {
|
|
39745
39844
|
var _a4;
|
|
39746
39845
|
if ((_a4 = this.options.ui.factory.modal) == null ? void 0 : _a4.isMounted) {
|
|
39747
|
-
yield this.storage.
|
|
39846
|
+
yield this.storage.removeTransportType();
|
|
39748
39847
|
}
|
|
39749
39848
|
});
|
|
39750
39849
|
};
|
|
@@ -39761,70 +39860,65 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39761
39860
|
};
|
|
39762
39861
|
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
39763
39862
|
return __async(this, null, function* () {
|
|
39764
|
-
|
|
39765
|
-
|
|
39766
|
-
|
|
39767
|
-
|
|
39768
|
-
|
|
39769
|
-
|
|
39770
|
-
|
|
39771
|
-
|
|
39772
|
-
|
|
39773
|
-
|
|
39774
|
-
|
|
39775
|
-
|
|
39776
|
-
sessionRequest,
|
|
39777
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
39778
|
-
});
|
|
39779
|
-
}
|
|
39780
|
-
);
|
|
39781
|
-
(() => __async(this, null, function* () {
|
|
39782
|
-
var _a4;
|
|
39783
|
-
try {
|
|
39784
|
-
yield this.transport.connect({
|
|
39785
|
-
scopes,
|
|
39786
|
-
caipAccountIds,
|
|
39787
|
-
sessionProperties
|
|
39788
|
-
});
|
|
39789
|
-
yield this.options.ui.factory.unload();
|
|
39790
|
-
(_a4 = this.options.ui.factory.modal) == null ? void 0 : _a4.unmount();
|
|
39791
|
-
this.status = "connected";
|
|
39792
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
39793
|
-
} catch (error) {
|
|
39794
|
-
const { ProtocolError, ErrorCode: ErrorCode4 } = yield Promise.resolve().then(() => __toESM(require_dist()));
|
|
39795
|
-
if (error instanceof ProtocolError) {
|
|
39796
|
-
if (error.code !== ErrorCode4.REQUEST_EXPIRED) {
|
|
39797
|
-
this.status = "disconnected";
|
|
39798
|
-
yield this.options.ui.factory.unload(error);
|
|
39799
|
-
reject(error);
|
|
39800
|
-
}
|
|
39801
|
-
} else {
|
|
39802
|
-
this.status = "disconnected";
|
|
39803
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
39804
|
-
yield this.options.ui.factory.unload(normalizedError);
|
|
39805
|
-
reject(normalizedError);
|
|
39806
|
-
}
|
|
39807
|
-
}
|
|
39808
|
-
}))().catch(() => {
|
|
39809
|
-
});
|
|
39863
|
+
const completion = createDeferredPromise();
|
|
39864
|
+
const createConnectionRequest = () => __async(this, null, function* () {
|
|
39865
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
39866
|
+
yield this.dappClient.disconnect();
|
|
39867
|
+
}
|
|
39868
|
+
const sessionRequestDeferred = createDeferredPromise();
|
|
39869
|
+
this.dappClient.on(
|
|
39870
|
+
"session_request",
|
|
39871
|
+
(sessionRequest) => {
|
|
39872
|
+
sessionRequestDeferred.resolve({
|
|
39873
|
+
sessionRequest,
|
|
39874
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
39810
39875
|
});
|
|
39811
|
-
}
|
|
39812
|
-
|
|
39813
|
-
|
|
39814
|
-
|
|
39815
|
-
|
|
39816
|
-
|
|
39817
|
-
|
|
39818
|
-
|
|
39876
|
+
}
|
|
39877
|
+
);
|
|
39878
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
39879
|
+
var _a4;
|
|
39880
|
+
yield this.options.ui.factory.unload();
|
|
39881
|
+
(_a4 = this.options.ui.factory.modal) == null ? void 0 : _a4.unmount();
|
|
39882
|
+
this.status = "connected";
|
|
39883
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
39884
|
+
})).catch((error) => __async(this, null, function* () {
|
|
39885
|
+
const { ProtocolError, ErrorCode: ErrorCode4 } = yield Promise.resolve().then(() => __toESM(require_dist()));
|
|
39886
|
+
if (error instanceof ProtocolError) {
|
|
39887
|
+
if (error.code !== ErrorCode4.REQUEST_EXPIRED) {
|
|
39888
|
+
this.status = "disconnected";
|
|
39889
|
+
yield this.options.ui.factory.unload(error);
|
|
39890
|
+
completion.reject(error);
|
|
39819
39891
|
}
|
|
39820
|
-
}
|
|
39821
|
-
|
|
39822
|
-
|
|
39892
|
+
} else {
|
|
39893
|
+
this.status = "disconnected";
|
|
39894
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
39895
|
+
yield this.options.ui.factory.unload(normalizedError);
|
|
39896
|
+
completion.reject(normalizedError);
|
|
39823
39897
|
}
|
|
39824
|
-
)
|
|
39825
|
-
|
|
39826
|
-
|
|
39898
|
+
}));
|
|
39899
|
+
return sessionRequestDeferred.promise;
|
|
39900
|
+
});
|
|
39901
|
+
this.options.ui.factory.renderInstallModal(
|
|
39902
|
+
desktopPreferred,
|
|
39903
|
+
createConnectionRequest,
|
|
39904
|
+
(error) => __async(this, null, function* () {
|
|
39905
|
+
if (error) {
|
|
39906
|
+
yield this.storage.removeTransportType();
|
|
39907
|
+
completion.reject(error);
|
|
39908
|
+
} else {
|
|
39909
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
39910
|
+
completion.resolve();
|
|
39911
|
+
}
|
|
39912
|
+
}),
|
|
39913
|
+
(uri) => {
|
|
39914
|
+
this.emit("display_uri", uri);
|
|
39915
|
+
}
|
|
39916
|
+
).catch((error) => {
|
|
39917
|
+
completion.reject(
|
|
39918
|
+
error instanceof Error ? error : new Error(String(error))
|
|
39919
|
+
);
|
|
39827
39920
|
});
|
|
39921
|
+
return completion.promise;
|
|
39828
39922
|
});
|
|
39829
39923
|
};
|
|
39830
39924
|
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
@@ -39840,39 +39934,37 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39840
39934
|
};
|
|
39841
39935
|
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
39842
39936
|
return __async(this, null, function* () {
|
|
39843
|
-
|
|
39844
|
-
|
|
39845
|
-
|
|
39846
|
-
|
|
39937
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
39938
|
+
yield this.dappClient.disconnect().catch(() => void 0);
|
|
39939
|
+
}
|
|
39940
|
+
const onSessionRequest = (sessionRequest) => {
|
|
39941
|
+
const connectionRequest = {
|
|
39942
|
+
sessionRequest,
|
|
39943
|
+
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
39944
|
+
};
|
|
39945
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
39946
|
+
this.emit("display_uri", deeplink);
|
|
39947
|
+
};
|
|
39948
|
+
this.dappClient.on("session_request", onSessionRequest);
|
|
39949
|
+
try {
|
|
39950
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({
|
|
39951
|
+
scopes,
|
|
39952
|
+
caipAccountIds,
|
|
39953
|
+
sessionProperties
|
|
39954
|
+
});
|
|
39955
|
+
this.status = "connected";
|
|
39956
|
+
yield this.storage.setTransportType("mwp" /* MWP */);
|
|
39957
|
+
} catch (error) {
|
|
39958
|
+
const { ProtocolError } = yield Promise.resolve().then(() => __toESM(require_dist()));
|
|
39959
|
+
this.status = "disconnected";
|
|
39960
|
+
yield this.storage.removeTransportType();
|
|
39961
|
+
if (error instanceof ProtocolError || error instanceof Error) {
|
|
39962
|
+
throw error;
|
|
39847
39963
|
}
|
|
39848
|
-
|
|
39849
|
-
|
|
39850
|
-
|
|
39851
|
-
|
|
39852
|
-
sessionRequest,
|
|
39853
|
-
metadata: __privateMethod(this, _MetaMaskConnectMultichain_instances, buildConnectionMetadata_fn).call(this)
|
|
39854
|
-
};
|
|
39855
|
-
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
39856
|
-
this.emit("display_uri", deeplink);
|
|
39857
|
-
}
|
|
39858
|
-
);
|
|
39859
|
-
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
39860
|
-
this.status = "connected";
|
|
39861
|
-
yield this.storage.setTransport("mwp" /* MWP */);
|
|
39862
|
-
resolve();
|
|
39863
|
-
})).catch((error) => __async(this, null, function* () {
|
|
39864
|
-
const { ProtocolError } = yield Promise.resolve().then(() => __toESM(require_dist()));
|
|
39865
|
-
if (error instanceof ProtocolError) {
|
|
39866
|
-
this.status = "disconnected";
|
|
39867
|
-
yield this.storage.removeTransport();
|
|
39868
|
-
reject(error);
|
|
39869
|
-
} else {
|
|
39870
|
-
this.status = "disconnected";
|
|
39871
|
-
yield this.storage.removeTransport();
|
|
39872
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
39873
|
-
}
|
|
39874
|
-
}));
|
|
39875
|
-
});
|
|
39964
|
+
throw new Error(String(error));
|
|
39965
|
+
} finally {
|
|
39966
|
+
this.dappClient.off("session_request", onSessionRequest);
|
|
39967
|
+
}
|
|
39876
39968
|
});
|
|
39877
39969
|
};
|
|
39878
39970
|
setupDefaultTransport_fn = function() {
|
|
@@ -39881,7 +39973,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39881
39973
|
return __privateGet(this, _transport2);
|
|
39882
39974
|
}
|
|
39883
39975
|
if (options == null ? void 0 : options.persist) {
|
|
39884
|
-
yield this.storage.
|
|
39976
|
+
yield this.storage.setTransportType("browser" /* Browser */);
|
|
39885
39977
|
}
|
|
39886
39978
|
const transport = new DefaultTransport();
|
|
39887
39979
|
__privateSet(this, _listener, transport.onNotification(
|
|
@@ -39914,7 +40006,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39914
40006
|
};
|
|
39915
40007
|
this.dappClient.on("message", dappClientMessageHandler);
|
|
39916
40008
|
let timeout;
|
|
39917
|
-
if (this.
|
|
40009
|
+
if (__privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).isConnected()) {
|
|
39918
40010
|
timeout = setTimeout(() => {
|
|
39919
40011
|
this.openSimpleDeeplinkIfNeeded();
|
|
39920
40012
|
}, 250);
|
|
@@ -39942,8 +40034,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
39942
40034
|
}
|
|
39943
40035
|
);
|
|
39944
40036
|
}
|
|
39945
|
-
return this.
|
|
39946
|
-
yield this.storage.
|
|
40037
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, transportOrThrow_fn).call(this).connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
40038
|
+
yield this.storage.removeTransportType();
|
|
39947
40039
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
39948
40040
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
39949
40041
|
})).finally(() => {
|
|
@@ -40009,7 +40101,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
40009
40101
|
};
|
|
40010
40102
|
if ((_a4 = __privateGet(this, _transport2)) == null ? void 0 : _a4.isConnected()) {
|
|
40011
40103
|
try {
|
|
40012
|
-
const response = yield this.
|
|
40104
|
+
const response = yield __privateGet(this, _transport2).request({
|
|
40013
40105
|
method: "wallet_getSession"
|
|
40014
40106
|
});
|
|
40015
40107
|
if (response.result) {
|
|
@@ -40103,14 +40195,14 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
40103
40195
|
super();
|
|
40104
40196
|
this.adapter = adapter;
|
|
40105
40197
|
}
|
|
40106
|
-
|
|
40198
|
+
getTransportType() {
|
|
40107
40199
|
return __async(this, null, function* () {
|
|
40108
40200
|
try {
|
|
40109
|
-
const
|
|
40110
|
-
if (!
|
|
40201
|
+
const transportType = yield this.adapter.get("multichain-transport");
|
|
40202
|
+
if (!transportType) {
|
|
40111
40203
|
return null;
|
|
40112
40204
|
}
|
|
40113
|
-
return getTransportType(
|
|
40205
|
+
return getTransportType(transportType);
|
|
40114
40206
|
} catch (err3) {
|
|
40115
40207
|
throw new StorageGetErr(
|
|
40116
40208
|
this.adapter.platform,
|
|
@@ -40120,10 +40212,10 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
40120
40212
|
}
|
|
40121
40213
|
});
|
|
40122
40214
|
}
|
|
40123
|
-
|
|
40215
|
+
setTransportType(transportType) {
|
|
40124
40216
|
return __async(this, null, function* () {
|
|
40125
40217
|
try {
|
|
40126
|
-
yield this.adapter.set("multichain-transport",
|
|
40218
|
+
yield this.adapter.set("multichain-transport", transportType);
|
|
40127
40219
|
} catch (err3) {
|
|
40128
40220
|
throw new StorageSetErr(
|
|
40129
40221
|
this.adapter.platform,
|
|
@@ -40133,7 +40225,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
40133
40225
|
}
|
|
40134
40226
|
});
|
|
40135
40227
|
}
|
|
40136
|
-
|
|
40228
|
+
removeTransportType() {
|
|
40137
40229
|
return __async(this, null, function* () {
|
|
40138
40230
|
try {
|
|
40139
40231
|
yield this.adapter.delete("multichain-transport");
|
|
@@ -40616,7 +40708,11 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
40616
40708
|
(_a5 = this.displayUriCallback) == null ? void 0 : _a5.call(this, newLink);
|
|
40617
40709
|
return newLink;
|
|
40618
40710
|
}),
|
|
40619
|
-
onClose:
|
|
40711
|
+
onClose: (shouldTerminate) => {
|
|
40712
|
+
this.onCloseModal(shouldTerminate).catch((error) => {
|
|
40713
|
+
console.error("Failed to close modal:", error);
|
|
40714
|
+
});
|
|
40715
|
+
},
|
|
40620
40716
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
40621
40717
|
createConnectionRequest,
|
|
40622
40718
|
onDisplayUri: this.displayUriCallback
|
|
@@ -40654,7 +40750,7 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
|
|
|
40654
40750
|
}
|
|
40655
40751
|
try {
|
|
40656
40752
|
const { defineCustomElements: defineCustomElements2 } = yield Promise.resolve().then(() => (init_loader2(), loader_exports));
|
|
40657
|
-
|
|
40753
|
+
defineCustomElements2();
|
|
40658
40754
|
} catch (error) {
|
|
40659
40755
|
console.error("Failed to load customElements:", error);
|
|
40660
40756
|
}
|