@tetherto/wdk-wallet-evm 1.0.0-beta.11 → 1.0.0-beta.12

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.
@@ -4,6 +4,7 @@ require('@nomicfoundation/hardhat-ethers')
4
4
  module.exports = {
5
5
  networks: {
6
6
  hardhat: {
7
+ chainId: 1,
7
8
  hardfork: 'prague',
8
9
  accounts: {
9
10
  mnemonic: 'anger burst story spy face pattern whale quit delay fiction ball solve',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-evm",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "A simple package to manage BIP-32 wallets for evm blockchains.",
5
5
  "keywords": [
6
6
  "wdk",
@@ -30,7 +30,8 @@
30
30
  "@noble/curves": "1.9.2",
31
31
  "@noble/hashes": "1.8.0",
32
32
  "@noble/secp256k1": "2.2.3",
33
- "@tetherto/wdk-wallet": "1.0.0-beta.7",
33
+ "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
34
+ "@tetherto/wdk-wallet": "1.0.0-beta.8",
34
35
  "bare-node-runtime": "^1.1.4",
35
36
  "bip39": "3.1.0",
36
37
  "ethers": "6.14.4",
@@ -45,9 +46,14 @@
45
46
  "typescript": "5.8.3"
46
47
  },
47
48
  "overrides": {
49
+ "brace-expansion": "1.1.13",
48
50
  "cookie": "1.0.2",
51
+ "immutable": "4.3.8",
52
+ "picomatch@2": "2.3.2",
53
+ "serialize-javascript": ">=7.0.5",
49
54
  "tmp": "0.2.5",
50
- "undici": "7.21.0"
55
+ "undici": ">=7.24.0",
56
+ "uuid": "14.0.0"
51
57
  },
52
58
  "exports": {
53
59
  ".": {
@@ -147,6 +147,19 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
147
147
  return await this._account.signTypedData(domain, types, message)
148
148
  }
149
149
 
150
+ /**
151
+ * Signs a transaction.
152
+ *
153
+ * @param {EvmTransaction} tx - The transaction to sign.
154
+ * @returns {Promise<string>} The signed transaction as a hex string.
155
+ */
156
+ async signTransaction (tx) {
157
+ return await this._account.signTransaction({
158
+ from: await this.getAddress(),
159
+ ...tx
160
+ })
161
+ }
162
+
150
163
  /**
151
164
  * Sends a transaction.
152
165
  *
@@ -234,9 +247,11 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
234
247
  * @returns {Promise<WalletAccountReadOnlyEvm>} The read-only account.
235
248
  */
236
249
  async toReadOnlyAccount () {
237
- const readOnlyAccount = new WalletAccountReadOnlyEvm(this._account.address, this._config)
250
+ if (!this._evmReadOnlyAccount) {
251
+ this._evmReadOnlyAccount = new WalletAccountReadOnlyEvm(this._account.address, this._config)
252
+ }
238
253
 
239
- return readOnlyAccount
254
+ return this._evmReadOnlyAccount
240
255
  }
241
256
 
242
257
  /**
@@ -20,6 +20,8 @@ import { BrowserProvider, Contract, Interface, JsonRpcProvider, Network, Signatu
20
20
 
21
21
  import { multicall } from './multicall.js'
22
22
 
23
+ import FailoverProvider from '@tetherto/wdk-failover-provider'
24
+
23
25
  /** @typedef {import('ethers').Provider} Provider */
24
26
  /** @typedef {import('ethers').Eip1193Provider} Eip1193Provider */
25
27
  /** @typedef {import('ethers').TypedDataDomain} TypedDataDomain */
@@ -54,6 +56,7 @@ import { multicall } from './multicall.js'
54
56
  * @property {number | bigint} [maxPriorityFeePerGas] - The price (in wei) per unit of gas this transaction will allow in addition to the [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee to bribe miners into giving this transaction priority. This is included in the maxFeePerGas, so this will not affect the total maximum cost set with maxFeePerGas.
55
57
  * @property {number} [type] - The transaction type (e.g. 4 for ERC-7702).
56
58
  * @property {number} [nonce] - The transaction nonce.
59
+ * @property {number | bigint} [chainId] - The chain ID of the network.
57
60
  * @property {AuthorizationLike[]} [authorizationList] - An optional list of ERC-7702 signed authorizations for type 4 transactions.
58
61
  */
59
62
 
@@ -67,7 +70,9 @@ import { multicall } from './multicall.js'
67
70
 
68
71
  /**
69
72
  * @typedef {Object} EvmWalletConfig
70
- * @property {string | Eip1193Provider} [provider] - The url of the rpc provider, or an instance of a class that implements eip-1193.
73
+ * @property {string | Eip1193Provider | Array<string | Eip1193Provider>} [provider] - The url of the rpc provider, or an instance of a class that implements eip-1193. It's also possible to provide an array of urls or EIP 1193 providers instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
74
+ * @property {number} [retries] - If set and if 'provider' is a list of urls or EIP 1193 providers, the number of additional retry attempts after the initial call fails. Total attempts = `1 + retries`. For example, `retries: 3` with 4 providers will try each provider once before throwing. If `retries` exceeds the number of providers, the failover will loop back and retry already-failed providers in round-robin order. Default: 3.
75
+ * @property {number} [chainId] - The chain ID of the network. When provided, skips automatic chain ID detection from the provider.
71
76
  * @property {number | bigint} [transferMaxFee] - The maximum fee amount for transfer operations.
72
77
  */
73
78
 
@@ -93,18 +98,36 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
93
98
  */
94
99
  this._config = config
95
100
 
96
- const { provider } = config
97
-
98
- if (provider) {
99
- /**
100
- * An ethers provider to interact with a node of the blockchain.
101
- *
102
- * @protected
103
- * @type {Provider | undefined}
104
- */
105
- this._provider = typeof provider === 'string'
106
- ? new JsonRpcProvider(provider, Network.from(config.chainId), { staticNetwork: true })
107
- : new BrowserProvider(provider)
101
+ /**
102
+ * An ethers provider to interact with a node of the blockchain.
103
+ *
104
+ * @protected
105
+ * @type {Provider | undefined}
106
+ */
107
+ this._provider = undefined
108
+
109
+ const { provider, retries = 3 } = config
110
+ const network = config.chainId ? Network.from(config.chainId) : undefined
111
+ const providerOpts = config.chainId ? { staticNetwork: true } : undefined
112
+
113
+ if (Array.isArray(provider)) {
114
+ if (provider.length > 0) {
115
+ const failoverProvider = new FailoverProvider({ retries })
116
+
117
+ for (const entry of provider) {
118
+ const option = typeof entry === 'string'
119
+ ? new JsonRpcProvider(entry, network, providerOpts)
120
+ : new BrowserProvider(entry)
121
+ failoverProvider.addProvider(option)
122
+ }
123
+
124
+ this._provider = failoverProvider.initialize()
125
+ }
126
+ } else if (provider) {
127
+ this._provider =
128
+ typeof provider === 'string'
129
+ ? new JsonRpcProvider(provider, network, providerOpts)
130
+ : new BrowserProvider(provider)
108
131
  }
109
132
  }
110
133
 
@@ -18,6 +18,8 @@ import WalletManager from '@tetherto/wdk-wallet'
18
18
 
19
19
  import { BrowserProvider, JsonRpcProvider } from 'ethers'
20
20
 
21
+ import FailoverProvider from '@tetherto/wdk-failover-provider'
22
+
21
23
  import WalletAccountEvm from './wallet-account-evm.js'
22
24
 
23
25
  /** @typedef {import('ethers').Provider} Provider */
@@ -60,18 +62,34 @@ export default class WalletManagerEvm extends WalletManager {
60
62
  */
61
63
  this._config = config
62
64
 
63
- const { provider } = config
64
-
65
- if (provider) {
66
- /**
67
- * An ethers provider to interact with a node of the blockchain.
68
- *
69
- * @protected
70
- * @type {Provider | undefined}
71
- */
72
- this._provider = typeof provider === 'string'
73
- ? new JsonRpcProvider(provider)
74
- : new BrowserProvider(provider)
65
+ /**
66
+ * An ethers provider to interact with a node of the blockchain.
67
+ *
68
+ * @protected
69
+ * @type {Provider | undefined}
70
+ */
71
+ this._provider = undefined
72
+
73
+ const { provider, retries = 3 } = config
74
+
75
+ if (Array.isArray(provider)) {
76
+ if (provider.length > 0) {
77
+ const failoverProvider = new FailoverProvider({ retries })
78
+
79
+ for (const entry of provider) {
80
+ const option = typeof entry === 'string'
81
+ ? new JsonRpcProvider(entry)
82
+ : new BrowserProvider(entry)
83
+ failoverProvider.addProvider(option)
84
+ }
85
+
86
+ this._provider = failoverProvider.initialize()
87
+ }
88
+ } else if (provider) {
89
+ this._provider =
90
+ typeof provider === 'string'
91
+ ? new JsonRpcProvider(provider)
92
+ : new BrowserProvider(provider)
75
93
  }
76
94
  }
77
95
 
@@ -54,6 +54,13 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
54
54
  * @returns {Promise<string>} The typed data signature.
55
55
  */
56
56
  signTypedData({ domain, types, message }: TypedData): Promise<string>;
57
+ /**
58
+ * Signs a transaction.
59
+ *
60
+ * @param {EvmTransaction} tx - The transaction to sign.
61
+ * @returns {Promise<string>} The signed transaction as a hex string.
62
+ */
63
+ signTransaction(tx: EvmTransaction): Promise<string>;
57
64
  /**
58
65
  * Sends a transaction.
59
66
  *
@@ -176,6 +176,10 @@ export type EvmTransaction = {
176
176
  * - The transaction nonce.
177
177
  */
178
178
  nonce?: number;
179
+ /**
180
+ * - The chain ID of the network.
181
+ */
182
+ chainId?: number | bigint;
179
183
  /**
180
184
  * - An optional list of ERC-7702 signed authorizations for type 4 transactions.
181
185
  */
@@ -201,9 +205,17 @@ export type EvmTransferOptions = {
201
205
  };
202
206
  export type EvmWalletConfig = {
203
207
  /**
204
- * - The url of the rpc provider, or an instance of a class that implements eip-1193.
208
+ * - The url of the rpc provider, or an instance of a class that implements eip-1193. It's also possible to provide an array of urls or EIP 1193 providers instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list.
209
+ */
210
+ provider?: string | Eip1193Provider | Array<string | Eip1193Provider>;
211
+ /**
212
+ * - If set and if 'provider' is a list of urls or EIP 1193 providers, the number of additional retry attempts after the initial call fails. Total attempts = `1 + retries`. For example, `retries: 3` with 4 providers will try each provider once before throwing. If `retries` exceeds the number of providers, the failover will loop back and retry already-failed providers in round-robin order. Default: 3.
213
+ */
214
+ retries?: number;
215
+ /**
216
+ * - The chain ID of the network. When provided, skips automatic chain ID detection from the provider.
205
217
  */
206
- provider?: string | Eip1193Provider;
218
+ chainId?: number;
207
219
  /**
208
220
  * - The maximum fee amount for transfer operations.
209
221
  */