@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
|
}
|
|
@@ -1080,6 +1075,13 @@ var init_rn2 = __esm({
|
|
|
1080
1075
|
}
|
|
1081
1076
|
});
|
|
1082
1077
|
|
|
1078
|
+
// src/polyfills/buffer-shim.ts
|
|
1079
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
1080
|
+
var g = typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {};
|
|
1081
|
+
if (!g.Buffer) {
|
|
1082
|
+
g.Buffer = Buffer2;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1083
1085
|
// src/multichain/index.ts
|
|
1084
1086
|
import { analytics as analytics2 } from "@metamask/analytics";
|
|
1085
1087
|
import {
|
|
@@ -1446,7 +1448,8 @@ var DefaultTransport = class {
|
|
|
1446
1448
|
getValidAccounts((_g = options == null ? void 0 : options.caipAccountIds) != null ? _g : [])
|
|
1447
1449
|
);
|
|
1448
1450
|
const createSessionParams = {
|
|
1449
|
-
optionalScopes
|
|
1451
|
+
optionalScopes,
|
|
1452
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1450
1453
|
};
|
|
1451
1454
|
const response = yield this.request(
|
|
1452
1455
|
{ method: "wallet_createSession", params: createSessionParams },
|
|
@@ -1588,6 +1591,7 @@ var MULTICHAIN_PROVIDER_STREAM_NAME = "metamask-multichain-provider";
|
|
|
1588
1591
|
var DEFAULT_REQUEST_TIMEOUT2 = 60 * 1e3;
|
|
1589
1592
|
var CONNECTION_GRACE_PERIOD = 60 * 1e3;
|
|
1590
1593
|
var DEFAULT_CONNECTION_TIMEOUT = DEFAULT_REQUEST_TIMEOUT2 + CONNECTION_GRACE_PERIOD;
|
|
1594
|
+
var DEFAULT_RESUME_TIMEOUT = 10 * 1e3;
|
|
1591
1595
|
var SESSION_STORE_KEY = "cache_wallet_getSession";
|
|
1592
1596
|
var ACCOUNTS_STORE_KEY = "cache_eth_accounts";
|
|
1593
1597
|
var CHAIN_STORE_KEY = "cache_eth_chainId";
|
|
@@ -1604,7 +1608,8 @@ var logger = createLogger("metamask-sdk:transport");
|
|
|
1604
1608
|
var MWPTransport = class {
|
|
1605
1609
|
constructor(dappClient, kvstore, options = {
|
|
1606
1610
|
requestTimeout: DEFAULT_REQUEST_TIMEOUT2,
|
|
1607
|
-
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT
|
|
1611
|
+
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
|
|
1612
|
+
resumeTimeout: DEFAULT_RESUME_TIMEOUT
|
|
1608
1613
|
}) {
|
|
1609
1614
|
this.dappClient = dappClient;
|
|
1610
1615
|
this.kvstore = kvstore;
|
|
@@ -1679,6 +1684,13 @@ var MWPTransport = class {
|
|
|
1679
1684
|
)
|
|
1680
1685
|
);
|
|
1681
1686
|
}
|
|
1687
|
+
if (message.data.method === "wallet_sessionChanged") {
|
|
1688
|
+
const notification = message.data;
|
|
1689
|
+
const response = {
|
|
1690
|
+
result: notification.params
|
|
1691
|
+
};
|
|
1692
|
+
this.kvstore.set(SESSION_STORE_KEY, JSON.stringify(response));
|
|
1693
|
+
}
|
|
1682
1694
|
this.notifyCallbacks(message.data);
|
|
1683
1695
|
}
|
|
1684
1696
|
}
|
|
@@ -1688,6 +1700,7 @@ var MWPTransport = class {
|
|
|
1688
1700
|
return __async(this, null, function* () {
|
|
1689
1701
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1690
1702
|
try {
|
|
1703
|
+
yield this.waitForWalletSessionIfNotCached();
|
|
1691
1704
|
const sessionRequest = yield this.request({
|
|
1692
1705
|
method: "wallet_getSession"
|
|
1693
1706
|
});
|
|
@@ -1792,7 +1805,7 @@ var MWPTransport = class {
|
|
|
1792
1805
|
}
|
|
1793
1806
|
let timeout;
|
|
1794
1807
|
let initialConnectionMessageHandler;
|
|
1795
|
-
const connectionPromise = new Promise((resolve, reject) => {
|
|
1808
|
+
const connectionPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
|
1796
1809
|
let connection;
|
|
1797
1810
|
if (session) {
|
|
1798
1811
|
connection = new Promise((resumeResolve, resumeReject) => {
|
|
@@ -1815,7 +1828,8 @@ var MWPTransport = class {
|
|
|
1815
1828
|
getValidAccounts((_b = options == null ? void 0 : options.caipAccountIds) != null ? _b : [])
|
|
1816
1829
|
);
|
|
1817
1830
|
const sessionRequest = {
|
|
1818
|
-
optionalScopes
|
|
1831
|
+
optionalScopes,
|
|
1832
|
+
sessionProperties: options == null ? void 0 : options.sessionProperties
|
|
1819
1833
|
};
|
|
1820
1834
|
const request = {
|
|
1821
1835
|
jsonrpc: "2.0",
|
|
@@ -1870,7 +1884,7 @@ var MWPTransport = class {
|
|
|
1870
1884
|
reject(new TransportTimeoutError());
|
|
1871
1885
|
}, this.options.connectionTimeout);
|
|
1872
1886
|
connection.then(resolve).catch(reject);
|
|
1873
|
-
});
|
|
1887
|
+
}));
|
|
1874
1888
|
return connectionPromise.catch((error) => {
|
|
1875
1889
|
throw error;
|
|
1876
1890
|
}).finally(() => {
|
|
@@ -2055,6 +2069,43 @@ var MWPTransport = class {
|
|
|
2055
2069
|
}
|
|
2056
2070
|
});
|
|
2057
2071
|
}
|
|
2072
|
+
// This method checks if an existing CAIP session response is cached or waits for one
|
|
2073
|
+
// to be received from the wallet if not cached. This is necessary because there is an edge
|
|
2074
|
+
// case during the initial connection flow where after the user has accepted the permission approval
|
|
2075
|
+
// and returned back to the dapp from the wallet, the dapp page may have gotten unloaded and refreshed.
|
|
2076
|
+
// When it is unloaded and refreshed, it will try to resume the session by making a request for wallet_getSession
|
|
2077
|
+
// which should resolve from cache, but because a race condition makes it possible for the response from the wallet
|
|
2078
|
+
// for the initial wallet_createSession connection request to not have been handled and cached yet. This results
|
|
2079
|
+
// in the wallet_getSession request never resolving unless we wait for it explicitly as done in this method.
|
|
2080
|
+
waitForWalletSessionIfNotCached() {
|
|
2081
|
+
return __async(this, null, function* () {
|
|
2082
|
+
const cachedWalletGetSessionResponse = yield this.kvstore.get(SESSION_STORE_KEY);
|
|
2083
|
+
if (cachedWalletGetSessionResponse) {
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
let unsubscribe;
|
|
2087
|
+
const responsePromise = new Promise((resolve) => {
|
|
2088
|
+
unsubscribe = this.onNotification((message) => {
|
|
2089
|
+
if (typeof message === "object" && message !== null) {
|
|
2090
|
+
if ("data" in message) {
|
|
2091
|
+
const messagePayload = message.data;
|
|
2092
|
+
if (messagePayload.method === "wallet_getSession" || messagePayload.method === "wallet_sessionChanged") {
|
|
2093
|
+
unsubscribe();
|
|
2094
|
+
resolve();
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
});
|
|
2100
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
2101
|
+
setTimeout(() => {
|
|
2102
|
+
unsubscribe();
|
|
2103
|
+
reject(new TransportTimeoutError());
|
|
2104
|
+
}, this.options.resumeTimeout);
|
|
2105
|
+
});
|
|
2106
|
+
return Promise.race([responsePromise, timeoutPromise]);
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2058
2109
|
};
|
|
2059
2110
|
|
|
2060
2111
|
// src/multichain/transports/mwp/KeyManager.ts
|
|
@@ -2086,9 +2137,167 @@ var keymanager = new KeyManager();
|
|
|
2086
2137
|
|
|
2087
2138
|
// src/multichain/index.ts
|
|
2088
2139
|
init_utils();
|
|
2140
|
+
|
|
2141
|
+
// src/multichain/transports/multichainApiClientWrapper/index.ts
|
|
2142
|
+
import { providerErrors } from "@metamask/rpc-errors";
|
|
2143
|
+
var MAX = 4294967295;
|
|
2144
|
+
var idCounter = Math.floor(Math.random() * MAX);
|
|
2145
|
+
var getUniqueId = () => {
|
|
2146
|
+
idCounter = (idCounter + 1) % MAX;
|
|
2147
|
+
return idCounter;
|
|
2148
|
+
};
|
|
2149
|
+
var _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn, walletGetSession_fn, walletRevokeSession_fn, walletInvokeMethod_fn;
|
|
2150
|
+
var MultichainApiClientWrapperTransport = class {
|
|
2151
|
+
constructor(metamaskConnectMultichain) {
|
|
2152
|
+
this.metamaskConnectMultichain = metamaskConnectMultichain;
|
|
2153
|
+
__privateAdd(this, _MultichainApiClientWrapperTransport_instances);
|
|
2154
|
+
this.requestId = getUniqueId();
|
|
2155
|
+
this.notificationCallbacks = /* @__PURE__ */ new Set();
|
|
2156
|
+
}
|
|
2157
|
+
isTransportDefined() {
|
|
2158
|
+
try {
|
|
2159
|
+
return Boolean(this.metamaskConnectMultichain.transport);
|
|
2160
|
+
} catch (error) {
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
clearNotificationCallbacks() {
|
|
2165
|
+
this.notificationCallbacks.clear();
|
|
2166
|
+
}
|
|
2167
|
+
notifyCallbacks(data) {
|
|
2168
|
+
this.notificationCallbacks.forEach((callback) => {
|
|
2169
|
+
callback(data);
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
setupNotifcationListener() {
|
|
2173
|
+
this.metamaskConnectMultichain.transport.onNotification(
|
|
2174
|
+
this.notifyCallbacks.bind(this)
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
2177
|
+
connect() {
|
|
2178
|
+
return __async(this, null, function* () {
|
|
2179
|
+
console.log("\u{1F4DA} connect");
|
|
2180
|
+
return Promise.resolve();
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
disconnect() {
|
|
2184
|
+
return __async(this, null, function* () {
|
|
2185
|
+
return Promise.resolve();
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
isConnected() {
|
|
2189
|
+
return true;
|
|
2190
|
+
}
|
|
2191
|
+
request(_0) {
|
|
2192
|
+
return __async(this, arguments, function* (params, _options = {}) {
|
|
2193
|
+
const id = this.requestId++;
|
|
2194
|
+
const requestPayload = __spreadValues({
|
|
2195
|
+
id,
|
|
2196
|
+
jsonrpc: "2.0"
|
|
2197
|
+
}, params);
|
|
2198
|
+
switch (requestPayload.method) {
|
|
2199
|
+
case "wallet_createSession":
|
|
2200
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletCreateSession_fn).call(this, requestPayload);
|
|
2201
|
+
case "wallet_getSession":
|
|
2202
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletGetSession_fn).call(this, requestPayload);
|
|
2203
|
+
case "wallet_revokeSession":
|
|
2204
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletRevokeSession_fn).call(this, requestPayload);
|
|
2205
|
+
case "wallet_invokeMethod":
|
|
2206
|
+
return __privateMethod(this, _MultichainApiClientWrapperTransport_instances, walletInvokeMethod_fn).call(this, requestPayload);
|
|
2207
|
+
default:
|
|
2208
|
+
throw new Error(`Unsupported method: ${requestPayload.method}`);
|
|
2209
|
+
}
|
|
2210
|
+
throw new Error(`Unknown method: ${requestPayload.method}`);
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
onNotification(callback) {
|
|
2214
|
+
if (!this.isTransportDefined()) {
|
|
2215
|
+
this.notificationCallbacks.add(callback);
|
|
2216
|
+
return () => {
|
|
2217
|
+
this.notificationCallbacks.delete(callback);
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
return this.metamaskConnectMultichain.transport.onNotification(callback);
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
_MultichainApiClientWrapperTransport_instances = new WeakSet();
|
|
2224
|
+
walletCreateSession_fn = function(request) {
|
|
2225
|
+
return __async(this, null, function* () {
|
|
2226
|
+
console.log("\u{1F4DA} #walletCreateSession", request);
|
|
2227
|
+
const createSessionParams = request.params;
|
|
2228
|
+
const scopes = Object.keys(__spreadValues(__spreadValues({}, createSessionParams.optionalScopes), createSessionParams.requiredScopes));
|
|
2229
|
+
const scopeAccounts = [];
|
|
2230
|
+
scopes.forEach((scope) => {
|
|
2231
|
+
var _a2, _b, _c, _d;
|
|
2232
|
+
const requiredScope = (_a2 = createSessionParams.requiredScopes) == null ? void 0 : _a2[scope];
|
|
2233
|
+
const optionalScope = (_b = createSessionParams.optionalScopes) == null ? void 0 : _b[scope];
|
|
2234
|
+
if (requiredScope) {
|
|
2235
|
+
scopeAccounts.push(...(_c = requiredScope.accounts) != null ? _c : []);
|
|
2236
|
+
}
|
|
2237
|
+
if (optionalScope) {
|
|
2238
|
+
scopeAccounts.push(...(_d = optionalScope.accounts) != null ? _d : []);
|
|
2239
|
+
}
|
|
2240
|
+
});
|
|
2241
|
+
const accounts = [...new Set(scopeAccounts)];
|
|
2242
|
+
console.log("\u{1F4DA} SDK connect");
|
|
2243
|
+
yield this.metamaskConnectMultichain.connect(
|
|
2244
|
+
scopes,
|
|
2245
|
+
accounts,
|
|
2246
|
+
createSessionParams.sessionProperties
|
|
2247
|
+
);
|
|
2248
|
+
console.log("\u{1F4DA} SDK connected");
|
|
2249
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
2250
|
+
method: "wallet_getSession"
|
|
2251
|
+
});
|
|
2252
|
+
});
|
|
2253
|
+
};
|
|
2254
|
+
walletGetSession_fn = function(request) {
|
|
2255
|
+
return __async(this, null, function* () {
|
|
2256
|
+
if (!this.isTransportDefined()) {
|
|
2257
|
+
return {
|
|
2258
|
+
jsonrpc: "2.0",
|
|
2259
|
+
id: request.id,
|
|
2260
|
+
result: {
|
|
2261
|
+
sessionScopes: {}
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
return this.metamaskConnectMultichain.transport.request({
|
|
2266
|
+
method: "wallet_getSession"
|
|
2267
|
+
});
|
|
2268
|
+
});
|
|
2269
|
+
};
|
|
2270
|
+
walletRevokeSession_fn = function(request) {
|
|
2271
|
+
return __async(this, null, function* () {
|
|
2272
|
+
if (!this.isTransportDefined()) {
|
|
2273
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2274
|
+
}
|
|
2275
|
+
try {
|
|
2276
|
+
this.metamaskConnectMultichain.disconnect();
|
|
2277
|
+
return { jsonrpc: "2.0", id: request.id, result: true };
|
|
2278
|
+
} catch (error) {
|
|
2279
|
+
return { jsonrpc: "2.0", id: request.id, result: false };
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
};
|
|
2283
|
+
walletInvokeMethod_fn = function(request) {
|
|
2284
|
+
return __async(this, null, function* () {
|
|
2285
|
+
if (!this.isTransportDefined()) {
|
|
2286
|
+
return { error: providerErrors.unauthorized() };
|
|
2287
|
+
}
|
|
2288
|
+
const result = this.metamaskConnectMultichain.invokeMethod(
|
|
2289
|
+
request.params
|
|
2290
|
+
);
|
|
2291
|
+
return {
|
|
2292
|
+
result
|
|
2293
|
+
};
|
|
2294
|
+
});
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
// src/multichain/index.ts
|
|
2089
2298
|
var logger2 = createLogger("metamask-sdk:core");
|
|
2090
|
-
var _a, _provider, _transport2, _dappClient, _beforeUnloadListener, _listener, _sdkInfo,
|
|
2091
|
-
var
|
|
2299
|
+
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;
|
|
2300
|
+
var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
|
|
2092
2301
|
constructor(options) {
|
|
2093
2302
|
var _a2, _b, _c, _d, _e, _f;
|
|
2094
2303
|
const withDappMetadata = setupDappMetadata(options);
|
|
@@ -2104,34 +2313,30 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2104
2313
|
})
|
|
2105
2314
|
});
|
|
2106
2315
|
super(allOptions);
|
|
2107
|
-
__privateAdd(this,
|
|
2316
|
+
__privateAdd(this, _MetaMaskConnectMultichain_instances);
|
|
2108
2317
|
__privateAdd(this, _provider);
|
|
2318
|
+
__privateAdd(this, _providerTransportWrapper);
|
|
2109
2319
|
__privateAdd(this, _transport2);
|
|
2110
2320
|
__privateAdd(this, _dappClient);
|
|
2111
2321
|
__privateAdd(this, _beforeUnloadListener);
|
|
2112
|
-
this.
|
|
2322
|
+
this._status = "pending";
|
|
2113
2323
|
__privateAdd(this, _listener);
|
|
2114
2324
|
__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}`);
|
|
2325
|
+
__privateSet(this, _providerTransportWrapper, new MultichainApiClientWrapperTransport(this));
|
|
2326
|
+
__privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _providerTransportWrapper) }));
|
|
2115
2327
|
}
|
|
2116
|
-
get
|
|
2117
|
-
return this.
|
|
2328
|
+
get status() {
|
|
2329
|
+
return this._status;
|
|
2118
2330
|
}
|
|
2119
|
-
set
|
|
2331
|
+
set status(value) {
|
|
2120
2332
|
var _a2, _b;
|
|
2121
|
-
this.
|
|
2333
|
+
this._status = value;
|
|
2122
2334
|
(_b = (_a2 = this.options.transport) == null ? void 0 : _a2.onNotification) == null ? void 0 : _b.call(_a2, {
|
|
2123
2335
|
method: "stateChanged",
|
|
2124
2336
|
params: value
|
|
2125
2337
|
});
|
|
2126
2338
|
}
|
|
2127
2339
|
get provider() {
|
|
2128
|
-
if (!__privateGet(this, _provider) && __privateGet(this, _transport2)) {
|
|
2129
|
-
__privateSet(this, _provider, getMultichainClient({ transport: __privateGet(this, _transport2) }));
|
|
2130
|
-
return __privateGet(this, _provider);
|
|
2131
|
-
}
|
|
2132
|
-
if (!__privateGet(this, _provider)) {
|
|
2133
|
-
throw new Error("Provider not initialized, establish connection first");
|
|
2134
|
-
}
|
|
2135
2340
|
return __privateGet(this, _provider);
|
|
2136
2341
|
}
|
|
2137
2342
|
get transport() {
|
|
@@ -2155,7 +2360,7 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2155
2360
|
static create(options) {
|
|
2156
2361
|
return __async(this, null, function* () {
|
|
2157
2362
|
var _a2;
|
|
2158
|
-
const instance = new
|
|
2363
|
+
const instance = new _MetaMaskConnectMultichain(options);
|
|
2159
2364
|
const isEnabled2 = yield isEnabled(
|
|
2160
2365
|
"metamask-sdk:core",
|
|
2161
2366
|
instance.options.storage
|
|
@@ -2163,14 +2368,15 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2163
2368
|
if (isEnabled2) {
|
|
2164
2369
|
enableDebug("metamask-sdk:core");
|
|
2165
2370
|
}
|
|
2166
|
-
yield __privateMethod(_a2 = instance,
|
|
2371
|
+
yield __privateMethod(_a2 = instance, _MetaMaskConnectMultichain_instances, init_fn).call(_a2);
|
|
2167
2372
|
return instance;
|
|
2168
2373
|
});
|
|
2169
2374
|
}
|
|
2170
|
-
|
|
2375
|
+
// TODO: make this into param object
|
|
2376
|
+
connect(scopes, caipAccountIds, sessionProperties, forceRequest) {
|
|
2171
2377
|
return __async(this, null, function* () {
|
|
2172
2378
|
var _a2;
|
|
2173
|
-
if (this.
|
|
2379
|
+
if (this.status !== "connected") {
|
|
2174
2380
|
yield this.disconnect();
|
|
2175
2381
|
}
|
|
2176
2382
|
const { ui } = this.options;
|
|
@@ -2202,7 +2408,7 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2202
2408
|
logger2("Error tracking connection_initiated event", error);
|
|
2203
2409
|
}
|
|
2204
2410
|
if (((_a2 = __privateGet(this, _transport2)) == null ? void 0 : _a2.isConnected()) && !secure) {
|
|
2205
|
-
return __privateMethod(this,
|
|
2411
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateGet(this, _transport2).connect({ scopes, caipAccountIds, sessionProperties, forceRequest }).then(() => __async(this, null, function* () {
|
|
2206
2412
|
if (__privateGet(this, _transport2) instanceof MWPTransport) {
|
|
2207
2413
|
return this.storage.setTransport("mwp" /* MWP */);
|
|
2208
2414
|
}
|
|
@@ -2210,19 +2416,19 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2210
2416
|
})), scopes, transportType);
|
|
2211
2417
|
}
|
|
2212
2418
|
if (platformType === "in-app-browser" /* MetaMaskMobileWebview */) {
|
|
2213
|
-
const defaultTransport = yield __privateMethod(this,
|
|
2214
|
-
return __privateMethod(this,
|
|
2419
|
+
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2420
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2215
2421
|
}
|
|
2216
2422
|
if (isWeb && hasExtensionInstalled && preferExtension) {
|
|
2217
|
-
const defaultTransport = yield __privateMethod(this,
|
|
2218
|
-
return __privateMethod(this,
|
|
2423
|
+
const defaultTransport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupDefaultTransport_fn).call(this);
|
|
2424
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }), scopes, transportType);
|
|
2219
2425
|
}
|
|
2220
|
-
yield __privateMethod(this,
|
|
2426
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupMWP_fn).call(this);
|
|
2221
2427
|
const shouldShowInstallModal = hasExtensionInstalled ? showInstallModal : !preferExtension || showInstallModal;
|
|
2222
2428
|
if (secure && !shouldShowInstallModal) {
|
|
2223
|
-
return __privateMethod(this,
|
|
2429
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, deeplinkConnect_fn).call(this, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2224
2430
|
}
|
|
2225
|
-
return __privateMethod(this,
|
|
2431
|
+
return __privateMethod(this, _MetaMaskConnectMultichain_instances, handleConnection_fn).call(this, __privateMethod(this, _MetaMaskConnectMultichain_instances, showInstallModal_fn).call(this, shouldShowInstallModal, scopes, caipAccountIds, sessionProperties), scopes, transportType);
|
|
2226
2432
|
});
|
|
2227
2433
|
}
|
|
2228
2434
|
emit(event, args) {
|
|
@@ -2241,15 +2447,13 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2241
2447
|
__privateSet(this, _listener, void 0);
|
|
2242
2448
|
__privateSet(this, _beforeUnloadListener, void 0);
|
|
2243
2449
|
__privateSet(this, _transport2, void 0);
|
|
2244
|
-
|
|
2450
|
+
__privateGet(this, _providerTransportWrapper).clearNotificationCallbacks();
|
|
2245
2451
|
__privateSet(this, _dappClient, void 0);
|
|
2246
2452
|
});
|
|
2247
2453
|
}
|
|
2248
2454
|
invokeMethod(request) {
|
|
2249
2455
|
return __async(this, null, function* () {
|
|
2250
|
-
var _a2;
|
|
2251
2456
|
const { transport, options } = this;
|
|
2252
|
-
(_a2 = __privateGet(this, _provider)) != null ? _a2 : __privateSet(this, _provider, getMultichainClient({ transport }));
|
|
2253
2457
|
const rpcClient = new RpcClient(options, __privateGet(this, _sdkInfo));
|
|
2254
2458
|
const requestRouter = new RequestRouter(transport, rpcClient, options);
|
|
2255
2459
|
return requestRouter.invokeMethod(request);
|
|
@@ -2278,12 +2482,13 @@ var _MultichainSDK = class _MultichainSDK extends MultichainCore {
|
|
|
2278
2482
|
}
|
|
2279
2483
|
};
|
|
2280
2484
|
_provider = new WeakMap();
|
|
2485
|
+
_providerTransportWrapper = new WeakMap();
|
|
2281
2486
|
_transport2 = new WeakMap();
|
|
2282
2487
|
_dappClient = new WeakMap();
|
|
2283
2488
|
_beforeUnloadListener = new WeakMap();
|
|
2284
2489
|
_listener = new WeakMap();
|
|
2285
2490
|
_sdkInfo = new WeakMap();
|
|
2286
|
-
|
|
2491
|
+
_MetaMaskConnectMultichain_instances = new WeakSet();
|
|
2287
2492
|
setupAnalytics_fn = function() {
|
|
2288
2493
|
return __async(this, null, function* () {
|
|
2289
2494
|
var _a2;
|
|
@@ -2324,19 +2529,21 @@ getStoredTransport_fn = function() {
|
|
|
2324
2529
|
if (hasExtensionInstalled) {
|
|
2325
2530
|
const apiTransport = new DefaultTransport();
|
|
2326
2531
|
__privateSet(this, _transport2, apiTransport);
|
|
2532
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2327
2533
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2328
|
-
__privateMethod(this,
|
|
2534
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2329
2535
|
));
|
|
2330
2536
|
return apiTransport;
|
|
2331
2537
|
}
|
|
2332
2538
|
} else if (transportType === "mwp" /* MWP */) {
|
|
2333
2539
|
const { adapter: kvstore } = this.options.storage;
|
|
2334
|
-
const dappClient = yield __privateMethod(this,
|
|
2540
|
+
const dappClient = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, createDappClient_fn).call(this);
|
|
2335
2541
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2336
2542
|
__privateSet(this, _dappClient, dappClient);
|
|
2337
2543
|
__privateSet(this, _transport2, apiTransport);
|
|
2544
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2338
2545
|
__privateSet(this, _listener, apiTransport.onNotification(
|
|
2339
|
-
__privateMethod(this,
|
|
2546
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2340
2547
|
));
|
|
2341
2548
|
return apiTransport;
|
|
2342
2549
|
}
|
|
@@ -2347,20 +2554,20 @@ getStoredTransport_fn = function() {
|
|
|
2347
2554
|
};
|
|
2348
2555
|
setupTransport_fn = function() {
|
|
2349
2556
|
return __async(this, null, function* () {
|
|
2350
|
-
const transport = yield __privateMethod(this,
|
|
2557
|
+
const transport = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getStoredTransport_fn).call(this);
|
|
2351
2558
|
if (transport) {
|
|
2352
2559
|
if (!this.transport.isConnected()) {
|
|
2353
|
-
this.
|
|
2560
|
+
this.status = "connecting";
|
|
2354
2561
|
yield this.transport.connect();
|
|
2355
2562
|
}
|
|
2356
|
-
this.
|
|
2563
|
+
this.status = "connected";
|
|
2357
2564
|
if (this.transport instanceof MWPTransport) {
|
|
2358
2565
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2359
2566
|
} else {
|
|
2360
2567
|
yield this.storage.setTransport("browser" /* Browser */);
|
|
2361
2568
|
}
|
|
2362
2569
|
} else {
|
|
2363
|
-
this.
|
|
2570
|
+
this.status = "loaded";
|
|
2364
2571
|
}
|
|
2365
2572
|
});
|
|
2366
2573
|
};
|
|
@@ -2371,8 +2578,8 @@ init_fn = function() {
|
|
|
2371
2578
|
if (typeof window !== "undefined" && ((_a2 = window.mmsdk) == null ? void 0 : _a2.isInitialized)) {
|
|
2372
2579
|
logger2("MetaMaskSDK: init already initialized");
|
|
2373
2580
|
} else {
|
|
2374
|
-
yield __privateMethod(this,
|
|
2375
|
-
yield __privateMethod(this,
|
|
2581
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(this);
|
|
2582
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, setupTransport_fn).call(this);
|
|
2376
2583
|
try {
|
|
2377
2584
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2378
2585
|
this.options,
|
|
@@ -2388,7 +2595,7 @@ init_fn = function() {
|
|
|
2388
2595
|
}
|
|
2389
2596
|
} catch (error) {
|
|
2390
2597
|
yield this.storage.removeTransport();
|
|
2391
|
-
this.
|
|
2598
|
+
this.status = "pending";
|
|
2392
2599
|
logger2("MetaMaskSDK error during initialization", error);
|
|
2393
2600
|
}
|
|
2394
2601
|
});
|
|
@@ -2416,12 +2623,13 @@ setupMWP_fn = function() {
|
|
|
2416
2623
|
return;
|
|
2417
2624
|
}
|
|
2418
2625
|
const { adapter: kvstore } = this.options.storage;
|
|
2419
|
-
const dappClient = yield __privateMethod(this,
|
|
2626
|
+
const dappClient = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, createDappClient_fn).call(this);
|
|
2420
2627
|
__privateSet(this, _dappClient, dappClient);
|
|
2421
2628
|
const apiTransport = new MWPTransport(dappClient, kvstore);
|
|
2422
2629
|
__privateSet(this, _transport2, apiTransport);
|
|
2630
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2423
2631
|
__privateSet(this, _listener, this.transport.onNotification(
|
|
2424
|
-
__privateMethod(this,
|
|
2632
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2425
2633
|
));
|
|
2426
2634
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2427
2635
|
});
|
|
@@ -2436,18 +2644,18 @@ onBeforeUnload_fn = function() {
|
|
|
2436
2644
|
};
|
|
2437
2645
|
createBeforeUnloadListener_fn = function() {
|
|
2438
2646
|
if (typeof window !== "undefined" && typeof window.addEventListener !== "undefined") {
|
|
2439
|
-
window.addEventListener("beforeunload", __privateMethod(this,
|
|
2647
|
+
window.addEventListener("beforeunload", __privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this));
|
|
2440
2648
|
}
|
|
2441
2649
|
return () => {
|
|
2442
2650
|
if (typeof window !== "undefined" && typeof window.removeEventListener !== "undefined") {
|
|
2443
2651
|
window.removeEventListener(
|
|
2444
2652
|
"beforeunload",
|
|
2445
|
-
__privateMethod(this,
|
|
2653
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onBeforeUnload_fn).bind(this)
|
|
2446
2654
|
);
|
|
2447
2655
|
}
|
|
2448
2656
|
};
|
|
2449
2657
|
};
|
|
2450
|
-
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2658
|
+
renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2451
2659
|
return __async(this, null, function* () {
|
|
2452
2660
|
return new Promise((resolve, reject) => {
|
|
2453
2661
|
this.options.ui.factory.renderInstallModal(
|
|
@@ -2475,19 +2683,19 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds)
|
|
|
2475
2683
|
(() => __async(this, null, function* () {
|
|
2476
2684
|
var _a2;
|
|
2477
2685
|
try {
|
|
2478
|
-
yield this.transport.connect({ scopes, caipAccountIds });
|
|
2686
|
+
yield this.transport.connect({ scopes, caipAccountIds, sessionProperties });
|
|
2479
2687
|
yield this.options.ui.factory.unload();
|
|
2480
2688
|
(_a2 = this.options.ui.factory.modal) == null ? void 0 : _a2.unmount();
|
|
2481
|
-
this.
|
|
2689
|
+
this.status = "connected";
|
|
2482
2690
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2483
2691
|
} catch (error) {
|
|
2484
2692
|
if (error instanceof ProtocolError) {
|
|
2485
2693
|
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
2486
|
-
this.
|
|
2694
|
+
this.status = "disconnected";
|
|
2487
2695
|
reject(error);
|
|
2488
2696
|
}
|
|
2489
2697
|
} else {
|
|
2490
|
-
this.
|
|
2698
|
+
this.status = "disconnected";
|
|
2491
2699
|
reject(
|
|
2492
2700
|
error instanceof Error ? error : new Error(String(error))
|
|
2493
2701
|
);
|
|
@@ -2505,33 +2713,83 @@ renderInstallModalAsync_fn = function(desktopPreferred, scopes, caipAccountIds)
|
|
|
2505
2713
|
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2506
2714
|
resolve();
|
|
2507
2715
|
}
|
|
2508
|
-
})
|
|
2716
|
+
}),
|
|
2717
|
+
(uri) => {
|
|
2718
|
+
this.emit("display_uri", uri);
|
|
2719
|
+
}
|
|
2509
2720
|
).catch((error) => {
|
|
2510
2721
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2511
2722
|
});
|
|
2512
2723
|
});
|
|
2513
2724
|
});
|
|
2514
2725
|
};
|
|
2515
|
-
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds) {
|
|
2726
|
+
showInstallModal_fn = function(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
2516
2727
|
return __async(this, null, function* () {
|
|
2517
2728
|
var _a2;
|
|
2518
|
-
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this,
|
|
2519
|
-
|
|
2729
|
+
(_a2 = __privateGet(this, _beforeUnloadListener)) != null ? _a2 : __privateSet(this, _beforeUnloadListener, __privateMethod(this, _MetaMaskConnectMultichain_instances, createBeforeUnloadListener_fn).call(this));
|
|
2730
|
+
if (this.options.ui.headless) {
|
|
2731
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, headlessConnect_fn).call(this, scopes, caipAccountIds, sessionProperties);
|
|
2732
|
+
} else {
|
|
2733
|
+
yield __privateMethod(this, _MetaMaskConnectMultichain_instances, renderInstallModalAsync_fn).call(this, desktopPreferred, scopes, caipAccountIds, sessionProperties);
|
|
2734
|
+
}
|
|
2735
|
+
});
|
|
2736
|
+
};
|
|
2737
|
+
headlessConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2738
|
+
return __async(this, null, function* () {
|
|
2739
|
+
return new Promise((resolve, reject) => {
|
|
2740
|
+
if (this.dappClient.state === "CONNECTED" || this.dappClient.state === "CONNECTING") {
|
|
2741
|
+
this.dappClient.disconnect().catch(() => {
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
this.dappClient.on(
|
|
2745
|
+
"session_request",
|
|
2746
|
+
(sessionRequest) => {
|
|
2747
|
+
const connectionRequest = {
|
|
2748
|
+
sessionRequest,
|
|
2749
|
+
metadata: {
|
|
2750
|
+
dapp: this.options.dapp,
|
|
2751
|
+
sdk: {
|
|
2752
|
+
version: getVersion(),
|
|
2753
|
+
platform: getPlatformType()
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
};
|
|
2757
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
2758
|
+
this.emit("display_uri", deeplink);
|
|
2759
|
+
}
|
|
2760
|
+
);
|
|
2761
|
+
this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(() => __async(this, null, function* () {
|
|
2762
|
+
this.status = "connected";
|
|
2763
|
+
yield this.storage.setTransport("mwp" /* MWP */);
|
|
2764
|
+
resolve();
|
|
2765
|
+
})).catch((error) => __async(this, null, function* () {
|
|
2766
|
+
if (error instanceof ProtocolError) {
|
|
2767
|
+
this.status = "disconnected";
|
|
2768
|
+
yield this.storage.removeTransport();
|
|
2769
|
+
reject(error);
|
|
2770
|
+
} else {
|
|
2771
|
+
this.status = "disconnected";
|
|
2772
|
+
yield this.storage.removeTransport();
|
|
2773
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2774
|
+
}
|
|
2775
|
+
}));
|
|
2776
|
+
});
|
|
2520
2777
|
});
|
|
2521
2778
|
};
|
|
2522
2779
|
setupDefaultTransport_fn = function() {
|
|
2523
2780
|
return __async(this, null, function* () {
|
|
2524
|
-
this.
|
|
2781
|
+
this.status = "connecting";
|
|
2525
2782
|
yield this.storage.setTransport("browser" /* Browser */);
|
|
2526
2783
|
const transport = new DefaultTransport();
|
|
2527
2784
|
__privateSet(this, _listener, transport.onNotification(
|
|
2528
|
-
__privateMethod(this,
|
|
2785
|
+
__privateMethod(this, _MetaMaskConnectMultichain_instances, onTransportNotification_fn).bind(this)
|
|
2529
2786
|
));
|
|
2530
2787
|
__privateSet(this, _transport2, transport);
|
|
2788
|
+
__privateGet(this, _providerTransportWrapper).setupNotifcationListener();
|
|
2531
2789
|
return transport;
|
|
2532
2790
|
});
|
|
2533
2791
|
};
|
|
2534
|
-
deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
2792
|
+
deeplinkConnect_fn = function(scopes, caipAccountIds, sessionProperties) {
|
|
2535
2793
|
return __async(this, null, function* () {
|
|
2536
2794
|
return new Promise((resolve, reject) => {
|
|
2537
2795
|
const dappClientMessageHandler = (payload) => {
|
|
@@ -2574,6 +2832,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2574
2832
|
const universalLink = this.options.ui.factory.createConnectionUniversalLink(
|
|
2575
2833
|
connectionRequest
|
|
2576
2834
|
);
|
|
2835
|
+
this.emit("display_uri", deeplink);
|
|
2577
2836
|
if ((_a2 = this.options.mobile) == null ? void 0 : _a2.preferredOpenLink) {
|
|
2578
2837
|
this.options.mobile.preferredOpenLink(deeplink, "_self");
|
|
2579
2838
|
} else {
|
|
@@ -2582,7 +2841,7 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2582
2841
|
}
|
|
2583
2842
|
);
|
|
2584
2843
|
}
|
|
2585
|
-
return this.transport.connect({ scopes, caipAccountIds }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2844
|
+
return this.transport.connect({ scopes, caipAccountIds, sessionProperties }).then(resolve).catch((error) => __async(this, null, function* () {
|
|
2586
2845
|
yield this.storage.removeTransport();
|
|
2587
2846
|
this.dappClient.off("message", dappClientMessageHandler);
|
|
2588
2847
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -2596,9 +2855,9 @@ deeplinkConnect_fn = function(scopes, caipAccountIds) {
|
|
|
2596
2855
|
};
|
|
2597
2856
|
handleConnection_fn = function(promise, scopes, transportType) {
|
|
2598
2857
|
return __async(this, null, function* () {
|
|
2599
|
-
this.
|
|
2858
|
+
this.status = "connecting";
|
|
2600
2859
|
return promise.then(() => __async(this, null, function* () {
|
|
2601
|
-
this.
|
|
2860
|
+
this.status = "connected";
|
|
2602
2861
|
try {
|
|
2603
2862
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2604
2863
|
this.options,
|
|
@@ -2613,7 +2872,7 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
2613
2872
|
}
|
|
2614
2873
|
return void 0;
|
|
2615
2874
|
})).catch((error) => __async(this, null, function* () {
|
|
2616
|
-
this.
|
|
2875
|
+
this.status = "disconnected";
|
|
2617
2876
|
try {
|
|
2618
2877
|
const baseProps = yield getBaseAnalyticsProperties(
|
|
2619
2878
|
this.options,
|
|
@@ -2636,7 +2895,7 @@ handleConnection_fn = function(promise, scopes, transportType) {
|
|
|
2636
2895
|
}));
|
|
2637
2896
|
});
|
|
2638
2897
|
};
|
|
2639
|
-
var
|
|
2898
|
+
var MetaMaskConnectMultichain = _MetaMaskConnectMultichain;
|
|
2640
2899
|
|
|
2641
2900
|
// src/store/index.ts
|
|
2642
2901
|
import * as uuid from "uuid";
|
|
@@ -2817,19 +3076,11 @@ var Store = class extends StoreClient {
|
|
|
2817
3076
|
}
|
|
2818
3077
|
};
|
|
2819
3078
|
|
|
2820
|
-
// src/ui/
|
|
3079
|
+
// src/ui/ModalFactory.ts
|
|
2821
3080
|
import MetaMaskOnboarding from "@metamask/onboarding";
|
|
2822
3081
|
init_domain();
|
|
2823
3082
|
init_utils();
|
|
2824
|
-
|
|
2825
|
-
// src/ui/preload.native.ts
|
|
2826
|
-
function preload() {
|
|
2827
|
-
return __async(this, null, function* () {
|
|
2828
|
-
});
|
|
2829
|
-
}
|
|
2830
|
-
|
|
2831
|
-
// src/ui/index.ts
|
|
2832
|
-
var ModalFactory = class {
|
|
3083
|
+
var BaseModalFactory = class {
|
|
2833
3084
|
/**
|
|
2834
3085
|
* Creates a new modal factory instance.
|
|
2835
3086
|
*
|
|
@@ -2918,15 +3169,17 @@ var ModalFactory = class {
|
|
|
2918
3169
|
onStartDesktopOnboarding() {
|
|
2919
3170
|
new MetaMaskOnboarding().startOnboarding();
|
|
2920
3171
|
}
|
|
2921
|
-
renderInstallModal(showInstallModal, createConnectionRequest, successCallback) {
|
|
3172
|
+
renderInstallModal(showInstallModal, createConnectionRequest, successCallback, onDisplayUri) {
|
|
2922
3173
|
return __async(this, null, function* () {
|
|
2923
|
-
var _a2;
|
|
3174
|
+
var _a2, _b;
|
|
2924
3175
|
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2925
|
-
yield preload();
|
|
3176
|
+
yield this.preload();
|
|
2926
3177
|
this.successCallback = successCallback;
|
|
3178
|
+
this.displayUriCallback = onDisplayUri;
|
|
2927
3179
|
const parentElement = this.getMountedContainer();
|
|
2928
3180
|
const connectionRequest = yield createConnectionRequest();
|
|
2929
3181
|
const qrCodeLink = this.createConnectionDeeplink(connectionRequest);
|
|
3182
|
+
(_b = this.displayUriCallback) == null ? void 0 : _b.call(this, qrCodeLink);
|
|
2930
3183
|
const modal = new this.options.InstallModal({
|
|
2931
3184
|
expiresIn: (connectionRequest.sessionRequest.expiresAt - Date.now()) / 1e3,
|
|
2932
3185
|
connectionRequest,
|
|
@@ -2935,11 +3188,15 @@ var ModalFactory = class {
|
|
|
2935
3188
|
link: qrCodeLink,
|
|
2936
3189
|
sdkVersion: getVersion(),
|
|
2937
3190
|
generateQRCode: (request) => __async(this, null, function* () {
|
|
2938
|
-
|
|
3191
|
+
var _a3;
|
|
3192
|
+
const newLink = this.createConnectionDeeplink(request);
|
|
3193
|
+
(_a3 = this.displayUriCallback) == null ? void 0 : _a3.call(this, newLink);
|
|
3194
|
+
return newLink;
|
|
2939
3195
|
}),
|
|
2940
3196
|
onClose: this.onCloseModal.bind(this),
|
|
2941
3197
|
startDesktopOnboarding: this.onStartDesktopOnboarding.bind(this),
|
|
2942
|
-
createConnectionRequest
|
|
3198
|
+
createConnectionRequest,
|
|
3199
|
+
onDisplayUri: this.displayUriCallback
|
|
2943
3200
|
});
|
|
2944
3201
|
this.modal = modal;
|
|
2945
3202
|
modal.mount();
|
|
@@ -2949,7 +3206,7 @@ var ModalFactory = class {
|
|
|
2949
3206
|
return __async(this, null, function* () {
|
|
2950
3207
|
var _a2;
|
|
2951
3208
|
(_a2 = this.modal) == null ? void 0 : _a2.unmount();
|
|
2952
|
-
yield preload();
|
|
3209
|
+
yield this.preload();
|
|
2953
3210
|
this.successCallback = successCallback;
|
|
2954
3211
|
const container = this.getMountedContainer();
|
|
2955
3212
|
const otpCode = yield createOTPCode();
|
|
@@ -2967,9 +3224,18 @@ var ModalFactory = class {
|
|
|
2967
3224
|
}
|
|
2968
3225
|
};
|
|
2969
3226
|
|
|
3227
|
+
// src/ui/index.native.ts
|
|
3228
|
+
var ModalFactory = class extends BaseModalFactory {
|
|
3229
|
+
// No-op for React Native - web components are not applicable
|
|
3230
|
+
preload() {
|
|
3231
|
+
return __async(this, null, function* () {
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
|
|
2970
3236
|
// src/index.native.ts
|
|
2971
3237
|
init_domain();
|
|
2972
|
-
var
|
|
3238
|
+
var createMultichainClient = (options) => __async(null, null, function* () {
|
|
2973
3239
|
const uiModules = yield Promise.resolve().then(() => (init_rn(), rn_exports));
|
|
2974
3240
|
let storage;
|
|
2975
3241
|
if (!options.storage) {
|
|
@@ -2980,7 +3246,7 @@ var createMetamaskConnect = (options) => __async(null, null, function* () {
|
|
|
2980
3246
|
storage = options.storage;
|
|
2981
3247
|
}
|
|
2982
3248
|
const factory = new ModalFactory(uiModules);
|
|
2983
|
-
return
|
|
3249
|
+
return MetaMaskConnectMultichain.create(__spreadProps(__spreadValues({}, options), {
|
|
2984
3250
|
storage,
|
|
2985
3251
|
ui: __spreadProps(__spreadValues({}, options.ui), {
|
|
2986
3252
|
factory
|
|
@@ -3002,7 +3268,7 @@ export {
|
|
|
3002
3268
|
StoreClient,
|
|
3003
3269
|
TransportType,
|
|
3004
3270
|
createLogger,
|
|
3005
|
-
|
|
3271
|
+
createMultichainClient,
|
|
3006
3272
|
enableDebug,
|
|
3007
3273
|
getInfuraRpcUrls,
|
|
3008
3274
|
getPlatformType,
|