@dynamic-labs/ethereum 0.19.0-alpha.2 → 0.19.0-alpha.21

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