@dynamic-labs/ethereum-aa 4.10.3 → 4.10.4-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.
Files changed (40) hide show
  1. package/CHANGELOG.md +15 -4
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +11 -9
  5. package/src/AccountAbstractionConnector.cjs +75 -0
  6. package/src/AccountAbstractionConnector.d.ts +56 -0
  7. package/src/AccountAbstractionConnector.js +71 -0
  8. package/src/ZKsync/client.cjs +31 -0
  9. package/src/ZKsync/client.d.ts +25 -0
  10. package/src/ZKsync/client.js +27 -0
  11. package/src/ZKsync/ecdsaAccount.cjs +32 -0
  12. package/src/ZKsync/ecdsaAccount.d.ts +13 -0
  13. package/src/ZKsync/ecdsaAccount.js +28 -0
  14. package/src/ZKsync/getEip712Domain.cjs +62 -0
  15. package/src/ZKsync/getEip712Domain.d.ts +2 -0
  16. package/src/ZKsync/getEip712Domain.js +58 -0
  17. package/src/ZKsync/session.cjs +1218 -0
  18. package/src/ZKsync/session.d.ts +904 -0
  19. package/src/ZKsync/session.js +1211 -0
  20. package/src/ZKsync/types.cjs +52 -0
  21. package/src/ZKsync/types.d.ts +9 -0
  22. package/src/ZKsync/types.js +48 -0
  23. package/src/ZKsync/walletActions.cjs +93 -0
  24. package/src/ZKsync/walletActions.d.ts +15 -0
  25. package/src/ZKsync/walletActions.js +87 -0
  26. package/src/ZKsyncConnector.cjs +536 -0
  27. package/src/ZKsyncConnector.d.ts +24923 -0
  28. package/src/ZKsyncConnector.js +532 -0
  29. package/src/ZeroDevConnector.cjs +17 -13
  30. package/src/ZeroDevConnector.d.ts +17 -16
  31. package/src/ZeroDevConnector.js +18 -14
  32. package/src/index.cjs +11 -0
  33. package/src/index.d.ts +2 -0
  34. package/src/index.js +10 -1
  35. package/src/utils/abi.cjs +88 -0
  36. package/src/utils/abi.d.ts +102 -0
  37. package/src/utils/abi.js +84 -0
  38. package/src/utils/isZKsyncConnector.cjs +8 -0
  39. package/src/utils/isZKsyncConnector.d.ts +3 -0
  40. package/src/utils/isZKsyncConnector.js +4 -0
@@ -0,0 +1,532 @@
1
+ 'use client'
2
+ import { __awaiter } from '../_virtual/_tslib.js';
3
+ import { createPublicClient, http, publicActions, custom, createWalletClient, walletActions, toBytes, keccak256, toHex } from 'viem';
4
+ import { getGeneralPaymasterInput, eip712WalletActions } from 'viem/zksync';
5
+ import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client/passkey';
6
+ import { encodeModuleData, getPublicKeyBytesFromPasskeySignature, encodePasskeyModuleParameters } from 'zksync-sso/utils';
7
+ import { createZksyncSessionClient } from 'zksync-sso/client';
8
+ import { EthereumWallet, getOrMapViemChain, confirmationTransport, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
9
+ import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
10
+ import { AccountAbstractionConnector } from './AccountAbstractionConnector.js';
11
+ import { AAFactoryABI } from './utils/abi.js';
12
+ import { createZksyncEcdsaClient } from './ZKsync/client.js';
13
+ import { zksyncSsoEcdsaWalletActions } from './ZKsync/walletActions.js';
14
+
15
+ class ZKsyncConnector extends AccountAbstractionConnector {
16
+ constructor(props) {
17
+ var _a, _b, _c, _d, _e, _f, _g, _h;
18
+ super(props);
19
+ // Core wallet properties
20
+ this.ChainWallet = EthereumWallet;
21
+ this.name = 'ZKsync';
22
+ this.overrideKey = 'zksync';
23
+ // Chain configuration
24
+ this.connectedChain = 'EVM';
25
+ this.evmNetworks = [];
26
+ this.supportedChains = ['ETH', 'EVM'];
27
+ this._isSmartAccountDeployed = false;
28
+ this.enablePasskeys = true;
29
+ this.enableEIP7702Mode = false;
30
+ this.walletFallback = {
31
+ brand: {
32
+ alt: 'Smart Wallet',
33
+ spriteId: 'smartwallet',
34
+ },
35
+ name: 'ZKsync',
36
+ };
37
+ this._walletUiUtils = props.walletUiUtils;
38
+ this.providersConfig = (_a = props.providersConfig) !== null && _a !== void 0 ? _a : {};
39
+ this.chainId = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.defaultChainId;
40
+ this.evmNetworks = parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
41
+ this.factoryAddress = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress; // Fallback if not provided
42
+ this.paymasterAddress = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress; // Fallback if not provided
43
+ this.passkeyAddress = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.passkeyAddress; // Fallback if not provided
44
+ this.sessionKeyAddress = (_f = props.apiProviders.zksync) === null || _f === void 0 ? void 0 : _f.sessionAddress; // Fallback if not provided
45
+ this.enablePasskeys =
46
+ (_h = (_g = props.settings.sdk.accountAbstraction) === null || _g === void 0 ? void 0 : _g.enablePasskeys) !== null && _h !== void 0 ? _h : false;
47
+ }
48
+ getEnabledNetworks() {
49
+ return this.evmNetworks;
50
+ }
51
+ getConnectedAccounts() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ var _a;
54
+ yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
55
+ if (!this.smartAccountAddress) {
56
+ throw new Error('Smart account address is not initialized');
57
+ }
58
+ return [this.smartAccountAddress];
59
+ });
60
+ }
61
+ getNetwork() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ var _a;
64
+ yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
65
+ if (!this.smartAccountAddress) {
66
+ throw new Error('Smart account address is not initialized');
67
+ }
68
+ return this.chainId;
69
+ });
70
+ }
71
+ getPublicClient() {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ return createPublicClient({
74
+ chain: getOrMapViemChain(this.evmNetworks[0]),
75
+ transport: http(),
76
+ });
77
+ });
78
+ }
79
+ canSponsorTransactionGas() {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ return false;
82
+ });
83
+ }
84
+ getAccountAbstractionProvider() {
85
+ return this.smartAccount;
86
+ }
87
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
88
+ getWalletClient() {
89
+ if (!this.smartAccount) {
90
+ return undefined;
91
+ }
92
+ return this.smartAccount;
93
+ }
94
+ getTransport(provider) {
95
+ const transport = confirmationTransport({
96
+ getAccounts: () => __awaiter(this, void 0, void 0, function* () { return [provider.account.address]; }),
97
+ onPersonalSign: (_a) => __awaiter(this, [_a], void 0, function* ({ message }) {
98
+ this._walletUiUtils.disabledConfirmationOnce();
99
+ if (!this._isSmartAccountDeployed) {
100
+ yield this.deploySmartAccount({
101
+ withPaymaster: true,
102
+ });
103
+ }
104
+ this._walletUiUtils.disabledConfirmationOnce();
105
+ return provider.signMessage({
106
+ message,
107
+ });
108
+ }),
109
+ onSignTypedData: (_b) => __awaiter(this, [_b], void 0, function* ({ message }) {
110
+ this._walletUiUtils.disabledConfirmationOnce();
111
+ const signTypedData = JSON.parse(message);
112
+ if (!this._isSmartAccountDeployed) {
113
+ yield this.deploySmartAccount({
114
+ withPaymaster: true,
115
+ });
116
+ }
117
+ this._walletUiUtils.disabledConfirmationOnce();
118
+ return provider.signTypedData({
119
+ domain: signTypedData.domain,
120
+ message: signTypedData.message,
121
+ primaryType: signTypedData.primaryType,
122
+ types: signTypedData.types,
123
+ });
124
+ }),
125
+ provider: provider.extend(publicActions),
126
+ transport: custom(provider, this.providersConfig.httpTransportConfig),
127
+ // TODO: remove this. We should not be passing references to wallet connectors
128
+ walletConnector: this,
129
+ walletUiUtils: this._walletUiUtils,
130
+ });
131
+ return transport;
132
+ }
133
+ getSigner() {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ return this.getWalletClient();
136
+ });
137
+ }
138
+ createEcdsaClient(eoaConnector) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ const eoaSigner = yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.getSigner());
141
+ if (!eoaSigner) {
142
+ throw new Error('EOA wallet client not found');
143
+ }
144
+ const transport = this.getTransport(eoaSigner);
145
+ const ownerWithTransport = createWalletClient(Object.assign(Object.assign({}, eoaSigner), { transport }));
146
+ const walletClient = yield createZksyncEcdsaClient({
147
+ address: this.smartAccountAddress,
148
+ chain: getOrMapViemChain(this.evmNetworks[0]),
149
+ contracts: {
150
+ accountFactory: this.factoryAddress,
151
+ session: this.sessionKeyAddress,
152
+ },
153
+ owner: ownerWithTransport,
154
+ transport: http(),
155
+ });
156
+ return walletClient;
157
+ });
158
+ }
159
+ /**
160
+ * Implementation of the interface method required by IAccountAbstractionWalletConnector
161
+ * @param eoaConnector - The EOA connector to use for signing transactions
162
+ * @param smartAccountAddress - The address of the smart account
163
+ */
164
+ initializeZksyncConnector(_a) {
165
+ return __awaiter(this, arguments, void 0, function* ({ eoaConnector, smartAccountAddress, }) {
166
+ this.initializedDeferredPromise = this.initializedDeferredPromise
167
+ ? this.initializedDeferredPromise
168
+ : new DeferredPromise();
169
+ this.eoaConnector = eoaConnector;
170
+ this.eoaAddress = yield eoaConnector.getAddress();
171
+ this.smartAccountAddress = smartAccountAddress;
172
+ this.smartAccount = (yield this.createEcdsaClient(eoaConnector));
173
+ yield this.checkIsDeployed();
174
+ this.initializedDeferredPromise.resolve();
175
+ });
176
+ }
177
+ createSessionClient(sessionKey, sessionConfig) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ if (!this.smartAccountAddress) {
180
+ throw new Error('Smart account address is not initialized');
181
+ }
182
+ return createZksyncSessionClient({
183
+ address: this.smartAccountAddress,
184
+ chain: getOrMapViemChain(this.evmNetworks[0]),
185
+ contracts: {
186
+ session: this.sessionKeyAddress,
187
+ },
188
+ sessionConfig,
189
+ sessionKey,
190
+ transport: http(),
191
+ });
192
+ });
193
+ }
194
+ /**
195
+ * Creates a passkey client for ZKsync authentication
196
+ *
197
+ * This method initializes a passkey client using stored credentials and
198
+ * configures it with the necessary contract addresses and chain information.
199
+ *
200
+ */
201
+ createPasskeyClient() {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ if (!this.smartAccountAddress) {
204
+ throw new Error('Smart account address is not initialized');
205
+ }
206
+ const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
207
+ if (!storedCredentialPublicKey) {
208
+ throw new Error('Credential public key not found');
209
+ }
210
+ const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
211
+ const publicClient = yield this.getTypedPublicClient();
212
+ const { chain } = publicClient;
213
+ if (!chain) {
214
+ throw new Error('Chain information not available');
215
+ }
216
+ const contractAddresses = {
217
+ accountFactory: this.factoryAddress,
218
+ passkey: this.passkeyAddress,
219
+ session: this.sessionKeyAddress,
220
+ };
221
+ this.passkeyClient = createZksyncPasskeyClient({
222
+ address: this.smartAccountAddress,
223
+ chain,
224
+ contracts: contractAddresses,
225
+ credentialPublicKey,
226
+ transport: http(),
227
+ userDisplayName: this.smartAccountAddress,
228
+ userName: this.smartAccountAddress,
229
+ });
230
+ });
231
+ }
232
+ registerPasskeyAndDeploy() {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ const { credentialPublicKey, credentialId } = yield registerNewPasskey({
235
+ attestationType: 'none',
236
+ authenticatorSelection: {
237
+ authenticatorAttachment: 'platform',
238
+ requireResidentKey: false,
239
+ userVerification: 'required',
240
+ },
241
+ userDisplayName: this.smartAccountAddress,
242
+ userName: this.smartAccountAddress,
243
+ });
244
+ StorageService.setItem('credentialPublicKey', credentialPublicKey);
245
+ StorageService.setItem('credentialId', credentialId);
246
+ yield this.deploySmartAccount({
247
+ withPaymaster: true,
248
+ });
249
+ });
250
+ }
251
+ deploySmartAccount(_a) {
252
+ return __awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
253
+ if (withPaymaster && this.paymasterAddress) {
254
+ yield this.deploySmartAccountWithPaymaster();
255
+ }
256
+ else {
257
+ yield this.deploySmartAccountWithoutPaymaster();
258
+ }
259
+ });
260
+ }
261
+ deploySmartAccountWithPaymaster() {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ if (!this.paymasterAddress) {
264
+ throw new Error('Paymaster address is not initialized');
265
+ }
266
+ const paymaster = this.paymasterAddress;
267
+ const publicClient = yield this.getTypedPublicClient();
268
+ const walletClient = yield this.getTypedWalletClient();
269
+ const deploymentParams = yield this.getDeploymentParameters();
270
+ const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
271
+ const paymasterInput = getGeneralPaymasterInput({
272
+ innerInput: new Uint8Array(),
273
+ });
274
+ const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
275
+ paymasterInput });
276
+ yield this.executeAccountDeployment(walletClient, requestWithPaymaster);
277
+ });
278
+ }
279
+ /**
280
+ * Deploys a new smart account contract
281
+ * @throws {ZkSyncConnectorError} If deployment fails
282
+ * @testable This method can be mocked in tests
283
+ */
284
+ deploySmartAccountWithoutPaymaster() {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ if (!this.eoaConnector) {
287
+ throw new Error('EOA connector is not initialized');
288
+ }
289
+ const walletClient = yield this.getTypedWalletClient();
290
+ const publicClient = yield this.getTypedPublicClient();
291
+ const deploymentParams = yield this.getDeploymentParameters();
292
+ // Simulate the contract deployment first
293
+ const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
294
+ // Execute the deployment transaction
295
+ yield this.executeAccountDeployment(walletClient, request);
296
+ });
297
+ }
298
+ /**
299
+ * Gets typed public client from EOA connector
300
+ * @throws {ZkSyncConnectorError} If public client cannot be obtained
301
+ * @testable This method can be mocked in tests
302
+ */
303
+ getTypedPublicClient() {
304
+ return __awaiter(this, void 0, void 0, function* () {
305
+ if (!this.eoaConnector) {
306
+ throw new Error('EOA connector is not initialized');
307
+ }
308
+ const publicClient = yield this.eoaConnector.getPublicClient();
309
+ if (!publicClient) {
310
+ throw new Error('Failed to get public client from EOA connector');
311
+ }
312
+ return publicClient;
313
+ });
314
+ }
315
+ /**
316
+ * Gets typed wallet client from EOA connector
317
+ * @throws {ZkSyncConnectorError} If wallet client cannot be obtained
318
+ * @testable This method can be mocked in tests
319
+ */
320
+ getTypedWalletClient() {
321
+ return __awaiter(this, void 0, void 0, function* () {
322
+ if (!this.eoaConnector) {
323
+ throw new Error('EOA connector is not initialized');
324
+ }
325
+ const walletClient = yield this.eoaConnector.getWalletClient();
326
+ if (!walletClient) {
327
+ throw new Error('Failed to get wallet client from EOA connector');
328
+ }
329
+ return walletClient
330
+ .extend(publicActions)
331
+ .extend(walletActions)
332
+ .extend(eip712WalletActions())
333
+ .extend(zksyncSsoEcdsaWalletActions);
334
+ });
335
+ }
336
+ /**
337
+ * Returns the parameters needed for deploying the smart account
338
+ * @returns Deployment parameters object
339
+ * @testable This method can be overridden in tests
340
+ */
341
+ getDeploymentParameters() {
342
+ return __awaiter(this, void 0, void 0, function* () {
343
+ const salt = `0x${Buffer.from(toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
344
+ const initialValidators = [];
345
+ const initialK1Owners = [this.eoaAddress];
346
+ // TODO: revisit this logic, maybe we should always add the passkey module data,
347
+ // otherwise if people active passkeys later, old accounts will not be able to use passkey module
348
+ if (this.enablePasskeys && this.passkeyAddress) {
349
+ const encodedPasskeyModuleData = yield this.getEncodedPasskeyModuleData();
350
+ initialValidators.push(encodedPasskeyModuleData);
351
+ }
352
+ if (this.sessionKeyAddress) {
353
+ const encodedSessionKeyModuleData = encodeModuleData({
354
+ address: this.sessionKeyAddress,
355
+ parameters: '0x',
356
+ });
357
+ initialValidators.push(encodedSessionKeyModuleData);
358
+ }
359
+ return {
360
+ initialK1Owners,
361
+ initialValidators,
362
+ salt,
363
+ };
364
+ });
365
+ }
366
+ /**
367
+ * Retrieves and encodes passkey module data for smart account deployment
368
+ * @returns Encoded passkey module data as a hex string
369
+ * @throws {Error} If credential public key or ID is not found
370
+ * @private
371
+ */
372
+ getEncodedPasskeyModuleData() {
373
+ return __awaiter(this, void 0, void 0, function* () {
374
+ const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
375
+ if (!storedCredentialPublicKey) {
376
+ throw new Error('Credential public key not found');
377
+ }
378
+ const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
379
+ const credentialId = StorageService.getItem('credentialId');
380
+ if (!credentialId) {
381
+ throw new Error('Credential ID not found');
382
+ }
383
+ const passkeyPublicKey = getPublicKeyBytesFromPasskeySignature(credentialPublicKey);
384
+ const encodedPasskeyParameters = encodePasskeyModuleParameters({
385
+ credentialId: credentialId,
386
+ expectedOrigin: window.location.origin, // TODO: how is this going to be set?
387
+ passkeyPublicKey,
388
+ });
389
+ return encodeModuleData({
390
+ address: this.passkeyAddress,
391
+ parameters: encodedPasskeyParameters,
392
+ });
393
+ });
394
+ }
395
+ /**
396
+ * Simulates the smart account deployment
397
+ * @param publicClient - The public client to use for simulation
398
+ * @param walletClient - The wallet client to use for account information
399
+ * @param params - The deployment parameters
400
+ * @returns The simulation result
401
+ * @throws {ZkSyncConnectorError} If simulation fails
402
+ * @testable This method can be mocked in tests
403
+ */
404
+ simulateAccountDeployment(publicClient_1, walletClient_1, params_1) {
405
+ return __awaiter(this, arguments, void 0, function* (publicClient, walletClient, params, checkBalance = true) {
406
+ var _a, _b, _c;
407
+ // this is to keep the same salt as calculated on zksync sso package
408
+ const salt = keccak256(toHex(params.salt));
409
+ const gasEstimate = yield publicClient.estimateContractGas({
410
+ abi: AAFactoryABI,
411
+ account: (_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address,
412
+ address: this.factoryAddress,
413
+ args: [salt, params.initialValidators, params.initialK1Owners],
414
+ functionName: 'deployProxySsoAccount',
415
+ });
416
+ if (checkBalance) {
417
+ const balance = yield publicClient.getBalance({
418
+ address: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
419
+ });
420
+ if (balance < gasEstimate) {
421
+ throw new Error('Insufficient balance to deploy account');
422
+ }
423
+ }
424
+ // Simulate the contract call
425
+ return publicClient.simulateContract({
426
+ abi: AAFactoryABI,
427
+ account: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
428
+ address: this.factoryAddress,
429
+ args: [salt, params.initialValidators, params.initialK1Owners],
430
+ functionName: 'deployProxySsoAccount',
431
+ });
432
+ });
433
+ }
434
+ /**
435
+ * Executes the smart account deployment transaction
436
+ * @param walletClient - The wallet client to use for transaction execution
437
+ * @param request - The deployment request object containing transaction parameters
438
+ * @returns Promise that resolves when the deployment transaction is confirmed
439
+ * @throws {DynamicError} If the smart account address is not initialized
440
+ * @throws {Error} If transaction execution or confirmation fails
441
+ */
442
+ executeAccountDeployment(walletClient, request) {
443
+ return __awaiter(this, void 0, void 0, function* () {
444
+ if (!this.smartAccountAddress) {
445
+ throw new Error('Smart account address is not initialized');
446
+ }
447
+ const tx = yield walletClient.writeContract(request);
448
+ const publicClient = yield this.getPublicClient();
449
+ yield publicClient.waitForTransactionReceipt({ hash: tx });
450
+ this._isSmartAccountDeployed = true;
451
+ });
452
+ }
453
+ signMessage(message) {
454
+ return __awaiter(this, void 0, void 0, function* () {
455
+ const walletClient = this.getWalletClient();
456
+ if (!walletClient) {
457
+ throw new Error('Wallet client not found');
458
+ }
459
+ return yield walletClient.signMessage({
460
+ account: walletClient.account,
461
+ message,
462
+ });
463
+ });
464
+ }
465
+ /**
466
+ * Checks if a smart account is deployed
467
+ * @throws {ZkSyncConnectorError} If the check fails
468
+ * @returns Promise that resolves when the check is complete
469
+ */
470
+ checkIsDeployed() {
471
+ return __awaiter(this, void 0, void 0, function* () {
472
+ const client = yield this.getPublicClient();
473
+ if (!client) {
474
+ throw new Error('Failed to get public client from EOA connector');
475
+ }
476
+ const code = yield client.getCode({
477
+ address: this.smartAccountAddress,
478
+ });
479
+ const isDeployed = Boolean(code);
480
+ this._isSmartAccountDeployed = isDeployed;
481
+ });
482
+ }
483
+ getAddress() {
484
+ return __awaiter(this, void 0, void 0, function* () {
485
+ var _a;
486
+ yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
487
+ if (!this.smartAccount) {
488
+ throw new Error('Smart account is not initialized');
489
+ }
490
+ return this.smartAccountAddress;
491
+ });
492
+ }
493
+ validateActiveWallet(expectedAddress) {
494
+ return __awaiter(this, void 0, void 0, function* () {
495
+ const currentAddress = yield this.getAddress();
496
+ if (currentAddress !== expectedAddress) {
497
+ throw new DynamicError('Invalid active wallet');
498
+ }
499
+ return;
500
+ });
501
+ }
502
+ createUiTransaction(from) {
503
+ return __awaiter(this, void 0, void 0, function* () {
504
+ yield this.validateActiveWallet(from);
505
+ const walletClient = this.getWalletClient();
506
+ const publicClient = yield this.getPublicClient();
507
+ if (!publicClient || !walletClient) {
508
+ throw new DynamicError('No public client available');
509
+ }
510
+ return createViemUiTransaction({
511
+ from: from,
512
+ publicClient: publicClient,
513
+ walletClient: walletClient,
514
+ });
515
+ });
516
+ }
517
+ isSmartAccountDeployed() {
518
+ return __awaiter(this, arguments, void 0, function* (refetch = false) {
519
+ if (refetch) {
520
+ yield this.checkIsDeployed();
521
+ }
522
+ return this._isSmartAccountDeployed;
523
+ });
524
+ }
525
+ registerEoa(_a) {
526
+ return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }) {
527
+ throw new Error('Not implemented');
528
+ });
529
+ }
530
+ }
531
+
532
+ export { ZKsyncConnector };
@@ -16,8 +16,9 @@ var createEcsdaKernelAccountClient = require('./utils/createEcsdaKernelAccountCl
16
16
  var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
17
17
  var getEntryPoint = require('./utils/getEntryPoint.cjs');
18
18
  var getKernelVersion = require('./utils/getKernelVersion.cjs');
19
+ var AccountAbstractionConnector = require('./AccountAbstractionConnector.cjs');
19
20
 
20
- class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
21
+ class ZeroDevConnector extends AccountAbstractionConnector.AccountAbstractionConnector {
21
22
  constructor(opts) {
22
23
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
23
24
  super(opts);
@@ -28,7 +29,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
28
29
  this.ChainWallet = ethereumCore.EthereumWallet;
29
30
  this.connectedChain = 'EVM';
30
31
  this.supportedChains = ['ETH', 'EVM'];
31
- this.isGasSponsorshipDisabled = false;
32
32
  this.isEmbeddedWallet = true;
33
33
  this.providersFromApi = [];
34
34
  this.name = 'ZeroDev';
@@ -60,6 +60,9 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
60
60
  this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
61
61
  this.ecdsaProviderType = (_j = opts.apiProviders.zerodev) === null || _j === void 0 ? void 0 : _j.ecdsaProviderType;
62
62
  }
63
+ confirmTransactionStatus() {
64
+ throw new Error('confirmTransactionStatus not implemented in ZeroDevConnector');
65
+ }
63
66
  get currentNetworkProvider() {
64
67
  // check if the last used chain id is in the provider map
65
68
  if (this.providerMap[this.lastUsedChainId]) {
@@ -104,13 +107,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
104
107
  handleChainChange(chainId);
105
108
  });
106
109
  }
107
- /**
108
- * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
109
- * from the useSmartWallet hook
110
- */
111
- getEOAConnector() {
112
- return this.eoaConnector;
113
- }
114
110
  getAccountAbstractionProvider({ withSponsorship, } = {}) {
115
111
  if (withSponsorship && this.kernelClientWithSponsorship) {
116
112
  return this.kernelClientWithSponsorship;
@@ -122,6 +118,14 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
122
118
  utils.StorageService.removeItem(constants.ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
123
119
  });
124
120
  }
121
+ initialize(_a) {
122
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }) {
123
+ yield this.registerEoa(Object.assign({ eoaAddress,
124
+ eoaConnector,
125
+ shouldSetEoaConnector,
126
+ smartWalletAddress }, properties));
127
+ });
128
+ }
125
129
  registerEoa(_a) {
126
130
  return _tslib.__awaiter(this, void 0, void 0, function* () {
127
131
  var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
@@ -369,7 +373,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
369
373
  onSendTransaction: (_b) => _tslib.__awaiter(this, [_b], void 0, function* ({ transaction }) {
370
374
  try {
371
375
  this._walletUiUtils.disabledConfirmationOnce();
372
- const effectiveProvider = this.isGasSponsorshipDisabled
376
+ const effectiveProvider = this.isGasSponsorshipDisabled()
373
377
  ? provider
374
378
  : this.kernelClientWithSponsorship;
375
379
  if (!effectiveProvider) {
@@ -540,9 +544,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
540
544
  return sponsored;
541
545
  });
542
546
  }
543
- disableGasSponsorshipOnce() {
544
- this.isGasSponsorshipDisabled = true;
545
- }
546
547
  getBalance(address) {
547
548
  return _tslib.__awaiter(this, void 0, void 0, function* () {
548
549
  var _a;
@@ -604,6 +605,9 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
604
605
  getEnabledNetworks() {
605
606
  return this.evmNetworks;
606
607
  }
608
+ initializeZksyncConnector() {
609
+ throw new Error('Not implemented');
610
+ }
607
611
  }
608
612
 
609
613
  exports.ZeroDevConnector = ZeroDevConnector;