@dynamic-labs/ethereum 4.0.0-alpha.30 → 4.0.0-alpha.31

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 CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ## [4.0.0-alpha.31](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.30...v4.0.0-alpha.31) (2024-11-13)
3
+
4
+
5
+ ### Features
6
+
7
+ * allow passing telegram auth token into telegramSignIn function ([#7423](https://github.com/dynamic-labs/dynamic-auth/issues/7423)) ([4b8d594](https://github.com/dynamic-labs/dynamic-auth/commit/4b8d594984d1ac7851ce8d94fe4329ba94730f35))
8
+
2
9
  ## [4.0.0-alpha.30](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.29...v4.0.0-alpha.30) (2024-11-13)
3
10
 
4
11
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.0.0-alpha.30";
6
+ var version = "4.0.0-alpha.31";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.0.0-alpha.30";
2
+ var version = "4.0.0-alpha.31";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "4.0.0-alpha.30",
3
+ "version": "4.0.0-alpha.31",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -23,13 +23,15 @@
23
23
  "@walletconnect/types": "2.10.6",
24
24
  "eventemitter3": "5.0.1",
25
25
  "buffer": "6.0.3",
26
- "@dynamic-labs/assert-package-version": "4.0.0-alpha.30",
27
- "@dynamic-labs/embedded-wallet-evm": "4.0.0-alpha.30",
28
- "@dynamic-labs/ethereum-core": "4.0.0-alpha.30",
29
- "@dynamic-labs/types": "4.0.0-alpha.30",
30
- "@dynamic-labs/utils": "4.0.0-alpha.30",
31
- "@dynamic-labs/wallet-book": "4.0.0-alpha.30",
32
- "@dynamic-labs/wallet-connector-core": "4.0.0-alpha.30"
26
+ "@metamask/sdk": "0.30.1",
27
+ "@dynamic-labs/assert-package-version": "4.0.0-alpha.31",
28
+ "@dynamic-labs/embedded-wallet-evm": "4.0.0-alpha.31",
29
+ "@dynamic-labs/ethereum-core": "4.0.0-alpha.31",
30
+ "@dynamic-labs/logger": "4.0.0-alpha.31",
31
+ "@dynamic-labs/types": "4.0.0-alpha.31",
32
+ "@dynamic-labs/utils": "4.0.0-alpha.31",
33
+ "@dynamic-labs/wallet-book": "4.0.0-alpha.31",
34
+ "@dynamic-labs/wallet-connector-core": "4.0.0-alpha.31"
33
35
  },
34
36
  "peerDependencies": {
35
37
  "viem": "^2.7.6"
@@ -25,6 +25,9 @@ class EthProviderHelper {
25
25
  if (eip6963Provider) {
26
26
  return eip6963Provider;
27
27
  }
28
+ return this.getInjectedProvider();
29
+ }
30
+ getInjectedProvider() {
28
31
  const config = this.getInjectedConfig();
29
32
  if (!config ||
30
33
  !config.extensionLocators ||
@@ -9,6 +9,7 @@ export declare class EthProviderHelper {
9
9
  constructor(wallet: WalletSchema, connector?: InjectedWalletBase);
10
10
  private get connector();
11
11
  getInstalledProvider(): IEthereum | undefined;
12
+ getInjectedProvider(): IEthereum | undefined;
12
13
  getEip6963Provider(): IEthereum | undefined;
13
14
  getInjectedConfig(): {
14
15
  chain: string;
@@ -21,6 +21,9 @@ class EthProviderHelper {
21
21
  if (eip6963Provider) {
22
22
  return eip6963Provider;
23
23
  }
24
+ return this.getInjectedProvider();
25
+ }
26
+ getInjectedProvider() {
24
27
  const config = this.getInjectedConfig();
25
28
  if (!config ||
26
29
  !config.extensionLocators ||
package/src/index.cjs CHANGED
@@ -17,6 +17,7 @@ require('./walletConnect/walletConnect.cjs');
17
17
  var fetchWalletConnectWallets = require('./walletConnect/fetchWalletConnectWallets.cjs');
18
18
  var coinbase = require('./coinbase/coinbase.cjs');
19
19
  var ethereumCore = require('@dynamic-labs/ethereum-core');
20
+ var MetaMaskConnector = require('./metaMask/MetaMaskConnector.cjs');
20
21
  var ethProviderHelper = require('./ethProviderHelper.cjs');
21
22
  var constants = require('./constants.cjs');
22
23
 
@@ -26,6 +27,7 @@ const EthereumWalletConnectors = (props) => [
26
27
  ...fetchInjectedWalletConnectors.fetchInjectedWalletConnector(props),
27
28
  ...fetchWalletConnectWallets.fetchWalletConnectWallets(props),
28
29
  ...embeddedWalletEvm.TurnkeyEVMWalletConnectors(props),
30
+ MetaMaskConnector.MetaMaskConnector,
29
31
  coinbase.Coinbase,
30
32
  UnknownInjected.UnknownInjected,
31
33
  FallbackEvmConnector.FallbackEvmConnector,
package/src/index.js CHANGED
@@ -16,6 +16,7 @@ import './walletConnect/walletConnect.js';
16
16
  import { fetchWalletConnectWallets, getWalletConnectConnector } from './walletConnect/fetchWalletConnectWallets.js';
17
17
  import { Coinbase } from './coinbase/coinbase.js';
18
18
  export { EthereumWalletConnector, isEthereumWallet } from '@dynamic-labs/ethereum-core';
19
+ import { MetaMaskConnector } from './metaMask/MetaMaskConnector.js';
19
20
  export { EthProviderHelper } from './ethProviderHelper.js';
20
21
  export { INFURA_ID } from './constants.js';
21
22
 
@@ -25,6 +26,7 @@ const EthereumWalletConnectors = (props) => [
25
26
  ...fetchInjectedWalletConnector(props),
26
27
  ...fetchWalletConnectWallets(props),
27
28
  ...TurnkeyEVMWalletConnectors(props),
29
+ MetaMaskConnector,
28
30
  Coinbase,
29
31
  UnknownInjected,
30
32
  FallbackEvmConnector,
@@ -18,6 +18,7 @@ const filteredInjectedWalletKeysOverrides = [
18
18
  'coinbase',
19
19
  'exodusevm',
20
20
  'abstract',
21
+ 'metamask',
21
22
  ];
22
23
  const fetchInjectedWalletConnector = ({ walletBook, }) => {
23
24
  var _a;
@@ -14,6 +14,7 @@ const filteredInjectedWalletKeysOverrides = [
14
14
  'coinbase',
15
15
  'exodusevm',
16
16
  'abstract',
17
+ 'metamask',
17
18
  ];
18
19
  const fetchInjectedWalletConnector = ({ walletBook, }) => {
19
20
  var _a;
@@ -0,0 +1,399 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var sdk = require('@metamask/sdk');
8
+ var viem = require('viem');
9
+ var ethereumCore = require('@dynamic-labs/ethereum-core');
10
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
+ var utils = require('@dynamic-labs/utils');
12
+ var walletBook = require('@dynamic-labs/wallet-book');
13
+ var logger = require('../utils/logger.cjs');
14
+ var ethProviderHelper = require('../ethProviderHelper.cjs');
15
+ var createMetaMaskSDKDisplayUriState = require('./utils/createMetaMaskSDKDisplayUriState.cjs');
16
+ var waitForConnection = require('./utils/waitForConnection.cjs');
17
+ var isPendingWalletRequestPermissionError = require('./utils/isPendingWalletRequestPermissionError.cjs');
18
+
19
+ /**
20
+ * The MetaMask SDK must be initialized only once, so we store the instance
21
+ * in these variables to avoid initializing it multiple times
22
+ */
23
+ let _metaMaskSDK = null;
24
+ let _metaMaskSDKDisplayUriState = null;
25
+ const eventTimeline = utils.createEventTimeline();
26
+ class MetaMaskConnector extends ethereumCore.EthereumWalletConnector {
27
+ constructor(props) {
28
+ super(props);
29
+ this.name = 'MetaMask';
30
+ this.overrideKey = 'metamask';
31
+ this.canConnectViaQrCode = true;
32
+ this.isInAppBrowser = false;
33
+ this.appName = props.appName;
34
+ this.appLogoUrl = props.appLogoUrl;
35
+ /**
36
+ * The isInAppBrowser must be calculated before initializing the MetaMask SDK.
37
+ *
38
+ * The isInAppBrowser is calculated by checking if the window provider is installed
39
+ * in the browser and if it is running on a mobile device.
40
+ *
41
+ * But the MetaMask SDK will inject its own provider to the window if not provider is injected.
42
+ * This means the MetaMask SDK can interfere with the isInAppBrowser calculation.
43
+ *
44
+ * So we need to calculate the isInAppBrowser before initializing the MetaMask SDK
45
+ * to prevent a false negative
46
+ */
47
+ this.isInAppBrowser = this.getIsInAppBrowser();
48
+ if (!_metaMaskSDK) {
49
+ this.createMetaMaskSDK();
50
+ }
51
+ }
52
+ getSupportedNetworks() {
53
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
54
+ return this.evmNetworks.map((network) => network.chainId.toString());
55
+ });
56
+ }
57
+ get ethProviderHelper() {
58
+ return new ethProviderHelper.EthProviderHelper(walletBook.getWalletBookWallet(this.walletBook, this.key));
59
+ }
60
+ get metaMaskSDK() {
61
+ if (!_metaMaskSDK)
62
+ throw new Error('MetaMaskSDK not initialized');
63
+ return _metaMaskSDK;
64
+ }
65
+ set metaMaskSDK(metaMaskSDK) {
66
+ _metaMaskSDK = metaMaskSDK;
67
+ }
68
+ get metaMaskSDKDisplayUriState() {
69
+ if (!_metaMaskSDKDisplayUriState)
70
+ throw new Error('MetaMaskSDKDisplayUriState not initialized');
71
+ return _metaMaskSDKDisplayUriState;
72
+ }
73
+ createMetaMaskSDK() {
74
+ const dappMetadata = {
75
+ iconUrl: this.appLogoUrl,
76
+ name: this.appName,
77
+ url: utils.PlatformService.getOrigin(),
78
+ };
79
+ _metaMaskSDK = new sdk.MetaMaskSDK({
80
+ _source: 'dynamic-labs',
81
+ checkInstallationImmediately: true,
82
+ dappMetadata,
83
+ enableAnalytics: true,
84
+ extensionOnly: this.isInstalledOnBrowser(),
85
+ headless: true,
86
+ openDeeplink: utils.PlatformService.openURL,
87
+ preferDesktop: !utils.isMobile(),
88
+ readonlyRPCMap: getReadonlyRPCMap(this.evmNetworkRpcMap()),
89
+ useDeeplink: true,
90
+ });
91
+ _metaMaskSDKDisplayUriState =
92
+ createMetaMaskSDKDisplayUriState.createMetaMaskSDKDisplayUriState(_metaMaskSDK);
93
+ }
94
+ endSession() {
95
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
96
+ eventTimeline.postEvent('disconnect');
97
+ /**
98
+ * The MetaMask SDK must be terminated and reinitialized on mobile
99
+ * to prevent deeplinks not working
100
+ */
101
+ if (utils.isMobile()) {
102
+ return this.metaMaskSDK.terminate().then(() => {
103
+ _metaMaskSDK = null;
104
+ _metaMaskSDKDisplayUriState = null;
105
+ return this.createMetaMaskSDK();
106
+ });
107
+ }
108
+ /**
109
+ * Just terminate the SDK on desktop
110
+ */
111
+ return this.metaMaskSDK.terminate();
112
+ });
113
+ }
114
+ getAddress(opts) {
115
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
116
+ return new Promise((resolve, reject) => {
117
+ var _a, _b, _c, _d;
118
+ // QR Code flow
119
+ if (!utils.isMobile() && Boolean(opts === null || opts === void 0 ? void 0 : opts.onDisplayUri)) {
120
+ this.metaMaskSDKDisplayUriState
121
+ .consumeDisplayUri()
122
+ .then((displayUri) => {
123
+ var _a;
124
+ if (!displayUri) {
125
+ reject(new Error('MetaMask display uri not found'));
126
+ return;
127
+ }
128
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, displayUri);
129
+ });
130
+ }
131
+ // Deep link to MetaMask app in-app browser
132
+ if (this.shouldDeepLinkToMetaMaskInAppBrowser() &&
133
+ ((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.inAppBrowser)) {
134
+ // Redirect to the in-app browser and append the current url
135
+ window.location.href = `${(_d = (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.inAppBrowser}/${window.location.href}`;
136
+ resolve(undefined);
137
+ return;
138
+ }
139
+ // Connect to MetaMask
140
+ this.getConnectedAccountsSafely().then((initialConnectedAccounts) => _tslib.__awaiter(this, void 0, void 0, function* () {
141
+ if (initialConnectedAccounts.length) {
142
+ resolve(initialConnectedAccounts[0]);
143
+ return;
144
+ }
145
+ try {
146
+ yield this.metaMaskSDK.connect();
147
+ }
148
+ catch (error) {
149
+ const isRequestPendingError = isPendingWalletRequestPermissionError.isPendingWalletRequestPermissionError(error);
150
+ if (!isRequestPendingError) {
151
+ throw error;
152
+ }
153
+ else {
154
+ yield waitForConnection.waitForConnection(this.getProvider());
155
+ }
156
+ }
157
+ const accounts = yield this.getConnectedAccounts();
158
+ resolve(accounts[0]);
159
+ }));
160
+ });
161
+ });
162
+ }
163
+ getConnectedAccountsSafely() {
164
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
165
+ try {
166
+ const connectedAccounts = yield this.getConnectedAccounts();
167
+ return connectedAccounts;
168
+ }
169
+ catch (err) {
170
+ logger.logger.error(err);
171
+ return [];
172
+ }
173
+ });
174
+ }
175
+ getConnectedAccounts() {
176
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
177
+ // Wait for for MetaMask SDK to initialize
178
+ yield this.metaMaskSDK.sdkInitPromise;
179
+ const provider = this.getProvider();
180
+ if (!provider) {
181
+ return [];
182
+ }
183
+ /**
184
+ * The eth_accounts method can hang on mobile devices when
185
+ * the MetaMask SDK has not connected yet. So we use a retryable
186
+ * to ensure the timeout will be respected
187
+ */
188
+ const accounts = yield utils.retryableFn(() => provider.request({
189
+ method: 'eth_accounts',
190
+ params: [],
191
+ }), {
192
+ fallbackValue: [],
193
+ timeoutMs: 1000,
194
+ });
195
+ if (!(accounts === null || accounts === void 0 ? void 0 : accounts.length)) {
196
+ return [];
197
+ }
198
+ return accounts;
199
+ });
200
+ }
201
+ signMessage(messageToSign, withAddress) {
202
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
203
+ yield this.metaMaskSDK.sdkInitPromise;
204
+ /**
205
+ * Should wait for the window to be focused on mobile
206
+ * to account for the user moving between the MetaMaskApp
207
+ * and the browser
208
+ */
209
+ const windowFocusPromiseForMobile = !this.isInAppBrowser && utils.isMobile()
210
+ ? waitForFocusWindowEvent()
211
+ : Promise.resolve();
212
+ const provider = this.getProvider();
213
+ if (!provider) {
214
+ return undefined;
215
+ }
216
+ const [selectedAddress] = yield this.getConnectedAccounts();
217
+ const effectiveAddress = withAddress !== null && withAddress !== void 0 ? withAddress : selectedAddress;
218
+ if (!effectiveAddress) {
219
+ return undefined;
220
+ }
221
+ const walletClient = this.getWalletClientForAddress(effectiveAddress);
222
+ if (!walletClient)
223
+ return undefined;
224
+ const signature = yield walletClient.signMessage({
225
+ message: messageToSign,
226
+ });
227
+ yield windowFocusPromiseForMobile;
228
+ return signature;
229
+ });
230
+ }
231
+ chooseAccountsToConnect() {
232
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
233
+ return [];
234
+ });
235
+ }
236
+ getWalletClient(chainId) {
237
+ const provider = this.getProvider();
238
+ if (!provider) {
239
+ return undefined;
240
+ }
241
+ const selectedAddress = provider.getSelectedAddress();
242
+ return this.getWalletClientForAddress(selectedAddress || undefined, chainId);
243
+ }
244
+ get rdns() {
245
+ const { rdns } = this.metadata;
246
+ if (!rdns) {
247
+ throw new Error('rdns not found in metadata');
248
+ }
249
+ return rdns;
250
+ }
251
+ isInstalledOnBrowser() {
252
+ var _a;
253
+ const metaMaskEip6963Provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.eip6963ProviderLookup(this.rdns);
254
+ const isInstalled = Boolean(metaMaskEip6963Provider);
255
+ return isInstalled;
256
+ }
257
+ setupEventListeners() {
258
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
259
+ yield this.metaMaskSDK.sdkInitPromise;
260
+ const metaMaskProvider = this.getProvider();
261
+ if (!metaMaskProvider) {
262
+ return;
263
+ }
264
+ const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
265
+ const handleAccountsChangedFromMetaMask = (accounts) => {
266
+ /**
267
+ * MetaMask emits an account changed event when the wallet is disconnected
268
+ * so we ignore the accountsChanged event if the disconnect event was recent
269
+ */
270
+ if (eventTimeline.isEventRecent('disconnect', 1000)) {
271
+ return;
272
+ }
273
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
274
+ // @ts-ignore
275
+ handleAccountChange(accounts);
276
+ };
277
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
278
+ // @ts-ignore
279
+ metaMaskProvider.on('accountsChanged', handleAccountsChangedFromMetaMask);
280
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
281
+ // @ts-ignore
282
+ metaMaskProvider.on('chainChanged', handleChainChange);
283
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
284
+ // @ts-ignore
285
+ metaMaskProvider.on('disconnect', handleDisconnect);
286
+ this.teardownEventListeners = () => {
287
+ metaMaskProvider.off('accountsChanged', handleAccountsChangedFromMetaMask);
288
+ metaMaskProvider.off('chainChanged', handleChainChange);
289
+ metaMaskProvider.off('disconnect', handleDisconnect);
290
+ };
291
+ });
292
+ }
293
+ /**
294
+ * This override is necessary to wait for the MetaMask SDK to initialize
295
+ * before calling the super method. Otherwise, the super method may fail
296
+ * to fetch the provider
297
+ */
298
+ getNetwork() {
299
+ const _super = Object.create(null, {
300
+ getNetwork: { get: () => super.getNetwork }
301
+ });
302
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
303
+ yield this.metaMaskSDK.sdkInitPromise;
304
+ const net = yield _super.getNetwork.call(this);
305
+ return net;
306
+ });
307
+ }
308
+ // Utils
309
+ getProvider() {
310
+ var _a;
311
+ return ((_a = this.metaMaskSDK.getProvider()) !== null && _a !== void 0 ? _a : this.metaMaskSDK.getMobileProvider());
312
+ }
313
+ evmNetworkByChainId(chainId) {
314
+ return this.evmNetworks.find((network) => network.chainId === chainId);
315
+ }
316
+ getWalletClientForAddress(address, chainId) {
317
+ var _a, _b;
318
+ const provider = this.getProvider();
319
+ if (!provider) {
320
+ return undefined;
321
+ }
322
+ const effectiveChainId = (_b = (_a = this.toInt(chainId)) !== null && _a !== void 0 ? _a : this.getCurrentChainId()) !== null && _b !== void 0 ? _b : '1';
323
+ const network = this.evmNetworkByChainId(effectiveChainId);
324
+ return viem.createWalletClient({
325
+ account: address,
326
+ chain: network ? ethereumCore.getOrMapViemChain(network) : this.getActiveChain(),
327
+ transport: viem.custom(provider),
328
+ });
329
+ }
330
+ toInt(chainId) {
331
+ if (!chainId)
332
+ return undefined;
333
+ try {
334
+ return parseInt(chainId);
335
+ }
336
+ catch (err) {
337
+ logger.logger.debug(err);
338
+ return undefined;
339
+ }
340
+ }
341
+ getCurrentChainId() {
342
+ const provider = this.getProvider();
343
+ if (!provider) {
344
+ return undefined;
345
+ }
346
+ const chainId = provider.getChainId();
347
+ if (viem.isHex(chainId)) {
348
+ return parseInt(chainId);
349
+ }
350
+ return chainId;
351
+ }
352
+ /**
353
+ * Checks if the current environment is the MetaMask in-app browser
354
+ * by checking if the MetaMask provider is installed in the window object
355
+ * on a mobile device
356
+ */
357
+ getIsInAppBrowser() {
358
+ var _a, _b;
359
+ if (!utils.isMobile())
360
+ return false;
361
+ const provider = ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.eip6963ProviderLookup(this.rdns)) ||
362
+ ((_b = this.ethProviderHelper) === null || _b === void 0 ? void 0 : _b.getInjectedProvider());
363
+ return Boolean(provider);
364
+ }
365
+ shouldDeepLinkToMetaMaskInAppBrowser() {
366
+ var _a;
367
+ // Not in an in-app browser
368
+ if (this.isInAppBrowser)
369
+ return false;
370
+ // Not a mobile device
371
+ if (!utils.isMobile())
372
+ return false;
373
+ // SDK is configured to use the in-app browser
374
+ if (this.mobileExperience !== 'in-app-browser')
375
+ return false;
376
+ const isAppBrowserLinkPresent = ((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) && this.wallet.mobile.inAppBrowser;
377
+ // Wallet has an in-app browser link
378
+ if (!isAppBrowserLinkPresent)
379
+ return false;
380
+ return true;
381
+ }
382
+ /**
383
+ * Get wallet book wallet information
384
+ */
385
+ get wallet() {
386
+ return walletBook.findWalletBookWallet(this.walletBook, this.key);
387
+ }
388
+ }
389
+ // Utils
390
+ const getReadonlyRPCMap = (evmNetworkRpcMap) => Object.keys(evmNetworkRpcMap).reduce((acc, chainId) => (Object.assign(Object.assign({}, acc), { [viem.toHex(parseInt(chainId))]: evmNetworkRpcMap[chainId] })), {});
391
+ /**
392
+ * Waits for the focus page event and await for an extra second
393
+ * This is necessary to ensure the verify call will succeed
394
+ */
395
+ const waitForFocusWindowEvent = () => new Promise((resolve) => {
396
+ window.addEventListener('focus', resolve);
397
+ }).then(() => new Promise((resolve) => setTimeout(resolve, 1000)));
398
+
399
+ exports.MetaMaskConnector = MetaMaskConnector;
@@ -0,0 +1,58 @@
1
+ import { MetaMaskSDK } from '@metamask/sdk';
2
+ import { Account, Transport, WalletClient, Chain as ViemChain } from 'viem';
3
+ import { EthereumWalletConnector, EthereumWalletConnectorOpts } from '@dynamic-labs/ethereum-core';
4
+ import { GetAddressOpts, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
5
+ import { EthProviderHelper } from '../ethProviderHelper';
6
+ import { MetaMaskSDKDisplayUriState } from './utils/createMetaMaskSDKDisplayUriState';
7
+ export type MetaMaskConnectorProps = EthereumWalletConnectorOpts & {
8
+ appName: string;
9
+ appLogoUrl: string;
10
+ };
11
+ export declare const clearMetaMaskSdk: () => void;
12
+ export declare class MetaMaskConnector extends EthereumWalletConnector implements IWalletConnectConnector {
13
+ name: string;
14
+ overrideKey: string;
15
+ canConnectViaQrCode: boolean;
16
+ private appName;
17
+ private appLogoUrl;
18
+ private isInAppBrowser;
19
+ constructor(props: MetaMaskConnectorProps);
20
+ getSupportedNetworks(): Promise<string[]>;
21
+ get ethProviderHelper(): EthProviderHelper | undefined;
22
+ get metaMaskSDK(): MetaMaskSDK;
23
+ set metaMaskSDK(metaMaskSDK: MetaMaskSDK);
24
+ get metaMaskSDKDisplayUriState(): MetaMaskSDKDisplayUriState;
25
+ createMetaMaskSDK(): void;
26
+ endSession(): Promise<void>;
27
+ getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
28
+ private getConnectedAccountsSafely;
29
+ getConnectedAccounts(): Promise<string[]>;
30
+ signMessage(messageToSign: string, withAddress?: string): Promise<string | undefined>;
31
+ chooseAccountsToConnect(): Promise<never[]>;
32
+ getWalletClient(chainId?: string): WalletClient<Transport, ViemChain, Account> | undefined;
33
+ get rdns(): string;
34
+ isInstalledOnBrowser(): boolean;
35
+ setupEventListeners(): Promise<void>;
36
+ /**
37
+ * This override is necessary to wait for the MetaMask SDK to initialize
38
+ * before calling the super method. Otherwise, the super method may fail
39
+ * to fetch the provider
40
+ */
41
+ getNetwork(): Promise<number | undefined>;
42
+ private getProvider;
43
+ private evmNetworkByChainId;
44
+ private getWalletClientForAddress;
45
+ private toInt;
46
+ private getCurrentChainId;
47
+ /**
48
+ * Checks if the current environment is the MetaMask in-app browser
49
+ * by checking if the MetaMask provider is installed in the window object
50
+ * on a mobile device
51
+ */
52
+ private getIsInAppBrowser;
53
+ private shouldDeepLinkToMetaMaskInAppBrowser;
54
+ /**
55
+ * Get wallet book wallet information
56
+ */
57
+ private get wallet();
58
+ }
@@ -0,0 +1,395 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { MetaMaskSDK } from '@metamask/sdk';
4
+ import { createWalletClient, custom, isHex, toHex } from 'viem';
5
+ import { EthereumWalletConnector, getOrMapViemChain } from '@dynamic-labs/ethereum-core';
6
+ import { eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
7
+ import { createEventTimeline, PlatformService, isMobile, retryableFn } from '@dynamic-labs/utils';
8
+ import { getWalletBookWallet, findWalletBookWallet } from '@dynamic-labs/wallet-book';
9
+ import { logger } from '../utils/logger.js';
10
+ import { EthProviderHelper } from '../ethProviderHelper.js';
11
+ import { createMetaMaskSDKDisplayUriState } from './utils/createMetaMaskSDKDisplayUriState.js';
12
+ import { waitForConnection } from './utils/waitForConnection.js';
13
+ import { isPendingWalletRequestPermissionError } from './utils/isPendingWalletRequestPermissionError.js';
14
+
15
+ /**
16
+ * The MetaMask SDK must be initialized only once, so we store the instance
17
+ * in these variables to avoid initializing it multiple times
18
+ */
19
+ let _metaMaskSDK = null;
20
+ let _metaMaskSDKDisplayUriState = null;
21
+ const eventTimeline = createEventTimeline();
22
+ class MetaMaskConnector extends EthereumWalletConnector {
23
+ constructor(props) {
24
+ super(props);
25
+ this.name = 'MetaMask';
26
+ this.overrideKey = 'metamask';
27
+ this.canConnectViaQrCode = true;
28
+ this.isInAppBrowser = false;
29
+ this.appName = props.appName;
30
+ this.appLogoUrl = props.appLogoUrl;
31
+ /**
32
+ * The isInAppBrowser must be calculated before initializing the MetaMask SDK.
33
+ *
34
+ * The isInAppBrowser is calculated by checking if the window provider is installed
35
+ * in the browser and if it is running on a mobile device.
36
+ *
37
+ * But the MetaMask SDK will inject its own provider to the window if not provider is injected.
38
+ * This means the MetaMask SDK can interfere with the isInAppBrowser calculation.
39
+ *
40
+ * So we need to calculate the isInAppBrowser before initializing the MetaMask SDK
41
+ * to prevent a false negative
42
+ */
43
+ this.isInAppBrowser = this.getIsInAppBrowser();
44
+ if (!_metaMaskSDK) {
45
+ this.createMetaMaskSDK();
46
+ }
47
+ }
48
+ getSupportedNetworks() {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ return this.evmNetworks.map((network) => network.chainId.toString());
51
+ });
52
+ }
53
+ get ethProviderHelper() {
54
+ return new EthProviderHelper(getWalletBookWallet(this.walletBook, this.key));
55
+ }
56
+ get metaMaskSDK() {
57
+ if (!_metaMaskSDK)
58
+ throw new Error('MetaMaskSDK not initialized');
59
+ return _metaMaskSDK;
60
+ }
61
+ set metaMaskSDK(metaMaskSDK) {
62
+ _metaMaskSDK = metaMaskSDK;
63
+ }
64
+ get metaMaskSDKDisplayUriState() {
65
+ if (!_metaMaskSDKDisplayUriState)
66
+ throw new Error('MetaMaskSDKDisplayUriState not initialized');
67
+ return _metaMaskSDKDisplayUriState;
68
+ }
69
+ createMetaMaskSDK() {
70
+ const dappMetadata = {
71
+ iconUrl: this.appLogoUrl,
72
+ name: this.appName,
73
+ url: PlatformService.getOrigin(),
74
+ };
75
+ _metaMaskSDK = new MetaMaskSDK({
76
+ _source: 'dynamic-labs',
77
+ checkInstallationImmediately: true,
78
+ dappMetadata,
79
+ enableAnalytics: true,
80
+ extensionOnly: this.isInstalledOnBrowser(),
81
+ headless: true,
82
+ openDeeplink: PlatformService.openURL,
83
+ preferDesktop: !isMobile(),
84
+ readonlyRPCMap: getReadonlyRPCMap(this.evmNetworkRpcMap()),
85
+ useDeeplink: true,
86
+ });
87
+ _metaMaskSDKDisplayUriState =
88
+ createMetaMaskSDKDisplayUriState(_metaMaskSDK);
89
+ }
90
+ endSession() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ eventTimeline.postEvent('disconnect');
93
+ /**
94
+ * The MetaMask SDK must be terminated and reinitialized on mobile
95
+ * to prevent deeplinks not working
96
+ */
97
+ if (isMobile()) {
98
+ return this.metaMaskSDK.terminate().then(() => {
99
+ _metaMaskSDK = null;
100
+ _metaMaskSDKDisplayUriState = null;
101
+ return this.createMetaMaskSDK();
102
+ });
103
+ }
104
+ /**
105
+ * Just terminate the SDK on desktop
106
+ */
107
+ return this.metaMaskSDK.terminate();
108
+ });
109
+ }
110
+ getAddress(opts) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ return new Promise((resolve, reject) => {
113
+ var _a, _b, _c, _d;
114
+ // QR Code flow
115
+ if (!isMobile() && Boolean(opts === null || opts === void 0 ? void 0 : opts.onDisplayUri)) {
116
+ this.metaMaskSDKDisplayUriState
117
+ .consumeDisplayUri()
118
+ .then((displayUri) => {
119
+ var _a;
120
+ if (!displayUri) {
121
+ reject(new Error('MetaMask display uri not found'));
122
+ return;
123
+ }
124
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, displayUri);
125
+ });
126
+ }
127
+ // Deep link to MetaMask app in-app browser
128
+ if (this.shouldDeepLinkToMetaMaskInAppBrowser() &&
129
+ ((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.inAppBrowser)) {
130
+ // Redirect to the in-app browser and append the current url
131
+ window.location.href = `${(_d = (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.inAppBrowser}/${window.location.href}`;
132
+ resolve(undefined);
133
+ return;
134
+ }
135
+ // Connect to MetaMask
136
+ this.getConnectedAccountsSafely().then((initialConnectedAccounts) => __awaiter(this, void 0, void 0, function* () {
137
+ if (initialConnectedAccounts.length) {
138
+ resolve(initialConnectedAccounts[0]);
139
+ return;
140
+ }
141
+ try {
142
+ yield this.metaMaskSDK.connect();
143
+ }
144
+ catch (error) {
145
+ const isRequestPendingError = isPendingWalletRequestPermissionError(error);
146
+ if (!isRequestPendingError) {
147
+ throw error;
148
+ }
149
+ else {
150
+ yield waitForConnection(this.getProvider());
151
+ }
152
+ }
153
+ const accounts = yield this.getConnectedAccounts();
154
+ resolve(accounts[0]);
155
+ }));
156
+ });
157
+ });
158
+ }
159
+ getConnectedAccountsSafely() {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ try {
162
+ const connectedAccounts = yield this.getConnectedAccounts();
163
+ return connectedAccounts;
164
+ }
165
+ catch (err) {
166
+ logger.error(err);
167
+ return [];
168
+ }
169
+ });
170
+ }
171
+ getConnectedAccounts() {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ // Wait for for MetaMask SDK to initialize
174
+ yield this.metaMaskSDK.sdkInitPromise;
175
+ const provider = this.getProvider();
176
+ if (!provider) {
177
+ return [];
178
+ }
179
+ /**
180
+ * The eth_accounts method can hang on mobile devices when
181
+ * the MetaMask SDK has not connected yet. So we use a retryable
182
+ * to ensure the timeout will be respected
183
+ */
184
+ const accounts = yield retryableFn(() => provider.request({
185
+ method: 'eth_accounts',
186
+ params: [],
187
+ }), {
188
+ fallbackValue: [],
189
+ timeoutMs: 1000,
190
+ });
191
+ if (!(accounts === null || accounts === void 0 ? void 0 : accounts.length)) {
192
+ return [];
193
+ }
194
+ return accounts;
195
+ });
196
+ }
197
+ signMessage(messageToSign, withAddress) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ yield this.metaMaskSDK.sdkInitPromise;
200
+ /**
201
+ * Should wait for the window to be focused on mobile
202
+ * to account for the user moving between the MetaMaskApp
203
+ * and the browser
204
+ */
205
+ const windowFocusPromiseForMobile = !this.isInAppBrowser && isMobile()
206
+ ? waitForFocusWindowEvent()
207
+ : Promise.resolve();
208
+ const provider = this.getProvider();
209
+ if (!provider) {
210
+ return undefined;
211
+ }
212
+ const [selectedAddress] = yield this.getConnectedAccounts();
213
+ const effectiveAddress = withAddress !== null && withAddress !== void 0 ? withAddress : selectedAddress;
214
+ if (!effectiveAddress) {
215
+ return undefined;
216
+ }
217
+ const walletClient = this.getWalletClientForAddress(effectiveAddress);
218
+ if (!walletClient)
219
+ return undefined;
220
+ const signature = yield walletClient.signMessage({
221
+ message: messageToSign,
222
+ });
223
+ yield windowFocusPromiseForMobile;
224
+ return signature;
225
+ });
226
+ }
227
+ chooseAccountsToConnect() {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ return [];
230
+ });
231
+ }
232
+ getWalletClient(chainId) {
233
+ const provider = this.getProvider();
234
+ if (!provider) {
235
+ return undefined;
236
+ }
237
+ const selectedAddress = provider.getSelectedAddress();
238
+ return this.getWalletClientForAddress(selectedAddress || undefined, chainId);
239
+ }
240
+ get rdns() {
241
+ const { rdns } = this.metadata;
242
+ if (!rdns) {
243
+ throw new Error('rdns not found in metadata');
244
+ }
245
+ return rdns;
246
+ }
247
+ isInstalledOnBrowser() {
248
+ var _a;
249
+ const metaMaskEip6963Provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.eip6963ProviderLookup(this.rdns);
250
+ const isInstalled = Boolean(metaMaskEip6963Provider);
251
+ return isInstalled;
252
+ }
253
+ setupEventListeners() {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ yield this.metaMaskSDK.sdkInitPromise;
256
+ const metaMaskProvider = this.getProvider();
257
+ if (!metaMaskProvider) {
258
+ return;
259
+ }
260
+ const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
261
+ const handleAccountsChangedFromMetaMask = (accounts) => {
262
+ /**
263
+ * MetaMask emits an account changed event when the wallet is disconnected
264
+ * so we ignore the accountsChanged event if the disconnect event was recent
265
+ */
266
+ if (eventTimeline.isEventRecent('disconnect', 1000)) {
267
+ return;
268
+ }
269
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
270
+ // @ts-ignore
271
+ handleAccountChange(accounts);
272
+ };
273
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
274
+ // @ts-ignore
275
+ metaMaskProvider.on('accountsChanged', handleAccountsChangedFromMetaMask);
276
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
277
+ // @ts-ignore
278
+ metaMaskProvider.on('chainChanged', handleChainChange);
279
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
280
+ // @ts-ignore
281
+ metaMaskProvider.on('disconnect', handleDisconnect);
282
+ this.teardownEventListeners = () => {
283
+ metaMaskProvider.off('accountsChanged', handleAccountsChangedFromMetaMask);
284
+ metaMaskProvider.off('chainChanged', handleChainChange);
285
+ metaMaskProvider.off('disconnect', handleDisconnect);
286
+ };
287
+ });
288
+ }
289
+ /**
290
+ * This override is necessary to wait for the MetaMask SDK to initialize
291
+ * before calling the super method. Otherwise, the super method may fail
292
+ * to fetch the provider
293
+ */
294
+ getNetwork() {
295
+ const _super = Object.create(null, {
296
+ getNetwork: { get: () => super.getNetwork }
297
+ });
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ yield this.metaMaskSDK.sdkInitPromise;
300
+ const net = yield _super.getNetwork.call(this);
301
+ return net;
302
+ });
303
+ }
304
+ // Utils
305
+ getProvider() {
306
+ var _a;
307
+ return ((_a = this.metaMaskSDK.getProvider()) !== null && _a !== void 0 ? _a : this.metaMaskSDK.getMobileProvider());
308
+ }
309
+ evmNetworkByChainId(chainId) {
310
+ return this.evmNetworks.find((network) => network.chainId === chainId);
311
+ }
312
+ getWalletClientForAddress(address, chainId) {
313
+ var _a, _b;
314
+ const provider = this.getProvider();
315
+ if (!provider) {
316
+ return undefined;
317
+ }
318
+ const effectiveChainId = (_b = (_a = this.toInt(chainId)) !== null && _a !== void 0 ? _a : this.getCurrentChainId()) !== null && _b !== void 0 ? _b : '1';
319
+ const network = this.evmNetworkByChainId(effectiveChainId);
320
+ return createWalletClient({
321
+ account: address,
322
+ chain: network ? getOrMapViemChain(network) : this.getActiveChain(),
323
+ transport: custom(provider),
324
+ });
325
+ }
326
+ toInt(chainId) {
327
+ if (!chainId)
328
+ return undefined;
329
+ try {
330
+ return parseInt(chainId);
331
+ }
332
+ catch (err) {
333
+ logger.debug(err);
334
+ return undefined;
335
+ }
336
+ }
337
+ getCurrentChainId() {
338
+ const provider = this.getProvider();
339
+ if (!provider) {
340
+ return undefined;
341
+ }
342
+ const chainId = provider.getChainId();
343
+ if (isHex(chainId)) {
344
+ return parseInt(chainId);
345
+ }
346
+ return chainId;
347
+ }
348
+ /**
349
+ * Checks if the current environment is the MetaMask in-app browser
350
+ * by checking if the MetaMask provider is installed in the window object
351
+ * on a mobile device
352
+ */
353
+ getIsInAppBrowser() {
354
+ var _a, _b;
355
+ if (!isMobile())
356
+ return false;
357
+ const provider = ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.eip6963ProviderLookup(this.rdns)) ||
358
+ ((_b = this.ethProviderHelper) === null || _b === void 0 ? void 0 : _b.getInjectedProvider());
359
+ return Boolean(provider);
360
+ }
361
+ shouldDeepLinkToMetaMaskInAppBrowser() {
362
+ var _a;
363
+ // Not in an in-app browser
364
+ if (this.isInAppBrowser)
365
+ return false;
366
+ // Not a mobile device
367
+ if (!isMobile())
368
+ return false;
369
+ // SDK is configured to use the in-app browser
370
+ if (this.mobileExperience !== 'in-app-browser')
371
+ return false;
372
+ const isAppBrowserLinkPresent = ((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) && this.wallet.mobile.inAppBrowser;
373
+ // Wallet has an in-app browser link
374
+ if (!isAppBrowserLinkPresent)
375
+ return false;
376
+ return true;
377
+ }
378
+ /**
379
+ * Get wallet book wallet information
380
+ */
381
+ get wallet() {
382
+ return findWalletBookWallet(this.walletBook, this.key);
383
+ }
384
+ }
385
+ // Utils
386
+ const getReadonlyRPCMap = (evmNetworkRpcMap) => Object.keys(evmNetworkRpcMap).reduce((acc, chainId) => (Object.assign(Object.assign({}, acc), { [toHex(parseInt(chainId))]: evmNetworkRpcMap[chainId] })), {});
387
+ /**
388
+ * Waits for the focus page event and await for an extra second
389
+ * This is necessary to ensure the verify call will succeed
390
+ */
391
+ const waitForFocusWindowEvent = () => new Promise((resolve) => {
392
+ window.addEventListener('focus', resolve);
393
+ }).then(() => new Promise((resolve) => setTimeout(resolve, 1000)));
394
+
395
+ export { MetaMaskConnector };
@@ -0,0 +1,58 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+
8
+ /**
9
+ * Listens for the `display_uri` event emitted by the MetaMask SDK.
10
+ *
11
+ * The `display_uri` event is triggered during SDK initialization or when the `connect` method is called.
12
+ * Calling `terminate` in the MetaMask SDK resets the connection, and a new `display_uri` will only be emitted
13
+ * when `connect` is called again.
14
+ *
15
+ * This function manages the new `display_uri` received from these events.
16
+ */
17
+ const createMetaMaskSDKDisplayUriState = (metaMaskSDK) => {
18
+ let lastKnownMetaMaskDeepLinkUri = null;
19
+ let displayUri = null;
20
+ metaMaskSDK.on('display_uri', (latestDisplayUri) => {
21
+ if (lastKnownMetaMaskDeepLinkUri !== latestDisplayUri) {
22
+ lastKnownMetaMaskDeepLinkUri = latestDisplayUri;
23
+ displayUri = latestDisplayUri.trim();
24
+ }
25
+ });
26
+ return {
27
+ consumeDisplayUri: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
28
+ const currentDisplayUri = displayUri;
29
+ if (currentDisplayUri) {
30
+ displayUri = null;
31
+ return currentDisplayUri;
32
+ }
33
+ return new Promise((resolve) => {
34
+ let timeoutId = null;
35
+ let intervalId = null;
36
+ const cleanUp = () => {
37
+ if (timeoutId)
38
+ clearTimeout(timeoutId);
39
+ if (intervalId)
40
+ clearInterval(intervalId);
41
+ };
42
+ timeoutId = setTimeout(() => {
43
+ cleanUp();
44
+ resolve(undefined);
45
+ }, 1000);
46
+ intervalId = setInterval(() => {
47
+ if (displayUri) {
48
+ cleanUp();
49
+ resolve(displayUri);
50
+ displayUri = null;
51
+ }
52
+ }, 10);
53
+ });
54
+ }),
55
+ };
56
+ };
57
+
58
+ exports.createMetaMaskSDKDisplayUriState = createMetaMaskSDKDisplayUriState;
@@ -0,0 +1,14 @@
1
+ import { MetaMaskSDK } from '@metamask/sdk';
2
+ export type MetaMaskSDKDisplayUriState = {
3
+ consumeDisplayUri: () => Promise<string | undefined>;
4
+ };
5
+ /**
6
+ * Listens for the `display_uri` event emitted by the MetaMask SDK.
7
+ *
8
+ * The `display_uri` event is triggered during SDK initialization or when the `connect` method is called.
9
+ * Calling `terminate` in the MetaMask SDK resets the connection, and a new `display_uri` will only be emitted
10
+ * when `connect` is called again.
11
+ *
12
+ * This function manages the new `display_uri` received from these events.
13
+ */
14
+ export declare const createMetaMaskSDKDisplayUriState: (metaMaskSDK: MetaMaskSDK) => MetaMaskSDKDisplayUriState;
@@ -0,0 +1,54 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+
4
+ /**
5
+ * Listens for the `display_uri` event emitted by the MetaMask SDK.
6
+ *
7
+ * The `display_uri` event is triggered during SDK initialization or when the `connect` method is called.
8
+ * Calling `terminate` in the MetaMask SDK resets the connection, and a new `display_uri` will only be emitted
9
+ * when `connect` is called again.
10
+ *
11
+ * This function manages the new `display_uri` received from these events.
12
+ */
13
+ const createMetaMaskSDKDisplayUriState = (metaMaskSDK) => {
14
+ let lastKnownMetaMaskDeepLinkUri = null;
15
+ let displayUri = null;
16
+ metaMaskSDK.on('display_uri', (latestDisplayUri) => {
17
+ if (lastKnownMetaMaskDeepLinkUri !== latestDisplayUri) {
18
+ lastKnownMetaMaskDeepLinkUri = latestDisplayUri;
19
+ displayUri = latestDisplayUri.trim();
20
+ }
21
+ });
22
+ return {
23
+ consumeDisplayUri: () => __awaiter(void 0, void 0, void 0, function* () {
24
+ const currentDisplayUri = displayUri;
25
+ if (currentDisplayUri) {
26
+ displayUri = null;
27
+ return currentDisplayUri;
28
+ }
29
+ return new Promise((resolve) => {
30
+ let timeoutId = null;
31
+ let intervalId = null;
32
+ const cleanUp = () => {
33
+ if (timeoutId)
34
+ clearTimeout(timeoutId);
35
+ if (intervalId)
36
+ clearInterval(intervalId);
37
+ };
38
+ timeoutId = setTimeout(() => {
39
+ cleanUp();
40
+ resolve(undefined);
41
+ }, 1000);
42
+ intervalId = setInterval(() => {
43
+ if (displayUri) {
44
+ cleanUp();
45
+ resolve(displayUri);
46
+ displayUri = null;
47
+ }
48
+ }, 10);
49
+ });
50
+ }),
51
+ };
52
+ };
53
+
54
+ export { createMetaMaskSDKDisplayUriState };
@@ -0,0 +1,11 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isPendingWalletRequestPermissionError = (error) => typeof error === 'object' &&
7
+ error !== null &&
8
+ 'message' in error &&
9
+ error.message.includes("Request of type 'wallet_requestPermissions' already pending for origin");
10
+
11
+ exports.isPendingWalletRequestPermissionError = isPendingWalletRequestPermissionError;
@@ -0,0 +1 @@
1
+ export declare const isPendingWalletRequestPermissionError: (error: any) => any;
@@ -0,0 +1,7 @@
1
+ 'use client'
2
+ const isPendingWalletRequestPermissionError = (error) => typeof error === 'object' &&
3
+ error !== null &&
4
+ 'message' in error &&
5
+ error.message.includes("Request of type 'wallet_requestPermissions' already pending for origin");
6
+
7
+ export { isPendingWalletRequestPermissionError };
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const waitForConnection = (provider) => new Promise((resolve) => {
7
+ provider.once('connect', () => resolve());
8
+ });
9
+
10
+ exports.waitForConnection = waitForConnection;
@@ -0,0 +1,2 @@
1
+ import { SDKProvider } from '@metamask/sdk';
2
+ export declare const waitForConnection: (provider: SDKProvider) => Promise<void>;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ const waitForConnection = (provider) => new Promise((resolve) => {
3
+ provider.once('connect', () => resolve());
4
+ });
5
+
6
+ export { waitForConnection };
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var logger$1 = require('@dynamic-labs/logger');
7
+
8
+ const logger = new logger$1.Logger('@dynamic-labs/ethereum');
9
+
10
+ exports.logger = logger;
@@ -0,0 +1,2 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+ export declare const logger: Logger;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { Logger } from '@dynamic-labs/logger';
3
+
4
+ const logger = new Logger('@dynamic-labs/ethereum');
5
+
6
+ export { logger };