@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.23 → 1.0.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/index.js +1 -0
- package/package.json +10 -4
- package/src/errors.js +3 -2
- package/src/signers/bare.js +18 -0
- package/src/signers/index.js +19 -0
- package/src/wallet-account-evm-erc-4337.js +180 -37
- package/src/wallet-account-read-only-evm-erc-4337.js +41 -12
- package/src/wallet-manager-evm-erc-4337.js +135 -18
- package/types/index.d.ts +1 -0
- package/types/src/errors.d.ts +2 -1
- package/types/src/signers/index.d.ts +2 -0
- package/types/src/wallet-account-evm-erc-4337.d.ts +87 -13
- package/types/src/wallet-account-read-only-evm-erc-4337.d.ts +7 -0
- package/types/src/wallet-manager-evm-erc-4337.d.ts +60 -7
package/README.md
CHANGED
|
@@ -77,6 +77,31 @@ that authenticate via the URL (e.g. an `apikey` query parameter) keep working un
|
|
|
77
77
|
- **Per-Call Config Overrides**: Switch gas payment modes on a per-transaction basis
|
|
78
78
|
- **Parallel Nonce Lanes**: Send independent operations concurrently via ERC-4337 two-dimensional nonces (`parallel: true` or a reusable `nonceKey`)
|
|
79
79
|
- **Secure Memory Disposal**: Clear private keys from memory when done
|
|
80
|
+
- **Pluggable Signers**: Use a seed phrase, a derivable signer, or a private-key signer as the safe's owner
|
|
81
|
+
|
|
82
|
+
## Signers
|
|
83
|
+
|
|
84
|
+
The safe's owner can be any evm signer, not just a seed phrase. The signers are re-exported from `@tetherto/wdk-wallet-evm-erc-4337/signers`, so you don't need to install `@tetherto/wdk-wallet-evm` yourself.
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
import WalletManagerEvmErc4337, { WalletAccountEvmErc4337 } from '@tetherto/wdk-wallet-evm-erc-4337'
|
|
88
|
+
import { PrivateKeySignerEvm, SeedSignerEvm } from '@tetherto/wdk-wallet-evm-erc-4337/signers'
|
|
89
|
+
|
|
90
|
+
// The default signer must be derivable.
|
|
91
|
+
const wallet = new WalletManagerEvmErc4337(new SeedSignerEvm(seedPhrase, "m/44'/60'"), config)
|
|
92
|
+
|
|
93
|
+
// Other signers are registered by name.
|
|
94
|
+
wallet.addSigner('treasury', new PrivateKeySignerEvm(privateKey))
|
|
95
|
+
const treasury = await wallet.getAccount('treasury')
|
|
96
|
+
|
|
97
|
+
// Standalone accounts, without a wallet manager.
|
|
98
|
+
const account = WalletAccountEvmErc4337.fromPrivateKey(privateKey, config)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Notes:**
|
|
102
|
+
- A wallet created from a seed wipes its default signer on `dispose()`. Signers you supply are never wiped by the wallet, and an account wipes a signer you give it only with `shouldWipeSignerOnDisposal: true`.
|
|
103
|
+
- The safe's address is predicted from the signer's `getAddress()` on first use, so signers that only provide their address asynchronously (e.g. hardware signers) are supported.
|
|
104
|
+
- `account.path` and `account.keyPair` are `null` for signers without a derivation path or key material.
|
|
80
105
|
|
|
81
106
|
## Concurrent / Parallel Sends (nonce lanes)
|
|
82
107
|
|
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
/** @typedef {import('@tetherto/wdk-wallet-evm').FeeRates} FeeRates */
|
|
27
27
|
|
|
28
28
|
/** @typedef {import('@tetherto/wdk-wallet-evm').KeyPair} KeyPair */
|
|
29
|
+
/** @typedef {import('@tetherto/wdk-wallet-evm').SignerOptions} SignerOptions */
|
|
29
30
|
/** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337Transaction} EvmErc4337Transaction */
|
|
30
31
|
/** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337GasOverrides} EvmErc4337GasOverrides */
|
|
31
32
|
/** @typedef {import('./src/wallet-account-read-only-evm-erc-4337.js').EvmErc4337TransferOptions} EvmErc4337TransferOptions */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet-evm-erc-4337",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.25",
|
|
4
4
|
"description": "ERC-4337 wallet module for EVM-compatible blockchains in WDK (Wallet Development Kit) by Tether.",
|
|
5
5
|
"homepage": "https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/",
|
|
6
6
|
"keywords": [
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@tetherto/wdk-failover-provider": "1.0.0-beta.2",
|
|
35
|
-
"@tetherto/wdk-wallet": "1.0.0-beta.
|
|
36
|
-
"@tetherto/wdk-wallet-evm": "1.0.0-beta.
|
|
37
|
-
"abstractionkit": "0.4.
|
|
35
|
+
"@tetherto/wdk-wallet": "1.0.0-beta.25",
|
|
36
|
+
"@tetherto/wdk-wallet-evm": "1.0.0-beta.26",
|
|
37
|
+
"abstractionkit": "0.4.3",
|
|
38
38
|
"bare-node-runtime": "^1.5.2",
|
|
39
39
|
"ethers": "6.17.0"
|
|
40
40
|
},
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
"bare": "./bare.js",
|
|
69
69
|
"default": "./index.js"
|
|
70
70
|
},
|
|
71
|
+
"./signers": {
|
|
72
|
+
"types": "./types/src/signers/index.d.ts",
|
|
73
|
+
"bare": "./src/signers/bare.js",
|
|
74
|
+
"default": "./src/signers/index.js"
|
|
75
|
+
},
|
|
71
76
|
"./package": {
|
|
72
77
|
"default": "./package.json"
|
|
73
78
|
}
|
|
@@ -79,6 +84,7 @@
|
|
|
79
84
|
"standard": {
|
|
80
85
|
"ignore": [
|
|
81
86
|
"bare.js",
|
|
87
|
+
"src/signers/bare.js",
|
|
82
88
|
"tests/**/*.js"
|
|
83
89
|
]
|
|
84
90
|
}
|
package/src/errors.js
CHANGED
|
@@ -26,9 +26,10 @@ export class ConfigurationError extends ValueError {
|
|
|
26
26
|
* Create a new configuration error.
|
|
27
27
|
*
|
|
28
28
|
* @param {string} message - The error message.
|
|
29
|
+
* @param {ErrorOptions} [options] - The error's options.
|
|
29
30
|
*/
|
|
30
|
-
constructor (message) {
|
|
31
|
-
super(message)
|
|
31
|
+
constructor (message, options) {
|
|
32
|
+
super(message, options)
|
|
32
33
|
|
|
33
34
|
this.name = 'ConfigurationError'
|
|
34
35
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 'bare-node-runtime/global'
|
|
17
|
+
|
|
18
|
+
export * from './index.js' with { imports: 'bare-node-runtime/imports' }
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
|
|
15
|
+
'use strict'
|
|
16
|
+
|
|
17
|
+
/** @typedef {import('@tetherto/wdk-wallet-evm/signers').TransactionLike} TransactionLike */
|
|
18
|
+
|
|
19
|
+
export * from '@tetherto/wdk-wallet-evm/signers'
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
import { Contract, hexlify, keccak256, randomBytes, toUtf8Bytes } from 'ethers'
|
|
18
18
|
|
|
19
|
-
import { MaximumFeeExceededError, ProviderRequiredError, TransactionError, TransactionErrorReason, UnsupportedOperationError, ValueError } from '@tetherto/wdk-wallet'
|
|
19
|
+
import { DisposalError, MaximumFeeExceededError, ProviderRequiredError, TransactionError, TransactionErrorReason, UnsupportedOperationError, ValueError } from '@tetherto/wdk-wallet'
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import { PrivateKeySignerEvm, SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
22
22
|
|
|
23
23
|
import { ENTRYPOINT_V7, calculateUserOperationMaxGasCost, fetchAccountNonce } from 'abstractionkit'
|
|
24
24
|
|
|
@@ -40,6 +40,8 @@ import WalletAccountReadOnlyEvmErc4337, { FEE_TOLERANCE_COEFFICIENT } from './wa
|
|
|
40
40
|
/** @typedef {import('@tetherto/wdk-wallet').IWalletAccount} IWalletAccount */
|
|
41
41
|
|
|
42
42
|
/** @typedef {import('@tetherto/wdk-wallet-evm').KeyPair} KeyPair */
|
|
43
|
+
/** @typedef {import('@tetherto/wdk-wallet-evm/signers').ISignerEvm} ISignerEvm */
|
|
44
|
+
/** @typedef {import('@tetherto/wdk-wallet-evm').SignerOptions} SignerOptions */
|
|
43
45
|
|
|
44
46
|
/** @typedef {import('@tetherto/wdk-wallet-evm').TransactionResult} TransactionResult */
|
|
45
47
|
/** @typedef {import('@tetherto/wdk-wallet-evm').TransferResult} TransferResult */
|
|
@@ -68,22 +70,59 @@ const MAX_UINT192 = (1n << 192n) - 1n
|
|
|
68
70
|
|
|
69
71
|
const USDT_MAINNET_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'
|
|
70
72
|
|
|
73
|
+
const BIP_44_ETH_DERIVATION_PATH_PREFIX = "m/44'/60'"
|
|
74
|
+
|
|
75
|
+
const DEFAULT_ACCOUNT_PATH = "0'/0/0"
|
|
76
|
+
|
|
71
77
|
/** @implements {IWalletAccount<UserOperationV7>} */
|
|
72
78
|
export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc4337 {
|
|
73
79
|
/**
|
|
74
|
-
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account.
|
|
80
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account from a BIP-39 seed.
|
|
81
|
+
*
|
|
82
|
+
* @overload
|
|
83
|
+
* @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
84
|
+
* @param {string} path - The BIP-44 derivation path, relative to "m/44'/60'" (e.g. "0'/0/0").
|
|
85
|
+
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
86
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account from a BIP-39 seed at path m/44'/60'/0'/0/0.
|
|
75
91
|
*
|
|
92
|
+
* @overload
|
|
76
93
|
* @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
77
|
-
* @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
|
|
78
94
|
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
95
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
79
96
|
*/
|
|
80
|
-
constructor (seed, path, config) {
|
|
81
|
-
// Owner EOA only needs keys/address for 4337; strip `provider` so
|
|
82
|
-
// wdk-wallet-evm does not open a second JsonRpcProvider.
|
|
83
|
-
const { provider: _provider, ...ownerConfig } = config
|
|
84
|
-
const ownerAccount = new WalletAccountEvm(seed, path, ownerConfig)
|
|
85
97
|
|
|
86
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account using a signer as the safe's owner.
|
|
100
|
+
*
|
|
101
|
+
* The signer is wiped on {@link dispose} only if `shouldWipeSignerOnDisposal` is set. The safe's address is
|
|
102
|
+
* predicted from the signer's address on the first call to {@link getAddress}.
|
|
103
|
+
*
|
|
104
|
+
* @overload
|
|
105
|
+
* @param {ISignerEvm} signer - A signer implementing the EVM signer interface.
|
|
106
|
+
* @param {EvmErc4337WalletConfig & SignerOptions} config - The configuration object.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
constructor (seedOrSigner, pathOrConfig, config) {
|
|
110
|
+
const isSeed = typeof seedOrSigner === 'string' || seedOrSigner instanceof Uint8Array
|
|
111
|
+
const hasPath = typeof pathOrConfig === 'string'
|
|
112
|
+
const [signer, configuration] = isSeed
|
|
113
|
+
? [
|
|
114
|
+
new SeedSignerEvm(seedOrSigner, `${BIP_44_ETH_DERIVATION_PATH_PREFIX}/${hasPath ? pathOrConfig : DEFAULT_ACCOUNT_PATH}`),
|
|
115
|
+
hasPath ? config : pathOrConfig
|
|
116
|
+
]
|
|
117
|
+
: [seedOrSigner, pathOrConfig]
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
super(undefined, configuration)
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (isSeed) signer.dispose()
|
|
123
|
+
|
|
124
|
+
throw error
|
|
125
|
+
}
|
|
87
126
|
|
|
88
127
|
/**
|
|
89
128
|
* The evm erc-4337 wallet account configuration.
|
|
@@ -91,18 +130,46 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
91
130
|
* @protected
|
|
92
131
|
* @type {EvmErc4337WalletConfig}
|
|
93
132
|
*/
|
|
94
|
-
this._config =
|
|
133
|
+
this._config = configuration
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* If true, disposes the signer on calls to the 'dispose' method.
|
|
137
|
+
*
|
|
138
|
+
* @protected
|
|
139
|
+
* @type {boolean}
|
|
140
|
+
*/
|
|
141
|
+
this._shouldWipeSignerOnDisposal = isSeed || Boolean(configuration.shouldWipeSignerOnDisposal)
|
|
142
|
+
|
|
143
|
+
/** @private */
|
|
144
|
+
this._signer = signer
|
|
95
145
|
|
|
96
146
|
/** @private */
|
|
97
|
-
this.
|
|
147
|
+
this._safeAddress = undefined
|
|
98
148
|
|
|
99
149
|
/**
|
|
100
|
-
* Cached quotes from fee estimations, keyed by serialized transaction.
|
|
150
|
+
* Cached quotes from fee estimations, keyed by serialized transaction and paymaster configuration.
|
|
101
151
|
*
|
|
102
152
|
* @private
|
|
103
153
|
* @type {Map<string, TransactionQuote>}
|
|
104
154
|
*/
|
|
105
155
|
this._quoteCache = new Map()
|
|
156
|
+
|
|
157
|
+
/** @private */
|
|
158
|
+
this._disposed = false
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* True once this account's own {@link dispose} method has been called.
|
|
163
|
+
*
|
|
164
|
+
* This reflects the account's lifecycle only. A caller-supplied signer disposed externally
|
|
165
|
+
* does not flip this flag -- the account is still considered alive until it is disposed itself,
|
|
166
|
+
* even though its signer-dependent methods will throw a {@link DisposalError} (propagated from
|
|
167
|
+
* the disposed signer) in the meantime.
|
|
168
|
+
*
|
|
169
|
+
* @type {boolean}
|
|
170
|
+
*/
|
|
171
|
+
get disposed () {
|
|
172
|
+
return this._disposed
|
|
106
173
|
}
|
|
107
174
|
|
|
108
175
|
/**
|
|
@@ -119,21 +186,34 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
119
186
|
}
|
|
120
187
|
|
|
121
188
|
/**
|
|
122
|
-
*
|
|
189
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account whose safe owner is a raw private key.
|
|
190
|
+
*
|
|
191
|
+
* The account owns the key and wipes it on {@link dispose}.
|
|
123
192
|
*
|
|
124
|
-
* @
|
|
193
|
+
* @param {string | Uint8Array} privateKey - The raw private key (hex string with or without 0x, or 32 bytes).
|
|
194
|
+
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
195
|
+
* @returns {WalletAccountEvmErc4337} The wallet account.
|
|
125
196
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
197
|
+
static fromPrivateKey (privateKey, config) {
|
|
198
|
+
const signer = new PrivateKeySignerEvm(privateKey)
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
return new WalletAccountEvmErc4337(signer, { ...config, shouldWipeSignerOnDisposal: true })
|
|
202
|
+
} catch (error) {
|
|
203
|
+
signer.dispose()
|
|
204
|
+
|
|
205
|
+
throw error
|
|
206
|
+
}
|
|
128
207
|
}
|
|
129
208
|
|
|
130
209
|
/**
|
|
131
|
-
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki))
|
|
210
|
+
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
|
|
211
|
+
* or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
|
|
132
212
|
*
|
|
133
|
-
* @type {string}
|
|
213
|
+
* @type {string | null}
|
|
134
214
|
*/
|
|
135
215
|
get path () {
|
|
136
|
-
return this.
|
|
216
|
+
return this._signer.path
|
|
137
217
|
}
|
|
138
218
|
|
|
139
219
|
/**
|
|
@@ -143,10 +223,22 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
143
223
|
* 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
|
|
144
224
|
* content, client code should never do so.
|
|
145
225
|
*
|
|
146
|
-
* @type {KeyPair}
|
|
226
|
+
* @type {KeyPair | null}
|
|
147
227
|
*/
|
|
148
228
|
get keyPair () {
|
|
149
|
-
return this.
|
|
229
|
+
return this._signer.keyPair
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Returns the account's address, which is the safe's address predicted from the signer's address.
|
|
234
|
+
*
|
|
235
|
+
* @returns {Promise<string>} The account's address.
|
|
236
|
+
* @throws {ValueError} If the signer's address is not a well-formed evm address.
|
|
237
|
+
*/
|
|
238
|
+
async getAddress () {
|
|
239
|
+
this._safeAddress ??= WalletAccountReadOnlyEvmErc4337.predictSafeAddress(await this._signer.getAddress(), this._config)
|
|
240
|
+
|
|
241
|
+
return this._safeAddress
|
|
150
242
|
}
|
|
151
243
|
|
|
152
244
|
/**
|
|
@@ -154,9 +246,12 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
154
246
|
*
|
|
155
247
|
* @param {string} message - The message to sign.
|
|
156
248
|
* @returns {Promise<string>} The message's signature.
|
|
249
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
157
250
|
*/
|
|
158
251
|
async sign (message) {
|
|
159
|
-
|
|
252
|
+
this._guardDisposed()
|
|
253
|
+
|
|
254
|
+
return await this._signer.sign(message)
|
|
160
255
|
}
|
|
161
256
|
|
|
162
257
|
/**
|
|
@@ -164,9 +259,12 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
164
259
|
*
|
|
165
260
|
* @param {TypedData} typedData - The typed data to sign.
|
|
166
261
|
* @returns {Promise<string>} The typed data signature.
|
|
262
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
167
263
|
*/
|
|
168
264
|
async signTypedData ({ domain, types, message }) {
|
|
169
|
-
|
|
265
|
+
this._guardDisposed()
|
|
266
|
+
|
|
267
|
+
return await this._signer.signTypedData({ domain, types, message })
|
|
170
268
|
}
|
|
171
269
|
|
|
172
270
|
/**
|
|
@@ -181,8 +279,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
181
279
|
* @throws {ConfigurationError} If, in token mode, the configured `paymasterAddress` does not match the paymaster address returned by the paymaster RPC. This guards against the auto-generated ERC-20 approval targeting an unexpected paymaster contract.
|
|
182
280
|
* @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
|
|
183
281
|
* @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
|
|
282
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
184
283
|
*/
|
|
185
284
|
async signTransaction (tx, config) {
|
|
285
|
+
this._guardDisposed()
|
|
286
|
+
|
|
186
287
|
const mergedConfig = { ...this._config, ...config }
|
|
187
288
|
|
|
188
289
|
if (config) {
|
|
@@ -212,8 +313,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
212
313
|
* @returns {Promise<TransactionResult>} - The transaction's result.
|
|
213
314
|
* @throws {ProviderRequiredError} - If the wallet is not connected to a provider.
|
|
214
315
|
* @throws {ValueError} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
|
|
316
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
215
317
|
*/
|
|
216
318
|
async approve (options) {
|
|
319
|
+
this._guardDisposed()
|
|
320
|
+
|
|
217
321
|
if (!this._provider) {
|
|
218
322
|
throw new ProviderRequiredError('The wallet must be connected to a provider to approve funds.')
|
|
219
323
|
}
|
|
@@ -249,8 +353,9 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
249
353
|
* Quotes the costs of a send transaction operation.
|
|
250
354
|
*
|
|
251
355
|
* The result is cached internally for up to 2 minutes. A subsequent `sendTransaction` with the
|
|
252
|
-
* same transaction reuses the cached operation — skipping the
|
|
253
|
-
* round-trips — after a lightweight on-chain nonce check, re-quoting
|
|
356
|
+
* same transaction and paymaster configuration reuses the cached operation — skipping the
|
|
357
|
+
* gas-estimation and paymaster round-trips — after a lightweight on-chain nonce check, re-quoting
|
|
358
|
+
* only if the nonce has moved.
|
|
254
359
|
*
|
|
255
360
|
* In a batched call (`tx` passed as `[tx1, tx2, ...]`), only the gas overrides on `tx1` are
|
|
256
361
|
* honored — a UserOperation has a single set of gas fields regardless of how many calls it batches.
|
|
@@ -277,7 +382,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
277
382
|
return { fee: mergedConfig.isSponsored ? 0n : WalletAccountEvmErc4337._getSignedUserOperationFee(tx) }
|
|
278
383
|
}
|
|
279
384
|
|
|
280
|
-
const txKey = WalletAccountEvmErc4337._getTxKey(tx)
|
|
385
|
+
const txKey = WalletAccountEvmErc4337._getTxKey(tx, mergedConfig)
|
|
281
386
|
|
|
282
387
|
if (mergedConfig.isSponsored) {
|
|
283
388
|
this._quoteCache.set(txKey, { fee: 0n, createdAt: Date.now() })
|
|
@@ -319,8 +424,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
319
424
|
* @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
|
|
320
425
|
* @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
|
|
321
426
|
* @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
|
|
427
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
322
428
|
*/
|
|
323
429
|
async sendTransaction (tx, config) {
|
|
430
|
+
this._guardDisposed()
|
|
431
|
+
|
|
324
432
|
const mergedConfig = { ...this._config, ...config }
|
|
325
433
|
|
|
326
434
|
if (config) {
|
|
@@ -360,8 +468,11 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
360
468
|
* @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transfer's cost surpasses the transfer max. fee option.
|
|
361
469
|
* @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
|
|
362
470
|
* @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
|
|
471
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
363
472
|
*/
|
|
364
473
|
async transfer (options, config) {
|
|
474
|
+
this._guardDisposed()
|
|
475
|
+
|
|
365
476
|
const mergedConfig = { ...this._config, ...config }
|
|
366
477
|
|
|
367
478
|
if (config) {
|
|
@@ -389,18 +500,41 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
389
500
|
* @returns {Promise<WalletAccountReadOnlyEvmErc4337>} The read-only account.
|
|
390
501
|
*/
|
|
391
502
|
async toReadOnlyAccount () {
|
|
392
|
-
const address = await this.
|
|
503
|
+
const address = await this._getOwnerAddress()
|
|
393
504
|
|
|
394
505
|
const readOnlyAccount = new WalletAccountReadOnlyEvmErc4337(address, this._config)
|
|
395
506
|
|
|
396
507
|
return readOnlyAccount
|
|
397
508
|
}
|
|
398
509
|
|
|
510
|
+
/**
|
|
511
|
+
* Returns the safe owner's address, as given by the signer.
|
|
512
|
+
*
|
|
513
|
+
* @protected
|
|
514
|
+
* @returns {Promise<string>} The owner's address.
|
|
515
|
+
*/
|
|
516
|
+
async _getOwnerAddress () {
|
|
517
|
+
return await this._signer.getAddress()
|
|
518
|
+
}
|
|
519
|
+
|
|
399
520
|
/**
|
|
400
521
|
* Disposes the wallet account, erasing the private key from the memory.
|
|
401
522
|
*/
|
|
402
523
|
dispose () {
|
|
403
|
-
this.
|
|
524
|
+
if (this._disposed) return
|
|
525
|
+
|
|
526
|
+
if (this._shouldWipeSignerOnDisposal) {
|
|
527
|
+
this._signer.dispose()
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
this._disposed = true
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** @private */
|
|
534
|
+
_guardDisposed () {
|
|
535
|
+
if (this.disposed) {
|
|
536
|
+
throw new DisposalError('The account has been disposed.')
|
|
537
|
+
}
|
|
404
538
|
}
|
|
405
539
|
|
|
406
540
|
/** @private */
|
|
@@ -408,7 +542,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
408
542
|
const nonce = await this._resolveNonce(config)
|
|
409
543
|
|
|
410
544
|
if (nonce === undefined) {
|
|
411
|
-
const cached = this._consumeCachedQuote(tx)
|
|
545
|
+
const cached = this._consumeCachedQuote(tx, config)
|
|
412
546
|
if (cached?.userOp) {
|
|
413
547
|
const onChainNonce = await fetchAccountNonce(this._eip1193Provider, cached.smartAccount.entrypointAddress, cached.smartAccount.accountAddress)
|
|
414
548
|
if (cached.userOp.nonce === onChainNonce) {
|
|
@@ -460,7 +594,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
460
594
|
throw new ValueError('nonceKey must be within the uint192 range (0 to 2^192 - 1).')
|
|
461
595
|
}
|
|
462
596
|
}
|
|
463
|
-
return await fetchAccountNonce(this._eip1193Provider, ENTRYPOINT_V7, this.
|
|
597
|
+
return await fetchAccountNonce(this._eip1193Provider, ENTRYPOINT_V7, await this.getAddress(), key)
|
|
464
598
|
}
|
|
465
599
|
|
|
466
600
|
if (config.parallel) {
|
|
@@ -471,13 +605,22 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
471
605
|
}
|
|
472
606
|
|
|
473
607
|
/** @private */
|
|
474
|
-
static _getTxKey (tx) {
|
|
475
|
-
return JSON.stringify(
|
|
608
|
+
static _getTxKey (tx, config = {}) {
|
|
609
|
+
return JSON.stringify({
|
|
610
|
+
txs: [tx].flat(),
|
|
611
|
+
useNativeCoins: Boolean(config.useNativeCoins),
|
|
612
|
+
isSponsored: Boolean(config.isSponsored),
|
|
613
|
+
paymasterUrl: config.paymasterUrl,
|
|
614
|
+
paymasterHeaders: config.paymasterHeaders,
|
|
615
|
+
paymasterToken: config.paymasterToken?.address?.toLowerCase(),
|
|
616
|
+
paymasterAddress: config.paymasterAddress?.toLowerCase(),
|
|
617
|
+
sponsorshipPolicyId: config.sponsorshipPolicyId
|
|
618
|
+
}, (_, v) => typeof v === 'bigint' ? v.toString() : v)
|
|
476
619
|
}
|
|
477
620
|
|
|
478
621
|
/** @private */
|
|
479
|
-
_consumeCachedQuote (tx) {
|
|
480
|
-
const txKey = WalletAccountEvmErc4337._getTxKey(tx)
|
|
622
|
+
_consumeCachedQuote (tx, config) {
|
|
623
|
+
const txKey = WalletAccountEvmErc4337._getTxKey(tx, config)
|
|
481
624
|
const quote = this._quoteCache.get(txKey)
|
|
482
625
|
|
|
483
626
|
if (!quote) {
|
|
@@ -504,8 +647,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
504
647
|
)
|
|
505
648
|
|
|
506
649
|
const signer = {
|
|
507
|
-
address: this.
|
|
508
|
-
|
|
650
|
+
address: await this._getOwnerAddress(),
|
|
651
|
+
signTypedData: async (typedData) => await this._signer.signTypedData(typedData)
|
|
509
652
|
}
|
|
510
653
|
userOp.signature = await smartAccount.signUserOperationWithSigners(
|
|
511
654
|
userOp,
|
|
@@ -210,11 +210,11 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
const { [PINNED_SAFE_ADDRESS]: pinnedSafeAddress, ...unpinnedConfig } = config
|
|
213
|
-
const [accountConfig, ownerAccountAddress] =
|
|
213
|
+
const [accountConfig, ownerAccountAddress] = address && !pinnedSafeAddress
|
|
214
214
|
? [config, address]
|
|
215
215
|
: [unpinnedConfig, undefined]
|
|
216
216
|
|
|
217
|
-
super(pinnedSafeAddress ?? WalletAccountReadOnlyEvmErc4337.predictSafeAddress(address, config))
|
|
217
|
+
super(pinnedSafeAddress ?? (address ? WalletAccountReadOnlyEvmErc4337.predictSafeAddress(address, config) : undefined))
|
|
218
218
|
|
|
219
219
|
/**
|
|
220
220
|
* The read-only evm erc-4337 wallet account configuration.
|
|
@@ -547,11 +547,13 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
|
|
|
547
547
|
* @returns {Promise<boolean>} True if the signature is valid.
|
|
548
548
|
*/
|
|
549
549
|
async verify (message, signature) {
|
|
550
|
-
|
|
550
|
+
const ownerAddress = await this._getOwnerAddress()
|
|
551
|
+
|
|
552
|
+
if (ownerAddress === undefined) {
|
|
551
553
|
throw new UnsupportedOperationError('verify(message, signature)')
|
|
552
554
|
}
|
|
553
555
|
|
|
554
|
-
const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(
|
|
556
|
+
const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(ownerAddress, {
|
|
555
557
|
...this._config,
|
|
556
558
|
provider: this._provider
|
|
557
559
|
})
|
|
@@ -567,11 +569,13 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
|
|
|
567
569
|
* @returns {Promise<boolean>} True if the signature is valid.
|
|
568
570
|
*/
|
|
569
571
|
async verifyTypedData (typedData, signature) {
|
|
570
|
-
|
|
572
|
+
const ownerAddress = await this._getOwnerAddress()
|
|
573
|
+
|
|
574
|
+
if (ownerAddress === undefined) {
|
|
571
575
|
throw new UnsupportedOperationError('verifyTypedData(typedData, signature)')
|
|
572
576
|
}
|
|
573
577
|
|
|
574
|
-
const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(
|
|
578
|
+
const evmReadOnlyAccount = new WalletAccountReadOnlyEvm(ownerAddress, {
|
|
575
579
|
...this._config,
|
|
576
580
|
provider: this._provider
|
|
577
581
|
})
|
|
@@ -639,11 +643,23 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
|
|
|
639
643
|
return this._deployedSmartAccount
|
|
640
644
|
}
|
|
641
645
|
|
|
642
|
-
|
|
646
|
+
const ownerAddress = await this._getOwnerAddress()
|
|
647
|
+
|
|
648
|
+
if (ownerAddress === undefined) {
|
|
643
649
|
throw new ConfigurationError(`The safe at '${safeAddress}' is not deployed. Deploying it requires the owner's address, which an account created from a safe address does not have.`)
|
|
644
650
|
}
|
|
645
651
|
|
|
646
|
-
return SafeAccount030.initializeNewAccount([
|
|
652
|
+
return SafeAccount030.initializeNewAccount([ownerAddress], overrides)
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Returns the safe owner's address.
|
|
657
|
+
*
|
|
658
|
+
* @protected
|
|
659
|
+
* @returns {Promise<string | undefined>} The owner's address, or `undefined` if the account was created from a safe address.
|
|
660
|
+
*/
|
|
661
|
+
async _getOwnerAddress () {
|
|
662
|
+
return this._ownerAccountAddress
|
|
647
663
|
}
|
|
648
664
|
|
|
649
665
|
/**
|
|
@@ -1009,14 +1025,27 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
|
|
|
1009
1025
|
bundlerRpc,
|
|
1010
1026
|
context,
|
|
1011
1027
|
paymasterOverrides
|
|
1012
|
-
)
|
|
1028
|
+
).catch((error) => {
|
|
1029
|
+
// AbstractionKit throws this when the ERC-20 approval is not for the final paymaster.
|
|
1030
|
+
if (error instanceof AbstractionKitError && error.context?.approveSpender !== undefined) {
|
|
1031
|
+
const { approveSpender, finalPaymaster } = error.context
|
|
1032
|
+
|
|
1033
|
+
throw new ConfigurationError(
|
|
1034
|
+
`paymasterAddress mismatch: the paymaster RPC quoted ${approveSpender} for the ERC-20 approval ` +
|
|
1035
|
+
`but returned ${finalPaymaster || 'no paymaster'}.`,
|
|
1036
|
+
{ cause: error }
|
|
1037
|
+
)
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
throw error
|
|
1041
|
+
})
|
|
1013
1042
|
|
|
1014
1043
|
const sponsoredOp = result.userOperation
|
|
1015
1044
|
|
|
1016
|
-
if (mode === PaymasterMode.TOKEN &&
|
|
1017
|
-
sponsoredOp.paymaster
|
|
1045
|
+
if (mode === PaymasterMode.TOKEN &&
|
|
1046
|
+
sponsoredOp.paymaster?.toLowerCase() !== config.paymasterAddress.toLowerCase()) {
|
|
1018
1047
|
throw new ConfigurationError(
|
|
1019
|
-
`paymasterAddress mismatch: configured ${config.paymasterAddress} but RPC
|
|
1048
|
+
`paymasterAddress mismatch: configured ${config.paymasterAddress} but the paymaster RPC returned ${sponsoredOp.paymaster || 'no paymaster'}. ` +
|
|
1020
1049
|
'The generated ERC-20 approval would target an unexpected paymaster.'
|
|
1021
1050
|
)
|
|
1022
1051
|
}
|
|
@@ -14,18 +14,26 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict'
|
|
16
16
|
|
|
17
|
-
import WalletManager, { ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
|
|
17
|
+
import WalletManager, { DisposalError, InvalidSignerError, ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
|
|
18
18
|
|
|
19
19
|
import WalletManagerEvm, { WalletAccountReadOnlyEvm } from '@tetherto/wdk-wallet-evm'
|
|
20
20
|
|
|
21
|
+
import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
22
|
+
|
|
21
23
|
import WalletAccountEvmErc4337 from './wallet-account-evm-erc-4337.js'
|
|
22
24
|
|
|
23
25
|
/** @typedef {import('ethers').Provider} Provider */
|
|
24
26
|
|
|
25
27
|
/** @typedef {import('@tetherto/wdk-wallet-evm').FeeRates} FeeRates */
|
|
28
|
+
/** @typedef {import('@tetherto/wdk-wallet-evm/signers').ISignerEvm} ISignerEvm */
|
|
29
|
+
|
|
30
|
+
/** @typedef {import('@tetherto/wdk-wallet').NoSuchElementError} NoSuchElementError */
|
|
26
31
|
|
|
27
32
|
/** @typedef {import('./wallet-account-evm-erc-4337.js').EvmErc4337WalletConfig} EvmErc4337WalletConfig */
|
|
28
33
|
|
|
34
|
+
const BIP_44_ETH_DERIVATION_PATH_PREFIX = "m/44'/60'"
|
|
35
|
+
|
|
36
|
+
/** @extends {WalletManager<ISignerEvm>} */
|
|
29
37
|
export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
30
38
|
/**
|
|
31
39
|
* An ethers provider to interact with a node of the blockchain.
|
|
@@ -38,12 +46,42 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
38
46
|
/**
|
|
39
47
|
* Creates a new wallet manager for evm blockchains that implements the [erc-4337](https://www.erc4337.io/docs) standard and its account abstraction features.
|
|
40
48
|
*
|
|
49
|
+
* @overload
|
|
41
50
|
* @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
42
51
|
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
52
|
+
* @throws {ValueError} If the seed phrase is invalid.
|
|
53
|
+
* @throws {ValueError} If the `provider` option is set to an empty list.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new wallet manager for evm blockchains that implements the [erc-4337](https://www.erc4337.io/docs) standard from a default signer.
|
|
58
|
+
*
|
|
59
|
+
* The default signer must be derivable. Non-derivable signers (e.g. private-key signers) can only be registered by
|
|
60
|
+
* name via {@link addSigner}. The manager never disposes a signer you supplied.
|
|
61
|
+
*
|
|
62
|
+
* @overload
|
|
63
|
+
* @param {ISignerEvm} signer - The default signer.
|
|
64
|
+
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
65
|
+
* @throws {InvalidSignerError} If the default signer does not support account derivation.
|
|
43
66
|
* @throws {ValueError} If the `provider` option is set to an empty list.
|
|
44
67
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
|
|
69
|
+
constructor (seedOrSigner, config) {
|
|
70
|
+
if (Array.isArray(config.provider) && config.provider.length === 0) {
|
|
71
|
+
throw new ValueError("The 'provider' option cannot be set to an empty list.")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const isSeed = typeof seedOrSigner === 'string' || seedOrSigner instanceof Uint8Array
|
|
75
|
+
|
|
76
|
+
super(isSeed ? new SeedSignerEvm(seedOrSigner, BIP_44_ETH_DERIVATION_PATH_PREFIX) : seedOrSigner, config)
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* If true, disposes the default signer on calls to the 'dispose' method.
|
|
80
|
+
*
|
|
81
|
+
* @protected
|
|
82
|
+
* @type {boolean}
|
|
83
|
+
*/
|
|
84
|
+
this._shouldWipeDefaultSignerOnDisposal = isSeed
|
|
47
85
|
|
|
48
86
|
/**
|
|
49
87
|
* The evm erc-4337 wallet configuration.
|
|
@@ -53,24 +91,58 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
53
91
|
*/
|
|
54
92
|
this._config = config
|
|
55
93
|
|
|
56
|
-
if (Array.isArray(config.provider) && config.provider.length === 0) {
|
|
57
|
-
throw new ValueError("The 'provider' option cannot be set to an empty list.")
|
|
58
|
-
}
|
|
59
|
-
|
|
60
94
|
this._provider = WalletAccountReadOnlyEvm._buildProvider(config)
|
|
61
95
|
}
|
|
62
96
|
|
|
63
97
|
/**
|
|
64
|
-
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki))
|
|
98
|
+
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
|
|
99
|
+
* e.g. `getAccount(1)` returns the account with derivation path m/44'/60'/0'/0/1.
|
|
65
100
|
*
|
|
66
|
-
* @
|
|
67
|
-
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
68
|
-
* const account = await wallet.getAccount(1);
|
|
101
|
+
* @overload
|
|
69
102
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
103
|
+
* @param {Object} [options] - Account options.
|
|
104
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
70
105
|
* @returns {Promise<WalletAccountEvmErc4337>} The account.
|
|
106
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
107
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
108
|
+
* @throws {DisposalError} If the wallet manager or the given signer has been disposed.
|
|
71
109
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Returns the wallet account associated with a registered signer. The signer is used as given, without deriving,
|
|
113
|
+
* and is left untouched when the account is disposed.
|
|
114
|
+
*
|
|
115
|
+
* @overload
|
|
116
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
117
|
+
* @returns {Promise<WalletAccountEvmErc4337>} The account.
|
|
118
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
119
|
+
* @throws {DisposalError} If the wallet manager or the given signer has been disposed.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
async getAccount (indexOrSignerName = 0, options = {}) {
|
|
123
|
+
if (typeof indexOrSignerName === 'string') {
|
|
124
|
+
if (this.disposed) {
|
|
125
|
+
throw new DisposalError('The wallet manager has been disposed.')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const key = indexOrSignerName
|
|
129
|
+
|
|
130
|
+
if (!this._accounts[key]) {
|
|
131
|
+
const signer = this.getSigner(indexOrSignerName)
|
|
132
|
+
|
|
133
|
+
if (signer.disposed) {
|
|
134
|
+
throw new DisposalError('The given signer has been disposed.')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this._accounts[key] = new WalletAccountEvmErc4337(signer, this._accountConfig())
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return this._accounts[key]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const { signerName } = options
|
|
144
|
+
|
|
145
|
+
return await this.getAccountByPath(`0'/0/${indexOrSignerName}`, { signerName })
|
|
74
146
|
}
|
|
75
147
|
|
|
76
148
|
/**
|
|
@@ -80,16 +152,50 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
80
152
|
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
81
153
|
* const account = await wallet.getAccountByPath("0'/0/1");
|
|
82
154
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
155
|
+
* @param {Object} [options] - Account options.
|
|
156
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
83
157
|
* @returns {Promise<WalletAccountEvmErc4337>} The account.
|
|
158
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
159
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
160
|
+
* @throws {DisposalError} If the wallet manager or the given signer has been disposed.
|
|
84
161
|
*/
|
|
85
|
-
async getAccountByPath (path) {
|
|
86
|
-
if (
|
|
87
|
-
|
|
162
|
+
async getAccountByPath (path, options = {}) {
|
|
163
|
+
if (this.disposed) {
|
|
164
|
+
throw new DisposalError('The wallet manager has been disposed.')
|
|
165
|
+
}
|
|
88
166
|
|
|
89
|
-
|
|
167
|
+
const { signerName } = options
|
|
168
|
+
|
|
169
|
+
const key = signerName ? `${signerName}:${path}` : path
|
|
170
|
+
|
|
171
|
+
if (!this._accounts[key]) {
|
|
172
|
+
const signer = this.getSigner(signerName)
|
|
173
|
+
|
|
174
|
+
if (signer.disposed) {
|
|
175
|
+
throw new DisposalError('The given signer has been disposed.')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!signer.isDerivable) {
|
|
179
|
+
throw new InvalidSignerError('The signer does not support account derivation.')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const childSigner = await signer.derive(path)
|
|
183
|
+
|
|
184
|
+
// A concurrent call may have cached this account while we were deriving.
|
|
185
|
+
if (this._accounts[key]) {
|
|
186
|
+
childSigner.dispose()
|
|
187
|
+
} else {
|
|
188
|
+
try {
|
|
189
|
+
this._accounts[key] = new WalletAccountEvmErc4337(childSigner, { ...this._accountConfig(), shouldWipeSignerOnDisposal: true })
|
|
190
|
+
} catch (error) {
|
|
191
|
+
childSigner.dispose()
|
|
192
|
+
|
|
193
|
+
throw error
|
|
194
|
+
}
|
|
195
|
+
}
|
|
90
196
|
}
|
|
91
197
|
|
|
92
|
-
return this._accounts[
|
|
198
|
+
return this._accounts[key]
|
|
93
199
|
}
|
|
94
200
|
|
|
95
201
|
/**
|
|
@@ -123,4 +229,15 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
123
229
|
fast: feeRate * WalletManagerEvm._FEE_RATE_FAST_MULTIPLIER / 100n
|
|
124
230
|
}
|
|
125
231
|
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Disposes all the wallet accounts, erasing their private keys from the memory.
|
|
235
|
+
*/
|
|
236
|
+
dispose () {
|
|
237
|
+
if (this._shouldWipeDefaultSignerOnDisposal) {
|
|
238
|
+
this._defaultSigner.dispose()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
super.dispose()
|
|
242
|
+
}
|
|
126
243
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTra
|
|
|
11
11
|
export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
|
|
12
12
|
export type FeeRates = import("@tetherto/wdk-wallet-evm").FeeRates;
|
|
13
13
|
export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
|
|
14
|
+
export type SignerOptions = import("@tetherto/wdk-wallet-evm").SignerOptions;
|
|
14
15
|
export type EvmErc4337Transaction = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
|
|
15
16
|
export type EvmErc4337GasOverrides = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337GasOverrides;
|
|
16
17
|
export type EvmErc4337TransferOptions = import("./src/wallet-account-read-only-evm-erc-4337.js").EvmErc4337TransferOptions;
|
package/types/src/errors.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export class ConfigurationError extends ValueError {
|
|
|
8
8
|
* Create a new configuration error.
|
|
9
9
|
*
|
|
10
10
|
* @param {string} message - The error message.
|
|
11
|
+
* @param {ErrorOptions} [options] - The error's options.
|
|
11
12
|
*/
|
|
12
|
-
constructor(message: string);
|
|
13
|
+
constructor(message: string, options?: ErrorOptions);
|
|
13
14
|
}
|
|
14
15
|
import { ValueError } from '@tetherto/wdk-wallet';
|
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
/** @implements {IWalletAccount} */
|
|
2
2
|
export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc4337 implements IWalletAccount<UserOperationV7> {
|
|
3
3
|
/**
|
|
4
|
-
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account.
|
|
4
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account whose safe owner is a raw private key.
|
|
5
5
|
*
|
|
6
|
+
* The account owns the key and wipes it on {@link dispose}.
|
|
7
|
+
*
|
|
8
|
+
* @param {string | Uint8Array} privateKey - The raw private key (hex string with or without 0x, or 32 bytes).
|
|
9
|
+
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
10
|
+
* @returns {WalletAccountEvmErc4337} The wallet account.
|
|
11
|
+
*/
|
|
12
|
+
static fromPrivateKey(privateKey: string | Uint8Array, config: EvmErc4337WalletConfig): WalletAccountEvmErc4337;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account from a BIP-39 seed.
|
|
15
|
+
*
|
|
16
|
+
* @overload
|
|
6
17
|
* @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
7
|
-
* @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
|
|
18
|
+
* @param {string} path - The BIP-44 derivation path, relative to "m/44'/60'" (e.g. "0'/0/0").
|
|
8
19
|
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
20
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
9
21
|
*/
|
|
10
22
|
constructor(seed: string | Uint8Array, path: string, config: EvmErc4337WalletConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account from a BIP-39 seed at path m/44'/60'/0'/0/0.
|
|
25
|
+
*
|
|
26
|
+
* @overload
|
|
27
|
+
* @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
28
|
+
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
29
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
30
|
+
*/
|
|
31
|
+
constructor(seed: string | Uint8Array, config: EvmErc4337WalletConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new evm [erc-4337](https://www.erc4337.io/docs) wallet account using a signer as the safe's owner.
|
|
34
|
+
*
|
|
35
|
+
* The signer is wiped on {@link dispose} only if `shouldWipeSignerOnDisposal` is set. The safe's address is
|
|
36
|
+
* predicted from the signer's address on the first call to {@link getAddress}.
|
|
37
|
+
*
|
|
38
|
+
* @overload
|
|
39
|
+
* @param {ISignerEvm} signer - A signer implementing the EVM signer interface.
|
|
40
|
+
* @param {EvmErc4337WalletConfig & SignerOptions} config - The configuration object.
|
|
41
|
+
*/
|
|
42
|
+
constructor(signer: ISignerEvm, config: EvmErc4337WalletConfig & SignerOptions);
|
|
11
43
|
/**
|
|
12
44
|
* Creates a read-only account for a safe whose address is already known. Not supported on the writable
|
|
13
45
|
* account: a safe address cannot produce a signer. Use {@link WalletAccountReadOnlyEvmErc4337.fromSafeAddress}.
|
|
@@ -25,22 +57,39 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
25
57
|
* @type {EvmErc4337WalletConfig}
|
|
26
58
|
*/
|
|
27
59
|
protected _config: EvmErc4337WalletConfig;
|
|
60
|
+
/**
|
|
61
|
+
* If true, disposes the signer on calls to the 'dispose' method.
|
|
62
|
+
*
|
|
63
|
+
* @protected
|
|
64
|
+
* @type {boolean}
|
|
65
|
+
*/
|
|
66
|
+
protected _shouldWipeSignerOnDisposal: boolean;
|
|
67
|
+
/** @private */
|
|
68
|
+
private _signer;
|
|
28
69
|
/** @private */
|
|
29
|
-
private
|
|
70
|
+
private _safeAddress;
|
|
30
71
|
/** @private */
|
|
31
72
|
private _quoteCache;
|
|
73
|
+
/** @private */
|
|
74
|
+
private _disposed;
|
|
32
75
|
/**
|
|
33
|
-
*
|
|
76
|
+
* True once this account's own {@link dispose} method has been called.
|
|
77
|
+
*
|
|
78
|
+
* This reflects the account's lifecycle only. A caller-supplied signer disposed externally
|
|
79
|
+
* does not flip this flag -- the account is still considered alive until it is disposed itself,
|
|
80
|
+
* even though its signer-dependent methods will throw a {@link DisposalError} (propagated from
|
|
81
|
+
* the disposed signer) in the meantime.
|
|
34
82
|
*
|
|
35
|
-
* @type {
|
|
83
|
+
* @type {boolean}
|
|
36
84
|
*/
|
|
37
|
-
get
|
|
85
|
+
get disposed(): boolean;
|
|
38
86
|
/**
|
|
39
|
-
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki))
|
|
87
|
+
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
|
|
88
|
+
* or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
|
|
40
89
|
*
|
|
41
|
-
* @type {string}
|
|
90
|
+
* @type {string | null}
|
|
42
91
|
*/
|
|
43
|
-
get path(): string;
|
|
92
|
+
get path(): string | null;
|
|
44
93
|
/**
|
|
45
94
|
* The account's key pair.
|
|
46
95
|
*
|
|
@@ -48,14 +97,22 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
48
97
|
* 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
|
|
49
98
|
* content, client code should never do so.
|
|
50
99
|
*
|
|
51
|
-
* @type {KeyPair}
|
|
100
|
+
* @type {KeyPair | null}
|
|
101
|
+
*/
|
|
102
|
+
get keyPair(): KeyPair | null;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the account's address, which is the safe's address predicted from the signer's address.
|
|
105
|
+
*
|
|
106
|
+
* @returns {Promise<string>} The account's address.
|
|
107
|
+
* @throws {ValueError} If the signer's address is not a well-formed evm address.
|
|
52
108
|
*/
|
|
53
|
-
|
|
109
|
+
getAddress(): Promise<string>;
|
|
54
110
|
/**
|
|
55
111
|
* Signs a message.
|
|
56
112
|
*
|
|
57
113
|
* @param {string} message - The message to sign.
|
|
58
114
|
* @returns {Promise<string>} The message's signature.
|
|
115
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
59
116
|
*/
|
|
60
117
|
sign(message: string): Promise<string>;
|
|
61
118
|
/**
|
|
@@ -63,6 +120,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
63
120
|
*
|
|
64
121
|
* @param {TypedData} typedData - The typed data to sign.
|
|
65
122
|
* @returns {Promise<string>} The typed data signature.
|
|
123
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
66
124
|
*/
|
|
67
125
|
signTypedData({ domain, types, message }: TypedData): Promise<string>;
|
|
68
126
|
/**
|
|
@@ -77,6 +135,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
77
135
|
* @throws {ConfigurationError} If, in token mode, the configured `paymasterAddress` does not match the paymaster address returned by the paymaster RPC. This guards against the auto-generated ERC-20 approval targeting an unexpected paymaster contract.
|
|
78
136
|
* @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
|
|
79
137
|
* @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
|
|
138
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
80
139
|
*/
|
|
81
140
|
signTransaction(tx: EvmErc4337Transaction, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<UserOperationV7>;
|
|
82
141
|
/**
|
|
@@ -86,14 +145,16 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
86
145
|
* @returns {Promise<TransactionResult>} - The transaction's result.
|
|
87
146
|
* @throws {ProviderRequiredError} - If the wallet is not connected to a provider.
|
|
88
147
|
* @throws {ValueError} - If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
|
|
148
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
89
149
|
*/
|
|
90
150
|
approve(options: EvmErc4337ApproveOptions): Promise<TransactionResult>;
|
|
91
151
|
/**
|
|
92
152
|
* Quotes the costs of a send transaction operation.
|
|
93
153
|
*
|
|
94
154
|
* The result is cached internally for up to 2 minutes. A subsequent `sendTransaction` with the
|
|
95
|
-
* same transaction reuses the cached operation — skipping the
|
|
96
|
-
* round-trips — after a lightweight on-chain nonce check, re-quoting
|
|
155
|
+
* same transaction and paymaster configuration reuses the cached operation — skipping the
|
|
156
|
+
* gas-estimation and paymaster round-trips — after a lightweight on-chain nonce check, re-quoting
|
|
157
|
+
* only if the nonce has moved.
|
|
97
158
|
*
|
|
98
159
|
* In a batched call (`tx` passed as `[tx1, tx2, ...]`), only the gas overrides on `tx1` are
|
|
99
160
|
* honored — a UserOperation has a single set of gas fields regardless of how many calls it batches.
|
|
@@ -122,6 +183,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
122
183
|
* @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transaction's cost surpasses the transaction max. fee option.
|
|
123
184
|
* @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
|
|
124
185
|
* @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
|
|
186
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
125
187
|
*/
|
|
126
188
|
sendTransaction(tx: EvmErc4337Transaction | EvmErc4337Transaction[] | UserOperationV7, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransactionResult>;
|
|
127
189
|
/**
|
|
@@ -137,6 +199,7 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
137
199
|
* @throws {MaximumFeeExceededError} If the transaction is not sponsored, and the transfer's cost surpasses the transfer max. fee option.
|
|
138
200
|
* @throws {ValueError} If `nonceKey` is a bigint outside the uint192 range (0 to 2^192 - 1).
|
|
139
201
|
* @throws {TransactionError} If the paymaster reports AA50 (the account cannot repay the paymaster).
|
|
202
|
+
* @throws {DisposalError} If the account, or the externally supplied signer it uses, has been disposed.
|
|
140
203
|
*/
|
|
141
204
|
transfer(options: EvmErc4337TransferOptions, config?: Partial<EvmErc4337WalletPaymasterTokenConfig | EvmErc4337WalletSponsorshipPolicyConfig | EvmErc4337WalletNativeCoinsConfig>): Promise<TransferResult>;
|
|
142
205
|
/**
|
|
@@ -145,11 +208,20 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
145
208
|
* @returns {Promise<WalletAccountReadOnlyEvmErc4337>} The read-only account.
|
|
146
209
|
*/
|
|
147
210
|
toReadOnlyAccount(): Promise<WalletAccountReadOnlyEvmErc4337>;
|
|
211
|
+
/**
|
|
212
|
+
* Returns the safe owner's address, as given by the signer.
|
|
213
|
+
*
|
|
214
|
+
* @protected
|
|
215
|
+
* @returns {Promise<string>} The owner's address.
|
|
216
|
+
*/
|
|
217
|
+
protected _getOwnerAddress(): Promise<string>;
|
|
148
218
|
/**
|
|
149
219
|
* Disposes the wallet account, erasing the private key from the memory.
|
|
150
220
|
*/
|
|
151
221
|
dispose(): void;
|
|
152
222
|
/** @private */
|
|
223
|
+
private _guardDisposed;
|
|
224
|
+
/** @private */
|
|
153
225
|
private _prepareForSend;
|
|
154
226
|
/** @private */
|
|
155
227
|
private _buildAtNonce;
|
|
@@ -170,6 +242,8 @@ export default class WalletAccountEvmErc4337 extends WalletAccountReadOnlyEvmErc
|
|
|
170
242
|
export type Eip1193Provider = import("ethers").Eip1193Provider;
|
|
171
243
|
export type IWalletAccount<TSignedTransaction> = import("@tetherto/wdk-wallet").IWalletAccount<TSignedTransaction>;
|
|
172
244
|
export type KeyPair = import("@tetherto/wdk-wallet-evm").KeyPair;
|
|
245
|
+
export type ISignerEvm = import("@tetherto/wdk-wallet-evm/signers").ISignerEvm;
|
|
246
|
+
export type SignerOptions = import("@tetherto/wdk-wallet-evm").SignerOptions;
|
|
173
247
|
export type EvmErc4337Transaction = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337Transaction;
|
|
174
248
|
export type EvmErc4337GasOverrides = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337GasOverrides;
|
|
175
249
|
export type EvmErc4337TransferOptions = import("./wallet-account-read-only-evm-erc-4337.js").EvmErc4337TransferOptions;
|
|
@@ -234,6 +234,13 @@ export default class WalletAccountReadOnlyEvmErc4337 extends WalletAccountReadOn
|
|
|
234
234
|
* @returns {Promise<SafeAccountV0_3_0>} The safe account instance.
|
|
235
235
|
*/
|
|
236
236
|
protected _getSmartAccount(config?: Omit<EvmErc4337WalletConfig, "transferMaxFee" | "transactionMaxFee">): Promise<import('abstractionkit').SafeAccountV0_3_0>;
|
|
237
|
+
/**
|
|
238
|
+
* Returns the safe owner's address.
|
|
239
|
+
*
|
|
240
|
+
* @protected
|
|
241
|
+
* @returns {Promise<string | undefined>} The owner's address, or `undefined` if the account was created from a safe address.
|
|
242
|
+
*/
|
|
243
|
+
protected _getOwnerAddress(): Promise<string | undefined>;
|
|
237
244
|
/**
|
|
238
245
|
* Builds the RPC transport for an AbstractionKit client (Bundler / Erc7677Paymaster).
|
|
239
246
|
*
|
|
@@ -1,12 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/** @extends {WalletManager<ISignerEvm>} */
|
|
2
|
+
export default class WalletManagerEvmErc4337 extends WalletManager<ISignerEvm> {
|
|
2
3
|
/**
|
|
3
4
|
* Creates a new wallet manager for evm blockchains that implements the [erc-4337](https://www.erc4337.io/docs) standard and its account abstraction features.
|
|
4
5
|
*
|
|
6
|
+
* @overload
|
|
5
7
|
* @param {string | Uint8Array} seed - A [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
6
8
|
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
9
|
+
* @throws {ValueError} If the seed phrase is invalid.
|
|
7
10
|
* @throws {ValueError} If the `provider` option is set to an empty list.
|
|
8
11
|
*/
|
|
9
12
|
constructor(seed: string | Uint8Array, config: EvmErc4337WalletConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new wallet manager for evm blockchains that implements the [erc-4337](https://www.erc4337.io/docs) standard from a default signer.
|
|
15
|
+
*
|
|
16
|
+
* The default signer must be derivable. Non-derivable signers (e.g. private-key signers) can only be registered by
|
|
17
|
+
* name via {@link addSigner}. The manager never disposes a signer you supplied.
|
|
18
|
+
*
|
|
19
|
+
* @overload
|
|
20
|
+
* @param {ISignerEvm} signer - The default signer.
|
|
21
|
+
* @param {EvmErc4337WalletConfig} config - The configuration object.
|
|
22
|
+
* @throws {InvalidSignerError} If the default signer does not support account derivation.
|
|
23
|
+
* @throws {ValueError} If the `provider` option is set to an empty list.
|
|
24
|
+
*/
|
|
25
|
+
constructor(signer: ISignerEvm, config: EvmErc4337WalletConfig);
|
|
10
26
|
/**
|
|
11
27
|
* An ethers provider to interact with a node of the blockchain.
|
|
12
28
|
*
|
|
@@ -15,15 +31,39 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
15
31
|
*/
|
|
16
32
|
protected _provider: Provider | undefined;
|
|
17
33
|
/**
|
|
18
|
-
*
|
|
34
|
+
* If true, disposes the default signer on calls to the 'dispose' method.
|
|
19
35
|
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
22
|
-
|
|
36
|
+
* @protected
|
|
37
|
+
* @type {boolean}
|
|
38
|
+
*/
|
|
39
|
+
protected _shouldWipeDefaultSignerOnDisposal: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
|
|
42
|
+
* e.g. `getAccount(1)` returns the account with derivation path m/44'/60'/0'/0/1.
|
|
43
|
+
*
|
|
44
|
+
* @overload
|
|
23
45
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
46
|
+
* @param {Object} [options] - Account options.
|
|
47
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
24
48
|
* @returns {Promise<WalletAccountEvmErc4337>} The account.
|
|
49
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
50
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
51
|
+
* @throws {DisposalError} If the wallet manager or the given signer has been disposed.
|
|
25
52
|
*/
|
|
26
|
-
getAccount(index?: number
|
|
53
|
+
getAccount(index?: number, options?: {
|
|
54
|
+
signerName?: string;
|
|
55
|
+
}): Promise<WalletAccountEvmErc4337>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the wallet account associated with a registered signer. The signer is used as given, without deriving,
|
|
58
|
+
* and is left untouched when the account is disposed.
|
|
59
|
+
*
|
|
60
|
+
* @overload
|
|
61
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
62
|
+
* @returns {Promise<WalletAccountEvmErc4337>} The account.
|
|
63
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
64
|
+
* @throws {DisposalError} If the wallet manager or the given signer has been disposed.
|
|
65
|
+
*/
|
|
66
|
+
getAccount(signerName: string): Promise<WalletAccountEvmErc4337>;
|
|
27
67
|
/**
|
|
28
68
|
* Returns the wallet account at a specific BIP-44 derivation path.
|
|
29
69
|
*
|
|
@@ -31,9 +71,16 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
31
71
|
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
32
72
|
* const account = await wallet.getAccountByPath("0'/0/1");
|
|
33
73
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
74
|
+
* @param {Object} [options] - Account options.
|
|
75
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
34
76
|
* @returns {Promise<WalletAccountEvmErc4337>} The account.
|
|
77
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
78
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
79
|
+
* @throws {DisposalError} If the wallet manager or the given signer has been disposed.
|
|
35
80
|
*/
|
|
36
|
-
getAccountByPath(path: string
|
|
81
|
+
getAccountByPath(path: string, options?: {
|
|
82
|
+
signerName?: string;
|
|
83
|
+
}): Promise<WalletAccountEvmErc4337>;
|
|
37
84
|
/**
|
|
38
85
|
* Builds the account config, injecting the manager's shared provider so accounts reuse the
|
|
39
86
|
* single ethers provider instance instead of opening their own.
|
|
@@ -49,9 +96,15 @@ export default class WalletManagerEvmErc4337 extends WalletManager {
|
|
|
49
96
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
50
97
|
*/
|
|
51
98
|
getFeeRates(): Promise<FeeRates>;
|
|
99
|
+
/**
|
|
100
|
+
* Disposes all the wallet accounts, erasing their private keys from the memory.
|
|
101
|
+
*/
|
|
102
|
+
dispose(): void;
|
|
52
103
|
}
|
|
53
104
|
export type Provider = import("ethers").Provider;
|
|
54
105
|
export type FeeRates = import("@tetherto/wdk-wallet-evm").FeeRates;
|
|
106
|
+
export type ISignerEvm = import("@tetherto/wdk-wallet-evm/signers").ISignerEvm;
|
|
107
|
+
export type NoSuchElementError = import("@tetherto/wdk-wallet").NoSuchElementError;
|
|
55
108
|
export type EvmErc4337WalletConfig = import("./wallet-account-evm-erc-4337.js").EvmErc4337WalletConfig;
|
|
56
109
|
import WalletManager from '@tetherto/wdk-wallet';
|
|
57
110
|
import WalletAccountEvmErc4337 from './wallet-account-evm-erc-4337.js';
|