@metamask/connect-multichain 0.4.0 → 0.5.1
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 +33 -1
- package/dist/browser/es/connect-multichain.d.mts +26 -9
- package/dist/browser/es/connect-multichain.mjs +370 -100
- 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 +26 -9
- package/dist/browser/iife/connect-multichain.js +2829 -224
- 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 +26 -9
- package/dist/browser/umd/connect-multichain.js +370 -100
- 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 +26 -9
- package/dist/node/cjs/connect-multichain.js +364 -101
- 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 +26 -9
- package/dist/node/es/connect-multichain.mjs +363 -100
- 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 +26 -9
- package/dist/react-native/es/connect-multichain.mjs +357 -91
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/multichain/index.d.ts +4 -4
- 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 +4 -3
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/ui/types.d.ts +7 -0
- package/dist/src/domain/ui/types.d.ts.map +1 -1
- package/dist/src/domain/ui/types.js.map +1 -1
- package/dist/src/index.browser.d.ts +2 -1
- package/dist/src/index.browser.d.ts.map +1 -1
- package/dist/src/index.browser.js +5 -3
- package/dist/src/index.browser.js.map +1 -1
- package/dist/src/index.native.d.ts +2 -1
- package/dist/src/index.native.d.ts.map +1 -1
- package/dist/src/index.native.js +6 -4
- package/dist/src/index.native.js.map +1 -1
- package/dist/src/index.node.d.ts +1 -1
- package/dist/src/index.node.d.ts.map +1 -1
- package/dist/src/index.node.js +3 -3
- package/dist/src/index.node.js.map +1 -1
- package/dist/src/multichain/index.d.ts +8 -8
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +161 -101
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts +2 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +1 -0
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +21 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +159 -0
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -0
- package/dist/src/multichain/transports/mwp/index.d.ts +4 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +54 -2
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/polyfills/buffer-shim.d.ts +2 -0
- package/dist/src/polyfills/buffer-shim.d.ts.map +1 -0
- package/dist/src/polyfills/buffer-shim.js +22 -0
- package/dist/src/polyfills/buffer-shim.js.map +1 -0
- package/dist/src/ui/ModalFactory.d.ts +54 -0
- package/dist/src/ui/ModalFactory.d.ts.map +1 -0
- package/dist/src/ui/ModalFactory.js +171 -0
- package/dist/src/ui/ModalFactory.js.map +1 -0
- package/dist/src/ui/index.d.ts +14 -38
- package/dist/src/ui/index.d.ts.map +1 -1
- package/dist/src/ui/index.js +24 -142
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/index.native.d.ts +13 -0
- package/dist/src/ui/index.native.d.ts.map +1 -0
- package/dist/src/ui/{preload.native.js → index.native.js} +12 -6
- package/dist/src/ui/index.native.js.map +1 -0
- package/dist/src/ui/modals/base/AbstractInstallModal.d.ts.map +1 -1
- package/dist/src/ui/modals/base/AbstractInstallModal.js +0 -4
- package/dist/src/ui/modals/base/AbstractInstallModal.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +26 -9
- package/package.json +9 -3
- package/dist/src/ui/preload.native.d.ts +0 -5
- package/dist/src/ui/preload.native.d.ts.map +0 -1
- package/dist/src/ui/preload.native.js.map +0 -1
- package/dist/src/ui/preload.web.d.ts +0 -5
- package/dist/src/ui/preload.web.d.ts.map +0 -1
- package/dist/src/ui/preload.web.js +0 -27
- package/dist/src/ui/preload.web.js.map +0 -1
|
@@ -973,11 +973,6 @@ var init_AbstractInstallModal = __esm({
|
|
|
973
973
|
`[UI: InstallModal-nodejs()] \u274C Error generating new QR code: ${error}`
|
|
974
974
|
);
|
|
975
975
|
}
|
|
976
|
-
} else {
|
|
977
|
-
const generateQRCode = yield this.options.generateQRCode(
|
|
978
|
-
currentConnectionRequest
|
|
979
|
-
);
|
|
980
|
-
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
981
976
|
}
|
|
982
977
|
}), 1e3);
|
|
983
978
|
}
|
|
@@ -1207,7 +1202,7 @@ __export(index_browser_exports, {
|
|
|
1207
1202
|
StoreClient: () => StoreClient,
|
|
1208
1203
|
TransportType: () => TransportType,
|
|
1209
1204
|
createLogger: () => createLogger,
|
|
1210
|
-
|
|
1205
|
+
createMultichainClient: () => createMultichainClient,
|
|
1211
1206
|
enableDebug: () => enableDebug,
|
|
1212
1207
|
getInfuraRpcUrls: () => getInfuraRpcUrls,
|
|
1213
1208
|
getPlatformType: () => getPlatformType,
|
|
@@ -1223,6 +1218,13 @@ __export(index_browser_exports, {
|
|
|
1223
1218
|
});
|
|
1224
1219
|
module.exports = __toCommonJS(index_browser_exports);
|
|
1225
1220
|
|
|
1221
|
+
// src/polyfills/buffer-shim.ts
|
|
1222
|
+
var import_buffer = require("buffer");
|
|
1223
|
+
var g = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
|
|
1224
|
+
if (!g.Buffer) {
|
|
1225
|
+
g.Buffer = import_buffer.Buffer;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1226
1228
|
// src/multichain/index.ts
|
|
1227
1229
|
var import_analytics4 = require("@metamask/analytics");
|
|
1228
1230
|
var import_mobile_wallet_protocol_core2 = require("@metamask/mobile-wallet-protocol-core");
|
|
@@ -1580,7 +1582,8 @@ var DefaultTransport = class {
|
|
|
1580
1582
|
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1581
1583
|
);
|
|
1582
1584
|
const createSessionParams = {
|
|
1583
|
-
optionalScopes
|
|
1585
|
+
optionalScopes,
|
|
1586
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1584
1587
|
};
|
|
1585
1588
|
const response = yield this.request(
|
|
1586
1589
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
@@ -1720,6 +1723,7 @@ var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
|
|
|
1720
1723
|
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
1721
1724
|
var CONNECTION_GRACE_PERIOD = 60 * 1e3;
|
|
1722
1725
|
var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT2 + CONNECTION_GRACE_PERIOD;
|
|
1726
|
+
var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
|
|
1723
1727
|
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1724
1728
|
var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
|
|
1725
1729
|
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
@@ -1736,7 +1740,8 @@ var logger = createLogger("metamask-sdk:transport");
|
|
|
1736
1740
|
var MWPTransport = class {
|
|
1737
1741
|
constructor(dappClient, kvstore, options = {
|
|
1738
1742
|
requestTimeout: DEFAULT_REQUEST_TIMEOUT2,
|
|
1739
|
-
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
|
|
1743
|
+
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
|
|
1744
|
+
resumeTimeout: DEFAULT_RESUME_TIMEOUT
|
|
1740
1745
|
}) {
|
|
1741
1746
|
this.dappClient = dappClient;
|
|
1742
1747
|
this.kvstore = kvstore;
|
|
@@ -1811,6 +1816,13 @@ var MWPTransport = class {
|
|
|
1811
1816
|
)
|
|
1812
1817
|
);
|
|
1813
1818
|
}
|
|
1819
|
+
if (message.data.method === "wallet_sessionChanged") {
|
|
1820
|
+
const notification = message.data;
|
|
1821
|
+
const response = {
|
|
1822
|
+
result: notification.params
|
|
1823
|
+
};
|
|
1824
|
+
this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
|
|
1825
|
+
}
|
|
1814
1826
|
this.notifyCallbacks(message.data);
|
|
1815
1827
|
}
|
|
1816
1828
|
}
|
|
@@ -1820,6 +1832,7 @@ var MWPTransport = class {
|
|
|
1820
1832
|
return __async(this, null, function* () {
|
|
1821
1833
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1822
1834
|
try {
|
|
1835
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1823
1836
|
const sessionRequest = yield this.request({
|
|
1824
1837
|
method: "wallet_getSession"
|
|
1825
1838
|
});
|
|
@@ -1924,7 +1937,7 @@ var MWPTransport = class {
|
|
|
1924
1937
|
}
|
|
1925
1938
|
let timeout;
|
|
1926
1939
|
let initialConnectionMessageHandler;
|
|
1927
|
-
const connectionPromise = new Promise((resolve, reject) => {
|
|
1940
|
+
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1928
1941
|
let connection;
|
|
1929
1942
|
if (session) {
|
|
1930
1943
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
@@ -1947,7 +1960,8 @@ var MWPTransport = class {
|
|
|
1947
1960
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1948
1961
|
);
|
|
1949
1962
|
const sessionRequest = {
|
|
1950
|
-
optionalScopes
|
|
1963
|
+
optionalScopes,
|
|
1964
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1951
1965
|
};
|
|
1952
1966
|
const request = {
|
|
1953
1967
|
jsonrpc: "2.0",
|
|
@@ -2002,7 +2016,7 @@ var MWPTransport = class {
|
|
|
2002
2016
|
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
2003
2017
|
}, this.options.connectionTimeout);
|
|
2004
2018
|
connection.then(resolve).catch(reject);
|
|
2005
|
-
});
|
|
2019
|
+
}));
|
|
2006
2020
|
return connectionPromise.catch((error) => {
|
|
2007
2021
|
throw error;
|
|
2008
2022
|
}).finally(() => {
|
|
@@ -2187,6 +2201,43 @@ var MWPTransport = class {
|
|
|
2187
2201
|
}
|
|
2188
2202
|
});
|
|
2189
2203
|
}
|
|
2204
|
+
// This method checks if an existing CAIP session response is cached or waits for one
|
|
2205
|
+
// to be received from the wallet if not cached. This is necessary because there is an edge
|
|
2206
|
+
// case during the initial connection flow where after the user has accepted the permission approval
|
|
2207
|
+
// and returned back to the dapp from the wallet, the dapp page may have gotten unloaded and refreshed.
|
|
2208
|
+
// When it is unloaded and refreshed, it will try to resume the session by making a request for wallet_getSession
|
|
2209
|
+
// which should resolve from cache, but because a race condition makes it possible for the response from the wallet
|
|
2210
|
+
// for the initial wallet_createSession connection request to not have been handled and cached yet. This results
|
|
2211
|
+
// in the wallet_getSession request never resolving unless we wait for it explicitly as done in this method.
|
|
2212
|
+
waitForWalletSessionIfNotCached() {
|
|
2213
|
+
return __async(this, null, function* () {
|
|
2214
|
+
const cachedWalletGetSessionResponse = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2215
|
+
if (cachedWalletGetSessionResponse) {
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
let unsubscribe;
|
|
2219
|
+
const responsePromise = new Promise((resolve) => {
|
|
2220
|
+
unsubscribe = this.onNotification((message) => {
|
|
2221
|
+
if (typeof message === "object" && message !== null) {
|
|
2222
|
+
if ("data" in message) {
|
|
2223
|
+
const messagePayload = message.data;
|
|
2224
|
+
if (messagePayload.method === "wallet_getSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
2225
|
+
unsubscribe();
|
|
2226
|
+
resolve();
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
});
|
|
2231
|
+
});
|
|
2232
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
2233
|
+
setTimeout(() => {
|
|
2234
|
+
unsubscribe();
|
|
2235
|
+
reject(new import_multichain_api_client2.TransportTimeoutError());
|
|
2236
|
+
}, this.options.resumeTimeout);
|
|
2237
|
+
});
|
|
2238
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2190
2241
|
};
|
|
2191
2242
|
|
|
2192
2243
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2218,9 +2269,167 @@ var keymanager = new KeyManager();
|
|
|
2218
2269
|
|
|
2219
2270
|
// src/multichain/index.ts
|
|
2220
2271
|
init_utils();
|
|
2272
|
+
|
|
2273
|
+
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2274
|
+
var import_rpc_errors = require("@metamask/rpc-errors");
|
|
2275
|
+
var MAX = 4294967295;
|
|
2276
|
+
var idCounter = Math.floor(Math.random() * MAX);
|
|
2277
|
+
var getUniqueId = () => {
|
|
2278
|
+
idCounter = (idCounter + 1) % MAX;
|
|
2279
|
+
return idCounter;
|
|
2280
|
+
};
|
|
2281
|
+
var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2282
|
+
var MultichainApiClientWrapperTransport = class {
|
|
2283
|
+
constructor(metamaskConnectMultichain) {
|
|
2284
|
+
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2285
|
+
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2286
|
+
this.requestId = getUniqueId();
|
|
2287
|
+
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
2288
|
+
}
|
|
2289
|
+
isTransportDefined() {
|
|
2290
|
+
try {
|
|
2291
|
+
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
return false;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
clearNotificationCallbacks() {
|
|
2297
|
+
this.notificationCallbacks.clear();
|
|
2298
|
+
}
|
|
2299
|
+
notifyCallbacks(data) {
|
|
2300
|
+
this.notificationCallbacks.forEach((callback) => {
|
|
2301
|
+
callback(data);
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
setupNotifcationListener() {
|
|
2305
|
+
this.metamaskConnectMultichain.transport.onNotification(
|
|
2306
|
+
this.notifyCallbacks.bind(this)
|
|
2307
|
+
);
|
|
2308
|
+
}
|
|
2309
|
+
connect() {
|
|
2310
|
+
return __async(this, null, function* () {
|
|
2311
|
+
console.log("\u{1F4DA} connect");
|
|
2312
|
+
return Promise.resolve();
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
disconnect() {
|
|
2316
|
+
return __async(this, null, function* () {
|
|
2317
|
+
return Promise.resolve();
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
isConnected() {
|
|
2321
|
+
return true;
|
|
2322
|
+
}
|
|
2323
|
+
request(_0) {
|
|
2324
|
+
return __async(this, arguments, function* (params, _options = {}) {
|
|
2325
|
+
const id = this.requestId++;
|
|
2326
|
+
const requestPayload = __spreadValues({
|
|
2327
|
+
id,
|
|
2328
|
+
jsonrpc: "2.0"
|
|
2329
|
+
}, params);
|
|
2330
|
+
switch (requestPayload.method) {
|
|
2331
|
+
case "wallet_createSession":
|
|
2332
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
2333
|
+
case "wallet_getSession":
|
|
2334
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
2335
|
+
case "wallet_revokeSession":
|
|
2336
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
2337
|
+
case "wallet_invokeMethod":
|
|
2338
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
2339
|
+
default:
|
|
2340
|
+
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
2341
|
+
}
|
|
2342
|
+
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
2343
|
+
});
|
|
2344
|
+
}
|
|
2345
|
+
onNotification(callback) {
|
|
2346
|
+
if (!this.isTransportDefined()) {
|
|
2347
|
+
this.notificationCallbacks.add(callback);
|
|
2348
|
+
return () => {
|
|
2349
|
+
this.notificationCallbacks.delete(callback);
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
return this.metamaskConnectMultichain.transport.onNotification(callback);
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2356
|
+
walletCreateSession_fn = function(request) {
|
|
2357
|
+
return __async(this, null, function* () {
|
|
2358
|
+
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
2359
|
+
const createSessionParams = request.params;
|
|
2360
|
+
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
2361
|
+
const scopeAccounts = [];
|
|
2362
|
+
scopes.forEach((scope) => {
|
|
2363
|
+
var _a2, _b, _c, _d;
|
|
2364
|
+
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
2365
|
+
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
2366
|
+
if (requiredScope) {
|
|
2367
|
+
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
2368
|
+
}
|
|
2369
|
+
if (optionalScope) {
|
|
2370
|
+
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
2371
|
+
}
|
|
2372
|
+
});
|
|
2373
|
+
const accounts = [...new Set(scopeAccounts)];
|
|
2374
|
+
console.log("\u{1F4DA} SDK connect");
|
|
2375
|
+
yield this.metamaskConnectMultichain.connect(
|
|
2376
|
+
scopes,
|
|
2377
|
+
accounts,
|
|
2378
|
+
createSessionParams.sessionProperties
|
|
2379
|
+
);
|
|
2380
|
+
console.log("\u{1F4DA} SDK connected");
|
|
2381
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
2382
|
+
method: "wallet_getSession"
|
|
2383
|
+
});
|
|
2384
|
+
});
|
|
2385
|
+
};
|
|
2386
|
+
walletGetSession_fn = function(request) {
|
|
2387
|
+
return __async(this, null, function* () {
|
|
2388
|
+
if (!this.isTransportDefined()) {
|
|
2389
|
+
return {
|
|
2390
|
+
jsonrpc: "2.0",
|
|
2391
|
+
id: request.id,
|
|
2392
|
+
result: {
|
|
2393
|
+
sessionScopes: {}
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
2398
|
+
method: "wallet_getSession"
|
|
2399
|
+
});
|
|
2400
|
+
});
|
|
2401
|
+
};
|
|
2402
|
+
walletRevokeSession_fn = function(request) {
|
|
2403
|
+
return __async(this, null, function* () {
|
|
2404
|
+
if (!this.isTransportDefined()) {
|
|
2405
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2406
|
+
}
|
|
2407
|
+
try {
|
|
2408
|
+
this.metamaskConnectMultichain.disconnect();
|
|
2409
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2410
|
+
} catch (error) {
|
|
2411
|
+
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
};
|
|
2415
|
+
walletInvokeMethod_fn = function(request) {
|
|
2416
|
+
return __async(this, null, function* () {
|
|
2417
|
+
if (!this.isTransportDefined()) {
|
|
2418
|
+
return { error: import_rpc_errors.providerErrors.unauthorized() };
|
|
2419
|
+
}
|
|
2420
|
+
const result = this.metamaskConnectMultichain.invokeMethod(
|
|
2421
|
+
request.params
|
|
2422
|
+
);
|
|
2423
|
+
return {
|
|
2424
|
+
result
|
|
2425
|
+
};
|
|
2426
|
+
});
|
|
2427
|
+
};
|
|
2428
|
+
|
|
2429
|
+
// src/multichain/index.ts
|
|
2221
2430
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2222
|
-
var _a, _provider, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo,
|
|
2223
|
-
var
|
|
2431
|
+
var _a, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, init_fn, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn;
|
|
2432
|
+
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2224
2433
|
constructor(options) {
|
|
2225
2434
|
var _a2, _b, _c, _d, _e, _f;
|
|
2226
2435
|
const withDappMetadata = setupDappMetadata(options);
|
|
@@ -2236,34 +2445,30 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2236
2445
|
})
|
|
2237
2446
|
});
|
|
2238
2447
|
super(allOptions);
|
|
2239
|
-
__privateAdd(this,
|
|
2448
|
+
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
2240
2449
|
__privateAdd(this, _provider);
|
|
2450
|
+
__privateAdd(this, _providerTransportWrapper);
|
|
2241
2451
|
__privateAdd(this, _transport2);
|
|
2242
2452
|
__privateAdd(this, _dappClient);
|
|
2243
2453
|
__privateAdd(this, _beforeUnloadListener);
|
|
2244
|
-
this.
|
|
2454
|
+
this._status = "pending";
|
|
2245
2455
|
__privateAdd(this, _listener);
|
|
2246
2456
|
__privateAdd(this, _sdkInfo, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_a = this.options.dapp.url) != null ? _a : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
2457
|
+
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
|
|
2458
|
+
__privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({ transport: __privateGet(this, _providerTransportWrapper) }));
|
|
2247
2459
|
}
|
|
2248
|
-
get
|
|
2249
|
-
return this.
|
|
2460
|
+
get status() {
|
|
2461
|
+
return this._status;
|
|
2250
2462
|
}
|
|
2251
|
-
set
|
|
2463
|
+
set status(value) {
|
|
2252
2464
|
var _a2, _b;
|
|
2253
|
-
this.
|
|
2465
|
+
this._status = value;
|
|
2254
2466
|
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2255
2467
|
method: "stateChanged",
|
|
2256
2468
|
params: value
|
|
2257
2469
|
});
|
|
2258
2470
|
}
|
|
2259
2471
|
get provider() {
|
|
2260
|
-
if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
|
|
2261
|
-
__privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({ transport: __privateGet(this, _transport2) }));
|
|
2262
|
-
return __privateGet(this, _provider);
|
|
2263
|
-
}
|
|
2264
|
-
if (!__privateGet(this, _provider)) {
|
|
2265
|
-
throw new Error("Provider not initialized, establish connection first");
|
|
2266
|
-
}
|
|
2267
2472
|
return __privateGet(this, _provider);
|
|
2268
2473
|
}
|
|
2269
2474
|
get transport() {
|
|
@@ -2287,7 +2492,7 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2287
2492
|
static create(options) {
|
|
2288
2493
|
return __async(this, null, function* () {
|
|
2289
2494
|
var _a2;
|
|
2290
|
-
const instance = new
|
|
2495
|
+
const instance = new _MetaMaskConnectMultichain(options);
|
|
2291
2496
|
const isEnabled2 = yield isEnabled(
|
|
2292
2497
|
"metamask-sdk:core",
|
|
2293
2498
|
instance.options.storage
|
|
@@ -2295,14 +2500,15 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2295
2500
|
if (isEnabled2) {
|
|
2296
2501
|
enableDebug("metamask-sdk:core");
|
|
2297
2502
|
}
|
|
2298
|
-
yield __privateMethod(_a2 = instance,
|
|
2503
|
+
yield __privateMethod(_a2 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a2);
|
|
2299
2504
|
return instance;
|
|
2300
2505
|
});
|
|
2301
2506
|
}
|
|
2302
|
-
|
|
2507
|
+
// TODO: make this into param object
|
|
2508
|
+
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
2303
2509
|
return __async(this, null, function* () {
|
|
2304
2510
|
var _a2;
|
|
2305
|
-
if (this.
|
|
2511
|
+
if (this.status !== "connected") {
|
|
2306
2512
|
yield this.disconnect();
|
|
2307
2513
|
}
|
|
2308
2514
|
const { ui } = this.options;
|
|
@@ -2334,7 +2540,7 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2334
2540
|
logger2("Error tracking connection_initiated event", error);
|
|
2335
2541
|
}
|
|
2336
2542
|
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2337
|
-
return __privateMethod(this,
|
|
2543
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties, forceRequest }).then(() => __async(this, null, function* () {
|
|
2338
2544
|
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2339
2545
|
return this.storage.setTransport("mwp" /* MWP */);
|
|
2340
2546
|
}
|
|
@@ -2342,19 +2548,19 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2342
2548
|
})), scopes, transportType);
|
|
2343
2549
|
}
|
|
2344
2550
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2345
|
-
const defaultTransport = yield __privateMethod(this,
|
|
2346
|
-
return __privateMethod(this,
|
|
2551
|
+
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2552
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2347
2553
|
}
|
|
2348
2554
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2349
|
-
const defaultTransport = yield __privateMethod(this,
|
|
2350
|
-
return __privateMethod(this,
|
|
2555
|
+
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2556
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2351
2557
|
}
|
|
2352
|
-
yield __privateMethod(this,
|
|
2558
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
|
|
2353
2559
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2354
2560
|
if (secure && !shouldShowInstallModal) {
|
|
2355
|
-
return __privateMethod(this,
|
|
2561
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2356
2562
|
}
|
|
2357
|
-
return __privateMethod(this,
|
|
2563
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2358
2564
|
});
|
|
2359
2565
|
}
|
|
2360
2566
|
emit(event, args) {
|
|
@@ -2373,15 +2579,13 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2373
2579
|
__privateSet(this, _listener, void 0);
|
|
2374
2580
|
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2375
2581
|
__privateSet(this, _transport2, void 0);
|
|
2376
|
-
|
|
2582
|
+
__privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
|
|
2377
2583
|
__privateSet(this, _dappClient, void 0);
|
|
2378
2584
|
});
|
|
2379
2585
|
}
|
|
2380
2586
|
invokeMethod(request) {
|
|
2381
2587
|
return __async(this, null, function* () {
|
|
2382
|
-
var _a2;
|
|
2383
2588
|
const { transport, options } = this;
|
|
2384
|
-
(_a2 = __privateGet(this, _provider)) != null ? _a2 : __privateSet(this, _provider, (0, import_multichain_api_client3.getMultichainClient)({ transport }));
|
|
2385
2589
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2386
2590
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2387
2591
|
return requestRouter.invokeMethod(request);
|
|
@@ -2410,12 +2614,13 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2410
2614
|
}
|
|
2411
2615
|
};
|
|
2412
2616
|
_provider = new WeakMap();
|
|
2617
|
+
_providerTransportWrapper = new WeakMap();
|
|
2413
2618
|
_transport2 = new WeakMap();
|
|
2414
2619
|
_dappClient = new WeakMap();
|
|
2415
2620
|
_beforeUnloadListener = new WeakMap();
|
|
2416
2621
|
_listener = new WeakMap();
|
|
2417
2622
|
_sdkInfo = new WeakMap();
|
|
2418
|
-
|
|
2623
|
+
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2419
2624
|
setupAnalytics_fn = function() {
|
|
2420
2625
|
return __async(this, null, function* () {
|
|
2421
2626
|
var _a2;
|
|
@@ -2456,19 +2661,21 @@ getStoredTransport_fn = function() {
|
|
|
2456
2661
|
if (hasExtensionInstalled) {
|
|
2457
2662
|
const apiTransport = new DefaultTransport();
|
|
2458
2663
|
__privateSet(this, _transport2, apiTransport);
|
|
2664
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2459
2665
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2460
|
-
__privateMethod(this,
|
|
2666
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2461
2667
|
));
|
|
2462
2668
|
return apiTransport;
|
|
2463
2669
|
}
|
|
2464
2670
|
} else if (transportType === "mwp" /* MWP */) {
|
|
2465
2671
|
const { adapter: kvstore } = this.options.storage;
|
|
2466
|
-
const dappClient = yield __privateMethod(this,
|
|
2672
|
+
const dappClient = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, createDappClient_fn).call(this);
|
|
2467
2673
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2468
2674
|
__privateSet(this, _dappClient, dappClient);
|
|
2469
2675
|
__privateSet(this, _transport2, apiTransport);
|
|
2676
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2470
2677
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2471
|
-
__privateMethod(this,
|
|
2678
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2472
2679
|
));
|
|
2473
2680
|
return apiTransport;
|
|
2474
2681
|
}
|
|
@@ -2479,20 +2686,20 @@ getStoredTransport_fn = function() {
|
|
|
2479
2686
|
};
|
|
2480
2687
|
setupTransport_fn = function() {
|
|
2481
2688
|
return __async(this, null, function* () {
|
|
2482
|
-
const transport = yield __privateMethod(this,
|
|
2689
|
+
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
2483
2690
|
if (transport) {
|
|
2484
2691
|
if (!this.transport.isConnected()) {
|
|
2485
|
-
this.
|
|
2692
|
+
this.status = "connecting";
|
|
2486
2693
|
yield this.transport.connect();
|
|
2487
2694
|
}
|
|
2488
|
-
this.
|
|
2695
|
+
this.status = "connected";
|
|
2489
2696
|
if (this.transport instanceof MWPTransport) {
|
|
2490
2697
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2491
2698
|
} else {
|
|
2492
2699
|
yield this.storage.setTransport("browser" /* Browser */);
|
|
2493
2700
|
}
|
|
2494
2701
|
} else {
|
|
2495
|
-
this.
|
|
2702
|
+
this.status = "loaded";
|
|
2496
2703
|
}
|
|
2497
2704
|
});
|
|
2498
2705
|
};
|
|
@@ -2503,8 +2710,8 @@ init_fn = function() {
|
|
|
2503
2710
|
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2504
2711
|
logger2("MetaMaskSDK: init already initialized");
|
|
2505
2712
|
} else {
|
|
2506
|
-
yield __privateMethod(this,
|
|
2507
|
-
yield __privateMethod(this,
|
|
2713
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
2714
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
2508
2715
|
try {
|
|
2509
2716
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2510
2717
|
this.options,
|
|
@@ -2520,7 +2727,7 @@ init_fn = function() {
|
|
|
2520
2727
|
}
|
|
2521
2728
|
} catch (error) {
|
|
2522
2729
|
yield this.storage.removeTransport();
|
|
2523
|
-
this.
|
|
2730
|
+
this.status = "pending";
|
|
2524
2731
|
logger2("MetaMaskSDK error during initialization", error);
|
|
2525
2732
|
}
|
|
2526
2733
|
});
|
|
@@ -2548,12 +2755,13 @@ setupMWP_fn = function() {
|
|
|
2548
2755
|
return;
|
|
2549
2756
|
}
|
|
2550
2757
|
const { adapter: kvstore } = this.options.storage;
|
|
2551
|
-
const dappClient = yield __privateMethod(this,
|
|
2758
|
+
const dappClient = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, createDappClient_fn).call(this);
|
|
2552
2759
|
__privateSet(this, _dappClient, dappClient);
|
|
2553
2760
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2554
2761
|
__privateSet(this, _transport2, apiTransport);
|
|
2762
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2555
2763
|
__privateSet(this, _listener, this.transport.onNotification(
|
|
2556
|
-
__privateMethod(this,
|
|
2764
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2557
2765
|
));
|
|
2558
2766
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2559
2767
|
});
|
|
@@ -2568,18 +2776,18 @@ onBeforeUnload_fn = function() {
|
|
|
2568
2776
|
};
|
|
2569
2777
|
createBeforeUnloadListener_fn = function() {
|
|
2570
2778
|
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2571
|
-
window.addEventListener("beforeunload", __privateMethod(this,
|
|
2779
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this));
|
|
2572
2780
|
}
|
|
2573
2781
|
return () => {
|
|
2574
2782
|
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2575
2783
|
window.removeEventListener(
|
|
2576
2784
|
"beforeunload",
|
|
2577
|
-
__privateMethod(this,
|
|
2785
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this)
|
|
2578
2786
|
);
|
|
2579
2787
|
}
|
|
2580
2788
|
};
|
|
2581
2789
|
};
|
|
2582
|
-
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2790
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2583
2791
|
return __async(this, null, function* () {
|
|
2584
2792
|
return new Promise((resolve, reject) => {
|
|
2585
2793
|
this.options.ui.factory.renderInstallModal(
|
|
@@ -2607,19 +2815,19 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds)
|
|
|
2607
2815
|
(() => __async(this, null, function* () {
|
|
2608
2816
|
var _a2;
|
|
2609
2817
|
try {
|
|
2610
|
-
yield this.transport.connect({ scopes, caipAccountIds });
|
|
2818
|
+
yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
|
|
2611
2819
|
yield this.options.ui.factory.unload();
|
|
2612
2820
|
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2613
|
-
this.
|
|
2821
|
+
this.status = "connected";
|
|
2614
2822
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2615
2823
|
} catch (error) {
|
|
2616
2824
|
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2617
2825
|
if (error.code !== import_mobile_wallet_protocol_core2.ErrorCode.REQUEST_EXPIRED) {
|
|
2618
|
-
this.
|
|
2826
|
+
this.status = "disconnected";
|
|
2619
2827
|
reject(error);
|
|
2620
2828
|
}
|
|
2621
2829
|
} else {
|
|
2622
|
-
this.
|
|
2830
|
+
this.status = "disconnected";
|
|
2623
2831
|
reject(
|
|
2624
2832
|
error instanceof Error ? error : new Error(String(error))
|
|
2625
2833
|
);
|
|
@@ -2637,33 +2845,83 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds)
|
|
|
2637
2845
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2638
2846
|
resolve();
|
|
2639
2847
|
}
|
|
2640
|
-
})
|
|
2848
|
+
}),
|
|
2849
|
+
(uri) => {
|
|
2850
|
+
this.emit("display_uri", uri);
|
|
2851
|
+
}
|
|
2641
2852
|
).catch((error) => {
|
|
2642
2853
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2643
2854
|
});
|
|
2644
2855
|
});
|
|
2645
2856
|
});
|
|
2646
2857
|
};
|
|
2647
|
-
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2858
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2648
2859
|
return __async(this, null, function* () {
|
|
2649
2860
|
var _a2;
|
|
2650
|
-
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this,
|
|
2651
|
-
|
|
2861
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
|
|
2862
|
+
if (this.options.ui.headless) {
|
|
2863
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
|
|
2864
|
+
} else {
|
|
2865
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
|
|
2866
|
+
}
|
|
2867
|
+
});
|
|
2868
|
+
};
|
|
2869
|
+
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2870
|
+
return __async(this, null, function* () {
|
|
2871
|
+
return new Promise((resolve, reject) => {
|
|
2872
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2873
|
+
this.dappClient.disconnect().catch(() => {
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
this.dappClient.on(
|
|
2877
|
+
"session_request",
|
|
2878
|
+
(sessionRequest) => {
|
|
2879
|
+
const connectionRequest = {
|
|
2880
|
+
sessionRequest,
|
|
2881
|
+
metadata: {
|
|
2882
|
+
dapp: this.options.dapp,
|
|
2883
|
+
sdk: {
|
|
2884
|
+
version: getVersion(),
|
|
2885
|
+
platform: getPlatformType()
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
};
|
|
2889
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2890
|
+
this.emit("display_uri", deeplink);
|
|
2891
|
+
}
|
|
2892
|
+
);
|
|
2893
|
+
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
2894
|
+
this.status = "connected";
|
|
2895
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2896
|
+
resolve();
|
|
2897
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2898
|
+
if (error instanceof import_mobile_wallet_protocol_core2.ProtocolError) {
|
|
2899
|
+
this.status = "disconnected";
|
|
2900
|
+
yield this.storage.removeTransport();
|
|
2901
|
+
reject(error);
|
|
2902
|
+
} else {
|
|
2903
|
+
this.status = "disconnected";
|
|
2904
|
+
yield this.storage.removeTransport();
|
|
2905
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2906
|
+
}
|
|
2907
|
+
}));
|
|
2908
|
+
});
|
|
2652
2909
|
});
|
|
2653
2910
|
};
|
|
2654
2911
|
setupDefaultTransport_fn = function() {
|
|
2655
2912
|
return __async(this, null, function* () {
|
|
2656
|
-
this.
|
|
2913
|
+
this.status = "connecting";
|
|
2657
2914
|
yield this.storage.setTransport("browser" /* Browser */);
|
|
2658
2915
|
const transport = new DefaultTransport();
|
|
2659
2916
|
__privateSet(this, _listener, transport.onNotification(
|
|
2660
|
-
__privateMethod(this,
|
|
2917
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2661
2918
|
));
|
|
2662
2919
|
__privateSet(this, _transport2, transport);
|
|
2920
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2663
2921
|
return transport;
|
|
2664
2922
|
});
|
|
2665
2923
|
};
|
|
2666
|
-
deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
2924
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2667
2925
|
return __async(this, null, function* () {
|
|
2668
2926
|
return new Promise((resolve, reject) => {
|
|
2669
2927
|
const dappClientMessageHandler = (payload) => {
|
|
@@ -2706,6 +2964,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2706
2964
|
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2707
2965
|
connectionRequest
|
|
2708
2966
|
);
|
|
2967
|
+
this.emit("display_uri", deeplink);
|
|
2709
2968
|
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2710
2969
|
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2711
2970
|
} else {
|
|
@@ -2714,7 +2973,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2714
2973
|
}
|
|
2715
2974
|
);
|
|
2716
2975
|
}
|
|
2717
|
-
return this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2976
|
+
return this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2718
2977
|
yield this.storage.removeTransport();
|
|
2719
2978
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
2720
2979
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -2728,9 +2987,9 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2728
2987
|
};
|
|
2729
2988
|
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2730
2989
|
return __async(this, null, function* () {
|
|
2731
|
-
this.
|
|
2990
|
+
this.status = "connecting";
|
|
2732
2991
|
return promise.then(() => __async(this, null, function* () {
|
|
2733
|
-
this.
|
|
2992
|
+
this.status = "connected";
|
|
2734
2993
|
try {
|
|
2735
2994
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2736
2995
|
this.options,
|
|
@@ -2745,7 +3004,7 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
2745
3004
|
}
|
|
2746
3005
|
return void 0;
|
|
2747
3006
|
})).catch((error) => __async(this, null, function* () {
|
|
2748
|
-
this.
|
|
3007
|
+
this.status = "disconnected";
|
|
2749
3008
|
try {
|
|
2750
3009
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2751
3010
|
this.options,
|
|
@@ -2768,7 +3027,7 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
2768
3027
|
}));
|
|
2769
3028
|
});
|
|
2770
3029
|
};
|
|
2771
|
-
var
|
|
3030
|
+
var MetaMaskConnectMultichain = _MetaMaskConnectMultichain;
|
|
2772
3031
|
|
|
2773
3032
|
// src/store/index.ts
|
|
2774
3033
|
var uuid = __toESM(require("uuid"));
|
|
@@ -2949,28 +3208,11 @@ var Store = class extends StoreClient {
|
|
|
2949
3208
|
}
|
|
2950
3209
|
};
|
|
2951
3210
|
|
|
2952
|
-
// src/ui/
|
|
3211
|
+
// src/ui/ModalFactory.ts
|
|
2953
3212
|
var import_onboarding = __toESM(require("@metamask/onboarding"));
|
|
2954
3213
|
init_domain();
|
|
2955
3214
|
init_utils();
|
|
2956
|
-
|
|
2957
|
-
// src/ui/preload.web.ts
|
|
2958
|
-
function preload() {
|
|
2959
|
-
return __async(this, null, function* () {
|
|
2960
|
-
if (typeof document === "undefined") {
|
|
2961
|
-
return;
|
|
2962
|
-
}
|
|
2963
|
-
try {
|
|
2964
|
-
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
2965
|
-
yield defineCustomElements();
|
|
2966
|
-
} catch (error) {
|
|
2967
|
-
console.error("Failed to load customElements:", error);
|
|
2968
|
-
}
|
|
2969
|
-
});
|
|
2970
|
-
}
|
|
2971
|
-
|
|
2972
|
-
// src/ui/index.ts
|
|
2973
|
-
var ModalFactory = class {
|
|
3215
|
+
var BaseModalFactory = class {
|
|
2974
3216
|
/**
|
|
2975
3217
|
* Creates a new modal factory instance.
|
|
2976
3218
|
*
|
|
@@ -3059,15 +3301,17 @@ var ModalFactory = class {
|
|
|
3059
3301
|
onStartDesktopOnboarding() {
|
|
3060
3302
|
new import_onboarding.default().startOnboarding();
|
|
3061
3303
|
}
|
|
3062
|
-
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
3304
|
+
renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
|
|
3063
3305
|
return __async(this, null, function* () {
|
|
3064
|
-
var _a2;
|
|
3306
|
+
var _a2, _b;
|
|
3065
3307
|
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3066
|
-
yield preload();
|
|
3308
|
+
yield this.preload();
|
|
3067
3309
|
this.successCallback = successCallback;
|
|
3310
|
+
this.displayUriCallback = onDisplayUri;
|
|
3068
3311
|
const parentElement = this.getMountedContainer();
|
|
3069
3312
|
const connectionRequest = yield createConnectionRequest();
|
|
3070
3313
|
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
3314
|
+
(_b = this.displayUriCallback) == null ? void 0 : _b.call(this, qrCodeLink);
|
|
3071
3315
|
const modal = new this.options.InstallModal({
|
|
3072
3316
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
3073
3317
|
connectionRequest,
|
|
@@ -3076,11 +3320,15 @@ var ModalFactory = class {
|
|
|
3076
3320
|
link: qrCodeLink,
|
|
3077
3321
|
sdkVersion: getVersion(),
|
|
3078
3322
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3079
|
-
|
|
3323
|
+
var _a3;
|
|
3324
|
+
const newLink = this.createConnectionDeeplink(request);
|
|
3325
|
+
(_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
|
|
3326
|
+
return newLink;
|
|
3080
3327
|
}),
|
|
3081
3328
|
onClose: this.onCloseModal.bind(this),
|
|
3082
3329
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
3083
|
-
createConnectionRequest
|
|
3330
|
+
createConnectionRequest,
|
|
3331
|
+
onDisplayUri: this.displayUriCallback
|
|
3084
3332
|
});
|
|
3085
3333
|
this.modal = modal;
|
|
3086
3334
|
modal.mount();
|
|
@@ -3090,7 +3338,7 @@ var ModalFactory = class {
|
|
|
3090
3338
|
return __async(this, null, function* () {
|
|
3091
3339
|
var _a2;
|
|
3092
3340
|
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3093
|
-
yield preload();
|
|
3341
|
+
yield this.preload();
|
|
3094
3342
|
this.successCallback = successCallback;
|
|
3095
3343
|
const container = this.getMountedContainer();
|
|
3096
3344
|
const otpCode = yield createOTPCode();
|
|
@@ -3108,9 +3356,31 @@ var ModalFactory = class {
|
|
|
3108
3356
|
}
|
|
3109
3357
|
};
|
|
3110
3358
|
|
|
3359
|
+
// src/ui/index.ts
|
|
3360
|
+
function preload() {
|
|
3361
|
+
return __async(this, null, function* () {
|
|
3362
|
+
if (typeof document === "undefined") {
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3365
|
+
try {
|
|
3366
|
+
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
3367
|
+
yield defineCustomElements();
|
|
3368
|
+
} catch (error) {
|
|
3369
|
+
console.error("Failed to load customElements:", error);
|
|
3370
|
+
}
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3373
|
+
var ModalFactory = class extends BaseModalFactory {
|
|
3374
|
+
preload() {
|
|
3375
|
+
return __async(this, null, function* () {
|
|
3376
|
+
return preload();
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
};
|
|
3380
|
+
|
|
3111
3381
|
// src/index.browser.ts
|
|
3112
3382
|
init_domain();
|
|
3113
|
-
var
|
|
3383
|
+
var createMultichainClient = (options) => __async(null, null, function* () {
|
|
3114
3384
|
const uiModules = yield Promise.resolve().then(() => (init_web(), web_exports));
|
|
3115
3385
|
let storage;
|
|
3116
3386
|
if (!options.storage) {
|
|
@@ -3121,7 +3391,7 @@ var createMetamaskConnect = (options) => __async(null, null, function* () {
|
|
|
3121
3391
|
storage = options.storage;
|
|
3122
3392
|
}
|
|
3123
3393
|
const factory = new ModalFactory(uiModules);
|
|
3124
|
-
return
|
|
3394
|
+
return MetaMaskConnectMultichain.create(__spreadProps(__spreadValues({}, options), {
|
|
3125
3395
|
storage,
|
|
3126
3396
|
ui: __spreadProps(__spreadValues({}, options.ui), {
|
|
3127
3397
|
factory
|