@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
|
@@ -955,11 +955,6 @@ var init_AbstractInstallModal = __esm({
|
|
|
955
955
|
`[UI: InstallModal-nodejs()] \u274C Error generating new QR code: ${error}`
|
|
956
956
|
);
|
|
957
957
|
}
|
|
958
|
-
} else {
|
|
959
|
-
const generateQRCode = yield this.options.generateQRCode(
|
|
960
|
-
currentConnectionRequest
|
|
961
|
-
);
|
|
962
|
-
this.renderQRCode(generateQRCode, currentConnectionRequest);
|
|
963
958
|
}
|
|
964
959
|
}), 1e3);
|
|
965
960
|
}
|
|
@@ -1172,6 +1167,13 @@ var init_web2 = __esm({
|
|
|
1172
1167
|
}
|
|
1173
1168
|
});
|
|
1174
1169
|
|
|
1170
|
+
// src/polyfills/buffer-shim.ts
|
|
1171
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
1172
|
+
var g = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
|
|
1173
|
+
if (!g.Buffer) {
|
|
1174
|
+
g.Buffer = Buffer2;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1175
1177
|
// src/multichain/index.ts
|
|
1176
1178
|
import { analytics as analytics2 } from "@metamask/analytics";
|
|
1177
1179
|
import {
|
|
@@ -1538,7 +1540,8 @@ var DefaultTransport = class {
|
|
|
1538
1540
|
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1539
1541
|
);
|
|
1540
1542
|
const createSessionParams = {
|
|
1541
|
-
optionalScopes
|
|
1543
|
+
optionalScopes,
|
|
1544
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1542
1545
|
};
|
|
1543
1546
|
const response = yield this.request(
|
|
1544
1547
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
@@ -1680,6 +1683,7 @@ var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
|
|
|
1680
1683
|
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
1681
1684
|
var CONNECTION_GRACE_PERIOD = 60 * 1e3;
|
|
1682
1685
|
var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT2 + CONNECTION_GRACE_PERIOD;
|
|
1686
|
+
var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
|
|
1683
1687
|
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1684
1688
|
var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
|
|
1685
1689
|
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
@@ -1696,7 +1700,8 @@ var logger = createLogger("metamask-sdk:transport");
|
|
|
1696
1700
|
var MWPTransport = class {
|
|
1697
1701
|
constructor(dappClient, kvstore, options = {
|
|
1698
1702
|
requestTimeout: DEFAULT_REQUEST_TIMEOUT2,
|
|
1699
|
-
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
|
|
1703
|
+
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
|
|
1704
|
+
resumeTimeout: DEFAULT_RESUME_TIMEOUT
|
|
1700
1705
|
}) {
|
|
1701
1706
|
this.dappClient = dappClient;
|
|
1702
1707
|
this.kvstore = kvstore;
|
|
@@ -1771,6 +1776,13 @@ var MWPTransport = class {
|
|
|
1771
1776
|
)
|
|
1772
1777
|
);
|
|
1773
1778
|
}
|
|
1779
|
+
if (message.data.method === "wallet_sessionChanged") {
|
|
1780
|
+
const notification = message.data;
|
|
1781
|
+
const response = {
|
|
1782
|
+
result: notification.params
|
|
1783
|
+
};
|
|
1784
|
+
this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
|
|
1785
|
+
}
|
|
1774
1786
|
this.notifyCallbacks(message.data);
|
|
1775
1787
|
}
|
|
1776
1788
|
}
|
|
@@ -1780,6 +1792,7 @@ var MWPTransport = class {
|
|
|
1780
1792
|
return __async(this, null, function* () {
|
|
1781
1793
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1782
1794
|
try {
|
|
1795
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1783
1796
|
const sessionRequest = yield this.request({
|
|
1784
1797
|
method: "wallet_getSession"
|
|
1785
1798
|
});
|
|
@@ -1884,7 +1897,7 @@ var MWPTransport = class {
|
|
|
1884
1897
|
}
|
|
1885
1898
|
let timeout;
|
|
1886
1899
|
let initialConnectionMessageHandler;
|
|
1887
|
-
const connectionPromise = new Promise((resolve, reject) => {
|
|
1900
|
+
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1888
1901
|
let connection;
|
|
1889
1902
|
if (session) {
|
|
1890
1903
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
@@ -1907,7 +1920,8 @@ var MWPTransport = class {
|
|
|
1907
1920
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1908
1921
|
);
|
|
1909
1922
|
const sessionRequest = {
|
|
1910
|
-
optionalScopes
|
|
1923
|
+
optionalScopes,
|
|
1924
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1911
1925
|
};
|
|
1912
1926
|
const request = {
|
|
1913
1927
|
jsonrpc: "2.0",
|
|
@@ -1962,7 +1976,7 @@ var MWPTransport = class {
|
|
|
1962
1976
|
reject(new TransportTimeoutError());
|
|
1963
1977
|
}, this.options.connectionTimeout);
|
|
1964
1978
|
connection.then(resolve).catch(reject);
|
|
1965
|
-
});
|
|
1979
|
+
}));
|
|
1966
1980
|
return connectionPromise.catch((error) => {
|
|
1967
1981
|
throw error;
|
|
1968
1982
|
}).finally(() => {
|
|
@@ -2147,6 +2161,43 @@ var MWPTransport = class {
|
|
|
2147
2161
|
}
|
|
2148
2162
|
});
|
|
2149
2163
|
}
|
|
2164
|
+
// This method checks if an existing CAIP session response is cached or waits for one
|
|
2165
|
+
// to be received from the wallet if not cached. This is necessary because there is an edge
|
|
2166
|
+
// case during the initial connection flow where after the user has accepted the permission approval
|
|
2167
|
+
// and returned back to the dapp from the wallet, the dapp page may have gotten unloaded and refreshed.
|
|
2168
|
+
// When it is unloaded and refreshed, it will try to resume the session by making a request for wallet_getSession
|
|
2169
|
+
// which should resolve from cache, but because a race condition makes it possible for the response from the wallet
|
|
2170
|
+
// for the initial wallet_createSession connection request to not have been handled and cached yet. This results
|
|
2171
|
+
// in the wallet_getSession request never resolving unless we wait for it explicitly as done in this method.
|
|
2172
|
+
waitForWalletSessionIfNotCached() {
|
|
2173
|
+
return __async(this, null, function* () {
|
|
2174
|
+
const cachedWalletGetSessionResponse = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2175
|
+
if (cachedWalletGetSessionResponse) {
|
|
2176
|
+
return;
|
|
2177
|
+
}
|
|
2178
|
+
let unsubscribe;
|
|
2179
|
+
const responsePromise = new Promise((resolve) => {
|
|
2180
|
+
unsubscribe = this.onNotification((message) => {
|
|
2181
|
+
if (typeof message === "object" && message !== null) {
|
|
2182
|
+
if ("data" in message) {
|
|
2183
|
+
const messagePayload = message.data;
|
|
2184
|
+
if (messagePayload.method === "wallet_getSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
2185
|
+
unsubscribe();
|
|
2186
|
+
resolve();
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
});
|
|
2191
|
+
});
|
|
2192
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
2193
|
+
setTimeout(() => {
|
|
2194
|
+
unsubscribe();
|
|
2195
|
+
reject(new TransportTimeoutError());
|
|
2196
|
+
}, this.options.resumeTimeout);
|
|
2197
|
+
});
|
|
2198
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2150
2201
|
};
|
|
2151
2202
|
|
|
2152
2203
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2178,9 +2229,167 @@ var keymanager = new KeyManager();
|
|
|
2178
2229
|
|
|
2179
2230
|
// src/multichain/index.ts
|
|
2180
2231
|
init_utils();
|
|
2232
|
+
|
|
2233
|
+
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2234
|
+
import { providerErrors } from "@metamask/rpc-errors";
|
|
2235
|
+
var MAX = 4294967295;
|
|
2236
|
+
var idCounter = Math.floor(Math.random() * MAX);
|
|
2237
|
+
var getUniqueId = () => {
|
|
2238
|
+
idCounter = (idCounter + 1) % MAX;
|
|
2239
|
+
return idCounter;
|
|
2240
|
+
};
|
|
2241
|
+
var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2242
|
+
var MultichainApiClientWrapperTransport = class {
|
|
2243
|
+
constructor(metamaskConnectMultichain) {
|
|
2244
|
+
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2245
|
+
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2246
|
+
this.requestId = getUniqueId();
|
|
2247
|
+
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
2248
|
+
}
|
|
2249
|
+
isTransportDefined() {
|
|
2250
|
+
try {
|
|
2251
|
+
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2252
|
+
} catch (error) {
|
|
2253
|
+
return false;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
clearNotificationCallbacks() {
|
|
2257
|
+
this.notificationCallbacks.clear();
|
|
2258
|
+
}
|
|
2259
|
+
notifyCallbacks(data) {
|
|
2260
|
+
this.notificationCallbacks.forEach((callback) => {
|
|
2261
|
+
callback(data);
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
setupNotifcationListener() {
|
|
2265
|
+
this.metamaskConnectMultichain.transport.onNotification(
|
|
2266
|
+
this.notifyCallbacks.bind(this)
|
|
2267
|
+
);
|
|
2268
|
+
}
|
|
2269
|
+
connect() {
|
|
2270
|
+
return __async(this, null, function* () {
|
|
2271
|
+
console.log("\u{1F4DA} connect");
|
|
2272
|
+
return Promise.resolve();
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
disconnect() {
|
|
2276
|
+
return __async(this, null, function* () {
|
|
2277
|
+
return Promise.resolve();
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
isConnected() {
|
|
2281
|
+
return true;
|
|
2282
|
+
}
|
|
2283
|
+
request(_0) {
|
|
2284
|
+
return __async(this, arguments, function* (params, _options = {}) {
|
|
2285
|
+
const id = this.requestId++;
|
|
2286
|
+
const requestPayload = __spreadValues({
|
|
2287
|
+
id,
|
|
2288
|
+
jsonrpc: "2.0"
|
|
2289
|
+
}, params);
|
|
2290
|
+
switch (requestPayload.method) {
|
|
2291
|
+
case "wallet_createSession":
|
|
2292
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
2293
|
+
case "wallet_getSession":
|
|
2294
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
2295
|
+
case "wallet_revokeSession":
|
|
2296
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
2297
|
+
case "wallet_invokeMethod":
|
|
2298
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
2299
|
+
default:
|
|
2300
|
+
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
2301
|
+
}
|
|
2302
|
+
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
onNotification(callback) {
|
|
2306
|
+
if (!this.isTransportDefined()) {
|
|
2307
|
+
this.notificationCallbacks.add(callback);
|
|
2308
|
+
return () => {
|
|
2309
|
+
this.notificationCallbacks.delete(callback);
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
return this.metamaskConnectMultichain.transport.onNotification(callback);
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
2315
|
+
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2316
|
+
walletCreateSession_fn = function(request) {
|
|
2317
|
+
return __async(this, null, function* () {
|
|
2318
|
+
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
2319
|
+
const createSessionParams = request.params;
|
|
2320
|
+
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
2321
|
+
const scopeAccounts = [];
|
|
2322
|
+
scopes.forEach((scope) => {
|
|
2323
|
+
var _a2, _b, _c, _d;
|
|
2324
|
+
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
2325
|
+
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
2326
|
+
if (requiredScope) {
|
|
2327
|
+
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
2328
|
+
}
|
|
2329
|
+
if (optionalScope) {
|
|
2330
|
+
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
const accounts = [...new Set(scopeAccounts)];
|
|
2334
|
+
console.log("\u{1F4DA} SDK connect");
|
|
2335
|
+
yield this.metamaskConnectMultichain.connect(
|
|
2336
|
+
scopes,
|
|
2337
|
+
accounts,
|
|
2338
|
+
createSessionParams.sessionProperties
|
|
2339
|
+
);
|
|
2340
|
+
console.log("\u{1F4DA} SDK connected");
|
|
2341
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
2342
|
+
method: "wallet_getSession"
|
|
2343
|
+
});
|
|
2344
|
+
});
|
|
2345
|
+
};
|
|
2346
|
+
walletGetSession_fn = function(request) {
|
|
2347
|
+
return __async(this, null, function* () {
|
|
2348
|
+
if (!this.isTransportDefined()) {
|
|
2349
|
+
return {
|
|
2350
|
+
jsonrpc: "2.0",
|
|
2351
|
+
id: request.id,
|
|
2352
|
+
result: {
|
|
2353
|
+
sessionScopes: {}
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
2358
|
+
method: "wallet_getSession"
|
|
2359
|
+
});
|
|
2360
|
+
});
|
|
2361
|
+
};
|
|
2362
|
+
walletRevokeSession_fn = function(request) {
|
|
2363
|
+
return __async(this, null, function* () {
|
|
2364
|
+
if (!this.isTransportDefined()) {
|
|
2365
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2366
|
+
}
|
|
2367
|
+
try {
|
|
2368
|
+
this.metamaskConnectMultichain.disconnect();
|
|
2369
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2370
|
+
} catch (error) {
|
|
2371
|
+
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
};
|
|
2375
|
+
walletInvokeMethod_fn = function(request) {
|
|
2376
|
+
return __async(this, null, function* () {
|
|
2377
|
+
if (!this.isTransportDefined()) {
|
|
2378
|
+
return { error: providerErrors.unauthorized() };
|
|
2379
|
+
}
|
|
2380
|
+
const result = this.metamaskConnectMultichain.invokeMethod(
|
|
2381
|
+
request.params
|
|
2382
|
+
);
|
|
2383
|
+
return {
|
|
2384
|
+
result
|
|
2385
|
+
};
|
|
2386
|
+
});
|
|
2387
|
+
};
|
|
2388
|
+
|
|
2389
|
+
// src/multichain/index.ts
|
|
2181
2390
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2182
|
-
var _a, _provider, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo,
|
|
2183
|
-
var
|
|
2391
|
+
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;
|
|
2392
|
+
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2184
2393
|
constructor(options) {
|
|
2185
2394
|
var _a2, _b, _c, _d, _e, _f;
|
|
2186
2395
|
const withDappMetadata = setupDappMetadata(options);
|
|
@@ -2196,34 +2405,30 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2196
2405
|
})
|
|
2197
2406
|
});
|
|
2198
2407
|
super(allOptions);
|
|
2199
|
-
__privateAdd(this,
|
|
2408
|
+
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
2200
2409
|
__privateAdd(this, _provider);
|
|
2410
|
+
__privateAdd(this, _providerTransportWrapper);
|
|
2201
2411
|
__privateAdd(this, _transport2);
|
|
2202
2412
|
__privateAdd(this, _dappClient);
|
|
2203
2413
|
__privateAdd(this, _beforeUnloadListener);
|
|
2204
|
-
this.
|
|
2414
|
+
this._status = "pending";
|
|
2205
2415
|
__privateAdd(this, _listener);
|
|
2206
2416
|
__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}`);
|
|
2417
|
+
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
|
|
2418
|
+
__privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _providerTransportWrapper) }));
|
|
2207
2419
|
}
|
|
2208
|
-
get
|
|
2209
|
-
return this.
|
|
2420
|
+
get status() {
|
|
2421
|
+
return this._status;
|
|
2210
2422
|
}
|
|
2211
|
-
set
|
|
2423
|
+
set status(value) {
|
|
2212
2424
|
var _a2, _b;
|
|
2213
|
-
this.
|
|
2425
|
+
this._status = value;
|
|
2214
2426
|
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2215
2427
|
method: "stateChanged",
|
|
2216
2428
|
params: value
|
|
2217
2429
|
});
|
|
2218
2430
|
}
|
|
2219
2431
|
get provider() {
|
|
2220
|
-
if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
|
|
2221
|
-
__privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _transport2) }));
|
|
2222
|
-
return __privateGet(this, _provider);
|
|
2223
|
-
}
|
|
2224
|
-
if (!__privateGet(this, _provider)) {
|
|
2225
|
-
throw new Error("Provider not initialized, establish connection first");
|
|
2226
|
-
}
|
|
2227
2432
|
return __privateGet(this, _provider);
|
|
2228
2433
|
}
|
|
2229
2434
|
get transport() {
|
|
@@ -2247,7 +2452,7 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2247
2452
|
static create(options) {
|
|
2248
2453
|
return __async(this, null, function* () {
|
|
2249
2454
|
var _a2;
|
|
2250
|
-
const instance = new
|
|
2455
|
+
const instance = new _MetaMaskConnectMultichain(options);
|
|
2251
2456
|
const isEnabled2 = yield isEnabled(
|
|
2252
2457
|
"metamask-sdk:core",
|
|
2253
2458
|
instance.options.storage
|
|
@@ -2255,14 +2460,15 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2255
2460
|
if (isEnabled2) {
|
|
2256
2461
|
enableDebug("metamask-sdk:core");
|
|
2257
2462
|
}
|
|
2258
|
-
yield __privateMethod(_a2 = instance,
|
|
2463
|
+
yield __privateMethod(_a2 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a2);
|
|
2259
2464
|
return instance;
|
|
2260
2465
|
});
|
|
2261
2466
|
}
|
|
2262
|
-
|
|
2467
|
+
// TODO: make this into param object
|
|
2468
|
+
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
2263
2469
|
return __async(this, null, function* () {
|
|
2264
2470
|
var _a2;
|
|
2265
|
-
if (this.
|
|
2471
|
+
if (this.status !== "connected") {
|
|
2266
2472
|
yield this.disconnect();
|
|
2267
2473
|
}
|
|
2268
2474
|
const { ui } = this.options;
|
|
@@ -2294,7 +2500,7 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2294
2500
|
logger2("Error tracking connection_initiated event", error);
|
|
2295
2501
|
}
|
|
2296
2502
|
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2297
|
-
return __privateMethod(this,
|
|
2503
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties, forceRequest }).then(() => __async(this, null, function* () {
|
|
2298
2504
|
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2299
2505
|
return this.storage.setTransport("mwp" /* MWP */);
|
|
2300
2506
|
}
|
|
@@ -2302,19 +2508,19 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2302
2508
|
})), scopes, transportType);
|
|
2303
2509
|
}
|
|
2304
2510
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2305
|
-
const defaultTransport = yield __privateMethod(this,
|
|
2306
|
-
return __privateMethod(this,
|
|
2511
|
+
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2512
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2307
2513
|
}
|
|
2308
2514
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2309
|
-
const defaultTransport = yield __privateMethod(this,
|
|
2310
|
-
return __privateMethod(this,
|
|
2515
|
+
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2516
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2311
2517
|
}
|
|
2312
|
-
yield __privateMethod(this,
|
|
2518
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
|
|
2313
2519
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2314
2520
|
if (secure && !shouldShowInstallModal) {
|
|
2315
|
-
return __privateMethod(this,
|
|
2521
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2316
2522
|
}
|
|
2317
|
-
return __privateMethod(this,
|
|
2523
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2318
2524
|
});
|
|
2319
2525
|
}
|
|
2320
2526
|
emit(event, args) {
|
|
@@ -2333,15 +2539,13 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2333
2539
|
__privateSet(this, _listener, void 0);
|
|
2334
2540
|
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2335
2541
|
__privateSet(this, _transport2, void 0);
|
|
2336
|
-
|
|
2542
|
+
__privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
|
|
2337
2543
|
__privateSet(this, _dappClient, void 0);
|
|
2338
2544
|
});
|
|
2339
2545
|
}
|
|
2340
2546
|
invokeMethod(request) {
|
|
2341
2547
|
return __async(this, null, function* () {
|
|
2342
|
-
var _a2;
|
|
2343
2548
|
const { transport, options } = this;
|
|
2344
|
-
(_a2 = __privateGet(this, _provider)) != null ? _a2 : __privateSet(this, _provider, getMultichainClient({ transport }));
|
|
2345
2549
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2346
2550
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2347
2551
|
return requestRouter.invokeMethod(request);
|
|
@@ -2370,12 +2574,13 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2370
2574
|
}
|
|
2371
2575
|
};
|
|
2372
2576
|
_provider = new WeakMap();
|
|
2577
|
+
_providerTransportWrapper = new WeakMap();
|
|
2373
2578
|
_transport2 = new WeakMap();
|
|
2374
2579
|
_dappClient = new WeakMap();
|
|
2375
2580
|
_beforeUnloadListener = new WeakMap();
|
|
2376
2581
|
_listener = new WeakMap();
|
|
2377
2582
|
_sdkInfo = new WeakMap();
|
|
2378
|
-
|
|
2583
|
+
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2379
2584
|
setupAnalytics_fn = function() {
|
|
2380
2585
|
return __async(this, null, function* () {
|
|
2381
2586
|
var _a2;
|
|
@@ -2416,19 +2621,21 @@ getStoredTransport_fn = function() {
|
|
|
2416
2621
|
if (hasExtensionInstalled) {
|
|
2417
2622
|
const apiTransport = new DefaultTransport();
|
|
2418
2623
|
__privateSet(this, _transport2, apiTransport);
|
|
2624
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2419
2625
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2420
|
-
__privateMethod(this,
|
|
2626
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2421
2627
|
));
|
|
2422
2628
|
return apiTransport;
|
|
2423
2629
|
}
|
|
2424
2630
|
} else if (transportType === "mwp" /* MWP */) {
|
|
2425
2631
|
const { adapter: kvstore } = this.options.storage;
|
|
2426
|
-
const dappClient = yield __privateMethod(this,
|
|
2632
|
+
const dappClient = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, createDappClient_fn).call(this);
|
|
2427
2633
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2428
2634
|
__privateSet(this, _dappClient, dappClient);
|
|
2429
2635
|
__privateSet(this, _transport2, apiTransport);
|
|
2636
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2430
2637
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2431
|
-
__privateMethod(this,
|
|
2638
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2432
2639
|
));
|
|
2433
2640
|
return apiTransport;
|
|
2434
2641
|
}
|
|
@@ -2439,20 +2646,20 @@ getStoredTransport_fn = function() {
|
|
|
2439
2646
|
};
|
|
2440
2647
|
setupTransport_fn = function() {
|
|
2441
2648
|
return __async(this, null, function* () {
|
|
2442
|
-
const transport = yield __privateMethod(this,
|
|
2649
|
+
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
2443
2650
|
if (transport) {
|
|
2444
2651
|
if (!this.transport.isConnected()) {
|
|
2445
|
-
this.
|
|
2652
|
+
this.status = "connecting";
|
|
2446
2653
|
yield this.transport.connect();
|
|
2447
2654
|
}
|
|
2448
|
-
this.
|
|
2655
|
+
this.status = "connected";
|
|
2449
2656
|
if (this.transport instanceof MWPTransport) {
|
|
2450
2657
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2451
2658
|
} else {
|
|
2452
2659
|
yield this.storage.setTransport("browser" /* Browser */);
|
|
2453
2660
|
}
|
|
2454
2661
|
} else {
|
|
2455
|
-
this.
|
|
2662
|
+
this.status = "loaded";
|
|
2456
2663
|
}
|
|
2457
2664
|
});
|
|
2458
2665
|
};
|
|
@@ -2463,8 +2670,8 @@ init_fn = function() {
|
|
|
2463
2670
|
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2464
2671
|
logger2("MetaMaskSDK: init already initialized");
|
|
2465
2672
|
} else {
|
|
2466
|
-
yield __privateMethod(this,
|
|
2467
|
-
yield __privateMethod(this,
|
|
2673
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
2674
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
2468
2675
|
try {
|
|
2469
2676
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2470
2677
|
this.options,
|
|
@@ -2480,7 +2687,7 @@ init_fn = function() {
|
|
|
2480
2687
|
}
|
|
2481
2688
|
} catch (error) {
|
|
2482
2689
|
yield this.storage.removeTransport();
|
|
2483
|
-
this.
|
|
2690
|
+
this.status = "pending";
|
|
2484
2691
|
logger2("MetaMaskSDK error during initialization", error);
|
|
2485
2692
|
}
|
|
2486
2693
|
});
|
|
@@ -2508,12 +2715,13 @@ setupMWP_fn = function() {
|
|
|
2508
2715
|
return;
|
|
2509
2716
|
}
|
|
2510
2717
|
const { adapter: kvstore } = this.options.storage;
|
|
2511
|
-
const dappClient = yield __privateMethod(this,
|
|
2718
|
+
const dappClient = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, createDappClient_fn).call(this);
|
|
2512
2719
|
__privateSet(this, _dappClient, dappClient);
|
|
2513
2720
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2514
2721
|
__privateSet(this, _transport2, apiTransport);
|
|
2722
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2515
2723
|
__privateSet(this, _listener, this.transport.onNotification(
|
|
2516
|
-
__privateMethod(this,
|
|
2724
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2517
2725
|
));
|
|
2518
2726
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2519
2727
|
});
|
|
@@ -2528,18 +2736,18 @@ onBeforeUnload_fn = function() {
|
|
|
2528
2736
|
};
|
|
2529
2737
|
createBeforeUnloadListener_fn = function() {
|
|
2530
2738
|
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2531
|
-
window.addEventListener("beforeunload", __privateMethod(this,
|
|
2739
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this));
|
|
2532
2740
|
}
|
|
2533
2741
|
return () => {
|
|
2534
2742
|
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2535
2743
|
window.removeEventListener(
|
|
2536
2744
|
"beforeunload",
|
|
2537
|
-
__privateMethod(this,
|
|
2745
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this)
|
|
2538
2746
|
);
|
|
2539
2747
|
}
|
|
2540
2748
|
};
|
|
2541
2749
|
};
|
|
2542
|
-
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2750
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2543
2751
|
return __async(this, null, function* () {
|
|
2544
2752
|
return new Promise((resolve, reject) => {
|
|
2545
2753
|
this.options.ui.factory.renderInstallModal(
|
|
@@ -2567,19 +2775,19 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds)
|
|
|
2567
2775
|
(() => __async(this, null, function* () {
|
|
2568
2776
|
var _a2;
|
|
2569
2777
|
try {
|
|
2570
|
-
yield this.transport.connect({ scopes, caipAccountIds });
|
|
2778
|
+
yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
|
|
2571
2779
|
yield this.options.ui.factory.unload();
|
|
2572
2780
|
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2573
|
-
this.
|
|
2781
|
+
this.status = "connected";
|
|
2574
2782
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2575
2783
|
} catch (error) {
|
|
2576
2784
|
if (error instanceof ProtocolError) {
|
|
2577
2785
|
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2578
|
-
this.
|
|
2786
|
+
this.status = "disconnected";
|
|
2579
2787
|
reject(error);
|
|
2580
2788
|
}
|
|
2581
2789
|
} else {
|
|
2582
|
-
this.
|
|
2790
|
+
this.status = "disconnected";
|
|
2583
2791
|
reject(
|
|
2584
2792
|
error instanceof Error ? error : new Error(String(error))
|
|
2585
2793
|
);
|
|
@@ -2597,33 +2805,83 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds)
|
|
|
2597
2805
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2598
2806
|
resolve();
|
|
2599
2807
|
}
|
|
2600
|
-
})
|
|
2808
|
+
}),
|
|
2809
|
+
(uri) => {
|
|
2810
|
+
this.emit("display_uri", uri);
|
|
2811
|
+
}
|
|
2601
2812
|
).catch((error) => {
|
|
2602
2813
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2603
2814
|
});
|
|
2604
2815
|
});
|
|
2605
2816
|
});
|
|
2606
2817
|
};
|
|
2607
|
-
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2818
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2608
2819
|
return __async(this, null, function* () {
|
|
2609
2820
|
var _a2;
|
|
2610
|
-
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this,
|
|
2611
|
-
|
|
2821
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
|
|
2822
|
+
if (this.options.ui.headless) {
|
|
2823
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
|
|
2824
|
+
} else {
|
|
2825
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2828
|
+
};
|
|
2829
|
+
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2830
|
+
return __async(this, null, function* () {
|
|
2831
|
+
return new Promise((resolve, reject) => {
|
|
2832
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2833
|
+
this.dappClient.disconnect().catch(() => {
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
this.dappClient.on(
|
|
2837
|
+
"session_request",
|
|
2838
|
+
(sessionRequest) => {
|
|
2839
|
+
const connectionRequest = {
|
|
2840
|
+
sessionRequest,
|
|
2841
|
+
metadata: {
|
|
2842
|
+
dapp: this.options.dapp,
|
|
2843
|
+
sdk: {
|
|
2844
|
+
version: getVersion(),
|
|
2845
|
+
platform: getPlatformType()
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
};
|
|
2849
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2850
|
+
this.emit("display_uri", deeplink);
|
|
2851
|
+
}
|
|
2852
|
+
);
|
|
2853
|
+
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
2854
|
+
this.status = "connected";
|
|
2855
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2856
|
+
resolve();
|
|
2857
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2858
|
+
if (error instanceof ProtocolError) {
|
|
2859
|
+
this.status = "disconnected";
|
|
2860
|
+
yield this.storage.removeTransport();
|
|
2861
|
+
reject(error);
|
|
2862
|
+
} else {
|
|
2863
|
+
this.status = "disconnected";
|
|
2864
|
+
yield this.storage.removeTransport();
|
|
2865
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2866
|
+
}
|
|
2867
|
+
}));
|
|
2868
|
+
});
|
|
2612
2869
|
});
|
|
2613
2870
|
};
|
|
2614
2871
|
setupDefaultTransport_fn = function() {
|
|
2615
2872
|
return __async(this, null, function* () {
|
|
2616
|
-
this.
|
|
2873
|
+
this.status = "connecting";
|
|
2617
2874
|
yield this.storage.setTransport("browser" /* Browser */);
|
|
2618
2875
|
const transport = new DefaultTransport();
|
|
2619
2876
|
__privateSet(this, _listener, transport.onNotification(
|
|
2620
|
-
__privateMethod(this,
|
|
2877
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2621
2878
|
));
|
|
2622
2879
|
__privateSet(this, _transport2, transport);
|
|
2880
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2623
2881
|
return transport;
|
|
2624
2882
|
});
|
|
2625
2883
|
};
|
|
2626
|
-
deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
2884
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2627
2885
|
return __async(this, null, function* () {
|
|
2628
2886
|
return new Promise((resolve, reject) => {
|
|
2629
2887
|
const dappClientMessageHandler = (payload) => {
|
|
@@ -2666,6 +2924,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2666
2924
|
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2667
2925
|
connectionRequest
|
|
2668
2926
|
);
|
|
2927
|
+
this.emit("display_uri", deeplink);
|
|
2669
2928
|
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2670
2929
|
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2671
2930
|
} else {
|
|
@@ -2674,7 +2933,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2674
2933
|
}
|
|
2675
2934
|
);
|
|
2676
2935
|
}
|
|
2677
|
-
return this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2936
|
+
return this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2678
2937
|
yield this.storage.removeTransport();
|
|
2679
2938
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
2680
2939
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -2688,9 +2947,9 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2688
2947
|
};
|
|
2689
2948
|
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2690
2949
|
return __async(this, null, function* () {
|
|
2691
|
-
this.
|
|
2950
|
+
this.status = "connecting";
|
|
2692
2951
|
return promise.then(() => __async(this, null, function* () {
|
|
2693
|
-
this.
|
|
2952
|
+
this.status = "connected";
|
|
2694
2953
|
try {
|
|
2695
2954
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2696
2955
|
this.options,
|
|
@@ -2705,7 +2964,7 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
2705
2964
|
}
|
|
2706
2965
|
return void 0;
|
|
2707
2966
|
})).catch((error) => __async(this, null, function* () {
|
|
2708
|
-
this.
|
|
2967
|
+
this.status = "disconnected";
|
|
2709
2968
|
try {
|
|
2710
2969
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2711
2970
|
this.options,
|
|
@@ -2728,7 +2987,7 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
2728
2987
|
}));
|
|
2729
2988
|
});
|
|
2730
2989
|
};
|
|
2731
|
-
var
|
|
2990
|
+
var MetaMaskConnectMultichain = _MetaMaskConnectMultichain;
|
|
2732
2991
|
|
|
2733
2992
|
// src/store/index.ts
|
|
2734
2993
|
import * as uuid from "uuid";
|
|
@@ -2909,28 +3168,11 @@ var Store = class extends StoreClient {
|
|
|
2909
3168
|
}
|
|
2910
3169
|
};
|
|
2911
3170
|
|
|
2912
|
-
// src/ui/
|
|
3171
|
+
// src/ui/ModalFactory.ts
|
|
2913
3172
|
import MetaMaskOnboarding from "@metamask/onboarding";
|
|
2914
3173
|
init_domain();
|
|
2915
3174
|
init_utils();
|
|
2916
|
-
|
|
2917
|
-
// src/ui/preload.web.ts
|
|
2918
|
-
function preload() {
|
|
2919
|
-
return __async(this, null, function* () {
|
|
2920
|
-
if (typeof document === "undefined") {
|
|
2921
|
-
return;
|
|
2922
|
-
}
|
|
2923
|
-
try {
|
|
2924
|
-
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
2925
|
-
yield defineCustomElements();
|
|
2926
|
-
} catch (error) {
|
|
2927
|
-
console.error("Failed to load customElements:", error);
|
|
2928
|
-
}
|
|
2929
|
-
});
|
|
2930
|
-
}
|
|
2931
|
-
|
|
2932
|
-
// src/ui/index.ts
|
|
2933
|
-
var ModalFactory = class {
|
|
3175
|
+
var BaseModalFactory = class {
|
|
2934
3176
|
/**
|
|
2935
3177
|
* Creates a new modal factory instance.
|
|
2936
3178
|
*
|
|
@@ -3019,15 +3261,17 @@ var ModalFactory = class {
|
|
|
3019
3261
|
onStartDesktopOnboarding() {
|
|
3020
3262
|
new MetaMaskOnboarding().startOnboarding();
|
|
3021
3263
|
}
|
|
3022
|
-
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
3264
|
+
renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
|
|
3023
3265
|
return __async(this, null, function* () {
|
|
3024
|
-
var _a2;
|
|
3266
|
+
var _a2, _b;
|
|
3025
3267
|
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3026
|
-
yield preload();
|
|
3268
|
+
yield this.preload();
|
|
3027
3269
|
this.successCallback = successCallback;
|
|
3270
|
+
this.displayUriCallback = onDisplayUri;
|
|
3028
3271
|
const parentElement = this.getMountedContainer();
|
|
3029
3272
|
const connectionRequest = yield createConnectionRequest();
|
|
3030
3273
|
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
3274
|
+
(_b = this.displayUriCallback) == null ? void 0 : _b.call(this, qrCodeLink);
|
|
3031
3275
|
const modal = new this.options.InstallModal({
|
|
3032
3276
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
3033
3277
|
connectionRequest,
|
|
@@ -3036,11 +3280,15 @@ var ModalFactory = class {
|
|
|
3036
3280
|
link: qrCodeLink,
|
|
3037
3281
|
sdkVersion: getVersion(),
|
|
3038
3282
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
3039
|
-
|
|
3283
|
+
var _a3;
|
|
3284
|
+
const newLink = this.createConnectionDeeplink(request);
|
|
3285
|
+
(_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
|
|
3286
|
+
return newLink;
|
|
3040
3287
|
}),
|
|
3041
3288
|
onClose: this.onCloseModal.bind(this),
|
|
3042
3289
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
3043
|
-
createConnectionRequest
|
|
3290
|
+
createConnectionRequest,
|
|
3291
|
+
onDisplayUri: this.displayUriCallback
|
|
3044
3292
|
});
|
|
3045
3293
|
this.modal = modal;
|
|
3046
3294
|
modal.mount();
|
|
@@ -3050,7 +3298,7 @@ var ModalFactory = class {
|
|
|
3050
3298
|
return __async(this, null, function* () {
|
|
3051
3299
|
var _a2;
|
|
3052
3300
|
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
3053
|
-
yield preload();
|
|
3301
|
+
yield this.preload();
|
|
3054
3302
|
this.successCallback = successCallback;
|
|
3055
3303
|
const container = this.getMountedContainer();
|
|
3056
3304
|
const otpCode = yield createOTPCode();
|
|
@@ -3068,9 +3316,31 @@ var ModalFactory = class {
|
|
|
3068
3316
|
}
|
|
3069
3317
|
};
|
|
3070
3318
|
|
|
3319
|
+
// src/ui/index.ts
|
|
3320
|
+
function preload() {
|
|
3321
|
+
return __async(this, null, function* () {
|
|
3322
|
+
if (typeof document === "undefined") {
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
try {
|
|
3326
|
+
const { defineCustomElements } = yield import("@metamask/multichain-ui/loader");
|
|
3327
|
+
yield defineCustomElements();
|
|
3328
|
+
} catch (error) {
|
|
3329
|
+
console.error("Failed to load customElements:", error);
|
|
3330
|
+
}
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
var ModalFactory = class extends BaseModalFactory {
|
|
3334
|
+
preload() {
|
|
3335
|
+
return __async(this, null, function* () {
|
|
3336
|
+
return preload();
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
};
|
|
3340
|
+
|
|
3071
3341
|
// src/index.browser.ts
|
|
3072
3342
|
init_domain();
|
|
3073
|
-
var
|
|
3343
|
+
var createMultichainClient = (options) => __async(null, null, function* () {
|
|
3074
3344
|
const uiModules = yield Promise.resolve().then(() => (init_web(), web_exports));
|
|
3075
3345
|
let storage;
|
|
3076
3346
|
if (!options.storage) {
|
|
@@ -3081,7 +3351,7 @@ var createMetamaskConnect = (options) => __async(null, null, function* () {
|
|
|
3081
3351
|
storage = options.storage;
|
|
3082
3352
|
}
|
|
3083
3353
|
const factory = new ModalFactory(uiModules);
|
|
3084
|
-
return
|
|
3354
|
+
return MetaMaskConnectMultichain.create(__spreadProps(__spreadValues({}, options), {
|
|
3085
3355
|
storage,
|
|
3086
3356
|
ui: __spreadProps(__spreadValues({}, options.ui), {
|
|
3087
3357
|
factory
|
|
@@ -3103,7 +3373,7 @@ export {
|
|
|
3103
3373
|
StoreClient,
|
|
3104
3374
|
TransportType,
|
|
3105
3375
|
createLogger,
|
|
3106
|
-
|
|
3376
|
+
createMultichainClient,
|
|
3107
3377
|
enableDebug,
|
|
3108
3378
|
getInfuraRpcUrls,
|
|
3109
3379
|
getPlatformType,
|