@dynamic-labs/ethereum-aa 4.4.2-preview.0 → 4.4.2

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,13 +1,19 @@
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)
2
+ ### [4.4.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.1...v4.4.2) (2025-01-30)
3
3
 
4
4
 
5
5
  ### Features
6
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))
7
+ * add support for Bitget BTC ([#7915](https://github.com/dynamic-labs/dynamic-auth/issues/7915)) ([3fe23f7](https://github.com/dynamic-labs/dynamic-auth/commit/3fe23f739818ef0f5d504c34f237d1d115e4f50c))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * add backpackeclipse to walletbook fallbacks ([#7932](https://github.com/dynamic-labs/dynamic-auth/issues/7932)) ([eeaa7da](https://github.com/dynamic-labs/dynamic-auth/commit/eeaa7da629cb06ffc856f2e7f99beefcb8553bbd))
13
+ * otp verified should always be true ([#7921](https://github.com/dynamic-labs/dynamic-auth/issues/7921)) ([ac884d6](https://github.com/dynamic-labs/dynamic-auth/commit/ac884d6475152778aabd72d2c923b3c0b7745b00))
14
+ * **qntm-2814:** return checksum address from coinbase and metamask ([#7927](https://github.com/dynamic-labs/dynamic-auth/issues/7927)) ([3169d4d](https://github.com/dynamic-labs/dynamic-auth/commit/3169d4dd717b840c3654d15bacb20780d515269b))
15
+ * fix: creation of embedded wallet sessions with external auth
16
+
11
17
 
12
18
  ### [4.4.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.0...v4.4.1) (2025-01-27)
13
19
 
@@ -18,18 +18,6 @@ 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
-
33
21
  function __awaiter(thisArg, _arguments, P, generator) {
34
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,4 +34,3 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
46
34
  };
47
35
 
48
36
  exports.__awaiter = __awaiter;
49
- exports.__rest = __rest;
@@ -14,18 +14,6 @@ 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
-
29
17
  function __awaiter(thisArg, _arguments, P, generator) {
30
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -41,4 +29,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
41
29
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
42
30
  };
43
31
 
44
- export { __awaiter, __rest };
32
+ export { __awaiter };
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.2-preview.0";
6
+ var version = "4.4.2";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.4.2-preview.0";
2
+ var version = "4.4.2";
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.2-preview.0",
3
+ "version": "4.4.2",
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.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"
25
+ "@dynamic-labs/assert-package-version": "4.4.2",
26
+ "@dynamic-labs/ethereum-core": "4.4.2",
27
+ "@dynamic-labs/logger": "4.4.2",
28
+ "@dynamic-labs/types": "4.4.2",
29
+ "@dynamic-labs/utils": "4.4.2",
30
+ "@dynamic-labs/wallet-book": "4.4.2",
31
+ "@dynamic-labs/wallet-connector-core": "4.4.2"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "viem": "^2.21.55"
@@ -7,7 +7,6 @@ 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');
11
10
  var ethereumCore = require('@dynamic-labs/ethereum-core');
12
11
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
13
12
  var utils = require('@dynamic-labs/utils');
@@ -20,7 +19,7 @@ var getKernelVersion = require('./utils/getKernelVersion.cjs');
20
19
 
21
20
  class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
22
21
  constructor(opts) {
23
- var _a, _b, _c, _d, _e, _f, _g;
22
+ var _a, _b, _c, _d, _e, _f;
24
23
  super(opts);
25
24
  // provider map maintains the kernel clients per chain
26
25
  this.providerMap = {};
@@ -41,27 +40,22 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
41
40
  },
42
41
  name: 'ZeroDev',
43
42
  };
44
- this.isEip7702Mode = (_a = opts.isEip7702) !== null && _a !== void 0 ? _a : true; // hack
45
43
  this._walletUiUtils = opts.walletUiUtils;
46
44
  this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
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);
45
+ this.entryPoint = getEntryPoint.getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
46
+ this.kernelVersion = getKernelVersion.getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
49
47
  this.enableKernelV3Migration =
50
- (_e = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.enableKernelV3Migration) !== null && _e !== void 0 ? _e : false;
48
+ (_d = (_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.enableKernelV3Migration) !== null && _d !== void 0 ? _d : false;
51
49
  // this is the list of providers from the api that are used for multi-chain account abstraction
52
50
  this.providersFromApi =
53
- ((_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.multichainAccountAbstractionProviders) || [];
51
+ ((_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.multichainAccountAbstractionProviders) || [];
54
52
  const [defaultProvider] = this.providersFromApi;
55
53
  this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
56
54
  if (!this.clientId) {
57
55
  throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
58
56
  }
59
57
  this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
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.');
58
+ this.ecdsaProviderType = (_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.ecdsaProviderType;
65
59
  }
66
60
  get currentNetworkProvider() {
67
61
  // check if the last used chain id is in the provider map
@@ -126,39 +120,31 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
126
120
  });
127
121
  }
128
122
  registerEoa(_a) {
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
- }
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) {
136
137
  yield this.setEoaConnector({
137
138
  connector: eoaConnector,
138
139
  eoaAddress,
139
140
  properties,
140
141
  });
141
142
  }
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
- }
157
143
  });
158
144
  }
159
145
  setEoaConnector(_a) {
160
146
  return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
161
- var _b, _c, _d;
147
+ var _b, _c;
162
148
  if (!connector) {
163
149
  logger.logger.error('No EOA connector provided');
164
150
  return;
@@ -184,18 +170,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
184
170
  }
185
171
  const signer = yield this.eoaConnector.getSigner();
186
172
  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;
199
173
  yield this.generateProviderMap(signer);
200
174
  this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
201
175
  this.kernelClientDeferredPromise.resolve();
@@ -222,15 +196,13 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
222
196
  yield Promise.all(this.providersFromApi.map((provider) => _tslib.__awaiter(this, void 0, void 0, function* () {
223
197
  if (!this.providerMap[provider.chain]) {
224
198
  const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
225
- this.createKernelClient({
199
+ this.getKernelClientWithoutSponsorshipValidation({
226
200
  chainId: provider.chain,
227
- paymaster: 'NONE',
228
201
  projectId: provider.clientId,
229
202
  signer,
230
203
  }),
231
- this.createKernelClient({
204
+ this.getKernelClientWithSponsorshipValidation({
232
205
  chainId: provider.chain,
233
- paymaster: 'SPONSOR',
234
206
  projectId: provider.clientId,
235
207
  signer,
236
208
  }),
@@ -244,47 +216,27 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
244
216
  })));
245
217
  });
246
218
  }
247
- createKernelClient(_a) {
248
- return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
219
+ getKernelClientWithoutSponsorshipValidation(_a) {
220
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
249
221
  if (chainId && this.providerMap[chainId]) {
250
222
  return this.providerMap[chainId].kernelClient;
251
223
  }
252
224
  const { eoaConnector } = this;
253
225
  if (!eoaConnector)
254
226
  throw new utils.DynamicError('No EOA connector');
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
- }
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
+ });
288
240
  utils.wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
289
241
  this._walletUiUtils.disabledConfirmationOnce();
290
242
  return original(...args);
@@ -292,12 +244,37 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
292
244
  return kernelClient;
293
245
  });
294
246
  }
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
+ }
295
275
  getAddress() {
296
276
  return _tslib.__awaiter(this, void 0, void 0, function* () {
297
277
  var _a, _b, _c;
298
- if (this.isEip7702Mode) {
299
- return this.eoaAddress;
300
- }
301
278
  yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
302
279
  return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
303
280
  });
@@ -313,7 +290,9 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
313
290
  }
314
291
  getNetwork() {
315
292
  return _tslib.__awaiter(this, void 0, void 0, function* () {
316
- return Number(this.lastUsedChainId);
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;
317
296
  });
318
297
  }
319
298
  getTransport(provider) {
@@ -533,14 +512,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
533
512
  }
534
513
  validateActiveWallet(expectedAddress) {
535
514
  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
544
515
  const eoa = this.eoaConnectorMap[expectedAddress];
545
516
  if (!eoa) {
546
517
  throw new utils.DynamicError('No EOA connector');
@@ -1,14 +1,13 @@
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';
5
4
  import { type Chain as ViemChain } from 'viem/chains';
6
5
  import { EntryPointType, KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
7
6
  import { EthereumWallet } from '@dynamic-labs/ethereum-core';
8
7
  import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders } from '@dynamic-labs/sdk-api-core';
9
8
  import { Chain, IZeroDevConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
10
9
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
11
- import { EvmNetwork, GenericNetwork, IUITransaction, TransactionReceipt, WalletUiUtils } from '@dynamic-labs/types';
10
+ import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
12
11
  import { BundlerProvider } from './utils';
13
12
  type ZeroDevConnectorProps = {
14
13
  apiProviders: {
@@ -18,8 +17,6 @@ type ZeroDevConnectorProps = {
18
17
  walletBook: WalletBookSchema;
19
18
  walletUiUtils: WalletUiUtils<InternalWalletConnector>;
20
19
  bundlerProvider: BundlerProvider | undefined;
21
- isEip7702?: boolean;
22
- authorization?: SignAuthorizationReturnType;
23
20
  };
24
21
  type KernelClient = KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>;
25
22
  export declare class ZeroDevConnector extends WalletConnectorBase<typeof EthereumWallet> implements IZeroDevConnector {
@@ -58,11 +55,8 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
58
55
  };
59
56
  name: string;
60
57
  };
61
- isEip7702Mode: boolean;
62
58
  private _walletUiUtils;
63
- private authorization?;
64
59
  constructor(opts: ZeroDevConnectorProps);
65
- confirmTransactionStatus?(txHash: string): Promise<TransactionReceipt>;
66
60
  get currentNetworkProvider(): {
67
61
  kernelClient: KernelClient;
68
62
  kernelClientWithSponsorship: KernelClient;
@@ -83,7 +77,7 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
83
77
  withSponsorship?: boolean;
84
78
  }): KernelClient | undefined;
85
79
  endSession(): Promise<void>;
86
- registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ...properties }: {
80
+ registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ecdsaProviderType, kernelVersion, entryPointVersion, enableKernelV3Migration, }: {
87
81
  smartWalletAddress: string;
88
82
  eoaAddress: string;
89
83
  eoaConnector: InternalWalletConnector;
@@ -91,11 +85,13 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
91
85
  ecdsaProviderType?: EcdsaValidatorOptions;
92
86
  kernelVersion?: ProviderKernelVersionEnum;
93
87
  entryPointVersion?: ProviderEntryPointVersionEnum;
88
+ enableKernelV3Migration?: boolean;
94
89
  }): Promise<void>;
95
90
  private setEoaConnector;
96
91
  private warnIfProjectChainNotEnabled;
97
92
  private generateProviderMap;
98
- private createKernelClient;
93
+ private getKernelClientWithoutSponsorshipValidation;
94
+ private getKernelClientWithSponsorshipValidation;
99
95
  getAddress(): Promise<string | undefined>;
100
96
  getConnectedAccounts(): Promise<string[]>;
101
97
  getNetwork(): Promise<number | undefined>;
@@ -1,22 +1,21 @@
1
1
  'use client'
2
- import { __awaiter, __rest } from '../_virtual/_tslib.js';
2
+ import { __awaiter } from '../_virtual/_tslib.js';
3
3
  import { publicActions, custom, createWalletClient, toHex, formatEther } from 'viem';
4
4
  import { toAccount } from 'viem/accounts';
5
- import { KERNEL_7702_DELEGATION_ADDRESS, getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
6
- import { odysseyTestnet } from 'viem/chains';
5
+ import { getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
7
6
  import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
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';
7
+ import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
8
+ import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
10
9
  import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
11
10
  import { logger } from './utils/logger.js';
12
- import { createEcdsaKernelAccountClientWith7702, createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
11
+ import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
13
12
  import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
14
13
  import { getEntryPoint } from './utils/getEntryPoint.js';
15
14
  import { getKernelVersion } from './utils/getKernelVersion.js';
16
15
 
17
16
  class ZeroDevConnector extends WalletConnectorBase {
18
17
  constructor(opts) {
19
- var _a, _b, _c, _d, _e, _f, _g;
18
+ var _a, _b, _c, _d, _e, _f;
20
19
  super(opts);
21
20
  // provider map maintains the kernel clients per chain
22
21
  this.providerMap = {};
@@ -37,27 +36,22 @@ class ZeroDevConnector extends WalletConnectorBase {
37
36
  },
38
37
  name: 'ZeroDev',
39
38
  };
40
- this.isEip7702Mode = (_a = opts.isEip7702) !== null && _a !== void 0 ? _a : true; // hack
41
39
  this._walletUiUtils = opts.walletUiUtils;
42
40
  this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
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);
41
+ this.entryPoint = getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
42
+ this.kernelVersion = getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
45
43
  this.enableKernelV3Migration =
46
- (_e = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.enableKernelV3Migration) !== null && _e !== void 0 ? _e : false;
44
+ (_d = (_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.enableKernelV3Migration) !== null && _d !== void 0 ? _d : false;
47
45
  // this is the list of providers from the api that are used for multi-chain account abstraction
48
46
  this.providersFromApi =
49
- ((_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.multichainAccountAbstractionProviders) || [];
47
+ ((_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.multichainAccountAbstractionProviders) || [];
50
48
  const [defaultProvider] = this.providersFromApi;
51
49
  this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
52
50
  if (!this.clientId) {
53
51
  throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
54
52
  }
55
53
  this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
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.');
54
+ this.ecdsaProviderType = (_f = opts.apiProviders.zerodev) === null || _f === void 0 ? void 0 : _f.ecdsaProviderType;
61
55
  }
62
56
  get currentNetworkProvider() {
63
57
  // check if the last used chain id is in the provider map
@@ -122,39 +116,31 @@ class ZeroDevConnector extends WalletConnectorBase {
122
116
  });
123
117
  }
124
118
  registerEoa(_a) {
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
- }
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) {
132
133
  yield this.setEoaConnector({
133
134
  connector: eoaConnector,
134
135
  eoaAddress,
135
136
  properties,
136
137
  });
137
138
  }
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
- }
153
139
  });
154
140
  }
155
141
  setEoaConnector(_a) {
156
142
  return __awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
157
- var _b, _c, _d;
143
+ var _b, _c;
158
144
  if (!connector) {
159
145
  logger.error('No EOA connector provided');
160
146
  return;
@@ -180,18 +166,6 @@ class ZeroDevConnector extends WalletConnectorBase {
180
166
  }
181
167
  const signer = yield this.eoaConnector.getSigner();
182
168
  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;
195
169
  yield this.generateProviderMap(signer);
196
170
  this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
197
171
  this.kernelClientDeferredPromise.resolve();
@@ -218,15 +192,13 @@ class ZeroDevConnector extends WalletConnectorBase {
218
192
  yield Promise.all(this.providersFromApi.map((provider) => __awaiter(this, void 0, void 0, function* () {
219
193
  if (!this.providerMap[provider.chain]) {
220
194
  const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
221
- this.createKernelClient({
195
+ this.getKernelClientWithoutSponsorshipValidation({
222
196
  chainId: provider.chain,
223
- paymaster: 'NONE',
224
197
  projectId: provider.clientId,
225
198
  signer,
226
199
  }),
227
- this.createKernelClient({
200
+ this.getKernelClientWithSponsorshipValidation({
228
201
  chainId: provider.chain,
229
- paymaster: 'SPONSOR',
230
202
  projectId: provider.clientId,
231
203
  signer,
232
204
  }),
@@ -240,47 +212,27 @@ class ZeroDevConnector extends WalletConnectorBase {
240
212
  })));
241
213
  });
242
214
  }
243
- createKernelClient(_a) {
244
- return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
215
+ getKernelClientWithoutSponsorshipValidation(_a) {
216
+ return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
245
217
  if (chainId && this.providerMap[chainId]) {
246
218
  return this.providerMap[chainId].kernelClient;
247
219
  }
248
220
  const { eoaConnector } = this;
249
221
  if (!eoaConnector)
250
222
  throw new DynamicError('No EOA connector');
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
- }
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
+ });
284
236
  wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
285
237
  this._walletUiUtils.disabledConfirmationOnce();
286
238
  return original(...args);
@@ -288,12 +240,37 @@ class ZeroDevConnector extends WalletConnectorBase {
288
240
  return kernelClient;
289
241
  });
290
242
  }
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
+ }
291
271
  getAddress() {
292
272
  return __awaiter(this, void 0, void 0, function* () {
293
273
  var _a, _b, _c;
294
- if (this.isEip7702Mode) {
295
- return this.eoaAddress;
296
- }
297
274
  yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
298
275
  return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
299
276
  });
@@ -309,7 +286,9 @@ class ZeroDevConnector extends WalletConnectorBase {
309
286
  }
310
287
  getNetwork() {
311
288
  return __awaiter(this, void 0, void 0, function* () {
312
- return Number(this.lastUsedChainId);
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;
313
292
  });
314
293
  }
315
294
  getTransport(provider) {
@@ -529,14 +508,6 @@ class ZeroDevConnector extends WalletConnectorBase {
529
508
  }
530
509
  validateActiveWallet(expectedAddress) {
531
510
  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
540
511
  const eoa = this.eoaConnectorMap[expectedAddress];
541
512
  if (!eoa) {
542
513
  throw new DynamicError('No EOA connector');
@@ -26,53 +26,13 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
26
26
  return rpc;
27
27
  };
28
28
  const isERC20 = (value) => viem.isAddress(value);
29
- const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain) => {
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);
30
32
  const publicClient = viem.createPublicClient({
31
33
  chain,
32
- transport: viem.http(bundlerRpc),
33
- });
34
- const zerodevPaymaster = clients.createZeroDevPaymasterClient({
35
- chain,
36
- transport: viem.http(paymasterRpc),
34
+ transport: viem.http(resolvedBundlerRpc),
37
35
  });
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);
76
36
  const validator = yield ecdsaValidator$1(publicClient, {
77
37
  entryPoint,
78
38
  kernelVersion,
@@ -80,11 +40,16 @@ const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], vo
80
40
  });
81
41
  const account = yield accounts.createKernelAccount(publicClient, {
82
42
  entryPoint,
43
+ index,
83
44
  kernelVersion,
84
45
  plugins: {
85
46
  sudo: validator,
86
47
  },
87
48
  });
49
+ const zerodevPaymaster = clients.createZeroDevPaymasterClient({
50
+ chain,
51
+ transport: viem.http(resolvedPaymasterRpc),
52
+ });
88
53
  let selectedAccount = account;
89
54
  if (enableKernelV3Migration) {
90
55
  const migrationVersion = constants.KERNEL_V3_1;
@@ -97,34 +62,34 @@ const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], vo
97
62
  signer,
98
63
  });
99
64
  }
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,
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); }),
120
88
  },
121
89
  });
122
- const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
123
- const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
124
- return clients.createKernelAccountClient(clientConfig);
90
+ return kernelClient;
125
91
  });
126
92
 
127
93
  exports.createEcdsaKernelAccountClient = createEcdsaKernelAccountClient;
128
- exports.createEcdsaKernelAccountClientWith7702 = createEcdsaKernelAccountClientWith7702;
129
94
  exports.getZeroDevBundlerRPC = getZeroDevBundlerRPC;
130
95
  exports.getZeroDevPaymasterRPC = getZeroDevPaymasterRPC;
@@ -1,29 +1,24 @@
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 Chain, type Client, type RpcSchema, type Transport } from 'viem';
4
+ import { Address, WalletClient, Account, type Client, type RpcSchema, type Transport } from 'viem';
5
5
  import { EntryPointType, GetKernelVersion } from '@zerodev/sdk/types';
6
- import { SignAuthorizationReturnType } from 'viem/experimental';
7
6
  export type BundlerProvider = 'STACKUP' | 'PIMLICO' | 'ALCHEMY' | 'GELATO';
8
7
  export type ERC20Paymaster = Address;
9
8
  export type PaymasterType = 'NONE' | 'SPONSOR' | ERC20Paymaster;
10
9
  export declare const getZeroDevBundlerRPC: (projectId: string, provider?: BundlerProvider) => string;
11
10
  export declare const getZeroDevPaymasterRPC: (projectId: string, provider?: BundlerProvider) => string;
12
- type CommonClientParams<TChain extends Chain | undefined = Chain | undefined> = {
13
- bundlerRpc?: 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;
14
13
  chain: TChain;
15
14
  projectId: string;
16
15
  signer: WalletClient<Transport, ViemChain, Account>;
17
16
  paymaster: PaymasterType;
18
- paymasterRpc?: string;
19
- entryPoint: EntryPointType<EntryPointVersion>;
20
- provider?: BundlerProvider;
21
- kernelVersion: GetKernelVersion<EntryPointVersion>;
17
+ paymasterRpc?: string | undefined;
18
+ entryPoint: EntryPointType<entryPoint>;
19
+ provider?: BundlerProvider | undefined;
20
+ index?: bigint | undefined;
21
+ kernelVersion: GetKernelVersion<entryPoint>;
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;
28
24
  }) => 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 { createKernelAccountClient, createZeroDevPaymasterClient } from '@zerodev/sdk/clients';
4
+ import { createZeroDevPaymasterClient, createKernelAccountClient } 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,53 +22,13 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
22
22
  return rpc;
23
23
  };
24
24
  const isERC20 = (value) => isAddress(value);
25
- const createPublicAndPaymasterClients = (bundlerRpc, paymasterRpc, chain) => {
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);
26
28
  const publicClient = createPublicClient({
27
29
  chain,
28
- transport: http(bundlerRpc),
29
- });
30
- const zerodevPaymaster = createZeroDevPaymasterClient({
31
- chain,
32
- transport: http(paymasterRpc),
30
+ transport: http(resolvedBundlerRpc),
33
31
  });
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);
72
32
  const validator = yield ecdsaValidator(publicClient, {
73
33
  entryPoint,
74
34
  kernelVersion,
@@ -76,11 +36,16 @@ const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, f
76
36
  });
77
37
  const account = yield createKernelAccount(publicClient, {
78
38
  entryPoint,
39
+ index,
79
40
  kernelVersion,
80
41
  plugins: {
81
42
  sudo: validator,
82
43
  },
83
44
  });
45
+ const zerodevPaymaster = createZeroDevPaymasterClient({
46
+ chain,
47
+ transport: http(resolvedPaymasterRpc),
48
+ });
84
49
  let selectedAccount = account;
85
50
  if (enableKernelV3Migration) {
86
51
  const migrationVersion = KERNEL_V3_1;
@@ -93,31 +58,32 @@ const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, f
93
58
  signer,
94
59
  });
95
60
  }
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,
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); }),
116
84
  },
117
85
  });
118
- const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
119
- const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
120
- return createKernelAccountClient(clientConfig);
86
+ return kernelClient;
121
87
  });
122
88
 
123
- export { createEcdsaKernelAccountClient, createEcdsaKernelAccountClientWith7702, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };
89
+ export { createEcdsaKernelAccountClient, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };