@dynamic-labs/ethereum 0.17.0-RC.10

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +793 -0
  2. package/LICENSE +21 -0
  3. package/README.md +0 -0
  4. package/_virtual/_tslib.cjs +43 -0
  5. package/_virtual/_tslib.js +38 -0
  6. package/package.json +40 -0
  7. package/src/EthWalletConnector.cjs +206 -0
  8. package/src/EthWalletConnector.d.ts +39 -0
  9. package/src/EthWalletConnector.js +202 -0
  10. package/src/constants.cjs +7 -0
  11. package/src/constants.d.ts +1 -0
  12. package/src/constants.js +3 -0
  13. package/src/ethProviderHelper.cjs +197 -0
  14. package/src/ethProviderHelper.d.ts +33 -0
  15. package/src/ethProviderHelper.js +193 -0
  16. package/src/index.cjs +52 -0
  17. package/src/index.d.ts +6 -0
  18. package/src/index.js +33 -0
  19. package/src/injected/BloctoInjected.cjs +14 -0
  20. package/src/injected/BloctoInjected.d.ts +4 -0
  21. package/src/injected/BloctoInjected.js +10 -0
  22. package/src/injected/BraveEvm.cjs +14 -0
  23. package/src/injected/BraveEvm.d.ts +4 -0
  24. package/src/injected/BraveEvm.js +10 -0
  25. package/src/injected/Dawn.cjs +14 -0
  26. package/src/injected/Dawn.d.ts +4 -0
  27. package/src/injected/Dawn.js +10 -0
  28. package/src/injected/ExodusEvm.cjs +14 -0
  29. package/src/injected/ExodusEvm.d.ts +4 -0
  30. package/src/injected/ExodusEvm.js +10 -0
  31. package/src/injected/Frame.cjs +14 -0
  32. package/src/injected/Frame.d.ts +4 -0
  33. package/src/injected/Frame.js +10 -0
  34. package/src/injected/GameStop.cjs +14 -0
  35. package/src/injected/GameStop.d.ts +4 -0
  36. package/src/injected/GameStop.js +10 -0
  37. package/src/injected/InjectedWalletBase.cjs +75 -0
  38. package/src/injected/InjectedWalletBase.d.ts +24 -0
  39. package/src/injected/InjectedWalletBase.js +73 -0
  40. package/src/injected/MetaMask.cjs +15 -0
  41. package/src/injected/MetaMask.d.ts +5 -0
  42. package/src/injected/MetaMask.js +11 -0
  43. package/src/injected/Opera.cjs +14 -0
  44. package/src/injected/Opera.d.ts +4 -0
  45. package/src/injected/Opera.js +10 -0
  46. package/src/injected/PhantomEvm.cjs +38 -0
  47. package/src/injected/PhantomEvm.d.ts +5 -0
  48. package/src/injected/PhantomEvm.js +34 -0
  49. package/src/injected/Trust.cjs +15 -0
  50. package/src/injected/Trust.d.ts +5 -0
  51. package/src/injected/Trust.js +11 -0
  52. package/src/injected/UnknownInjectedWallet.cjs +14 -0
  53. package/src/injected/UnknownInjectedWallet.d.ts +4 -0
  54. package/src/injected/UnknownInjectedWallet.js +10 -0
  55. package/src/injected/Zerion.cjs +15 -0
  56. package/src/injected/Zerion.d.ts +5 -0
  57. package/src/injected/Zerion.js +11 -0
  58. package/src/injected/index.cjs +45 -0
  59. package/src/injected/index.d.ts +14 -0
  60. package/src/injected/index.js +41 -0
  61. package/src/types.d.ts +21 -0
  62. package/src/utils/findEvmNetwork.cjs +20 -0
  63. package/src/utils/findEvmNetwork.d.ts +6 -0
  64. package/src/utils/findEvmNetwork.js +16 -0
  65. package/src/utils/isUnsupportedProviderError/index.d.ts +1 -0
  66. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +13 -0
  67. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +6 -0
  68. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +9 -0
  69. package/src/walletConnect/client/client.cjs +228 -0
  70. package/src/walletConnect/client/client.d.ts +21 -0
  71. package/src/walletConnect/client/client.js +212 -0
  72. package/src/walletConnect/client/index.d.ts +1 -0
  73. package/src/walletConnect/client/types.d.ts +4 -0
  74. package/src/walletConnect/fetchWalletConnectWallets.cjs +58 -0
  75. package/src/walletConnect/fetchWalletConnectWallets.d.ts +8 -0
  76. package/src/walletConnect/fetchWalletConnectWallets.js +52 -0
  77. package/src/walletConnect/index.d.ts +3 -0
  78. package/src/walletConnect/walletConnect.cjs +134 -0
  79. package/src/walletConnect/walletConnect.d.ts +33 -0
  80. package/src/walletConnect/walletConnect.js +126 -0
  81. package/src/walletConnect/walletConnectV2.cjs +268 -0
  82. package/src/walletConnect/walletConnectV2.d.ts +37 -0
  83. package/src/walletConnect/walletConnectV2.js +260 -0
@@ -0,0 +1,6 @@
1
+ type UnsupportedProviderError = {
2
+ reason: string;
3
+ value: unknown;
4
+ };
5
+ export declare const isUnsupportedProviderError: (error: UnsupportedProviderError | unknown) => error is UnsupportedProviderError;
6
+ export {};
@@ -0,0 +1,9 @@
1
+ const isUnsupportedProviderError = (error) => {
2
+ const isObject = typeof error === 'object';
3
+ if (!isObject)
4
+ return false;
5
+ const isUnsupportedProviderErrorReason = error['reason'] === 'unsupported provider';
6
+ return isUnsupportedProviderErrorReason;
7
+ };
8
+
9
+ export { isUnsupportedProviderError };
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../_virtual/_tslib.cjs');
6
+ var Client = require('@walletconnect/client');
7
+ var ethers = require('ethers');
8
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var utils = require('@dynamic-labs/utils');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var Client__default = /*#__PURE__*/_interopDefaultLegacy(Client);
14
+
15
+ const initClient = (name, settings) => {
16
+ const storageId = `walletconnect-${name}`;
17
+ const session = localStorage.getItem(storageId);
18
+ const clientArgs = session
19
+ ? { session: JSON.parse(session), storageId }
20
+ : { bridge: 'https://bridge.walletconnect.org', storageId };
21
+ return new Client__default["default"](Object.assign(Object.assign({}, clientArgs), settings));
22
+ };
23
+ /**
24
+ * Attach event handlers to WalletConnect events.
25
+ */
26
+ const setupWalletConnectEventListeners = (opts, client) => {
27
+ if (!client) {
28
+ return;
29
+ }
30
+ let prevAccount;
31
+ let prevChain;
32
+ if (client.connected) {
33
+ // eslint-disable-next-line prefer-destructuring
34
+ prevAccount = client.accounts[0];
35
+ prevChain = client.chainId;
36
+ }
37
+ client.on('disconnect', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
38
+ var _a;
39
+ yield ((_a = opts.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(opts));
40
+ }));
41
+ client.on('session_update', (_, payload) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
42
+ var _b, _c;
43
+ // eslint-disable-next-line prefer-destructuring
44
+ const { accounts, chainId } = payload.params[0];
45
+ const didAccountChange = !walletConnectorCore.isSameAddress(prevAccount || '', accounts[0], 'eip155');
46
+ const didChainChange = prevChain !== chainId;
47
+ // eslint-disable-next-line prefer-destructuring
48
+ prevAccount = accounts[0];
49
+ prevChain = chainId;
50
+ if (didAccountChange) {
51
+ yield ((_b = opts.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(opts, accounts));
52
+ }
53
+ if (didChainChange) {
54
+ yield ((_c = opts.onChainChange) === null || _c === void 0 ? void 0 : _c.call(opts, String(chainId)));
55
+ }
56
+ }));
57
+ };
58
+ const teardownWalletConnectEventListeners = (client) => {
59
+ client.off('disconnect');
60
+ client.off('session_update');
61
+ };
62
+ /**
63
+ * Initialize a client from a stored session and terminate the connection.
64
+ */
65
+ const killWalletConnectSession = (client) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
66
+ try {
67
+ if (client === null || client === void 0 ? void 0 : client.connected) {
68
+ yield client.killSession();
69
+ }
70
+ }
71
+ catch (e) {
72
+ walletConnectorCore.logger.debug(e);
73
+ }
74
+ });
75
+ const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
76
+ var _a, _b, _c, _d;
77
+ if (!utils.isMobile()) {
78
+ const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
79
+ if (removeWCUri)
80
+ return origin || '';
81
+ return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
82
+ }
83
+ // deeplinks for ios require special treatment
84
+ // see: https://docs.walletconnect.com/mobile-linking#for-ios
85
+ else if (utils.isIOS()) {
86
+ const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
87
+ if (removeWCUri)
88
+ return origin || '';
89
+ return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
90
+ }
91
+ // on android, the deeplink is simply the uri
92
+ // see: https://docs.walletconnect.com/mobile-linking#for-android
93
+ return uri;
94
+ };
95
+ const createSession = (client) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
96
+ return new Promise((resolve, reject) => {
97
+ client.on('connect', (error, payload) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
98
+ if (error)
99
+ throw error;
100
+ resolve(payload);
101
+ }));
102
+ client.on('disconnect', (error, payload) => {
103
+ reject(error || payload.params[0].message);
104
+ });
105
+ });
106
+ });
107
+ const useDeepLink = (metadata, wcClient, opts) => {
108
+ var _a, _b, _c;
109
+ const deepLink = getDeepLink(wcClient.uri, metadata);
110
+ if (utils.isMobile()) {
111
+ window.location.href = deepLink;
112
+ }
113
+ else {
114
+ if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
115
+ (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
116
+ }
117
+ (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
118
+ }
119
+ };
120
+ const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
121
+ var _a;
122
+ if (wcClient.connected) {
123
+ const [accountPublicAddress] = wcClient.accounts;
124
+ return accountPublicAddress;
125
+ }
126
+ // createSession will trigger the QR code...
127
+ yield wcClient.createSession();
128
+ useDeepLink(metadata, wcClient, opts);
129
+ const payload = yield createSession(wcClient);
130
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
131
+ const [accountPublicAddress] = payload.params[0].accounts;
132
+ return accountPublicAddress;
133
+ });
134
+ const signWalletConnectPersonalMessage = (messageToSign, metadata, client, rpcProvider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
135
+ var _b, _c;
136
+ const isCryptoWallet = ((_b = client === null || client === void 0 ? void 0 : client.peerMeta) === null || _b === void 0 ? void 0 : _b.name) === 'Crypto.com | DeFi Wallet' ||
137
+ ((_c = client === null || client === void 0 ? void 0 : client.peerMeta) === null || _c === void 0 ? void 0 : _c.name) === 'DeFi Wallet';
138
+ if (!client || !client.connected) {
139
+ return;
140
+ }
141
+ const [accountPublicAddress] = client.accounts;
142
+ if (utils.isMobile()) {
143
+ const deepLink = getDeepLink(client.uri, metadata, {
144
+ removeWCUri: utils.isIOS() && isCryptoWallet,
145
+ });
146
+ window.location.href = deepLink;
147
+ }
148
+ try {
149
+ // This delay is required for Crypto.com DeFi wallet, when there is no delay the app
150
+ // will not open the pop-up to sign. That seems to be a limitation in the standalone client
151
+ // so the delay is required to allow the users to sign the message
152
+ if (isCryptoWallet && utils.isMobile()) {
153
+ yield sleep(4000);
154
+ }
155
+ else {
156
+ // The delay of 1 second is necessary for some of the wallets to open the sign UI in the
157
+ // correct order, without this some wallets like Trust or OKX will no open properly,
158
+ // and not allowing the user to sign the message
159
+ yield sleep(1000);
160
+ }
161
+ const signature = yield client.signPersonalMessage([
162
+ messageToSign,
163
+ accountPublicAddress,
164
+ ]);
165
+ yield waitForSafeTransactionOrTimeout(accountPublicAddress, signature, messageToSign, client, rpcProvider);
166
+ return signature;
167
+ }
168
+ catch (e) {
169
+ walletConnectorCore.logger.debug(e);
170
+ throw e;
171
+ }
172
+ });
173
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
174
+ // Successful value as defined by the EIP
175
+ // https://eips.ethereum.org/EIPS/eip-1271#specification
176
+ const MAGIC_VALUE = '0x1626ba7e';
177
+ const IS_VALID_SIGNATURE_ABI = [
178
+ 'function isValidSignature(bytes32 _message, bytes _signature) public view returns (bytes4)',
179
+ ];
180
+ const waitForSafeTransactionOrTimeout = (accountPublicAddress, signature, messageToSign, client, rpcProvider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
181
+ var _d;
182
+ if (signature === '0x' &&
183
+ // this is what wallet connect client returns there's no `safe` or `Safe`
184
+ // exact string anywhere, so this seems like the best proxy
185
+ ((_d = client.peerMeta) === null || _d === void 0 ? void 0 : _d.name) === 'WalletConnect Safe App') {
186
+ if (!rpcProvider) {
187
+ return;
188
+ }
189
+ const contract = new ethers.Contract(accountPublicAddress, IS_VALID_SIGNATURE_ABI, yield rpcProvider());
190
+ const safeTransactionPromise = waitForSafeTransaction(signature, messageToSign, contract);
191
+ const timeoutPromise = new Promise((resolve) => {
192
+ setTimeout(resolve, 120000);
193
+ });
194
+ yield Promise.race([safeTransactionPromise, timeoutPromise]);
195
+ }
196
+ });
197
+ // this is a hack for safe
198
+ // before sending the signature downstream, we need to make sure
199
+ // the transaction is recorded first on the blockchain
200
+ // redcoast verify WILL fail if it attempts to verify the signature
201
+ // that has not yet been properly processed!
202
+ const waitForSafeTransaction = (signature, messageToSign, contract) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
203
+ // wait for safe wallet to finish txn on the blockchain contract
204
+ for (let i = 0; i < 120; i++) {
205
+ try {
206
+ // this will result in an exception if the transaction is still not ready
207
+ // we need to catch it below
208
+ const result = yield contract.isValidSignature(ethers.ethers.utils.hashMessage(messageToSign), signature);
209
+ if (result === MAGIC_VALUE)
210
+ return;
211
+ }
212
+ catch (err) {
213
+ walletConnectorCore.logger.info('Safe transaction cannot be validated yet. Retrying.');
214
+ }
215
+ // try again after 2 seconds
216
+ yield sleep(2000);
217
+ }
218
+ });
219
+
220
+ exports.createSession = createSession;
221
+ exports.fetchWalletConnectEVMPublicAddress = fetchWalletConnectEVMPublicAddress;
222
+ exports.getDeepLink = getDeepLink;
223
+ exports.initClient = initClient;
224
+ exports.killWalletConnectSession = killWalletConnectSession;
225
+ exports.setupWalletConnectEventListeners = setupWalletConnectEventListeners;
226
+ exports.signWalletConnectPersonalMessage = signWalletConnectPersonalMessage;
227
+ exports.teardownWalletConnectEventListeners = teardownWalletConnectEventListeners;
228
+ exports.useDeepLink = useDeepLink;
@@ -0,0 +1,21 @@
1
+ import Client from '@walletconnect/client';
2
+ import { ethers } from 'ethers';
3
+ import { FetchPublicAddressOpts, PayloadParams, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
4
+ import { WalletSchema } from '@dynamic-labs/wallet-book';
5
+ export declare const initClient: (name: string, settings?: any) => Client;
6
+ /**
7
+ * Attach event handlers to WalletConnect events.
8
+ */
9
+ export declare const setupWalletConnectEventListeners: (opts: WalletEventListeners, client: Client) => void;
10
+ export declare const teardownWalletConnectEventListeners: (client: Client) => void;
11
+ /**
12
+ * Initialize a client from a stored session and terminate the connection.
13
+ */
14
+ export declare const killWalletConnectSession: (client: Client) => Promise<void>;
15
+ export declare const getDeepLink: (uri: string, metadata: WalletSchema, { removeWCUri, }?: {
16
+ removeWCUri?: boolean | undefined;
17
+ }) => string;
18
+ export declare const createSession: (client: Client) => Promise<PayloadParams>;
19
+ export declare const useDeepLink: (metadata: WalletSchema, wcClient: Client, opts?: FetchPublicAddressOpts) => void;
20
+ export declare const fetchWalletConnectEVMPublicAddress: (metadata: WalletSchema, wcClient: Client, opts?: FetchPublicAddressOpts) => Promise<string | undefined>;
21
+ export declare const signWalletConnectPersonalMessage: (messageToSign: string, metadata: WalletSchema, client: Client, rpcProvider?: () => Promise<ethers.providers.JsonRpcProvider | undefined>) => Promise<string | undefined>;
@@ -0,0 +1,212 @@
1
+ import { __awaiter } from '../../../_virtual/_tslib.js';
2
+ import Client from '@walletconnect/client';
3
+ import { Contract, ethers } from 'ethers';
4
+ import { isSameAddress, logger } from '@dynamic-labs/wallet-connector-core';
5
+ import { isMobile, isIOS } from '@dynamic-labs/utils';
6
+
7
+ const initClient = (name, settings) => {
8
+ const storageId = `walletconnect-${name}`;
9
+ const session = localStorage.getItem(storageId);
10
+ const clientArgs = session
11
+ ? { session: JSON.parse(session), storageId }
12
+ : { bridge: 'https://bridge.walletconnect.org', storageId };
13
+ return new Client(Object.assign(Object.assign({}, clientArgs), settings));
14
+ };
15
+ /**
16
+ * Attach event handlers to WalletConnect events.
17
+ */
18
+ const setupWalletConnectEventListeners = (opts, client) => {
19
+ if (!client) {
20
+ return;
21
+ }
22
+ let prevAccount;
23
+ let prevChain;
24
+ if (client.connected) {
25
+ // eslint-disable-next-line prefer-destructuring
26
+ prevAccount = client.accounts[0];
27
+ prevChain = client.chainId;
28
+ }
29
+ client.on('disconnect', () => __awaiter(void 0, void 0, void 0, function* () {
30
+ var _a;
31
+ yield ((_a = opts.onDisconnect) === null || _a === void 0 ? void 0 : _a.call(opts));
32
+ }));
33
+ client.on('session_update', (_, payload) => __awaiter(void 0, void 0, void 0, function* () {
34
+ var _b, _c;
35
+ // eslint-disable-next-line prefer-destructuring
36
+ const { accounts, chainId } = payload.params[0];
37
+ const didAccountChange = !isSameAddress(prevAccount || '', accounts[0], 'eip155');
38
+ const didChainChange = prevChain !== chainId;
39
+ // eslint-disable-next-line prefer-destructuring
40
+ prevAccount = accounts[0];
41
+ prevChain = chainId;
42
+ if (didAccountChange) {
43
+ yield ((_b = opts.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(opts, accounts));
44
+ }
45
+ if (didChainChange) {
46
+ yield ((_c = opts.onChainChange) === null || _c === void 0 ? void 0 : _c.call(opts, String(chainId)));
47
+ }
48
+ }));
49
+ };
50
+ const teardownWalletConnectEventListeners = (client) => {
51
+ client.off('disconnect');
52
+ client.off('session_update');
53
+ };
54
+ /**
55
+ * Initialize a client from a stored session and terminate the connection.
56
+ */
57
+ const killWalletConnectSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
58
+ try {
59
+ if (client === null || client === void 0 ? void 0 : client.connected) {
60
+ yield client.killSession();
61
+ }
62
+ }
63
+ catch (e) {
64
+ logger.debug(e);
65
+ }
66
+ });
67
+ const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
68
+ var _a, _b, _c, _d;
69
+ if (!isMobile()) {
70
+ const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
71
+ if (removeWCUri)
72
+ return origin || '';
73
+ return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
74
+ }
75
+ // deeplinks for ios require special treatment
76
+ // see: https://docs.walletconnect.com/mobile-linking#for-ios
77
+ else if (isIOS()) {
78
+ const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
79
+ if (removeWCUri)
80
+ return origin || '';
81
+ return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
82
+ }
83
+ // on android, the deeplink is simply the uri
84
+ // see: https://docs.walletconnect.com/mobile-linking#for-android
85
+ return uri;
86
+ };
87
+ const createSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
88
+ return new Promise((resolve, reject) => {
89
+ client.on('connect', (error, payload) => __awaiter(void 0, void 0, void 0, function* () {
90
+ if (error)
91
+ throw error;
92
+ resolve(payload);
93
+ }));
94
+ client.on('disconnect', (error, payload) => {
95
+ reject(error || payload.params[0].message);
96
+ });
97
+ });
98
+ });
99
+ const useDeepLink = (metadata, wcClient, opts) => {
100
+ var _a, _b, _c;
101
+ const deepLink = getDeepLink(wcClient.uri, metadata);
102
+ if (isMobile()) {
103
+ window.location.href = deepLink;
104
+ }
105
+ else {
106
+ if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
107
+ (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
108
+ }
109
+ (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
110
+ }
111
+ };
112
+ const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => __awaiter(void 0, void 0, void 0, function* () {
113
+ var _a;
114
+ if (wcClient.connected) {
115
+ const [accountPublicAddress] = wcClient.accounts;
116
+ return accountPublicAddress;
117
+ }
118
+ // createSession will trigger the QR code...
119
+ yield wcClient.createSession();
120
+ useDeepLink(metadata, wcClient, opts);
121
+ const payload = yield createSession(wcClient);
122
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
123
+ const [accountPublicAddress] = payload.params[0].accounts;
124
+ return accountPublicAddress;
125
+ });
126
+ const signWalletConnectPersonalMessage = (messageToSign, metadata, client, rpcProvider) => __awaiter(void 0, void 0, void 0, function* () {
127
+ var _b, _c;
128
+ const isCryptoWallet = ((_b = client === null || client === void 0 ? void 0 : client.peerMeta) === null || _b === void 0 ? void 0 : _b.name) === 'Crypto.com | DeFi Wallet' ||
129
+ ((_c = client === null || client === void 0 ? void 0 : client.peerMeta) === null || _c === void 0 ? void 0 : _c.name) === 'DeFi Wallet';
130
+ if (!client || !client.connected) {
131
+ return;
132
+ }
133
+ const [accountPublicAddress] = client.accounts;
134
+ if (isMobile()) {
135
+ const deepLink = getDeepLink(client.uri, metadata, {
136
+ removeWCUri: isIOS() && isCryptoWallet,
137
+ });
138
+ window.location.href = deepLink;
139
+ }
140
+ try {
141
+ // This delay is required for Crypto.com DeFi wallet, when there is no delay the app
142
+ // will not open the pop-up to sign. That seems to be a limitation in the standalone client
143
+ // so the delay is required to allow the users to sign the message
144
+ if (isCryptoWallet && isMobile()) {
145
+ yield sleep(4000);
146
+ }
147
+ else {
148
+ // The delay of 1 second is necessary for some of the wallets to open the sign UI in the
149
+ // correct order, without this some wallets like Trust or OKX will no open properly,
150
+ // and not allowing the user to sign the message
151
+ yield sleep(1000);
152
+ }
153
+ const signature = yield client.signPersonalMessage([
154
+ messageToSign,
155
+ accountPublicAddress,
156
+ ]);
157
+ yield waitForSafeTransactionOrTimeout(accountPublicAddress, signature, messageToSign, client, rpcProvider);
158
+ return signature;
159
+ }
160
+ catch (e) {
161
+ logger.debug(e);
162
+ throw e;
163
+ }
164
+ });
165
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
166
+ // Successful value as defined by the EIP
167
+ // https://eips.ethereum.org/EIPS/eip-1271#specification
168
+ const MAGIC_VALUE = '0x1626ba7e';
169
+ const IS_VALID_SIGNATURE_ABI = [
170
+ 'function isValidSignature(bytes32 _message, bytes _signature) public view returns (bytes4)',
171
+ ];
172
+ const waitForSafeTransactionOrTimeout = (accountPublicAddress, signature, messageToSign, client, rpcProvider) => __awaiter(void 0, void 0, void 0, function* () {
173
+ var _d;
174
+ if (signature === '0x' &&
175
+ // this is what wallet connect client returns there's no `safe` or `Safe`
176
+ // exact string anywhere, so this seems like the best proxy
177
+ ((_d = client.peerMeta) === null || _d === void 0 ? void 0 : _d.name) === 'WalletConnect Safe App') {
178
+ if (!rpcProvider) {
179
+ return;
180
+ }
181
+ const contract = new Contract(accountPublicAddress, IS_VALID_SIGNATURE_ABI, yield rpcProvider());
182
+ const safeTransactionPromise = waitForSafeTransaction(signature, messageToSign, contract);
183
+ const timeoutPromise = new Promise((resolve) => {
184
+ setTimeout(resolve, 120000);
185
+ });
186
+ yield Promise.race([safeTransactionPromise, timeoutPromise]);
187
+ }
188
+ });
189
+ // this is a hack for safe
190
+ // before sending the signature downstream, we need to make sure
191
+ // the transaction is recorded first on the blockchain
192
+ // redcoast verify WILL fail if it attempts to verify the signature
193
+ // that has not yet been properly processed!
194
+ const waitForSafeTransaction = (signature, messageToSign, contract) => __awaiter(void 0, void 0, void 0, function* () {
195
+ // wait for safe wallet to finish txn on the blockchain contract
196
+ for (let i = 0; i < 120; i++) {
197
+ try {
198
+ // this will result in an exception if the transaction is still not ready
199
+ // we need to catch it below
200
+ const result = yield contract.isValidSignature(ethers.utils.hashMessage(messageToSign), signature);
201
+ if (result === MAGIC_VALUE)
202
+ return;
203
+ }
204
+ catch (err) {
205
+ logger.info('Safe transaction cannot be validated yet. Retrying.');
206
+ }
207
+ // try again after 2 seconds
208
+ yield sleep(2000);
209
+ }
210
+ });
211
+
212
+ export { createSession, fetchWalletConnectEVMPublicAddress, getDeepLink, initClient, killWalletConnectSession, setupWalletConnectEventListeners, signWalletConnectPersonalMessage, teardownWalletConnectEventListeners, useDeepLink };
@@ -0,0 +1 @@
1
+ export * from './client';
@@ -0,0 +1,4 @@
1
+ import Client from '@walletconnect/client';
2
+ export type InitializeWalletConnectClientOpts = {
3
+ bridge?: Client['bridge'];
4
+ };
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var walletBook = require('@dynamic-labs/wallet-book');
6
+ var walletConnectV2 = require('./walletConnectV2.cjs');
7
+ var walletConnect = require('./walletConnect.cjs');
8
+
9
+ // These wallets are either not supported or implement their
10
+ // own WalletConnect connector
11
+ const filteredWalletConnectWallets = [
12
+ 'MetaMask',
13
+ 'Gnosis Safe',
14
+ 'Trust',
15
+ 'lilico',
16
+ 'Keplr',
17
+ 'Zerion',
18
+ ];
19
+ const fetchWalletConnectWallets = ({ isWalletConnectV2Enabled, }) => Object.values(walletBook.useWalletBook().wallets)
20
+ .filter((wallet) => wallet.walletConnect &&
21
+ !filteredWalletConnectWallets.includes(wallet.shortName || wallet.name))
22
+ .map((wallet) => {
23
+ var _a;
24
+ const { shortName } = wallet;
25
+ const name = shortName || wallet.name;
26
+ // justification: we filtered out null/undefined above
27
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28
+ if (isWalletConnectV2Enabled &&
29
+ ((_a = wallet.walletConnect.sdks) === null || _a === void 0 ? void 0 : _a.includes('sign_v2'))) {
30
+ return class extends walletConnectV2.WalletConnectV2 {
31
+ constructor(props) {
32
+ super(Object.assign(Object.assign({}, props), { walletName: name }));
33
+ }
34
+ };
35
+ }
36
+ else {
37
+ return class extends walletConnect.WalletConnect {
38
+ constructor(props) {
39
+ super(Object.assign(Object.assign({}, props), { walletName: name }));
40
+ }
41
+ };
42
+ }
43
+ });
44
+ const getWalletConnectConnector = ({ isWalletConnectV2Enabled, }) => isWalletConnectV2Enabled
45
+ ? class extends walletConnectV2.WalletConnectV2 {
46
+ constructor(props) {
47
+ super(Object.assign(Object.assign({}, props), { walletName: 'WalletConnect' }));
48
+ }
49
+ }
50
+ : class extends walletConnect.WalletConnect {
51
+ constructor(props) {
52
+ super(Object.assign(Object.assign({}, props), { walletName: 'WalletConnect' }));
53
+ }
54
+ };
55
+
56
+ exports.fetchWalletConnectWallets = fetchWalletConnectWallets;
57
+ exports.filteredWalletConnectWallets = filteredWalletConnectWallets;
58
+ exports.getWalletConnectConnector = getWalletConnectConnector;
@@ -0,0 +1,8 @@
1
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
2
+ export declare const filteredWalletConnectWallets: string[];
3
+ export declare const fetchWalletConnectWallets: ({ isWalletConnectV2Enabled, }: {
4
+ isWalletConnectV2Enabled: boolean;
5
+ }) => Array<WalletConnectorConstructor>;
6
+ export declare const getWalletConnectConnector: ({ isWalletConnectV2Enabled, }: {
7
+ isWalletConnectV2Enabled: boolean;
8
+ }) => WalletConnectorConstructor;
@@ -0,0 +1,52 @@
1
+ import { useWalletBook } from '@dynamic-labs/wallet-book';
2
+ import { WalletConnectV2 } from './walletConnectV2.js';
3
+ import { WalletConnect } from './walletConnect.js';
4
+
5
+ // These wallets are either not supported or implement their
6
+ // own WalletConnect connector
7
+ const filteredWalletConnectWallets = [
8
+ 'MetaMask',
9
+ 'Gnosis Safe',
10
+ 'Trust',
11
+ 'lilico',
12
+ 'Keplr',
13
+ 'Zerion',
14
+ ];
15
+ const fetchWalletConnectWallets = ({ isWalletConnectV2Enabled, }) => Object.values(useWalletBook().wallets)
16
+ .filter((wallet) => wallet.walletConnect &&
17
+ !filteredWalletConnectWallets.includes(wallet.shortName || wallet.name))
18
+ .map((wallet) => {
19
+ var _a;
20
+ const { shortName } = wallet;
21
+ const name = shortName || wallet.name;
22
+ // justification: we filtered out null/undefined above
23
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24
+ if (isWalletConnectV2Enabled &&
25
+ ((_a = wallet.walletConnect.sdks) === null || _a === void 0 ? void 0 : _a.includes('sign_v2'))) {
26
+ return class extends WalletConnectV2 {
27
+ constructor(props) {
28
+ super(Object.assign(Object.assign({}, props), { walletName: name }));
29
+ }
30
+ };
31
+ }
32
+ else {
33
+ return class extends WalletConnect {
34
+ constructor(props) {
35
+ super(Object.assign(Object.assign({}, props), { walletName: name }));
36
+ }
37
+ };
38
+ }
39
+ });
40
+ const getWalletConnectConnector = ({ isWalletConnectV2Enabled, }) => isWalletConnectV2Enabled
41
+ ? class extends WalletConnectV2 {
42
+ constructor(props) {
43
+ super(Object.assign(Object.assign({}, props), { walletName: 'WalletConnect' }));
44
+ }
45
+ }
46
+ : class extends WalletConnect {
47
+ constructor(props) {
48
+ super(Object.assign(Object.assign({}, props), { walletName: 'WalletConnect' }));
49
+ }
50
+ };
51
+
52
+ export { fetchWalletConnectWallets, filteredWalletConnectWallets, getWalletConnectConnector };
@@ -0,0 +1,3 @@
1
+ export { WalletConnectV2, type WalletConnectorV2Opts } from './walletConnectV2';
2
+ export { WalletConnect } from './walletConnect';
3
+ export { fetchWalletConnectWallets } from './fetchWalletConnectWallets';