@dynamic-labs/ethereum-aa 4.9.13-preview.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +9 -2
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +9 -11
  5. package/src/ZeroDevConnector.cjs +17 -20
  6. package/src/ZeroDevConnector.d.ts +15 -21
  7. package/src/ZeroDevConnector.js +18 -21
  8. package/src/index.cjs +0 -11
  9. package/src/index.d.ts +0 -2
  10. package/src/index.js +1 -10
  11. package/src/utils/createEcsdaKernelAccountClient.d.ts +1 -1
  12. package/src/AccountAbstractionConnector.cjs +0 -75
  13. package/src/AccountAbstractionConnector.d.ts +0 -56
  14. package/src/AccountAbstractionConnector.js +0 -71
  15. package/src/ZKsync/client.cjs +0 -29
  16. package/src/ZKsync/client.d.ts +0 -24
  17. package/src/ZKsync/client.js +0 -25
  18. package/src/ZKsync/ecdsaAccount.cjs +0 -32
  19. package/src/ZKsync/ecdsaAccount.d.ts +0 -13
  20. package/src/ZKsync/ecdsaAccount.js +0 -28
  21. package/src/ZKsync/getEip712Domain.cjs +0 -62
  22. package/src/ZKsync/getEip712Domain.d.ts +0 -2
  23. package/src/ZKsync/getEip712Domain.js +0 -58
  24. package/src/ZKsync/types.cjs +0 -31
  25. package/src/ZKsync/types.d.ts +0 -9
  26. package/src/ZKsync/types.js +0 -27
  27. package/src/ZKsync/walletActions.cjs +0 -93
  28. package/src/ZKsync/walletActions.d.ts +0 -15
  29. package/src/ZKsync/walletActions.js +0 -87
  30. package/src/ZKsyncConnector.cjs +0 -430
  31. package/src/ZKsyncConnector.d.ts +0 -23259
  32. package/src/ZKsyncConnector.js +0 -426
  33. package/src/utils/abi.cjs +0 -88
  34. package/src/utils/abi.d.ts +0 -102
  35. package/src/utils/abi.js +0 -84
  36. package/src/utils/isZKsyncConnector.cjs +0 -8
  37. package/src/utils/isZKsyncConnector.d.ts +0 -3
  38. package/src/utils/isZKsyncConnector.js +0 -4
@@ -1,430 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../_virtual/_tslib.cjs');
7
- var viem = require('viem');
8
- var zksync = require('viem/zksync');
9
- var client$1 = require('zksync-sso/client');
10
- var passkey = require('zksync-sso/client/passkey');
11
- var ethereumCore = require('@dynamic-labs/ethereum-core');
12
- var utils = require('@dynamic-labs/utils');
13
- var AccountAbstractionConnector = require('./AccountAbstractionConnector.cjs');
14
- var abi = require('./utils/abi.cjs');
15
- var walletActions = require('./ZKsync/walletActions.cjs');
16
- var client = require('./ZKsync/client.cjs');
17
-
18
- class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConnector {
19
- constructor(props) {
20
- var _a, _b, _c, _d, _e;
21
- super(props);
22
- // Core wallet properties
23
- this.ChainWallet = ethereumCore.EthereumWallet;
24
- this.name = 'ZKsync';
25
- this.overrideKey = 'zksync';
26
- // Chain configuration
27
- this.connectedChain = 'EVM';
28
- this.evmNetworks = [];
29
- this.supportedChains = ['ETH', 'EVM'];
30
- this.enableEIP7702Mode = false;
31
- this.walletFallback = {
32
- brand: {
33
- alt: 'Smart Wallet',
34
- spriteId: 'smartwallet',
35
- },
36
- name: 'ZKsync',
37
- };
38
- this._walletUiUtils = props.walletUiUtils;
39
- this.chainId = (_a = props.apiProviders.zksync) === null || _a === void 0 ? void 0 : _a.defaultChainId;
40
- this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
41
- this.factoryAddress = ((_c = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.factoryAddress) !== null && _c !== void 0 ? _c : '0x2e620D52467CfA4C664F92005Ab0f0181d3d1E79'); // Fallback if not provided
42
- this.paymasterAddress = ((_e = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress) !== null && _e !== void 0 ? _e : '0xA78CAC56c9D491Ece2FF303aEcc627Bf71C6dc1c'); // Fallback if not provided
43
- }
44
- getEnabledNetworks() {
45
- return this.evmNetworks;
46
- }
47
- getConnectedAccounts() {
48
- return _tslib.__awaiter(this, void 0, void 0, function* () {
49
- if (!this.smartAccountAddress) {
50
- throw new Error('Smart account address is not initialized');
51
- }
52
- return [this.smartAccountAddress];
53
- });
54
- }
55
- getNetwork() {
56
- return _tslib.__awaiter(this, void 0, void 0, function* () {
57
- if (!this.smartAccountAddress) {
58
- throw new Error('Smart account address is not initialized');
59
- }
60
- return this.chainId;
61
- });
62
- }
63
- getPublicClient() {
64
- return _tslib.__awaiter(this, void 0, void 0, function* () {
65
- return viem.createPublicClient({
66
- chain: zksync.zksyncSepoliaTestnet,
67
- transport: viem.http(),
68
- });
69
- });
70
- }
71
- canSponsorTransactionGas() {
72
- return _tslib.__awaiter(this, void 0, void 0, function* () {
73
- return false;
74
- });
75
- }
76
- getAccountAbstractionProvider() {
77
- return this.smartAccount;
78
- }
79
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
80
- getWalletClient() {
81
- return _tslib.__awaiter(this, void 0, void 0, function* () {
82
- var _a;
83
- const eoaSigner = yield ((_a = this.eoaConnector) === null || _a === void 0 ? void 0 : _a.getSigner());
84
- if (!eoaSigner) {
85
- throw new Error('EOA wallet client not found');
86
- }
87
- const walletClient = yield client.createZksyncEcdsaClient({
88
- address: this.smartAccountAddress,
89
- chain: zksync.zksyncSepoliaTestnet,
90
- contracts: {
91
- accountFactory: this.factoryAddress,
92
- session: '0x5Da0ba1366F05a14603FC6aC906B99CdC6BA851A',
93
- },
94
- owner: eoaSigner,
95
- transport: viem.http(),
96
- });
97
- return walletClient;
98
- });
99
- }
100
- getSigner() {
101
- return _tslib.__awaiter(this, void 0, void 0, function* () {
102
- return this.getWalletClient();
103
- });
104
- }
105
- /**
106
- * Implementation of the interface method required by IAccountAbstractionWalletConnector
107
- * @param eoaConnector - The EOA connector to use for signing transactions
108
- * @param smartAccountAddress - The address of the smart account
109
- */
110
- initializeZksyncConnector(_a) {
111
- return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaConnector, smartAccountAddress, }) {
112
- this.eoaConnector = eoaConnector;
113
- this.eoaAddress = yield eoaConnector.getAddress();
114
- this.smartAccountAddress = smartAccountAddress;
115
- this.smartAccount = (yield this.getWalletClient());
116
- // Check if account needs deployment
117
- const shouldDeploy = yield this.shouldDeployAccount(smartAccountAddress);
118
- if (!shouldDeploy) {
119
- return;
120
- }
121
- });
122
- }
123
- createPasskeyClient() {
124
- return _tslib.__awaiter(this, void 0, void 0, function* () {
125
- const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
126
- const credentialPublicKey = storedCredentialPublicKey
127
- ? new Uint8Array(Object.values(storedCredentialPublicKey))
128
- : null;
129
- if (!credentialPublicKey) {
130
- throw new Error('Credential public key not found');
131
- }
132
- const publicClient = yield this.getTypedPublicClient();
133
- const { chain } = publicClient;
134
- if (!chain) {
135
- throw new Error('Chain not found');
136
- }
137
- const passkeyClient = passkey.createZksyncPasskeyClient({
138
- address: '0xf2484bEA13038C2d110dCf0DfCF3b251B8d6A7Ea',
139
- chain,
140
- contracts: {
141
- accountFactory: this.factoryAddress,
142
- passkey: '0xF69e92B224f527365F4434B729134aE69C60B963',
143
- session: '0x5Da0ba1366F05a14603FC6aC906B99CdC6BA851A',
144
- },
145
- credentialPublicKey,
146
- transport: viem.http(),
147
- userDisplayName: 'Vinicius',
148
- userName: 'vinicius.macelai@gmail.com',
149
- });
150
- this.passkeyClient = passkeyClient;
151
- });
152
- }
153
- // Create your account client
154
- createSmartAccountClient() {
155
- return _tslib.__awaiter(this, void 0, void 0, function* () {
156
- return this.smartAccount;
157
- });
158
- }
159
- deploySmartAccountWithZksyncSso() {
160
- return _tslib.__awaiter(this, void 0, void 0, function* () {
161
- var _a, _b;
162
- const walletClient = yield this.getWalletClient();
163
- if (!walletClient) {
164
- throw new Error('Wallet client not found');
165
- }
166
- const deploymentParams = yield this.getDeploymentParameters();
167
- if (!this.smartAccountAddress) {
168
- throw new Error('Smart account address is not initialized');
169
- }
170
- const shouldDeploy = yield this.shouldDeployAccount(this.smartAccountAddress);
171
- if (!shouldDeploy) {
172
- throw new Error('Smart account already deployed');
173
- }
174
- const paymasterInput = zksync.getGeneralPaymasterInput({
175
- innerInput: new Uint8Array(),
176
- });
177
- const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
178
- let credentialPublicKey = storedCredentialPublicKey
179
- ? new Uint8Array(Object.values(storedCredentialPublicKey))
180
- : null;
181
- if (!credentialPublicKey) {
182
- const { credentialPublicKey: newCredentialPublicKey } = yield passkey.registerNewPasskey({
183
- attestationType: 'none',
184
- authenticatorSelection: {
185
- authenticatorAttachment: 'platform',
186
- requireResidentKey: false,
187
- userVerification: 'required',
188
- },
189
- userDisplayName: this.smartAccountAddress,
190
- userName: this.smartAccountAddress,
191
- });
192
- utils.StorageService.setItem('credentialPublicKey', newCredentialPublicKey);
193
- credentialPublicKey = new Uint8Array(newCredentialPublicKey);
194
- }
195
- if (!((_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address)) {
196
- throw new Error('Wallet client not found');
197
- }
198
- yield client$1.deployAccount(walletClient, {
199
- contracts: {
200
- accountFactory: this.factoryAddress,
201
- passkey: '0xa9ab0dE9d83cc4827261EaccF536859f4A562b72',
202
- session: '0x5Da0ba1366F05a14603FC6aC906B99CdC6BA851A',
203
- },
204
- credentialId: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
205
- credentialPublicKey,
206
- paymasterAddress: '0xa20D5f00A693e4Eb260AAdc7458fe415981c8051',
207
- paymasterInput: paymasterInput,
208
- uniqueAccountId: deploymentParams.salt,
209
- });
210
- });
211
- }
212
- deploySmartAccountWithPaymaster() {
213
- return _tslib.__awaiter(this, void 0, void 0, function* () {
214
- const paymaster = this.paymasterAddress;
215
- const publicClient = yield this.getTypedPublicClient();
216
- const walletClient = yield this.getTypedWalletClient();
217
- const deploymentParams = yield this.getDeploymentParameters();
218
- const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
219
- const paymasterInput = zksync.getGeneralPaymasterInput({
220
- innerInput: new Uint8Array(),
221
- });
222
- const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
223
- paymasterInput });
224
- yield this.executeAccountDeployment(walletClient, requestWithPaymaster);
225
- });
226
- }
227
- signMessage(message) {
228
- return _tslib.__awaiter(this, void 0, void 0, function* () {
229
- const walletClient = yield this.getWalletClient();
230
- if (!walletClient) {
231
- throw new Error('Wallet client not found');
232
- }
233
- return yield walletClient.signMessage({
234
- account: walletClient.account,
235
- message,
236
- });
237
- });
238
- }
239
- /**
240
- * Deploys a new smart account contract
241
- * @throws {ZkSyncConnectorError} If deployment fails
242
- * @testable This method can be mocked in tests
243
- */
244
- deploySmartAccount() {
245
- return _tslib.__awaiter(this, void 0, void 0, function* () {
246
- if (!this.eoaConnector) {
247
- throw new Error('EOA connector is not initialized');
248
- }
249
- const walletClient = yield this.getTypedWalletClient();
250
- const publicClient = yield this.getTypedPublicClient();
251
- const deploymentParams = yield this.getDeploymentParameters();
252
- // Simulate the contract deployment first
253
- const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
254
- // Execute the deployment transaction
255
- yield this.executeAccountDeployment(walletClient, request);
256
- });
257
- }
258
- /**
259
- * Gets typed public client from EOA connector
260
- * @throws {ZkSyncConnectorError} If public client cannot be obtained
261
- * @testable This method can be mocked in tests
262
- */
263
- getTypedPublicClient() {
264
- return _tslib.__awaiter(this, void 0, void 0, function* () {
265
- if (!this.eoaConnector) {
266
- throw new Error('EOA connector is not initialized');
267
- }
268
- const publicClient = yield this.eoaConnector.getPublicClient();
269
- if (!publicClient) {
270
- throw new Error('Failed to get public client from EOA connector');
271
- }
272
- return publicClient;
273
- });
274
- }
275
- /**
276
- * Gets typed wallet client from EOA connector
277
- * @throws {ZkSyncConnectorError} If wallet client cannot be obtained
278
- * @testable This method can be mocked in tests
279
- */
280
- getTypedWalletClient() {
281
- return _tslib.__awaiter(this, void 0, void 0, function* () {
282
- if (!this.eoaConnector) {
283
- throw new Error('EOA connector is not initialized');
284
- }
285
- const walletClient = yield this.eoaConnector.getWalletClient();
286
- if (!walletClient) {
287
- throw new Error('Failed to get wallet client from EOA connector');
288
- }
289
- return walletClient
290
- .extend(viem.publicActions)
291
- .extend(viem.walletActions)
292
- .extend(zksync.eip712WalletActions())
293
- .extend(walletActions.zksyncSsoEcdsaWalletActions);
294
- });
295
- }
296
- /**
297
- * Returns the parameters needed for deploying the smart account
298
- * @returns Deployment parameters object
299
- * @testable This method can be overridden in tests
300
- */
301
- getDeploymentParameters() {
302
- return _tslib.__awaiter(this, void 0, void 0, function* () {
303
- const salt = `0x${Buffer.from(viem.toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
304
- const initialValidators = [];
305
- const initialK1Owners = [this.eoaAddress];
306
- return {
307
- initialK1Owners,
308
- initialValidators,
309
- salt,
310
- };
311
- });
312
- }
313
- /**
314
- * Simulates the smart account deployment
315
- * @param publicClient - The public client to use for simulation
316
- * @param walletClient - The wallet client to use for account information
317
- * @param params - The deployment parameters
318
- * @returns The simulation result
319
- * @throws {ZkSyncConnectorError} If simulation fails
320
- * @testable This method can be mocked in tests
321
- */
322
- simulateAccountDeployment(publicClient_1, walletClient_1, params_1) {
323
- return _tslib.__awaiter(this, arguments, void 0, function* (publicClient, walletClient, params, checkBalance = true) {
324
- var _a, _b, _c;
325
- // this is to keep the same salt as calculated on zksync sso package
326
- const salt = viem.keccak256(viem.toHex(params.salt));
327
- const gasEstimate = yield publicClient.estimateContractGas({
328
- abi: abi.AAFactoryABI,
329
- account: (_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address,
330
- address: this.factoryAddress,
331
- args: [salt, params.initialValidators, params.initialK1Owners],
332
- functionName: 'deployProxySsoAccount',
333
- });
334
- if (checkBalance) {
335
- const balance = yield publicClient.getBalance({
336
- address: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
337
- });
338
- if (balance < gasEstimate) {
339
- throw new Error('Insufficient balance to deploy account');
340
- }
341
- }
342
- // Simulate the contract call
343
- return yield publicClient.simulateContract({
344
- abi: abi.AAFactoryABI,
345
- account: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
346
- address: this.factoryAddress,
347
- args: [salt, params.initialValidators, params.initialK1Owners],
348
- functionName: 'deployProxySsoAccount',
349
- });
350
- });
351
- }
352
- /**
353
- * Executes the smart account deployment transaction
354
- * @param walletClient - The wallet client to use for transaction execution
355
- * @param request - The request to execute
356
- * @throws {ZkSyncConnectorError} If transaction execution fails
357
- * @testable This method can be mocked in tests
358
- */
359
- executeAccountDeployment(walletClient, request) {
360
- return _tslib.__awaiter(this, void 0, void 0, function* () {
361
- if (!this.smartAccountAddress) {
362
- throw new Error('Smart account address is not initialized');
363
- }
364
- const shouldDeploy = yield this.shouldDeployAccount(this.smartAccountAddress);
365
- if (!shouldDeploy) {
366
- throw new Error('Smart account already deployed');
367
- }
368
- yield walletClient.writeContract(request);
369
- });
370
- }
371
- /**
372
- * Checks if a smart account needs to be deployed
373
- * @param smartAccountAddress - The address of the smart account
374
- * @returns True if the account needs to be deployed, false otherwise
375
- * @throws {ZkSyncConnectorError} If the check fails
376
- * @testable This method can be mocked in tests
377
- */
378
- shouldDeployAccount(smartAccountAddress) {
379
- return _tslib.__awaiter(this, void 0, void 0, function* () {
380
- var _a;
381
- const client = yield ((_a = this.eoaConnector) === null || _a === void 0 ? void 0 : _a.getPublicClient());
382
- if (!client) {
383
- throw new Error('Failed to get public client from EOA connector');
384
- }
385
- const code = yield client.getCode({
386
- address: smartAccountAddress,
387
- });
388
- return !code || code === '0x';
389
- });
390
- }
391
- getAddress() {
392
- return _tslib.__awaiter(this, void 0, void 0, function* () {
393
- if (!this.smartAccount) {
394
- throw new Error('Smart account is not initialized');
395
- }
396
- return this.smartAccountAddress;
397
- });
398
- }
399
- validateActiveWallet(expectedAddress) {
400
- return _tslib.__awaiter(this, void 0, void 0, function* () {
401
- const currentAddress = yield this.getAddress();
402
- if (currentAddress !== expectedAddress) {
403
- throw new utils.DynamicError('Invalid active wallet');
404
- }
405
- return;
406
- });
407
- }
408
- createUiTransaction(from) {
409
- return _tslib.__awaiter(this, void 0, void 0, function* () {
410
- yield this.validateActiveWallet(from);
411
- const walletClient = this.getWalletClient();
412
- const publicClient = yield this.getPublicClient();
413
- if (!publicClient || !walletClient) {
414
- throw new utils.DynamicError('No public client available');
415
- }
416
- return ethereumCore.createViemUiTransaction({
417
- from: from,
418
- publicClient: publicClient,
419
- walletClient: walletClient,
420
- });
421
- });
422
- }
423
- registerEoa(_a) {
424
- return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }) {
425
- throw new Error('Not implemented');
426
- });
427
- }
428
- }
429
-
430
- exports.ZKsyncConnector = ZKsyncConnector;