@dynamic-labs/ethereum-aa 4.4.1 → 4.4.2-preview.0
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/CHANGELOG.md +10 -0
- package/_virtual/_tslib.cjs +13 -0
- package/_virtual/_tslib.js +13 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/ZeroDevConnector.cjs +98 -69
- package/src/ZeroDevConnector.d.ts +9 -5
- package/src/ZeroDevConnector.js +103 -74
- package/src/utils/createEcsdaKernelAccountClient.cjs +68 -33
- package/src/utils/createEcsdaKernelAccountClient.d.ts +13 -8
- package/src/utils/createEcsdaKernelAccountClient.js +69 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.4.2-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.1...v4.4.2-preview.0) (2025-01-28)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for 7702 on ZeroDevConnector ([a8c850a](https://github.com/dynamic-labs/dynamic-auth/commit/a8c850ab192d6113ad55a01a594d5d90ab0fbfa6))
|
|
8
|
+
* implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([96853fa](https://github.com/dynamic-labs/dynamic-auth/commit/96853fae170ca2f81cc01ccd6d9886446876412b))
|
|
9
|
+
* implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([d988e88](https://github.com/dynamic-labs/dynamic-auth/commit/d988e88eccd0b04ba5710c8aa437f5dfffeb1d74))
|
|
10
|
+
* implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([597f837](https://github.com/dynamic-labs/dynamic-auth/commit/597f8375bacef1e6a9a064604074c6920955a3e2))
|
|
11
|
+
|
|
2
12
|
### [4.4.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.0...v4.4.1) (2025-01-27)
|
|
3
13
|
|
|
4
14
|
|
package/_virtual/_tslib.cjs
CHANGED
|
@@ -18,6 +18,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
18
18
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
20
|
|
|
21
|
+
function __rest(s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
34
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
35
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -34,3 +46,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
34
46
|
};
|
|
35
47
|
|
|
36
48
|
exports.__awaiter = __awaiter;
|
|
49
|
+
exports.__rest = __rest;
|
package/_virtual/_tslib.js
CHANGED
|
@@ -14,6 +14,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
***************************************************************************** */
|
|
16
16
|
|
|
17
|
+
function __rest(s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
30
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
31
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -29,4 +41,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
29
41
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
42
|
};
|
|
31
43
|
|
|
32
|
-
export { __awaiter };
|
|
44
|
+
export { __awaiter, __rest };
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-aa",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2-preview.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"@zerodev/ecdsa-validator": "5.4.3",
|
|
23
23
|
"@zerodev/multi-chain-ecdsa-validator": "5.4.2",
|
|
24
24
|
"@zerodev/sdk": "5.4.17",
|
|
25
|
-
"@dynamic-labs/assert-package-version": "4.4.
|
|
26
|
-
"@dynamic-labs/ethereum-core": "4.4.
|
|
27
|
-
"@dynamic-labs/logger": "4.4.
|
|
28
|
-
"@dynamic-labs/types": "4.4.
|
|
29
|
-
"@dynamic-labs/utils": "4.4.
|
|
30
|
-
"@dynamic-labs/wallet-book": "4.4.
|
|
31
|
-
"@dynamic-labs/wallet-connector-core": "4.4.
|
|
25
|
+
"@dynamic-labs/assert-package-version": "4.4.2-preview.0",
|
|
26
|
+
"@dynamic-labs/ethereum-core": "4.4.2-preview.0",
|
|
27
|
+
"@dynamic-labs/logger": "4.4.2-preview.0",
|
|
28
|
+
"@dynamic-labs/types": "4.4.2-preview.0",
|
|
29
|
+
"@dynamic-labs/utils": "4.4.2-preview.0",
|
|
30
|
+
"@dynamic-labs/wallet-book": "4.4.2-preview.0",
|
|
31
|
+
"@dynamic-labs/wallet-connector-core": "4.4.2-preview.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"viem": "^2.21.55"
|
package/src/ZeroDevConnector.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var _tslib = require('../_virtual/_tslib.cjs');
|
|
|
7
7
|
var viem = require('viem');
|
|
8
8
|
var accounts = require('viem/accounts');
|
|
9
9
|
var constants$1 = require('@zerodev/sdk/constants');
|
|
10
|
+
var chains = require('viem/chains');
|
|
10
11
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
12
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
13
|
var utils = require('@dynamic-labs/utils');
|
|
@@ -19,7 +20,7 @@ var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
|
19
20
|
|
|
20
21
|
class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
21
22
|
constructor(opts) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f;
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
23
24
|
super(opts);
|
|
24
25
|
// provider map maintains the kernel clients per chain
|
|
25
26
|
this.providerMap = {};
|
|
@@ -40,22 +41,27 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
40
41
|
},
|
|
41
42
|
name: 'ZeroDev',
|
|
42
43
|
};
|
|
44
|
+
this.isEip7702Mode = (_a = opts.isEip7702) !== null && _a !== void 0 ? _a : true; // hack
|
|
43
45
|
this._walletUiUtils = opts.walletUiUtils;
|
|
44
46
|
this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
|
|
45
|
-
this.entryPoint = getEntryPoint.getEntryPoint((
|
|
46
|
-
this.kernelVersion = getKernelVersion.getKernelVersion((
|
|
47
|
+
this.entryPoint = getEntryPoint.getEntryPoint((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion);
|
|
48
|
+
this.kernelVersion = getKernelVersion.getKernelVersion((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.kernelVersion, this.entryPoint);
|
|
47
49
|
this.enableKernelV3Migration =
|
|
48
|
-
(
|
|
50
|
+
(_e = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.enableKernelV3Migration) !== null && _e !== void 0 ? _e : false;
|
|
49
51
|
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
50
52
|
this.providersFromApi =
|
|
51
|
-
((
|
|
53
|
+
((_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.multichainAccountAbstractionProviders) || [];
|
|
52
54
|
const [defaultProvider] = this.providersFromApi;
|
|
53
55
|
this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
|
|
54
56
|
if (!this.clientId) {
|
|
55
57
|
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
56
58
|
}
|
|
57
59
|
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
58
|
-
this.ecdsaProviderType = (
|
|
60
|
+
this.ecdsaProviderType = (_g = opts.apiProviders.zerodev) === null || _g === void 0 ? void 0 : _g.ecdsaProviderType;
|
|
61
|
+
}
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63
|
+
confirmTransactionStatus(txHash) {
|
|
64
|
+
throw new Error('Method not implemented.');
|
|
59
65
|
}
|
|
60
66
|
get currentNetworkProvider() {
|
|
61
67
|
// check if the last used chain id is in the provider map
|
|
@@ -120,31 +126,39 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
120
126
|
});
|
|
121
127
|
}
|
|
122
128
|
registerEoa(_a) {
|
|
123
|
-
return _tslib.__awaiter(this,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.eoaConnectorMap[smartWalletAddress] = {
|
|
131
|
-
eoaAddress,
|
|
132
|
-
eoaConnector,
|
|
133
|
-
properties,
|
|
134
|
-
};
|
|
135
|
-
// if this is the primary wallet, set the eoa connector and kernel clients
|
|
136
|
-
if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
|
|
129
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
|
|
131
|
+
if (this.isEip7702Mode) {
|
|
132
|
+
// In EIP-7702, addresses must match
|
|
133
|
+
if (smartWalletAddress !== eoaAddress) {
|
|
134
|
+
throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
|
|
135
|
+
}
|
|
137
136
|
yield this.setEoaConnector({
|
|
138
137
|
connector: eoaConnector,
|
|
139
138
|
eoaAddress,
|
|
140
139
|
properties,
|
|
141
140
|
});
|
|
142
141
|
}
|
|
142
|
+
else {
|
|
143
|
+
// Existing implementation for regular ZeroDev
|
|
144
|
+
this.eoaConnectorMap[smartWalletAddress] = {
|
|
145
|
+
eoaAddress,
|
|
146
|
+
eoaConnector,
|
|
147
|
+
properties,
|
|
148
|
+
};
|
|
149
|
+
if (shouldSetEoaConnector) {
|
|
150
|
+
yield this.setEoaConnector({
|
|
151
|
+
connector: eoaConnector,
|
|
152
|
+
eoaAddress,
|
|
153
|
+
properties,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
143
157
|
});
|
|
144
158
|
}
|
|
145
159
|
setEoaConnector(_a) {
|
|
146
160
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
147
|
-
var _b, _c;
|
|
161
|
+
var _b, _c, _d;
|
|
148
162
|
if (!connector) {
|
|
149
163
|
logger.logger.error('No EOA connector provided');
|
|
150
164
|
return;
|
|
@@ -170,6 +184,18 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
170
184
|
}
|
|
171
185
|
const signer = yield this.eoaConnector.getSigner();
|
|
172
186
|
signer.account = accounts.toAccount(eoaAddress);
|
|
187
|
+
if (!this.eoaConnector)
|
|
188
|
+
throw new utils.DynamicError('No EOA connector');
|
|
189
|
+
yield this.eoaConnector.switchNetwork({
|
|
190
|
+
networkChainId: chains.odysseyTestnet.id,
|
|
191
|
+
});
|
|
192
|
+
if (!walletConnectorCore.isTurnkeyWalletConnector(this.eoaConnector)) {
|
|
193
|
+
throw new utils.DynamicError('No EOA connector');
|
|
194
|
+
}
|
|
195
|
+
const authorization = yield ((_d = this.eoaConnector) === null || _d === void 0 ? void 0 : _d.experimental_signAuthorization({
|
|
196
|
+
contractAddress: constants$1.KERNEL_7702_DELEGATION_ADDRESS,
|
|
197
|
+
})); // add to localstorage, remove on logout
|
|
198
|
+
this.authorization = authorization;
|
|
173
199
|
yield this.generateProviderMap(signer);
|
|
174
200
|
this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
|
|
175
201
|
this.kernelClientDeferredPromise.resolve();
|
|
@@ -196,13 +222,15 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
196
222
|
yield Promise.all(this.providersFromApi.map((provider) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
197
223
|
if (!this.providerMap[provider.chain]) {
|
|
198
224
|
const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
|
|
199
|
-
this.
|
|
225
|
+
this.createKernelClient({
|
|
200
226
|
chainId: provider.chain,
|
|
227
|
+
paymaster: 'NONE',
|
|
201
228
|
projectId: provider.clientId,
|
|
202
229
|
signer,
|
|
203
230
|
}),
|
|
204
|
-
this.
|
|
231
|
+
this.createKernelClient({
|
|
205
232
|
chainId: provider.chain,
|
|
233
|
+
paymaster: 'SPONSOR',
|
|
206
234
|
projectId: provider.clientId,
|
|
207
235
|
signer,
|
|
208
236
|
}),
|
|
@@ -216,27 +244,47 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
216
244
|
})));
|
|
217
245
|
});
|
|
218
246
|
}
|
|
219
|
-
|
|
220
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ projectId, signer,
|
|
247
|
+
createKernelClient(_a) {
|
|
248
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
|
|
221
249
|
if (chainId && this.providerMap[chainId]) {
|
|
222
250
|
return this.providerMap[chainId].kernelClient;
|
|
223
251
|
}
|
|
224
252
|
const { eoaConnector } = this;
|
|
225
253
|
if (!eoaConnector)
|
|
226
254
|
throw new utils.DynamicError('No EOA connector');
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
255
|
+
const chain = ethereumCore.chainsMap[chainId];
|
|
256
|
+
let kernelClient;
|
|
257
|
+
if (this.isEip7702Mode && this.authorization) {
|
|
258
|
+
kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClientWith7702({
|
|
259
|
+
authorization: this.authorization,
|
|
260
|
+
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
261
|
+
chain,
|
|
262
|
+
ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
|
|
263
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
264
|
+
entryPoint: this.entryPoint,
|
|
265
|
+
kernelVersion: this.kernelVersion,
|
|
266
|
+
paymaster,
|
|
267
|
+
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
268
|
+
projectId,
|
|
269
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
270
|
+
signer,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
|
|
275
|
+
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
276
|
+
chain,
|
|
277
|
+
ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
|
|
278
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
279
|
+
entryPoint: this.entryPoint,
|
|
280
|
+
kernelVersion: this.kernelVersion,
|
|
281
|
+
paymaster,
|
|
282
|
+
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
283
|
+
projectId,
|
|
284
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
285
|
+
signer,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
240
288
|
utils.wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
241
289
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
242
290
|
return original(...args);
|
|
@@ -244,37 +292,12 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
244
292
|
return kernelClient;
|
|
245
293
|
});
|
|
246
294
|
}
|
|
247
|
-
getKernelClientWithSponsorshipValidation(_a) {
|
|
248
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
249
|
-
if (chainId && this.providerMap[chainId]) {
|
|
250
|
-
return this.providerMap[chainId].kernelClientWithSponsorship;
|
|
251
|
-
}
|
|
252
|
-
const { eoaConnector } = this;
|
|
253
|
-
if (!eoaConnector)
|
|
254
|
-
throw new utils.DynamicError('No EOA connector');
|
|
255
|
-
const kernelClientWithSponsorship = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
|
|
256
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
257
|
-
chain: ethereumCore.chainsMap[chainId],
|
|
258
|
-
ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
|
|
259
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
260
|
-
entryPoint: this.entryPoint,
|
|
261
|
-
kernelVersion: this.kernelVersion,
|
|
262
|
-
paymaster: 'SPONSOR',
|
|
263
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
264
|
-
projectId,
|
|
265
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
266
|
-
signer,
|
|
267
|
-
});
|
|
268
|
-
utils.wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
269
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
270
|
-
return original(...args);
|
|
271
|
-
});
|
|
272
|
-
return kernelClientWithSponsorship;
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
295
|
getAddress() {
|
|
276
296
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
277
297
|
var _a, _b, _c;
|
|
298
|
+
if (this.isEip7702Mode) {
|
|
299
|
+
return this.eoaAddress;
|
|
300
|
+
}
|
|
278
301
|
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
279
302
|
return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
|
|
280
303
|
});
|
|
@@ -290,9 +313,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
290
313
|
}
|
|
291
314
|
getNetwork() {
|
|
292
315
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
|
|
294
|
-
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
295
|
-
return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.chain) === null || _c === void 0 ? void 0 : _c.id;
|
|
316
|
+
return Number(this.lastUsedChainId);
|
|
296
317
|
});
|
|
297
318
|
}
|
|
298
319
|
getTransport(provider) {
|
|
@@ -512,6 +533,14 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
512
533
|
}
|
|
513
534
|
validateActiveWallet(expectedAddress) {
|
|
514
535
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
536
|
+
if (this.isEip7702Mode) {
|
|
537
|
+
const currentAddress = yield this.getAddress();
|
|
538
|
+
if (currentAddress !== expectedAddress) {
|
|
539
|
+
throw new utils.DynamicError('Invalid active wallet');
|
|
540
|
+
}
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
// Existing implementation for regular ZeroDev
|
|
515
544
|
const eoa = this.eoaConnectorMap[expectedAddress];
|
|
516
545
|
if (!eoa) {
|
|
517
546
|
throw new utils.DynamicError('No EOA connector');
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
2
2
|
import { SmartAccount, EntryPointVersion } from 'viem/account-abstraction';
|
|
3
3
|
import { Account, Client, PublicClient, RpcSchema, Transport, WalletClient } from 'viem';
|
|
4
|
+
import { SignAuthorizationReturnType } from 'viem/accounts';
|
|
4
5
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
5
6
|
import { EntryPointType, KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
6
7
|
import { EthereumWallet } from '@dynamic-labs/ethereum-core';
|
|
7
8
|
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders } from '@dynamic-labs/sdk-api-core';
|
|
8
9
|
import { Chain, IZeroDevConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
9
10
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
10
|
-
import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
11
|
+
import { EvmNetwork, GenericNetwork, IUITransaction, TransactionReceipt, WalletUiUtils } from '@dynamic-labs/types';
|
|
11
12
|
import { BundlerProvider } from './utils';
|
|
12
13
|
type ZeroDevConnectorProps = {
|
|
13
14
|
apiProviders: {
|
|
@@ -17,6 +18,8 @@ type ZeroDevConnectorProps = {
|
|
|
17
18
|
walletBook: WalletBookSchema;
|
|
18
19
|
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
19
20
|
bundlerProvider: BundlerProvider | undefined;
|
|
21
|
+
isEip7702?: boolean;
|
|
22
|
+
authorization?: SignAuthorizationReturnType;
|
|
20
23
|
};
|
|
21
24
|
type KernelClient = KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>;
|
|
22
25
|
export declare class ZeroDevConnector extends WalletConnectorBase<typeof EthereumWallet> implements IZeroDevConnector {
|
|
@@ -55,8 +58,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
55
58
|
};
|
|
56
59
|
name: string;
|
|
57
60
|
};
|
|
61
|
+
isEip7702Mode: boolean;
|
|
58
62
|
private _walletUiUtils;
|
|
63
|
+
private authorization?;
|
|
59
64
|
constructor(opts: ZeroDevConnectorProps);
|
|
65
|
+
confirmTransactionStatus?(txHash: string): Promise<TransactionReceipt>;
|
|
60
66
|
get currentNetworkProvider(): {
|
|
61
67
|
kernelClient: KernelClient;
|
|
62
68
|
kernelClientWithSponsorship: KernelClient;
|
|
@@ -77,7 +83,7 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
77
83
|
withSponsorship?: boolean;
|
|
78
84
|
}): KernelClient | undefined;
|
|
79
85
|
endSession(): Promise<void>;
|
|
80
|
-
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector,
|
|
86
|
+
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ...properties }: {
|
|
81
87
|
smartWalletAddress: string;
|
|
82
88
|
eoaAddress: string;
|
|
83
89
|
eoaConnector: InternalWalletConnector;
|
|
@@ -85,13 +91,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
85
91
|
ecdsaProviderType?: EcdsaValidatorOptions;
|
|
86
92
|
kernelVersion?: ProviderKernelVersionEnum;
|
|
87
93
|
entryPointVersion?: ProviderEntryPointVersionEnum;
|
|
88
|
-
enableKernelV3Migration?: boolean;
|
|
89
94
|
}): Promise<void>;
|
|
90
95
|
private setEoaConnector;
|
|
91
96
|
private warnIfProjectChainNotEnabled;
|
|
92
97
|
private generateProviderMap;
|
|
93
|
-
private
|
|
94
|
-
private getKernelClientWithSponsorshipValidation;
|
|
98
|
+
private createKernelClient;
|
|
95
99
|
getAddress(): Promise<string | undefined>;
|
|
96
100
|
getConnectedAccounts(): Promise<string[]>;
|
|
97
101
|
getNetwork(): Promise<number | undefined>;
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { __awaiter, __rest } from '../_virtual/_tslib.js';
|
|
3
3
|
import { publicActions, custom, createWalletClient, toHex, formatEther } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
|
-
import { getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
5
|
+
import { KERNEL_7702_DELEGATION_ADDRESS, getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
6
|
+
import { odysseyTestnet } from 'viem/chains';
|
|
6
7
|
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
-
import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
|
|
8
|
-
import { parseEvmNetworks, StorageService, DeferredPromise,
|
|
8
|
+
import { WalletConnectorBase, eventListenerHandlers, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
9
|
+
import { parseEvmNetworks, StorageService, DeferredPromise, DynamicError, parseChainId, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
9
10
|
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
10
11
|
import { logger } from './utils/logger.js';
|
|
11
|
-
import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
12
|
+
import { createEcdsaKernelAccountClientWith7702, createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
12
13
|
import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
13
14
|
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
14
15
|
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
15
16
|
|
|
16
17
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
17
18
|
constructor(opts) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
20
|
super(opts);
|
|
20
21
|
// provider map maintains the kernel clients per chain
|
|
21
22
|
this.providerMap = {};
|
|
@@ -36,22 +37,27 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
36
37
|
},
|
|
37
38
|
name: 'ZeroDev',
|
|
38
39
|
};
|
|
40
|
+
this.isEip7702Mode = (_a = opts.isEip7702) !== null && _a !== void 0 ? _a : true; // hack
|
|
39
41
|
this._walletUiUtils = opts.walletUiUtils;
|
|
40
42
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
|
|
41
|
-
this.entryPoint = getEntryPoint((
|
|
42
|
-
this.kernelVersion = getKernelVersion((
|
|
43
|
+
this.entryPoint = getEntryPoint((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion);
|
|
44
|
+
this.kernelVersion = getKernelVersion((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.kernelVersion, this.entryPoint);
|
|
43
45
|
this.enableKernelV3Migration =
|
|
44
|
-
(
|
|
46
|
+
(_e = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.enableKernelV3Migration) !== null && _e !== void 0 ? _e : false;
|
|
45
47
|
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
46
48
|
this.providersFromApi =
|
|
47
|
-
((
|
|
49
|
+
((_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.multichainAccountAbstractionProviders) || [];
|
|
48
50
|
const [defaultProvider] = this.providersFromApi;
|
|
49
51
|
this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
|
|
50
52
|
if (!this.clientId) {
|
|
51
53
|
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
52
54
|
}
|
|
53
55
|
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
54
|
-
this.ecdsaProviderType = (
|
|
56
|
+
this.ecdsaProviderType = (_g = opts.apiProviders.zerodev) === null || _g === void 0 ? void 0 : _g.ecdsaProviderType;
|
|
57
|
+
}
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
|
+
confirmTransactionStatus(txHash) {
|
|
60
|
+
throw new Error('Method not implemented.');
|
|
55
61
|
}
|
|
56
62
|
get currentNetworkProvider() {
|
|
57
63
|
// check if the last used chain id is in the provider map
|
|
@@ -116,31 +122,39 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
116
122
|
});
|
|
117
123
|
}
|
|
118
124
|
registerEoa(_a) {
|
|
119
|
-
return __awaiter(this,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.eoaConnectorMap[smartWalletAddress] = {
|
|
127
|
-
eoaAddress,
|
|
128
|
-
eoaConnector,
|
|
129
|
-
properties,
|
|
130
|
-
};
|
|
131
|
-
// if this is the primary wallet, set the eoa connector and kernel clients
|
|
132
|
-
if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = __rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
|
|
127
|
+
if (this.isEip7702Mode) {
|
|
128
|
+
// In EIP-7702, addresses must match
|
|
129
|
+
if (smartWalletAddress !== eoaAddress) {
|
|
130
|
+
throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
|
|
131
|
+
}
|
|
133
132
|
yield this.setEoaConnector({
|
|
134
133
|
connector: eoaConnector,
|
|
135
134
|
eoaAddress,
|
|
136
135
|
properties,
|
|
137
136
|
});
|
|
138
137
|
}
|
|
138
|
+
else {
|
|
139
|
+
// Existing implementation for regular ZeroDev
|
|
140
|
+
this.eoaConnectorMap[smartWalletAddress] = {
|
|
141
|
+
eoaAddress,
|
|
142
|
+
eoaConnector,
|
|
143
|
+
properties,
|
|
144
|
+
};
|
|
145
|
+
if (shouldSetEoaConnector) {
|
|
146
|
+
yield this.setEoaConnector({
|
|
147
|
+
connector: eoaConnector,
|
|
148
|
+
eoaAddress,
|
|
149
|
+
properties,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
139
153
|
});
|
|
140
154
|
}
|
|
141
155
|
setEoaConnector(_a) {
|
|
142
156
|
return __awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
143
|
-
var _b, _c;
|
|
157
|
+
var _b, _c, _d;
|
|
144
158
|
if (!connector) {
|
|
145
159
|
logger.error('No EOA connector provided');
|
|
146
160
|
return;
|
|
@@ -166,6 +180,18 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
166
180
|
}
|
|
167
181
|
const signer = yield this.eoaConnector.getSigner();
|
|
168
182
|
signer.account = toAccount(eoaAddress);
|
|
183
|
+
if (!this.eoaConnector)
|
|
184
|
+
throw new DynamicError('No EOA connector');
|
|
185
|
+
yield this.eoaConnector.switchNetwork({
|
|
186
|
+
networkChainId: odysseyTestnet.id,
|
|
187
|
+
});
|
|
188
|
+
if (!isTurnkeyWalletConnector(this.eoaConnector)) {
|
|
189
|
+
throw new DynamicError('No EOA connector');
|
|
190
|
+
}
|
|
191
|
+
const authorization = yield ((_d = this.eoaConnector) === null || _d === void 0 ? void 0 : _d.experimental_signAuthorization({
|
|
192
|
+
contractAddress: KERNEL_7702_DELEGATION_ADDRESS,
|
|
193
|
+
})); // add to localstorage, remove on logout
|
|
194
|
+
this.authorization = authorization;
|
|
169
195
|
yield this.generateProviderMap(signer);
|
|
170
196
|
this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
|
|
171
197
|
this.kernelClientDeferredPromise.resolve();
|
|
@@ -192,13 +218,15 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
192
218
|
yield Promise.all(this.providersFromApi.map((provider) => __awaiter(this, void 0, void 0, function* () {
|
|
193
219
|
if (!this.providerMap[provider.chain]) {
|
|
194
220
|
const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
|
|
195
|
-
this.
|
|
221
|
+
this.createKernelClient({
|
|
196
222
|
chainId: provider.chain,
|
|
223
|
+
paymaster: 'NONE',
|
|
197
224
|
projectId: provider.clientId,
|
|
198
225
|
signer,
|
|
199
226
|
}),
|
|
200
|
-
this.
|
|
227
|
+
this.createKernelClient({
|
|
201
228
|
chainId: provider.chain,
|
|
229
|
+
paymaster: 'SPONSOR',
|
|
202
230
|
projectId: provider.clientId,
|
|
203
231
|
signer,
|
|
204
232
|
}),
|
|
@@ -212,27 +240,47 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
212
240
|
})));
|
|
213
241
|
});
|
|
214
242
|
}
|
|
215
|
-
|
|
216
|
-
return __awaiter(this, arguments, void 0, function* ({ projectId, signer,
|
|
243
|
+
createKernelClient(_a) {
|
|
244
|
+
return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
|
|
217
245
|
if (chainId && this.providerMap[chainId]) {
|
|
218
246
|
return this.providerMap[chainId].kernelClient;
|
|
219
247
|
}
|
|
220
248
|
const { eoaConnector } = this;
|
|
221
249
|
if (!eoaConnector)
|
|
222
250
|
throw new DynamicError('No EOA connector');
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
251
|
+
const chain = chainsMap[chainId];
|
|
252
|
+
let kernelClient;
|
|
253
|
+
if (this.isEip7702Mode && this.authorization) {
|
|
254
|
+
kernelClient = yield createEcdsaKernelAccountClientWith7702({
|
|
255
|
+
authorization: this.authorization,
|
|
256
|
+
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
257
|
+
chain,
|
|
258
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
259
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
260
|
+
entryPoint: this.entryPoint,
|
|
261
|
+
kernelVersion: this.kernelVersion,
|
|
262
|
+
paymaster,
|
|
263
|
+
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
264
|
+
projectId,
|
|
265
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
266
|
+
signer,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
kernelClient = yield createEcdsaKernelAccountClient({
|
|
271
|
+
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
272
|
+
chain,
|
|
273
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
274
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
275
|
+
entryPoint: this.entryPoint,
|
|
276
|
+
kernelVersion: this.kernelVersion,
|
|
277
|
+
paymaster,
|
|
278
|
+
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
279
|
+
projectId,
|
|
280
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
281
|
+
signer,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
236
284
|
wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
237
285
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
238
286
|
return original(...args);
|
|
@@ -240,37 +288,12 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
240
288
|
return kernelClient;
|
|
241
289
|
});
|
|
242
290
|
}
|
|
243
|
-
getKernelClientWithSponsorshipValidation(_a) {
|
|
244
|
-
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
245
|
-
if (chainId && this.providerMap[chainId]) {
|
|
246
|
-
return this.providerMap[chainId].kernelClientWithSponsorship;
|
|
247
|
-
}
|
|
248
|
-
const { eoaConnector } = this;
|
|
249
|
-
if (!eoaConnector)
|
|
250
|
-
throw new DynamicError('No EOA connector');
|
|
251
|
-
const kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
252
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
253
|
-
chain: chainsMap[chainId],
|
|
254
|
-
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
255
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
256
|
-
entryPoint: this.entryPoint,
|
|
257
|
-
kernelVersion: this.kernelVersion,
|
|
258
|
-
paymaster: 'SPONSOR',
|
|
259
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
260
|
-
projectId,
|
|
261
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
262
|
-
signer,
|
|
263
|
-
});
|
|
264
|
-
wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
265
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
266
|
-
return original(...args);
|
|
267
|
-
});
|
|
268
|
-
return kernelClientWithSponsorship;
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
291
|
getAddress() {
|
|
272
292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
273
293
|
var _a, _b, _c;
|
|
294
|
+
if (this.isEip7702Mode) {
|
|
295
|
+
return this.eoaAddress;
|
|
296
|
+
}
|
|
274
297
|
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
275
298
|
return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
|
|
276
299
|
});
|
|
@@ -286,9 +309,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
286
309
|
}
|
|
287
310
|
getNetwork() {
|
|
288
311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
|
|
290
|
-
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
291
|
-
return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.chain) === null || _c === void 0 ? void 0 : _c.id;
|
|
312
|
+
return Number(this.lastUsedChainId);
|
|
292
313
|
});
|
|
293
314
|
}
|
|
294
315
|
getTransport(provider) {
|
|
@@ -508,6 +529,14 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
508
529
|
}
|
|
509
530
|
validateActiveWallet(expectedAddress) {
|
|
510
531
|
return __awaiter(this, void 0, void 0, function* () {
|
|
532
|
+
if (this.isEip7702Mode) {
|
|
533
|
+
const currentAddress = yield this.getAddress();
|
|
534
|
+
if (currentAddress !== expectedAddress) {
|
|
535
|
+
throw new DynamicError('Invalid active wallet');
|
|
536
|
+
}
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
// Existing implementation for regular ZeroDev
|
|
511
540
|
const eoa = this.eoaConnectorMap[expectedAddress];
|
|
512
541
|
if (!eoa) {
|
|
513
542
|
throw new DynamicError('No EOA connector');
|
|
@@ -26,13 +26,53 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
|
26
26
|
return rpc;
|
|
27
27
|
};
|
|
28
28
|
const isERC20 = (value) => viem.isAddress(value);
|
|
29
|
-
const
|
|
30
|
-
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
31
|
-
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
29
|
+
const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain) => {
|
|
32
30
|
const publicClient = viem.createPublicClient({
|
|
33
31
|
chain,
|
|
34
|
-
transport: viem.http(
|
|
32
|
+
transport: viem.http(bundlerRpc),
|
|
33
|
+
});
|
|
34
|
+
const zerodevPaymaster = clients.createZeroDevPaymasterClient({
|
|
35
|
+
chain,
|
|
36
|
+
transport: viem.http(paymasterRpc),
|
|
35
37
|
});
|
|
38
|
+
return { publicClient, zerodevPaymaster };
|
|
39
|
+
};
|
|
40
|
+
const createPaymasterHandler = (paymaster, zerodevPaymaster) => {
|
|
41
|
+
if (paymaster === 'NONE')
|
|
42
|
+
return undefined;
|
|
43
|
+
return {
|
|
44
|
+
getPaymasterData: (userOperation) => {
|
|
45
|
+
const _userOperation = userOperation;
|
|
46
|
+
if (isERC20(paymaster)) {
|
|
47
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
48
|
+
gasToken: paymaster,
|
|
49
|
+
userOperation: _userOperation,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
console.log('sponsoring user operation');
|
|
53
|
+
console.log(_userOperation);
|
|
54
|
+
console.log(zerodevPaymaster);
|
|
55
|
+
console.log(paymaster);
|
|
56
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
57
|
+
userOperation: _userOperation,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const createKernelClientConfig = (account, bundlerRpc, chain, publicClient, paymaster) => ({
|
|
63
|
+
account,
|
|
64
|
+
bundlerTransport: viem.http(bundlerRpc),
|
|
65
|
+
chain,
|
|
66
|
+
client: publicClient,
|
|
67
|
+
paymaster,
|
|
68
|
+
userOperation: {
|
|
69
|
+
estimateFeesPerGas: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator: ecdsaValidator$1, enableKernelV3Migration, }) {
|
|
73
|
+
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
74
|
+
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
75
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
36
76
|
const validator = yield ecdsaValidator$1(publicClient, {
|
|
37
77
|
entryPoint,
|
|
38
78
|
kernelVersion,
|
|
@@ -40,16 +80,11 @@ const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], vo
|
|
|
40
80
|
});
|
|
41
81
|
const account = yield accounts.createKernelAccount(publicClient, {
|
|
42
82
|
entryPoint,
|
|
43
|
-
index,
|
|
44
83
|
kernelVersion,
|
|
45
84
|
plugins: {
|
|
46
85
|
sudo: validator,
|
|
47
86
|
},
|
|
48
87
|
});
|
|
49
|
-
const zerodevPaymaster = clients.createZeroDevPaymasterClient({
|
|
50
|
-
chain,
|
|
51
|
-
transport: viem.http(resolvedPaymasterRpc),
|
|
52
|
-
});
|
|
53
88
|
let selectedAccount = account;
|
|
54
89
|
if (enableKernelV3Migration) {
|
|
55
90
|
const migrationVersion = constants.KERNEL_V3_1;
|
|
@@ -62,34 +97,34 @@ const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], vo
|
|
|
62
97
|
signer,
|
|
63
98
|
});
|
|
64
99
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
: undefined,
|
|
86
|
-
userOperation: {
|
|
87
|
-
estimateFeesPerGas: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
|
|
100
|
+
const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
|
|
101
|
+
const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
102
|
+
return clients.createKernelAccountClient(clientConfig);
|
|
103
|
+
});
|
|
104
|
+
const createEcdsaKernelAccountClientWith7702 = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
|
|
105
|
+
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
106
|
+
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
107
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
108
|
+
const validator = yield ecdsaValidator(publicClient, {
|
|
109
|
+
entryPoint,
|
|
110
|
+
kernelVersion,
|
|
111
|
+
signer,
|
|
112
|
+
});
|
|
113
|
+
const account = yield accounts.createKernelAccount(publicClient, {
|
|
114
|
+
address: signer.account.address,
|
|
115
|
+
eip7702Auth: authorization,
|
|
116
|
+
entryPoint,
|
|
117
|
+
kernelVersion,
|
|
118
|
+
plugins: {
|
|
119
|
+
sudo: validator,
|
|
88
120
|
},
|
|
89
121
|
});
|
|
90
|
-
|
|
122
|
+
const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
|
|
123
|
+
const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
124
|
+
return clients.createKernelAccountClient(clientConfig);
|
|
91
125
|
});
|
|
92
126
|
|
|
93
127
|
exports.createEcdsaKernelAccountClient = createEcdsaKernelAccountClient;
|
|
128
|
+
exports.createEcdsaKernelAccountClientWith7702 = createEcdsaKernelAccountClientWith7702;
|
|
94
129
|
exports.getZeroDevBundlerRPC = getZeroDevBundlerRPC;
|
|
95
130
|
exports.getZeroDevPaymasterRPC = getZeroDevPaymasterRPC;
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { SmartAccount, EntryPointVersion } from 'viem/account-abstraction';
|
|
2
2
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
3
3
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
4
|
-
import { Address, WalletClient, Account, type Client, type RpcSchema, type Transport } from 'viem';
|
|
4
|
+
import { Address, WalletClient, Account, type Chain, type Client, type RpcSchema, type Transport } from 'viem';
|
|
5
5
|
import { EntryPointType, GetKernelVersion } from '@zerodev/sdk/types';
|
|
6
|
+
import { SignAuthorizationReturnType } from 'viem/experimental';
|
|
6
7
|
export type BundlerProvider = 'STACKUP' | 'PIMLICO' | 'ALCHEMY' | 'GELATO';
|
|
7
8
|
export type ERC20Paymaster = Address;
|
|
8
9
|
export type PaymasterType = 'NONE' | 'SPONSOR' | ERC20Paymaster;
|
|
9
10
|
export declare const getZeroDevBundlerRPC: (projectId: string, provider?: BundlerProvider) => string;
|
|
10
11
|
export declare const getZeroDevPaymasterRPC: (projectId: string, provider?: BundlerProvider) => string;
|
|
11
|
-
|
|
12
|
-
bundlerRpc?: string
|
|
12
|
+
type CommonClientParams<TChain extends Chain | undefined = Chain | undefined> = {
|
|
13
|
+
bundlerRpc?: string;
|
|
13
14
|
chain: TChain;
|
|
14
15
|
projectId: string;
|
|
15
16
|
signer: WalletClient<Transport, ViemChain, Account>;
|
|
16
17
|
paymaster: PaymasterType;
|
|
17
|
-
paymasterRpc?: string
|
|
18
|
-
entryPoint: EntryPointType<
|
|
19
|
-
provider?: BundlerProvider
|
|
20
|
-
|
|
21
|
-
kernelVersion: GetKernelVersion<entryPoint>;
|
|
18
|
+
paymasterRpc?: string;
|
|
19
|
+
entryPoint: EntryPointType<EntryPointVersion>;
|
|
20
|
+
provider?: BundlerProvider;
|
|
21
|
+
kernelVersion: GetKernelVersion<EntryPointVersion>;
|
|
22
22
|
ecdsaValidator: any;
|
|
23
23
|
enableKernelV3Migration: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster, entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }: CommonClientParams<TChain>) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
26
|
+
export declare const createEcdsaKernelAccountClientWith7702: <TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster, entryPoint, kernelVersion, ecdsaValidator, }: CommonClientParams<TChain> & {
|
|
27
|
+
authorization: SignAuthorizationReturnType;
|
|
24
28
|
}) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
29
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { createKernelAccount } from '@zerodev/sdk/accounts';
|
|
4
|
-
import {
|
|
4
|
+
import { createKernelAccountClient, createZeroDevPaymasterClient } from '@zerodev/sdk/clients';
|
|
5
5
|
import { getUserOperationGasPrice } from '@zerodev/sdk/actions';
|
|
6
6
|
import { createPublicClient, http, isAddress } from 'viem';
|
|
7
7
|
import { createEcdsaKernelMigrationAccount } from '@zerodev/ecdsa-validator';
|
|
@@ -22,13 +22,53 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
|
22
22
|
return rpc;
|
|
23
23
|
};
|
|
24
24
|
const isERC20 = (value) => isAddress(value);
|
|
25
|
-
const
|
|
26
|
-
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
27
|
-
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
25
|
+
const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain) => {
|
|
28
26
|
const publicClient = createPublicClient({
|
|
29
27
|
chain,
|
|
30
|
-
transport: http(
|
|
28
|
+
transport: http(bundlerRpc),
|
|
29
|
+
});
|
|
30
|
+
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
31
|
+
chain,
|
|
32
|
+
transport: http(paymasterRpc),
|
|
31
33
|
});
|
|
34
|
+
return { publicClient, zerodevPaymaster };
|
|
35
|
+
};
|
|
36
|
+
const createPaymasterHandler = (paymaster, zerodevPaymaster) => {
|
|
37
|
+
if (paymaster === 'NONE')
|
|
38
|
+
return undefined;
|
|
39
|
+
return {
|
|
40
|
+
getPaymasterData: (userOperation) => {
|
|
41
|
+
const _userOperation = userOperation;
|
|
42
|
+
if (isERC20(paymaster)) {
|
|
43
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
44
|
+
gasToken: paymaster,
|
|
45
|
+
userOperation: _userOperation,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
console.log('sponsoring user operation');
|
|
49
|
+
console.log(_userOperation);
|
|
50
|
+
console.log(zerodevPaymaster);
|
|
51
|
+
console.log(paymaster);
|
|
52
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
53
|
+
userOperation: _userOperation,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const createKernelClientConfig = (account, bundlerRpc, chain, publicClient, paymaster) => ({
|
|
59
|
+
account,
|
|
60
|
+
bundlerTransport: http(bundlerRpc),
|
|
61
|
+
chain,
|
|
62
|
+
client: publicClient,
|
|
63
|
+
paymaster,
|
|
64
|
+
userOperation: {
|
|
65
|
+
estimateFeesPerGas: (_a) => __awaiter(void 0, [_a], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }) {
|
|
69
|
+
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
70
|
+
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
71
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
32
72
|
const validator = yield ecdsaValidator(publicClient, {
|
|
33
73
|
entryPoint,
|
|
34
74
|
kernelVersion,
|
|
@@ -36,16 +76,11 @@ const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, f
|
|
|
36
76
|
});
|
|
37
77
|
const account = yield createKernelAccount(publicClient, {
|
|
38
78
|
entryPoint,
|
|
39
|
-
index,
|
|
40
79
|
kernelVersion,
|
|
41
80
|
plugins: {
|
|
42
81
|
sudo: validator,
|
|
43
82
|
},
|
|
44
83
|
});
|
|
45
|
-
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
46
|
-
chain,
|
|
47
|
-
transport: http(resolvedPaymasterRpc),
|
|
48
|
-
});
|
|
49
84
|
let selectedAccount = account;
|
|
50
85
|
if (enableKernelV3Migration) {
|
|
51
86
|
const migrationVersion = KERNEL_V3_1;
|
|
@@ -58,32 +93,31 @@ const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, f
|
|
|
58
93
|
signer,
|
|
59
94
|
});
|
|
60
95
|
}
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
: undefined,
|
|
82
|
-
userOperation: {
|
|
83
|
-
estimateFeesPerGas: (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
|
|
96
|
+
const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
|
|
97
|
+
const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
98
|
+
return createKernelAccountClient(clientConfig);
|
|
99
|
+
});
|
|
100
|
+
const createEcdsaKernelAccountClientWith7702 = (_c) => __awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
|
|
101
|
+
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
102
|
+
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
103
|
+
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
|
|
104
|
+
const validator = yield ecdsaValidator(publicClient, {
|
|
105
|
+
entryPoint,
|
|
106
|
+
kernelVersion,
|
|
107
|
+
signer,
|
|
108
|
+
});
|
|
109
|
+
const account = yield createKernelAccount(publicClient, {
|
|
110
|
+
address: signer.account.address,
|
|
111
|
+
eip7702Auth: authorization,
|
|
112
|
+
entryPoint,
|
|
113
|
+
kernelVersion,
|
|
114
|
+
plugins: {
|
|
115
|
+
sudo: validator,
|
|
84
116
|
},
|
|
85
117
|
});
|
|
86
|
-
|
|
118
|
+
const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
|
|
119
|
+
const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
120
|
+
return createKernelAccountClient(clientConfig);
|
|
87
121
|
});
|
|
88
122
|
|
|
89
|
-
export { createEcdsaKernelAccountClient, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };
|
|
123
|
+
export { createEcdsaKernelAccountClient, createEcdsaKernelAccountClientWith7702, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };
|