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