@tetherto/wdk-wallet-evm 1.0.0-beta.20 → 1.0.0-beta.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.
@@ -15,274 +15,145 @@
15
15
 
16
16
  import * as bip39 from 'bip39'
17
17
 
18
- import MemorySafeHDNodeWallet from '../memory-safe/hd-node-wallet.js'
19
- import { ISigner, InvalidSignerError, NotImplementedError, ValueError } from '@tetherto/wdk-wallet'
20
-
21
- const BIP_44_ETH_DERIVATION_PATH_PREFIX = "m/44'/60'"
18
+ import { ValueError } from '@tetherto/wdk-wallet'
22
19
 
23
- // Relative path of the account derived when none is provided.
24
- const DEFAULT_ACCOUNT_PATH = "0'/0/0"
20
+ import MemorySafeHDNodeWallet from '../memory-safe/hd-node-wallet.js'
25
21
 
26
- /** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
27
- /** @typedef {import('@tetherto/wdk-wallet').ISigner} ISigner */
22
+ /** @typedef {import('./signer-evm.js').ISignerEvm} ISignerEvm */
28
23
  /** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
24
+ /** @typedef {import('ethers').TransactionLike} TransactionLike */
29
25
  /** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
30
26
  /** @typedef {import('ethers').Authorization} Authorization */
31
27
  /** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */
32
28
  /** @typedef {import('../memory-safe/hd-node-wallet.js').default} MemorySafeHDNodeWallet */
33
29
 
34
30
  /**
35
- * @typedef {Object} SeedSignerEvmOpts
36
- * @property {MemorySafeHDNodeWallet} [root] - An existing HD node wallet root to derive from.
37
- * @property {string} [path] - Relative BIP-44 path segment (e.g. "0'/0/0"). Defaults to the account at index 0.
38
- * @property {boolean} [isChild] - When true, the signer is a derived child and does not retain the root.
39
- */
40
-
41
- /**
42
- * Interface for EVM signers, extending the base `ISigner` from `@tetherto/wdk-wallet`.
31
+ * Absolute BIP-44 prefix for Ethereum (m/purpose'/coin_type'). Exported so callers that want
32
+ * "the standard Ethereum path" (WalletAccountEvm's seed overload, WalletManagerEvm's own
33
+ * internal default signer) can compose an absolute path without hardcoding it themselves.
43
34
  *
44
- * @extends {ISigner}
45
- * @interface
35
+ * @internal
46
36
  */
47
- export class ISignerEvm extends ISigner {
48
- /**
49
- * Whether this signer can derive child signers (i.e. it holds an HD root). Non-derivable
50
- * signers (e.g. private-key signers) are bound directly to an account; derivable signers
51
- * derive child accounts and keep the root for management only.
52
- * @type {boolean}
53
- */
54
- get isDerivable () {
55
- throw new NotImplementedError('isDerivable')
56
- }
57
-
58
- /**
59
- * The last component index for the derivation path of this signer, when applicable.
60
- * @type {number|undefined}
61
- */
62
- get index () {
63
- throw new NotImplementedError('index')
64
- }
65
-
66
- /**
67
- * The full derivation path if this is a child signer.
68
- * @type {string|undefined}
69
- */
70
- get path () {
71
- throw new NotImplementedError('path')
72
- }
73
-
74
- /**
75
- * The account's address, if available.
76
- * @type {string|undefined}
77
- */
78
- get address () {
79
- throw new NotImplementedError('address')
80
- }
81
-
82
- /**
83
- * The account's key pair.
84
- * @type {KeyPair}
85
- */
86
- get keyPair () {
87
- throw new NotImplementedError('keyPair')
88
- }
89
-
90
- /**
91
- * Derive a child signer from this signer using a relative path (e.g. "0'/0/0").
92
- *
93
- * @param {string} relPath - The relative BIP-44 path segment.
94
- * @returns {Promise<ISignerEvm>} The derived child signer.
95
- * @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
96
- */
97
- async derive (relPath) {
98
- throw new NotImplementedError('derive(relPath)')
99
- }
100
-
101
- /**
102
- * Returns the account's address.
103
- * @returns {Promise<string>}
104
- */
105
- async getAddress () {
106
- throw new NotImplementedError('getAddress()')
107
- }
108
-
109
- /**
110
- * Sign a plain message.
111
- * @param {string} message
112
- * @returns {Promise<string>}
113
- */
114
- async sign (message) {
115
- throw new NotImplementedError('sign(message)')
116
- }
117
-
118
- /**
119
- * Sign a transaction-like object compatible with ethers Transaction.from.
120
- * @param {UnsignedEvmTransaction} unsignedTx
121
- * @returns {Promise<string>} The serialized signed transaction hex.
122
- */
123
- async signTransaction (unsignedTx) {
124
- throw new NotImplementedError('signTransaction(unsignedTx)')
125
- }
126
-
127
- /**
128
- * Signs typed data according to EIP-712.
129
- *
130
- * @param {TypedData} typedData - The typed data to sign.
131
- * @returns {Promise<string>} The typed data signature.
132
- */
133
- async signTypedData ({ domain, types, message }) {
134
- throw new NotImplementedError('signTypedData(typedData)')
135
- }
136
-
137
- /**
138
- * Sign an ERC-7702 authorization tuple.
139
- * @param {AuthorizationRequest} auth
140
- * @returns {Promise<Authorization>}
141
- */
142
- async signAuthorization (auth) {
143
- throw new NotImplementedError('signAuthorization(auth)')
144
- }
145
-
146
- /** Clear any secret material from memory. */
147
- dispose () {
148
- throw new NotImplementedError('dispose()')
149
- }
150
- }
37
+ export const BIP_44_ETH_DERIVATION_PATH_PREFIX = "m/44'/60'"
151
38
 
152
39
  /**
153
- * @extends {ISignerEvm}
154
- * Signer implementation that derives keys from a BIP-39 seed using the BIP-44 Ethereum path.
155
- * Always holds a derived account (index 0 by default). A root signer also retains the HD root
156
- * and can derive child signers; a derived child holds only its own account.
40
+ * Signer implementation that derives keys from a BIP-39 seed using an HD path. Every signer
41
+ * holds exactly one HD node (the Ethereum BIP-44 coin node "m/44'/60'" by default, ready to
42
+ * derive accounts below it) and can derive child signers below its own path. Each signer owns
43
+ * an independent copy of its key, so disposing one never affects its parent, children or
44
+ * siblings.
45
+ *
46
+ * @implements {ISignerEvm}
157
47
  */
158
- export default class SeedSignerEvm extends ISignerEvm {
48
+ export default class SeedSignerEvm {
159
49
  /**
160
- * Create a SeedSignerEvm.
161
- * Provide either a mnemonic/seed or an existing root via opts.root (for children root is not stored internally)
50
+ * Create a SeedSignerEvm from a BIP-39 seed.
162
51
  *
163
- * @param {string|Uint8Array|null} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes). Omit when providing `opts.root`.
164
- * @param {SeedSignerEvmOpts} [opts] - Construction options for root reuse, direct child derivation or path definition (default is index 0).
165
- * @throws {ValueError} If neither a seed nor a root is provided, or if both are provided.
166
- * @throws {ValueError} If a seed is provided but is not a valid BIP-39 mnemonic.
52
+ * @param {string|Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
53
+ * @param {string} [path] - A BIP-32 path (default: "m/44'/60'").
54
+ * @throws {ValueError} If the given seed phrase is invalid.
167
55
  */
168
- constructor (seed, opts = {}) {
169
- super()
170
-
171
- // If a root is provided, do not expect a seed
172
- if (opts.root && seed) {
173
- throw new ValueError('Provide either a seed or a root, not both.')
174
- }
175
-
176
- if (!opts.root && !seed) {
177
- throw new ValueError('Seed or root is required.')
178
- }
179
-
56
+ constructor (seed, path = BIP_44_ETH_DERIVATION_PATH_PREFIX) {
180
57
  if (typeof seed === 'string') {
181
58
  if (!bip39.validateMnemonic(seed)) {
182
59
  throw new ValueError('The seed phrase is invalid.')
183
60
  }
61
+
184
62
  seed = bip39.mnemonicToSeedSync(seed)
185
63
  }
186
64
 
187
- const root = opts.root || (seed ? MemorySafeHDNodeWallet.fromSeed(seed) : undefined)
188
-
189
- const fullPath = `${BIP_44_ETH_DERIVATION_PATH_PREFIX}/${opts.path || DEFAULT_ACCOUNT_PATH}`
190
- const account = root.derivePath(fullPath)
191
-
192
- if (opts.isChild && !opts.root) root.dispose()
65
+ const root = MemorySafeHDNodeWallet.fromSeed(seed)
66
+ const account = root.derivePath(path)
67
+ if (account !== root) root.dispose()
193
68
 
194
69
  /** @private */
195
70
  this._account = account
196
- /** @private */
197
- this._address = account.address
198
- /** @private */
199
- this._path = fullPath
200
- /** @private */
201
- this._root = opts.isChild ? undefined : root
202
71
  }
203
72
 
204
73
  /**
205
- * Whether this signer can derive child signers. True for a root signer (which holds the
206
- * HD root); false for a derived child, which does not retain the root.
207
- * @type {boolean}
74
+ * Whether this signer can derive child signers. Always true: every seed signer holds an
75
+ * HD node with a private key and can derive below its own path.
76
+ *
77
+ * @type {true}
208
78
  */
209
79
  get isDerivable () {
210
- return Boolean(this._root)
211
- }
212
-
213
- /**
214
- * The last component index of the derivation path, if available.
215
- * @type {number|undefined}
216
- */
217
- get index () {
218
- if (!this._path) return undefined
219
- return +this._path.split('/').pop()
80
+ return true
220
81
  }
221
82
 
222
83
  /**
223
- * The full derivation path of this signer's account.
224
- * @type {string|undefined}
84
+ * The signer's absolute derivation path.
85
+ *
86
+ * @type {string}
225
87
  */
226
88
  get path () {
227
- return this._path
89
+ return this._account.path
228
90
  }
229
91
 
230
92
  /**
231
93
  * The account's derived address.
94
+ *
95
+ * @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
96
+ * release: not all signers (e.g. hardware signers) can expose the address synchronously.
232
97
  * @type {string}
233
98
  */
234
99
  get address () {
235
- return this._address
100
+ return this._account.address
236
101
  }
237
102
 
238
103
  /**
239
104
  * The account's key pair (private and public key buffers).
105
+ *
240
106
  * @type {KeyPair}
241
107
  */
242
108
  get keyPair () {
243
109
  return {
244
- privateKey: this._account ? this._account.privateKeyBuffer : null,
245
- publicKey: this._account ? this._account.publicKeyBuffer : null
110
+ privateKey: this._account.privateKeyBuffer ?? null,
111
+ publicKey: this._account.publicKeyBuffer
246
112
  }
247
113
  }
248
114
 
249
115
  /**
250
- * Derive a child signer using the provided relative path (e.g. "0'/0/0").
251
- * @param {string} relPath
252
- * @returns {Promise<SeedSignerEvm>}
253
- * @throws {InvalidSignerError} If called on a derived child signer, which does not retain the root.
116
+ * Derive a child signer relative to this signer's own path (e.g. calling derive("0'/0/1") on
117
+ * a signer at "m/44'/60'" yields a child at "m/44'/60'/0'/0/1"). Purely self-relative: no
118
+ * coin-specific prefix is ever assumed or injected. The child owns an independent copy of
119
+ * its key and can itself derive further.
120
+ *
121
+ * @param {string} relPath - The path segment to derive, relative to this signer's own path.
122
+ * @returns {Promise<SeedSignerEvm>} The derived child signer.
254
123
  */
255
124
  async derive (relPath) {
256
- if (!this._root) {
257
- throw new InvalidSignerError('Cannot derive: this signer has no root (it is a derived child or has been disposed).')
258
- }
259
- return new SeedSignerEvm(null, { root: this._root, path: relPath, isChild: true })
125
+ const signer = Object.create(SeedSignerEvm.prototype)
126
+ signer._account = this._account.derivePath(relPath)
127
+ return signer
260
128
  }
261
129
 
262
130
  /**
263
131
  * Returns the account's derived address.
264
- * @returns {Promise<string>}
132
+ *
133
+ * @returns {Promise<string>} The account's address.
265
134
  */
266
135
  async getAddress () {
267
- return this._address
136
+ return this._account.address
268
137
  }
269
138
 
270
139
  /**
271
- * Sign a plain message string.
272
- * @param {string} message
273
- * @returns {Promise<string>}
140
+ * Signs a message.
141
+ *
142
+ * @param {string} message - The message to sign.
143
+ * @returns {Promise<string>} The message's signature.
274
144
  */
275
145
  async sign (message) {
276
146
  return this._account.signMessage(message)
277
147
  }
278
148
 
279
149
  /**
280
- * Sign a transaction object and return its serialized form.
281
- * @param {UnsignedEvmTransaction} unsignedTx
282
- * @returns {Promise<string>}
150
+ * Signs a transaction.
151
+ *
152
+ * @param {TransactionLike} tx - The transaction to sign.
153
+ * @returns {Promise<string>} The signed transaction as a hex string.
283
154
  */
284
- async signTransaction (unsignedTx) {
285
- return this._account.signTransaction(unsignedTx)
155
+ async signTransaction (tx) {
156
+ return this._account.signTransaction(tx)
286
157
  }
287
158
 
288
159
  /**
@@ -296,19 +167,19 @@ export default class SeedSignerEvm extends ISignerEvm {
296
167
  }
297
168
 
298
169
  /**
299
- * Sign an ERC-7702 authorization tuple.
300
- * @param {AuthorizationRequest} auth
301
- * @returns {Promise<Authorization>}
170
+ * Signs an ERC-7702 authorization tuple.
171
+ *
172
+ * @param {AuthorizationRequest} auth - The authorization request.
173
+ * @returns {Promise<Authorization>} The signed authorization.
302
174
  */
303
175
  async signAuthorization (auth) {
304
176
  return this._account.authorizeSync(auth)
305
177
  }
306
178
 
307
- /** Disposes secrets from memory. */
179
+ /**
180
+ * Disposes the signer, erasing its secrets from memory.
181
+ */
308
182
  dispose () {
309
- if (this._account) this._account.dispose()
310
- this._account = undefined
311
- if (this._root) this._root.dispose()
312
- this._root = undefined
183
+ this._account.dispose()
313
184
  }
314
185
  }
@@ -0,0 +1,69 @@
1
+ // Copyright 2024 Tether Operations Limited
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ 'use strict'
15
+
16
+ import { ISigner, NotImplementedError } from '@tetherto/wdk-wallet'
17
+
18
+ /** @typedef {import('ethers').TransactionLike} TransactionLike */
19
+ /** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
20
+ /** @typedef {import('ethers').Authorization} Authorization */
21
+ /** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */
22
+
23
+ /**
24
+ * Interface for EVM signers, extending the base `ISigner` from `@tetherto/wdk-wallet`.
25
+ *
26
+ * @interface
27
+ */
28
+ export class ISignerEvm extends ISigner {
29
+ /**
30
+ * The account's address, if available.
31
+ *
32
+ * @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
33
+ * release: not all signers (e.g. hardware signers) can expose the address synchronously.
34
+ * @type {string | undefined}
35
+ */
36
+ get address () {
37
+ throw new NotImplementedError('address')
38
+ }
39
+
40
+ /**
41
+ * Signs a transaction.
42
+ *
43
+ * @param {TransactionLike} tx - The transaction to sign.
44
+ * @returns {Promise<string>} The signed transaction as a hex string.
45
+ */
46
+ async signTransaction (tx) {
47
+ throw new NotImplementedError('signTransaction(tx)')
48
+ }
49
+
50
+ /**
51
+ * Signs typed data according to EIP-712.
52
+ *
53
+ * @param {TypedData} typedData - The typed data to sign.
54
+ * @returns {Promise<string>} The typed data signature.
55
+ */
56
+ async signTypedData (typedData) {
57
+ throw new NotImplementedError('signTypedData(typedData)')
58
+ }
59
+
60
+ /**
61
+ * Signs an ERC-7702 authorization tuple.
62
+ *
63
+ * @param {AuthorizationRequest} auth - The authorization request.
64
+ * @returns {Promise<Authorization>} The signed authorization.
65
+ */
66
+ async signAuthorization (auth) {
67
+ throw new NotImplementedError('signAuthorization(auth)')
68
+ }
69
+ }
@@ -14,17 +14,16 @@
14
14
 
15
15
  'use strict'
16
16
 
17
- import { MaximumFeeExceededError, ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
17
+ import { Contract, VoidSigner, Transaction, ZeroAddress } from 'ethers'
18
18
 
19
- import { Contract, Transaction, ZeroAddress } from 'ethers'
19
+ import { MaximumFeeExceededError, ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
20
20
 
21
21
  import WalletAccountReadOnlyEvm from './wallet-account-read-only-evm.js'
22
22
 
23
- import SeedSignerEvm from './signers/seed-signer-evm.js'
23
+ import SeedSignerEvm, { BIP_44_ETH_DERIVATION_PATH_PREFIX } from './signers/seed-signer-evm.js'
24
24
  import PrivateKeySignerEvm from './signers/private-key-signer-evm.js'
25
- import { populateTransactionEvm } from './utils/tx-populator-evm.js'
26
25
 
27
- /** @typedef {import('./signers/seed-signer-evm.js').ISignerEvm} ISignerEvm */
26
+ /** @typedef {import('./signers/signer-evm.js').ISignerEvm} ISignerEvm */
28
27
  /** @typedef {import('ethers').HDNodeWallet} HDNodeWallet */
29
28
  /** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
30
29
  /** @typedef {import('ethers').Authorization} Authorization */
@@ -55,6 +54,15 @@ import { populateTransactionEvm } from './utils/tx-populator-evm.js'
55
54
  * @typedef {ApproveOptions & EvmGasOverrides} EvmApproveOptions
56
55
  */
57
56
 
57
+ /**
58
+ * @typedef {Object} SignerOptions
59
+ * @property {boolean} [shouldWipeSignerOnDisposal] - If true, wipes the signer given at construction on calls to the 'dispose' method.
60
+ */
61
+
62
+ // Default BIP-44 account path, relative to BIP_44_ETH_DERIVATION_PATH_PREFIX, used by the
63
+ // seed overload when no path is given.
64
+ const DEFAULT_ACCOUNT_PATH = "0'/0/0"
65
+
58
66
  const USDT_MAINNET_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'
59
67
 
60
68
  const DELEGATION_TX_GAS_LIMIT = 100_000
@@ -67,8 +75,18 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
67
75
  *
68
76
  * @overload
69
77
  * @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
70
- * @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
78
+ * @param {string} path - The BIP-44 account path, relative to "m/44'/60'" (e.g. "0'/0/0").
79
+ * @param {EvmWalletConfig} [config] - The configuration object.
80
+ * @throws {ValueError} If the given seed phrase is invalid.
81
+ */
82
+
83
+ /**
84
+ * Creates a new evm wallet account from a BIP-39 seed at path m/44'/60'/0'/0/0.
85
+ *
86
+ * @overload
87
+ * @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
71
88
  * @param {EvmWalletConfig} [config] - The configuration object.
89
+ * @throws {ValueError} If the given seed phrase is invalid.
72
90
  */
73
91
 
74
92
  /**
@@ -76,16 +94,29 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
76
94
  *
77
95
  * @overload
78
96
  * @param {ISignerEvm} signer - A signer implementing the EVM signer interface.
79
- * @param {EvmWalletConfig} [config] - The configuration object.
97
+ * @param {EvmWalletConfig & SignerOptions} [config] - The configuration object.
80
98
  */
81
99
 
82
100
  constructor (seedOrSigner, pathOrConfig = {}, config = {}) {
83
- const [signer, configuration] = typeof seedOrSigner === 'string' || seedOrSigner instanceof Uint8Array
84
- ? [new SeedSignerEvm(seedOrSigner, { path: pathOrConfig, isChild: true }), config]
101
+ const isSeed = typeof seedOrSigner === 'string' || seedOrSigner instanceof Uint8Array
102
+ const hasPath = typeof pathOrConfig === 'string'
103
+ const [signer, configuration] = isSeed
104
+ ? [
105
+ new SeedSignerEvm(seedOrSigner, `${BIP_44_ETH_DERIVATION_PATH_PREFIX}/${hasPath ? pathOrConfig : DEFAULT_ACCOUNT_PATH}`),
106
+ hasPath ? config : pathOrConfig
107
+ ]
85
108
  : [seedOrSigner, pathOrConfig]
86
109
 
87
110
  super(signer.address, configuration)
88
111
 
112
+ /**
113
+ * If true, disposes the signer on calls to the 'dispose' method.
114
+ *
115
+ * @protected
116
+ * @type {boolean}
117
+ */
118
+ this._shouldWipeSignerOnDisposal = isSeed || Boolean(configuration.shouldWipeSignerOnDisposal)
119
+
89
120
  /**
90
121
  * The wallet account configuration.
91
122
  *
@@ -99,18 +130,10 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
99
130
  }
100
131
 
101
132
  /**
102
- * The derivation path's index of this account.
103
- *
104
- * @type {number}
105
- */
106
- get index () {
107
- return this._signer.index
108
- }
109
-
110
- /**
111
- * The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
133
+ * The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
134
+ * or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
112
135
  *
113
- * @type {string}
136
+ * @type {string | null}
114
137
  */
115
138
  get path () {
116
139
  return this._signer.path
@@ -123,7 +146,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
123
146
  * it's strongly recommended to treat the key pair as a read-only view of the keys. While it's still technically possible to alter their
124
147
  * content, client code should never do so.
125
148
  *
126
- * @type {KeyPair}
149
+ * @type {KeyPair | null}
127
150
  */
128
151
  get keyPair () {
129
152
  return this._signer.keyPair
@@ -138,20 +161,16 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
138
161
  */
139
162
  static fromPrivateKey (privateKey, config = {}) {
140
163
  const signer = new PrivateKeySignerEvm(privateKey)
141
- return new WalletAccountEvm(signer, config)
164
+ return new WalletAccountEvm(signer, { ...config, shouldWipeSignerOnDisposal: true })
142
165
  }
143
166
 
144
167
  /**
145
- * Returns the account's address. If it wasn't resolved at construction time (e.g hardware signers), it asks the
146
- * underlying signer to resolve it, then caches it locally.
168
+ * Returns the account's address.
147
169
  *
148
170
  * @returns {Promise<string>} The account's address.
149
171
  */
150
172
  async getAddress () {
151
- if (this._address) return this._address
152
- const addr = await this._signer.getAddress()
153
- this.__address = addr
154
- return addr
173
+ return await this._signer.getAddress()
155
174
  }
156
175
 
157
176
  /**
@@ -210,6 +229,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
210
229
  if (!this._provider) {
211
230
  throw new ProviderRequiredError('The wallet must be connected to a provider to send transactions.')
212
231
  }
232
+
213
233
  const { fee } = await this.quoteSendTransaction(tx)
214
234
  if (this._config.transactionMaxFee !== undefined && fee > this._config.transactionMaxFee) {
215
235
  throw new MaximumFeeExceededError('Exceeded maximum fee cost for transaction operation.')
@@ -221,9 +241,10 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
221
241
  }
222
242
 
223
243
  // Build, sign and broadcast raw transaction using the signer
224
- const from = await this.getAddress()
225
- const unsignedTx = await populateTransactionEvm(this._provider, from, tx)
226
- const signed = await this._signer.signTransaction(unsignedTx)
244
+ const address = await this.getAddress()
245
+ const voidSigner = new VoidSigner(address, this._provider)
246
+ const populated = await voidSigner.populateTransaction(tx)
247
+ const signed = await this._signer.signTransaction(populated)
227
248
  const hash = await this._provider.send('eth_sendRawTransaction', [signed])
228
249
  return { hash, fee }
229
250
  }
@@ -240,6 +261,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
240
261
  * @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
241
262
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
242
263
  * @throws {ProviderRequiredError} If the wallet is not connected to a provider.
264
+ * @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
243
265
  * @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
244
266
  */
245
267
  async quoteSendTransaction (tx) {
@@ -338,12 +360,18 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
338
360
  /**
339
361
  * Signs an ERC-7702 authorization tuple.
340
362
  *
363
+ * The chainId and nonce are populated from the provider when not explicitly provided.
364
+ *
341
365
  * @param {AuthorizationRequest} auth - The authorization request.
342
366
  * @returns {Promise<Authorization>} The signed authorization.
367
+ * @throws {ProviderRequiredError} If the chainId or nonce are not provided and the wallet is not connected to a provider.
343
368
  */
344
369
  async signAuthorization (auth) {
345
370
  const populated = { ...auth }
346
- if (this._provider) {
371
+ if (populated.chainId === undefined || populated.nonce === undefined) {
372
+ if (!this._provider) {
373
+ throw new ProviderRequiredError('The wallet must be connected to a provider to populate the authorization chainId and nonce. Provide them explicitly to sign offline.')
374
+ }
347
375
  if (populated.chainId == null) {
348
376
  const { chainId } = await this._provider.getNetwork()
349
377
  populated.chainId = chainId
@@ -404,6 +432,8 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
404
432
  * Disposes the wallet account, erasing the private key from the memory.
405
433
  */
406
434
  dispose () {
407
- this._signer.dispose()
435
+ if (this._shouldWipeSignerOnDisposal) {
436
+ this._signer.dispose()
437
+ }
408
438
  }
409
439
  }