@dynamic-labs/ethereum-aa 4.4.1 → 4.4.2-preview.1

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 CHANGED
@@ -1,4 +1,25 @@
1
1
 
2
+ ### [4.4.2-preview.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.2...v4.4.2-preview.1) (2025-01-30)
3
+
4
+
5
+ ### Features
6
+
7
+ * add support for 7702 on ZeroDevConnector ([144e99a](https://github.com/dynamic-labs/dynamic-auth/commit/144e99a673abbe4c775ec2124375925e96f76071))
8
+ * implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([9622d1e](https://github.com/dynamic-labs/dynamic-auth/commit/9622d1e0e42bb3401fffbdda7b735db1736717ce))
9
+ * implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([7f367b8](https://github.com/dynamic-labs/dynamic-auth/commit/7f367b8bc9d6a0ece0268867bf9c7754d75d7949))
10
+ * implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([2019c4c](https://github.com/dynamic-labs/dynamic-auth/commit/2019c4cb89e4a042dc1c896a71b803db572e1842))
11
+ * override kernel address and add auth to localstorage ([1074ebc](https://github.com/dynamic-labs/dynamic-auth/commit/1074ebc0f3eca26fb868fd7acc9e3ac7c1048007))
12
+
13
+ ### [4.4.2-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.1...v4.4.2-preview.0) (2025-01-28)
14
+
15
+
16
+ ### Features
17
+
18
+ * add support for 7702 on ZeroDevConnector ([a8c850a](https://github.com/dynamic-labs/dynamic-auth/commit/a8c850ab192d6113ad55a01a594d5d90ab0fbfa6))
19
+ * 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))
20
+ * 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))
21
+ * 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))
22
+
2
23
  ### [4.4.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.0...v4.4.1) (2025-01-27)
3
24
 
4
25
 
@@ -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;
@@ -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
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.4.1";
6
+ var version = "4.4.2-preview.1";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.4.1";
2
+ var version = "4.4.2-preview.1";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa",
3
- "version": "4.4.1",
3
+ "version": "4.4.2-preview.1",
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.1",
26
- "@dynamic-labs/ethereum-core": "4.4.1",
27
- "@dynamic-labs/logger": "4.4.1",
28
- "@dynamic-labs/types": "4.4.1",
29
- "@dynamic-labs/utils": "4.4.1",
30
- "@dynamic-labs/wallet-book": "4.4.1",
31
- "@dynamic-labs/wallet-connector-core": "4.4.1"
25
+ "@dynamic-labs/assert-package-version": "4.4.2-preview.1",
26
+ "@dynamic-labs/ethereum-core": "4.4.2-preview.1",
27
+ "@dynamic-labs/logger": "4.4.2-preview.1",
28
+ "@dynamic-labs/types": "4.4.2-preview.1",
29
+ "@dynamic-labs/utils": "4.4.2-preview.1",
30
+ "@dynamic-labs/wallet-book": "4.4.2-preview.1",
31
+ "@dynamic-labs/wallet-connector-core": "4.4.2-preview.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "viem": "^2.21.55"
@@ -40,6 +40,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
40
40
  },
41
41
  name: 'ZeroDev',
42
42
  };
43
+ this.isEip7702Mode = true; //opts.apiProviders.zerodev?.isEip7702 ?? false;
43
44
  this._walletUiUtils = opts.walletUiUtils;
44
45
  this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
45
46
  this.entryPoint = getEntryPoint.getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
@@ -57,6 +58,10 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
57
58
  this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
58
59
  this.ecdsaProviderType = (_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.ecdsaProviderType;
59
60
  }
61
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
+ confirmTransactionStatus(txHash) {
63
+ throw new Error('Method not implemented.');
64
+ }
60
65
  get currentNetworkProvider() {
61
66
  // check if the last used chain id is in the provider map
62
67
  if (this.providerMap[this.lastUsedChainId]) {
@@ -120,26 +125,67 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
120
125
  });
121
126
  }
122
127
  registerEoa(_a) {
123
- return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, ecdsaProviderType, kernelVersion, entryPointVersion, enableKernelV3Migration, }) {
124
- const properties = {
125
- ecdsaProviderType,
126
- enableKernelV3Migration,
127
- entryPointVersion,
128
- kernelVersion,
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) {
128
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
129
+ var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
130
+ if (this.isEip7702Mode) {
131
+ // In EIP-7702, addresses must match
132
+ if (smartWalletAddress !== eoaAddress) {
133
+ throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
134
+ }
137
135
  yield this.setEoaConnector({
138
136
  connector: eoaConnector,
139
137
  eoaAddress,
140
138
  properties,
141
139
  });
142
140
  }
141
+ else {
142
+ // Existing implementation for regular ZeroDev
143
+ this.eoaConnectorMap[smartWalletAddress] = {
144
+ eoaAddress,
145
+ eoaConnector,
146
+ properties,
147
+ };
148
+ if (shouldSetEoaConnector) {
149
+ yield this.setEoaConnector({
150
+ connector: eoaConnector,
151
+ eoaAddress,
152
+ properties,
153
+ });
154
+ }
155
+ }
156
+ });
157
+ }
158
+ getOrCreateAuthorization() {
159
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
160
+ var _a, _b;
161
+ if (!this.eoaConnector)
162
+ throw new utils.DynamicError('No EOA connector');
163
+ if (!walletConnectorCore.isTurnkeyWalletConnector(this.eoaConnector)) {
164
+ throw new utils.DynamicError('No EOA connector');
165
+ }
166
+ const ZERODEV_AUTHORIZATION = 'zerodev_authorization';
167
+ try {
168
+ const storedAuthorization = utils.StorageService.getItem(ZERODEV_AUTHORIZATION);
169
+ if (storedAuthorization) {
170
+ return storedAuthorization;
171
+ }
172
+ const authorization = yield ((_a = this.eoaConnector) === null || _a === void 0 ? void 0 : _a.experimental_signAuthorization({
173
+ contractAddress: (_b = ZeroDevConnector.kernelDelegationAddress) !== null && _b !== void 0 ? _b : constants$1.KERNEL_7702_DELEGATION_ADDRESS,
174
+ }));
175
+ if (authorization) {
176
+ const serializedAuth = Object.entries(authorization).reduce((acc, [key, value]) => {
177
+ acc[key] = typeof value === 'bigint' ? value.toString() : value;
178
+ return acc;
179
+ }, {});
180
+ utils.StorageService.setItem(ZERODEV_AUTHORIZATION, serializedAuth);
181
+ }
182
+ return authorization;
183
+ }
184
+ catch (error) {
185
+ logger.logger.error('Failed to get/set authorization:', error);
186
+ utils.StorageService.removeItem(ZERODEV_AUTHORIZATION);
187
+ return undefined;
188
+ }
143
189
  });
144
190
  }
145
191
  setEoaConnector(_a) {
@@ -170,6 +216,9 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
170
216
  }
171
217
  const signer = yield this.eoaConnector.getSigner();
172
218
  signer.account = accounts.toAccount(eoaAddress);
219
+ if (this.isEip7702Mode) {
220
+ this.authorization = yield this.getOrCreateAuthorization();
221
+ }
173
222
  yield this.generateProviderMap(signer);
174
223
  this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
175
224
  this.kernelClientDeferredPromise.resolve();
@@ -196,13 +245,15 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
196
245
  yield Promise.all(this.providersFromApi.map((provider) => _tslib.__awaiter(this, void 0, void 0, function* () {
197
246
  if (!this.providerMap[provider.chain]) {
198
247
  const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
199
- this.getKernelClientWithoutSponsorshipValidation({
248
+ this.createKernelClient({
200
249
  chainId: provider.chain,
250
+ paymaster: 'NONE',
201
251
  projectId: provider.clientId,
202
252
  signer,
203
253
  }),
204
- this.getKernelClientWithSponsorshipValidation({
254
+ this.createKernelClient({
205
255
  chainId: provider.chain,
256
+ paymaster: 'SPONSOR',
206
257
  projectId: provider.clientId,
207
258
  signer,
208
259
  }),
@@ -216,27 +267,47 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
216
267
  })));
217
268
  });
218
269
  }
219
- getKernelClientWithoutSponsorshipValidation(_a) {
220
- return _tslib.__awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
270
+ createKernelClient(_a) {
271
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
221
272
  if (chainId && this.providerMap[chainId]) {
222
273
  return this.providerMap[chainId].kernelClient;
223
274
  }
224
275
  const { eoaConnector } = this;
225
276
  if (!eoaConnector)
226
277
  throw new utils.DynamicError('No EOA connector');
227
- const kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
228
- bundlerRpc: ZeroDevConnector.bundlerRpc,
229
- chain: ethereumCore.chainsMap[chainId],
230
- ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
231
- enableKernelV3Migration: this.enableKernelV3Migration,
232
- entryPoint: this.entryPoint,
233
- kernelVersion: this.kernelVersion,
234
- paymaster: 'NONE',
235
- paymasterRpc: ZeroDevConnector.paymasterRpc,
236
- projectId,
237
- provider: ZeroDevConnector.bundlerProvider,
238
- signer,
239
- });
278
+ const chain = ethereumCore.chainsMap[chainId];
279
+ let kernelClient;
280
+ if (this.isEip7702Mode && this.authorization) {
281
+ kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClientWith7702({
282
+ authorization: this.authorization,
283
+ bundlerRpc: ZeroDevConnector.bundlerRpc,
284
+ chain,
285
+ ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
286
+ enableKernelV3Migration: this.enableKernelV3Migration,
287
+ entryPoint: this.entryPoint,
288
+ kernelVersion: this.kernelVersion,
289
+ paymaster,
290
+ paymasterRpc: ZeroDevConnector.paymasterRpc,
291
+ projectId,
292
+ provider: ZeroDevConnector.bundlerProvider,
293
+ signer,
294
+ });
295
+ }
296
+ else {
297
+ kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
298
+ bundlerRpc: ZeroDevConnector.bundlerRpc,
299
+ chain,
300
+ ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
301
+ enableKernelV3Migration: this.enableKernelV3Migration,
302
+ entryPoint: this.entryPoint,
303
+ kernelVersion: this.kernelVersion,
304
+ paymaster,
305
+ paymasterRpc: ZeroDevConnector.paymasterRpc,
306
+ projectId,
307
+ provider: ZeroDevConnector.bundlerProvider,
308
+ signer,
309
+ });
310
+ }
240
311
  utils.wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
241
312
  this._walletUiUtils.disabledConfirmationOnce();
242
313
  return original(...args);
@@ -244,37 +315,12 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
244
315
  return kernelClient;
245
316
  });
246
317
  }
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
318
  getAddress() {
276
319
  return _tslib.__awaiter(this, void 0, void 0, function* () {
277
320
  var _a, _b, _c;
321
+ if (this.isEip7702Mode) {
322
+ return this.eoaAddress;
323
+ }
278
324
  yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
279
325
  return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
280
326
  });
@@ -290,9 +336,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
290
336
  }
291
337
  getNetwork() {
292
338
  return _tslib.__awaiter(this, void 0, void 0, function* () {
293
- var _a, _b, _c;
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;
339
+ return Number(this.lastUsedChainId);
296
340
  });
297
341
  }
298
342
  getTransport(provider) {
@@ -512,6 +556,14 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
512
556
  }
513
557
  validateActiveWallet(expectedAddress) {
514
558
  return _tslib.__awaiter(this, void 0, void 0, function* () {
559
+ if (this.isEip7702Mode) {
560
+ const currentAddress = yield this.getAddress();
561
+ if (currentAddress !== expectedAddress) {
562
+ throw new utils.DynamicError('Invalid active wallet');
563
+ }
564
+ return;
565
+ }
566
+ // Existing implementation for regular ZeroDev
515
567
  const eoa = this.eoaConnectorMap[expectedAddress];
516
568
  if (!eoa) {
517
569
  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 {
@@ -40,6 +43,7 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
40
43
  static bundlerProvider: BundlerProvider | undefined;
41
44
  static bundlerRpc: string | undefined;
42
45
  static paymasterRpc: string | undefined;
46
+ static kernelDelegationAddress: `0x${string}` | undefined;
43
47
  /**
44
48
  * Deferred promise that resolves when the ZeroDev provider is set.
45
49
  * This is used to make sure that the provider is set before any other method is called.
@@ -55,8 +59,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
55
59
  };
56
60
  name: string;
57
61
  };
62
+ isEip7702Mode: boolean;
58
63
  private _walletUiUtils;
64
+ private authorization?;
59
65
  constructor(opts: ZeroDevConnectorProps);
66
+ confirmTransactionStatus?(txHash: string): Promise<TransactionReceipt>;
60
67
  get currentNetworkProvider(): {
61
68
  kernelClient: KernelClient;
62
69
  kernelClientWithSponsorship: KernelClient;
@@ -77,7 +84,7 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
77
84
  withSponsorship?: boolean;
78
85
  }): KernelClient | undefined;
79
86
  endSession(): Promise<void>;
80
- registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ecdsaProviderType, kernelVersion, entryPointVersion, enableKernelV3Migration, }: {
87
+ registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ...properties }: {
81
88
  smartWalletAddress: string;
82
89
  eoaAddress: string;
83
90
  eoaConnector: InternalWalletConnector;
@@ -85,13 +92,12 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
85
92
  ecdsaProviderType?: EcdsaValidatorOptions;
86
93
  kernelVersion?: ProviderKernelVersionEnum;
87
94
  entryPointVersion?: ProviderEntryPointVersionEnum;
88
- enableKernelV3Migration?: boolean;
89
95
  }): Promise<void>;
96
+ private getOrCreateAuthorization;
90
97
  private setEoaConnector;
91
98
  private warnIfProjectChainNotEnabled;
92
99
  private generateProviderMap;
93
- private getKernelClientWithoutSponsorshipValidation;
94
- private getKernelClientWithSponsorshipValidation;
100
+ private createKernelClient;
95
101
  getAddress(): Promise<string | undefined>;
96
102
  getConnectedAccounts(): Promise<string[]>;
97
103
  getNetwork(): Promise<number | undefined>;
@@ -1,14 +1,14 @@
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
6
  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, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
7
+ import { WalletConnectorBase, eventListenerHandlers, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
8
+ import { parseEvmNetworks, StorageService, DynamicError, DeferredPromise, parseChainId, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
9
9
  import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
10
10
  import { logger } from './utils/logger.js';
11
- import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
11
+ import { createEcdsaKernelAccountClientWith7702, createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
12
12
  import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
13
13
  import { getEntryPoint } from './utils/getEntryPoint.js';
14
14
  import { getKernelVersion } from './utils/getKernelVersion.js';
@@ -36,6 +36,7 @@ class ZeroDevConnector extends WalletConnectorBase {
36
36
  },
37
37
  name: 'ZeroDev',
38
38
  };
39
+ this.isEip7702Mode = true; //opts.apiProviders.zerodev?.isEip7702 ?? false;
39
40
  this._walletUiUtils = opts.walletUiUtils;
40
41
  this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
41
42
  this.entryPoint = getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
@@ -53,6 +54,10 @@ class ZeroDevConnector extends WalletConnectorBase {
53
54
  this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
54
55
  this.ecdsaProviderType = (_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.ecdsaProviderType;
55
56
  }
57
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
+ confirmTransactionStatus(txHash) {
59
+ throw new Error('Method not implemented.');
60
+ }
56
61
  get currentNetworkProvider() {
57
62
  // check if the last used chain id is in the provider map
58
63
  if (this.providerMap[this.lastUsedChainId]) {
@@ -116,26 +121,67 @@ class ZeroDevConnector extends WalletConnectorBase {
116
121
  });
117
122
  }
118
123
  registerEoa(_a) {
119
- return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, ecdsaProviderType, kernelVersion, entryPointVersion, enableKernelV3Migration, }) {
120
- const properties = {
121
- ecdsaProviderType,
122
- enableKernelV3Migration,
123
- entryPointVersion,
124
- kernelVersion,
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) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = __rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
126
+ if (this.isEip7702Mode) {
127
+ // In EIP-7702, addresses must match
128
+ if (smartWalletAddress !== eoaAddress) {
129
+ throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
130
+ }
133
131
  yield this.setEoaConnector({
134
132
  connector: eoaConnector,
135
133
  eoaAddress,
136
134
  properties,
137
135
  });
138
136
  }
137
+ else {
138
+ // Existing implementation for regular ZeroDev
139
+ this.eoaConnectorMap[smartWalletAddress] = {
140
+ eoaAddress,
141
+ eoaConnector,
142
+ properties,
143
+ };
144
+ if (shouldSetEoaConnector) {
145
+ yield this.setEoaConnector({
146
+ connector: eoaConnector,
147
+ eoaAddress,
148
+ properties,
149
+ });
150
+ }
151
+ }
152
+ });
153
+ }
154
+ getOrCreateAuthorization() {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ var _a, _b;
157
+ if (!this.eoaConnector)
158
+ throw new DynamicError('No EOA connector');
159
+ if (!isTurnkeyWalletConnector(this.eoaConnector)) {
160
+ throw new DynamicError('No EOA connector');
161
+ }
162
+ const ZERODEV_AUTHORIZATION = 'zerodev_authorization';
163
+ try {
164
+ const storedAuthorization = StorageService.getItem(ZERODEV_AUTHORIZATION);
165
+ if (storedAuthorization) {
166
+ return storedAuthorization;
167
+ }
168
+ const authorization = yield ((_a = this.eoaConnector) === null || _a === void 0 ? void 0 : _a.experimental_signAuthorization({
169
+ contractAddress: (_b = ZeroDevConnector.kernelDelegationAddress) !== null && _b !== void 0 ? _b : KERNEL_7702_DELEGATION_ADDRESS,
170
+ }));
171
+ if (authorization) {
172
+ const serializedAuth = Object.entries(authorization).reduce((acc, [key, value]) => {
173
+ acc[key] = typeof value === 'bigint' ? value.toString() : value;
174
+ return acc;
175
+ }, {});
176
+ StorageService.setItem(ZERODEV_AUTHORIZATION, serializedAuth);
177
+ }
178
+ return authorization;
179
+ }
180
+ catch (error) {
181
+ logger.error('Failed to get/set authorization:', error);
182
+ StorageService.removeItem(ZERODEV_AUTHORIZATION);
183
+ return undefined;
184
+ }
139
185
  });
140
186
  }
141
187
  setEoaConnector(_a) {
@@ -166,6 +212,9 @@ class ZeroDevConnector extends WalletConnectorBase {
166
212
  }
167
213
  const signer = yield this.eoaConnector.getSigner();
168
214
  signer.account = toAccount(eoaAddress);
215
+ if (this.isEip7702Mode) {
216
+ this.authorization = yield this.getOrCreateAuthorization();
217
+ }
169
218
  yield this.generateProviderMap(signer);
170
219
  this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
171
220
  this.kernelClientDeferredPromise.resolve();
@@ -192,13 +241,15 @@ class ZeroDevConnector extends WalletConnectorBase {
192
241
  yield Promise.all(this.providersFromApi.map((provider) => __awaiter(this, void 0, void 0, function* () {
193
242
  if (!this.providerMap[provider.chain]) {
194
243
  const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
195
- this.getKernelClientWithoutSponsorshipValidation({
244
+ this.createKernelClient({
196
245
  chainId: provider.chain,
246
+ paymaster: 'NONE',
197
247
  projectId: provider.clientId,
198
248
  signer,
199
249
  }),
200
- this.getKernelClientWithSponsorshipValidation({
250
+ this.createKernelClient({
201
251
  chainId: provider.chain,
252
+ paymaster: 'SPONSOR',
202
253
  projectId: provider.clientId,
203
254
  signer,
204
255
  }),
@@ -212,27 +263,47 @@ class ZeroDevConnector extends WalletConnectorBase {
212
263
  })));
213
264
  });
214
265
  }
215
- getKernelClientWithoutSponsorshipValidation(_a) {
216
- return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
266
+ createKernelClient(_a) {
267
+ return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
217
268
  if (chainId && this.providerMap[chainId]) {
218
269
  return this.providerMap[chainId].kernelClient;
219
270
  }
220
271
  const { eoaConnector } = this;
221
272
  if (!eoaConnector)
222
273
  throw new DynamicError('No EOA connector');
223
- const kernelClient = yield createEcdsaKernelAccountClient({
224
- bundlerRpc: ZeroDevConnector.bundlerRpc,
225
- chain: chainsMap[chainId],
226
- ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
227
- enableKernelV3Migration: this.enableKernelV3Migration,
228
- entryPoint: this.entryPoint,
229
- kernelVersion: this.kernelVersion,
230
- paymaster: 'NONE',
231
- paymasterRpc: ZeroDevConnector.paymasterRpc,
232
- projectId,
233
- provider: ZeroDevConnector.bundlerProvider,
234
- signer,
235
- });
274
+ const chain = chainsMap[chainId];
275
+ let kernelClient;
276
+ if (this.isEip7702Mode && this.authorization) {
277
+ kernelClient = yield createEcdsaKernelAccountClientWith7702({
278
+ authorization: this.authorization,
279
+ bundlerRpc: ZeroDevConnector.bundlerRpc,
280
+ chain,
281
+ ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
282
+ enableKernelV3Migration: this.enableKernelV3Migration,
283
+ entryPoint: this.entryPoint,
284
+ kernelVersion: this.kernelVersion,
285
+ paymaster,
286
+ paymasterRpc: ZeroDevConnector.paymasterRpc,
287
+ projectId,
288
+ provider: ZeroDevConnector.bundlerProvider,
289
+ signer,
290
+ });
291
+ }
292
+ else {
293
+ kernelClient = yield createEcdsaKernelAccountClient({
294
+ bundlerRpc: ZeroDevConnector.bundlerRpc,
295
+ chain,
296
+ ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
297
+ enableKernelV3Migration: this.enableKernelV3Migration,
298
+ entryPoint: this.entryPoint,
299
+ kernelVersion: this.kernelVersion,
300
+ paymaster,
301
+ paymasterRpc: ZeroDevConnector.paymasterRpc,
302
+ projectId,
303
+ provider: ZeroDevConnector.bundlerProvider,
304
+ signer,
305
+ });
306
+ }
236
307
  wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
237
308
  this._walletUiUtils.disabledConfirmationOnce();
238
309
  return original(...args);
@@ -240,37 +311,12 @@ class ZeroDevConnector extends WalletConnectorBase {
240
311
  return kernelClient;
241
312
  });
242
313
  }
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
314
  getAddress() {
272
315
  return __awaiter(this, void 0, void 0, function* () {
273
316
  var _a, _b, _c;
317
+ if (this.isEip7702Mode) {
318
+ return this.eoaAddress;
319
+ }
274
320
  yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
275
321
  return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
276
322
  });
@@ -286,9 +332,7 @@ class ZeroDevConnector extends WalletConnectorBase {
286
332
  }
287
333
  getNetwork() {
288
334
  return __awaiter(this, void 0, void 0, function* () {
289
- var _a, _b, _c;
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;
335
+ return Number(this.lastUsedChainId);
292
336
  });
293
337
  }
294
338
  getTransport(provider) {
@@ -508,6 +552,14 @@ class ZeroDevConnector extends WalletConnectorBase {
508
552
  }
509
553
  validateActiveWallet(expectedAddress) {
510
554
  return __awaiter(this, void 0, void 0, function* () {
555
+ if (this.isEip7702Mode) {
556
+ const currentAddress = yield this.getAddress();
557
+ if (currentAddress !== expectedAddress) {
558
+ throw new DynamicError('Invalid active wallet');
559
+ }
560
+ return;
561
+ }
562
+ // Existing implementation for regular ZeroDev
511
563
  const eoa = this.eoaConnectorMap[expectedAddress];
512
564
  if (!eoa) {
513
565
  throw new DynamicError('No EOA connector');
package/src/index.cjs CHANGED
@@ -15,10 +15,11 @@ var ethereumAa = require('./ethereum-aa.cjs');
15
15
  var isZeroDevConnector = require('./utils/isZeroDevConnector.cjs');
16
16
 
17
17
  assertPackageVersion.assertPackageVersion('@dynamic-labs/ethereum-aa', _package.version);
18
- const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, } = {}) => {
18
+ const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, kernelDelegationAddress, } = {}) => {
19
19
  ZeroDevConnector.ZeroDevConnector.bundlerProvider = bundlerProvider;
20
20
  ZeroDevConnector.ZeroDevConnector.bundlerRpc = bundlerRpc;
21
21
  ZeroDevConnector.ZeroDevConnector.paymasterRpc = paymasterRpc;
22
+ ZeroDevConnector.ZeroDevConnector.kernelDelegationAddress = kernelDelegationAddress;
22
23
  return ZeroDevSmartWalletConnectors;
23
24
  };
24
25
  const ZeroDevSmartWalletConnectors = (props) => {
package/src/index.d.ts CHANGED
@@ -7,9 +7,10 @@ export { getEntryPoint } from './utils/getEntryPoint';
7
7
  export { getKernelVersion } from './utils/getKernelVersion';
8
8
  export * from './ethereum-aa';
9
9
  export { isZeroDevConnector } from './utils/isZeroDevConnector';
10
- export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, bundlerRpc, paymasterRpc, }?: {
10
+ export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, bundlerRpc, paymasterRpc, kernelDelegationAddress, }?: {
11
11
  bundlerProvider?: BundlerProvider;
12
12
  bundlerRpc?: string;
13
13
  paymasterRpc?: string;
14
+ kernelDelegationAddress?: `0x${string}`;
14
15
  }) => (props: any) => WalletConnectorConstructor[];
15
16
  export declare const ZeroDevSmartWalletConnectors: (props: any) => WalletConnectorConstructor[];
package/src/index.js CHANGED
@@ -11,10 +11,11 @@ export { EthereumAaConnector } from './ethereum-aa.js';
11
11
  export { isZeroDevConnector } from './utils/isZeroDevConnector.js';
12
12
 
13
13
  assertPackageVersion('@dynamic-labs/ethereum-aa', version);
14
- const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, } = {}) => {
14
+ const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, kernelDelegationAddress, } = {}) => {
15
15
  ZeroDevConnector.bundlerProvider = bundlerProvider;
16
16
  ZeroDevConnector.bundlerRpc = bundlerRpc;
17
17
  ZeroDevConnector.paymasterRpc = paymasterRpc;
18
+ ZeroDevConnector.kernelDelegationAddress = kernelDelegationAddress;
18
19
  return ZeroDevSmartWalletConnectors;
19
20
  };
20
21
  const ZeroDevSmartWalletConnectors = (props) => {
@@ -26,13 +26,49 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
26
26
  return rpc;
27
27
  };
28
28
  const isERC20 = (value) => viem.isAddress(value);
29
- const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator: ecdsaValidator$1, enableKernelV3Migration, }) {
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(resolvedBundlerRpc),
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
+ return zerodevPaymaster.sponsorUserOperation({
53
+ userOperation: _userOperation,
54
+ });
55
+ },
56
+ };
57
+ };
58
+ const createKernelClientConfig = (account, bundlerRpc, chain, publicClient, paymaster) => ({
59
+ account,
60
+ bundlerTransport: viem.http(bundlerRpc),
61
+ chain,
62
+ client: publicClient,
63
+ paymaster,
64
+ userOperation: {
65
+ estimateFeesPerGas: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
66
+ },
67
+ });
68
+ 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, }) {
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);
36
72
  const validator = yield ecdsaValidator$1(publicClient, {
37
73
  entryPoint,
38
74
  kernelVersion,
@@ -40,16 +76,11 @@ const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], vo
40
76
  });
41
77
  const account = yield accounts.createKernelAccount(publicClient, {
42
78
  entryPoint,
43
- index,
44
79
  kernelVersion,
45
80
  plugins: {
46
81
  sudo: validator,
47
82
  },
48
83
  });
49
- const zerodevPaymaster = clients.createZeroDevPaymasterClient({
50
- chain,
51
- transport: viem.http(resolvedPaymasterRpc),
52
- });
53
84
  let selectedAccount = account;
54
85
  if (enableKernelV3Migration) {
55
86
  const migrationVersion = constants.KERNEL_V3_1;
@@ -62,34 +93,34 @@ const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], vo
62
93
  signer,
63
94
  });
64
95
  }
65
- const kernelClient = clients.createKernelAccountClient({
66
- account: selectedAccount,
67
- bundlerTransport: viem.http(resolvedBundlerRpc),
68
- chain,
69
- client: publicClient,
70
- paymaster: paymaster !== 'NONE'
71
- ? {
72
- getPaymasterData: (userOperation) => {
73
- const _userOperation = userOperation;
74
- if (isERC20(paymaster)) {
75
- return zerodevPaymaster.sponsorUserOperation({
76
- gasToken: paymaster,
77
- userOperation: _userOperation,
78
- });
79
- }
80
- return zerodevPaymaster.sponsorUserOperation({
81
- userOperation: _userOperation,
82
- });
83
- },
84
- }
85
- : undefined,
86
- userOperation: {
87
- estimateFeesPerGas: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
96
+ const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
97
+ const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
98
+ return clients.createKernelAccountClient(clientConfig);
99
+ });
100
+ const createEcdsaKernelAccountClientWith7702 = (_c) => _tslib.__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 accounts.createKernelAccount(publicClient, {
110
+ address: signer.account.address,
111
+ eip7702Auth: authorization,
112
+ entryPoint,
113
+ kernelVersion,
114
+ plugins: {
115
+ sudo: validator,
88
116
  },
89
117
  });
90
- return kernelClient;
118
+ const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
119
+ const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
120
+ return clients.createKernelAccountClient(clientConfig);
91
121
  });
92
122
 
93
123
  exports.createEcdsaKernelAccountClient = createEcdsaKernelAccountClient;
124
+ exports.createEcdsaKernelAccountClientWith7702 = createEcdsaKernelAccountClientWith7702;
94
125
  exports.getZeroDevBundlerRPC = getZeroDevBundlerRPC;
95
126
  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
- export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster, entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }: {
12
- bundlerRpc?: string | undefined;
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 | undefined;
18
- entryPoint: EntryPointType<entryPoint>;
19
- provider?: BundlerProvider | undefined;
20
- index?: bigint | undefined;
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 { createZeroDevPaymasterClient, createKernelAccountClient } from '@zerodev/sdk/clients';
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,49 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
22
22
  return rpc;
23
23
  };
24
24
  const isERC20 = (value) => isAddress(value);
25
- const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }) {
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(resolvedBundlerRpc),
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
+ return zerodevPaymaster.sponsorUserOperation({
49
+ userOperation: _userOperation,
50
+ });
51
+ },
52
+ };
53
+ };
54
+ const createKernelClientConfig = (account, bundlerRpc, chain, publicClient, paymaster) => ({
55
+ account,
56
+ bundlerTransport: http(bundlerRpc),
57
+ chain,
58
+ client: publicClient,
59
+ paymaster,
60
+ userOperation: {
61
+ estimateFeesPerGas: (_a) => __awaiter(void 0, [_a], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
62
+ },
63
+ });
64
+ const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, }) {
65
+ const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
66
+ const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
67
+ const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
32
68
  const validator = yield ecdsaValidator(publicClient, {
33
69
  entryPoint,
34
70
  kernelVersion,
@@ -36,16 +72,11 @@ const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, f
36
72
  });
37
73
  const account = yield createKernelAccount(publicClient, {
38
74
  entryPoint,
39
- index,
40
75
  kernelVersion,
41
76
  plugins: {
42
77
  sudo: validator,
43
78
  },
44
79
  });
45
- const zerodevPaymaster = createZeroDevPaymasterClient({
46
- chain,
47
- transport: http(resolvedPaymasterRpc),
48
- });
49
80
  let selectedAccount = account;
50
81
  if (enableKernelV3Migration) {
51
82
  const migrationVersion = KERNEL_V3_1;
@@ -58,32 +89,31 @@ const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, f
58
89
  signer,
59
90
  });
60
91
  }
61
- const kernelClient = createKernelAccountClient({
62
- account: selectedAccount,
63
- bundlerTransport: http(resolvedBundlerRpc),
64
- chain,
65
- client: publicClient,
66
- paymaster: paymaster !== 'NONE'
67
- ? {
68
- getPaymasterData: (userOperation) => {
69
- const _userOperation = userOperation;
70
- if (isERC20(paymaster)) {
71
- return zerodevPaymaster.sponsorUserOperation({
72
- gasToken: paymaster,
73
- userOperation: _userOperation,
74
- });
75
- }
76
- return zerodevPaymaster.sponsorUserOperation({
77
- userOperation: _userOperation,
78
- });
79
- },
80
- }
81
- : undefined,
82
- userOperation: {
83
- estimateFeesPerGas: (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
92
+ const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
93
+ const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
94
+ return createKernelAccountClient(clientConfig);
95
+ });
96
+ const createEcdsaKernelAccountClientWith7702 = (_c) => __awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, authorization, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
97
+ const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
98
+ const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
99
+ const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain);
100
+ const validator = yield ecdsaValidator(publicClient, {
101
+ entryPoint,
102
+ kernelVersion,
103
+ signer,
104
+ });
105
+ const account = yield createKernelAccount(publicClient, {
106
+ address: signer.account.address,
107
+ eip7702Auth: authorization,
108
+ entryPoint,
109
+ kernelVersion,
110
+ plugins: {
111
+ sudo: validator,
84
112
  },
85
113
  });
86
- return kernelClient;
114
+ const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
115
+ const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
116
+ return createKernelAccountClient(clientConfig);
87
117
  });
88
118
 
89
- export { createEcdsaKernelAccountClient, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };
119
+ export { createEcdsaKernelAccountClient, createEcdsaKernelAccountClientWith7702, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };