@dynamic-labs/ethereum-aa-zksync 4.14.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.
- package/CHANGELOG.md +5345 -0
- package/LICENSE +21 -0
- package/README.md +22 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +34 -0
- package/src/connector/ZKsyncConnector.cjs +520 -0
- package/src/connector/ZKsyncConnector.d.ts +17416 -0
- package/src/connector/ZKsyncConnector.js +516 -0
- package/src/connector/index.d.ts +1 -0
- package/src/index.cjs +25 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +20 -0
- package/src/types/index.d.ts +8 -0
- package/src/utils/abi.cjs +88 -0
- package/src/utils/abi.d.ts +102 -0
- package/src/utils/abi.js +84 -0
- package/src/utils/deployment.cjs +97 -0
- package/src/utils/deployment.d.ts +37 -0
- package/src/utils/deployment.js +91 -0
- package/src/utils/getSalt.cjs +10 -0
- package/src/utils/getSalt.d.ts +1 -0
- package/src/utils/getSalt.js +6 -0
- package/src/utils/index.d.ts +5 -0
- package/src/utils/isZKsyncConnector.cjs +8 -0
- package/src/utils/isZKsyncConnector.d.ts +3 -0
- package/src/utils/isZKsyncConnector.js +4 -0
- package/src/utils/network.cjs +17 -0
- package/src/utils/network.d.ts +2 -0
- package/src/utils/network.js +13 -0
- package/src/utils/passkeys.cjs +41 -0
- package/src/utils/passkeys.d.ts +9 -0
- package/src/utils/passkeys.js +37 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { createWalletClient, custom, publicActions, createPublicClient, http, walletActions, toHex } from 'viem';
|
|
4
|
+
import { getGeneralPaymasterInput, eip712WalletActions } from 'viem/zksync';
|
|
5
|
+
import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client/passkey';
|
|
6
|
+
import { encodeModuleData } from 'zksync-sso/utils';
|
|
7
|
+
import { createZksyncSessionClient } from 'zksync-sso/client';
|
|
8
|
+
import { createZksyncEcdsaClient, zksyncSsoEcdsaWalletActions } from 'zksync-sso/client/ecdsa';
|
|
9
|
+
import { EthereumWallet, chainsMap, confirmationTransport, getOrMapViemChain } from '@dynamic-labs/ethereum-core';
|
|
10
|
+
import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
|
|
11
|
+
import { AccountAbstractionBaseConnector } from '@dynamic-labs/ethereum-aa-core';
|
|
12
|
+
import { getSalt } from '../utils/getSalt.js';
|
|
13
|
+
import { getEncodedPasskeyModuleData } from '../utils/passkeys.js';
|
|
14
|
+
import { getDeploymentParameters, simulateAccountDeployment, executeAccountDeployment } from '../utils/deployment.js';
|
|
15
|
+
import { ensureEoaConnectorNetwork } from '../utils/network.js';
|
|
16
|
+
|
|
17
|
+
class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
18
|
+
constructor(props) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
20
|
+
super(props);
|
|
21
|
+
// Core wallet properties
|
|
22
|
+
this.ChainWallet = EthereumWallet;
|
|
23
|
+
this.name = 'ZKsync';
|
|
24
|
+
this.overrideKey = 'zksync';
|
|
25
|
+
// Chain configuration
|
|
26
|
+
this.connectedChain = 'EVM';
|
|
27
|
+
this.evmNetworks = [];
|
|
28
|
+
this.supportedChains = ['ETH', 'EVM'];
|
|
29
|
+
this._isSmartAccountDeployed = false;
|
|
30
|
+
this.enablePasskeys = true;
|
|
31
|
+
this.enableEIP7702Mode = false;
|
|
32
|
+
this.walletFallback = {
|
|
33
|
+
brand: {
|
|
34
|
+
alt: 'Smart Wallet',
|
|
35
|
+
spriteId: 'smartwallet',
|
|
36
|
+
},
|
|
37
|
+
name: 'ZKsync',
|
|
38
|
+
};
|
|
39
|
+
this._walletUiUtils = props.walletUiUtils;
|
|
40
|
+
this.providersConfig = (_a = props.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
41
|
+
this.chainId = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.defaultChainId;
|
|
42
|
+
this.evmNetworks = parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
|
|
43
|
+
this.factoryAddress = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress; // Fallback if not provided
|
|
44
|
+
this.paymasterAddress = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress; // Fallback if not provided
|
|
45
|
+
this.passkeyAddress = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.passkeyAddress; // Fallback if not provided
|
|
46
|
+
this.sessionKeyAddress = (_f = props.apiProviders.zksync) === null || _f === void 0 ? void 0 : _f.sessionAddress; // Fallback if not provided
|
|
47
|
+
this.saltText = (_g = props.apiProviders.zksync) === null || _g === void 0 ? void 0 : _g.salt;
|
|
48
|
+
this.enablePasskeys =
|
|
49
|
+
(_j = (_h = props.settings.sdk.accountAbstraction) === null || _h === void 0 ? void 0 : _h.enablePasskeys) !== null && _j !== void 0 ? _j : false;
|
|
50
|
+
}
|
|
51
|
+
getEnabledNetworks() {
|
|
52
|
+
return this.evmNetworks;
|
|
53
|
+
}
|
|
54
|
+
getConnectedAccounts() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
var _a;
|
|
57
|
+
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
58
|
+
if (!this.smartAccountAddress) {
|
|
59
|
+
throw new Error('Smart account address is not initialized');
|
|
60
|
+
}
|
|
61
|
+
return [this.smartAccountAddress];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getNetwork() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a;
|
|
67
|
+
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
68
|
+
if (!this.smartAccountAddress) {
|
|
69
|
+
throw new Error('Smart account address is not initialized');
|
|
70
|
+
}
|
|
71
|
+
return this.chainId;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
getPublicClient() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return createPublicClient({
|
|
77
|
+
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
78
|
+
transport: http(),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
canSponsorTransactionGas() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return false;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
getAccountAbstractionProvider() {
|
|
88
|
+
return this.smartAccount;
|
|
89
|
+
}
|
|
90
|
+
getWalletClient(chainId) {
|
|
91
|
+
const smartAccountClient = this.smartAccount;
|
|
92
|
+
if (!smartAccountClient) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const transport = this.getWalletClientTransport(smartAccountClient);
|
|
96
|
+
return createWalletClient({
|
|
97
|
+
account: smartAccountClient.account,
|
|
98
|
+
chain: chainId ? chainsMap[chainId] : smartAccountClient.chain,
|
|
99
|
+
transport,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getWalletClientTransport(smartAccountClient) {
|
|
103
|
+
return custom({
|
|
104
|
+
request: (_a) => __awaiter(this, [_a], void 0, function* ({ method, params, }) {
|
|
105
|
+
const handleRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
var _b;
|
|
107
|
+
switch (method) {
|
|
108
|
+
case 'personal_sign':
|
|
109
|
+
// Delegate signing to the smart account client instance
|
|
110
|
+
return smartAccountClient.signMessage({ message: params[0] });
|
|
111
|
+
case 'eth_signTypedData_v4': {
|
|
112
|
+
// Delegate typed data signing to the smart account client instance
|
|
113
|
+
// Note: ZKsync usually expects JSON string for EIP712, but viem standard passes object.
|
|
114
|
+
// The smartAccountClient's signTypedData should handle the expected format internally.
|
|
115
|
+
const signTypedDataParams = params[1]; // Assuming standard viem format
|
|
116
|
+
return smartAccountClient.signTypedData(signTypedDataParams);
|
|
117
|
+
}
|
|
118
|
+
case 'eth_sendTransaction':
|
|
119
|
+
// Delegate transaction sending to the smart account client instance.
|
|
120
|
+
// This ensures deployment checks, paymaster logic, etc., are handled.
|
|
121
|
+
return smartAccountClient.sendTransaction(params[0]);
|
|
122
|
+
case 'eth_accounts':
|
|
123
|
+
case 'eth_requestAccounts':
|
|
124
|
+
// Return the smart account address
|
|
125
|
+
return ((_b = smartAccountClient.account) === null || _b === void 0 ? void 0 : _b.address)
|
|
126
|
+
? [smartAccountClient.account.address]
|
|
127
|
+
: [];
|
|
128
|
+
case 'eth_chainId': {
|
|
129
|
+
// Return chainId from the smart account client
|
|
130
|
+
const chainId = yield smartAccountClient.getChainId();
|
|
131
|
+
return toHex(chainId);
|
|
132
|
+
}
|
|
133
|
+
default: {
|
|
134
|
+
// For other read-only methods, delegate to a basic public client transport.
|
|
135
|
+
// Avoid creating a new client/transport on every call if possible,
|
|
136
|
+
// but for simplicity here, we create it transiently.
|
|
137
|
+
// Consider caching the provided client if performance becomes an issue.
|
|
138
|
+
return smartAccountClient.request({ method, params });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
// The internal confirmationTransport used by smartAccountClient via its 'owner'
|
|
143
|
+
// should handle the UI prompts. We don't need to add extra prompts here.
|
|
144
|
+
return handleRequest();
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
getTransport(provider) {
|
|
149
|
+
const transport = confirmationTransport({
|
|
150
|
+
getAccounts: () => __awaiter(this, void 0, void 0, function* () { return [provider.account.address]; }),
|
|
151
|
+
onPersonalSign: (_a) => __awaiter(this, [_a], void 0, function* ({ message }) {
|
|
152
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
153
|
+
if (!this._isSmartAccountDeployed) {
|
|
154
|
+
yield this.deploySmartAccount({
|
|
155
|
+
withPaymaster: true,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
159
|
+
return provider.signMessage({
|
|
160
|
+
message,
|
|
161
|
+
});
|
|
162
|
+
}),
|
|
163
|
+
onSignTypedData: (_b) => __awaiter(this, [_b], void 0, function* ({ message }) {
|
|
164
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
165
|
+
const signTypedData = JSON.parse(message);
|
|
166
|
+
if (!this._isSmartAccountDeployed) {
|
|
167
|
+
yield this.deploySmartAccount({
|
|
168
|
+
withPaymaster: true,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
172
|
+
return provider.signTypedData({
|
|
173
|
+
domain: signTypedData.domain,
|
|
174
|
+
message: signTypedData.message,
|
|
175
|
+
primaryType: signTypedData.primaryType,
|
|
176
|
+
types: signTypedData.types,
|
|
177
|
+
});
|
|
178
|
+
}),
|
|
179
|
+
provider: provider.extend(publicActions),
|
|
180
|
+
transport: custom(provider, this.providersConfig.httpTransportConfig),
|
|
181
|
+
walletConnector: this,
|
|
182
|
+
walletUiUtils: this._walletUiUtils,
|
|
183
|
+
});
|
|
184
|
+
return transport;
|
|
185
|
+
}
|
|
186
|
+
createEcdsaClient(eoaConnector) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const eoaSigner = yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.getSigner());
|
|
189
|
+
if (!eoaSigner) {
|
|
190
|
+
throw new Error('EOA wallet client not found');
|
|
191
|
+
}
|
|
192
|
+
if (!this.smartAccountAddress) {
|
|
193
|
+
throw new Error('Smart account address is not initialized');
|
|
194
|
+
}
|
|
195
|
+
const transport = this.getTransport(eoaSigner);
|
|
196
|
+
const ownerWithTransport = createWalletClient(Object.assign(Object.assign({}, eoaSigner), { transport }));
|
|
197
|
+
const walletClient = yield createZksyncEcdsaClient({
|
|
198
|
+
address: this.smartAccountAddress,
|
|
199
|
+
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
200
|
+
contracts: {
|
|
201
|
+
accountFactory: this.factoryAddress,
|
|
202
|
+
session: this.sessionKeyAddress,
|
|
203
|
+
},
|
|
204
|
+
owner: ownerWithTransport,
|
|
205
|
+
transport: custom(ownerWithTransport),
|
|
206
|
+
});
|
|
207
|
+
return walletClient;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Implementation of the interface method required by IAccountAbstractionWalletConnector
|
|
212
|
+
* @param eoaConnector - The EOA connector to use for signing transactions
|
|
213
|
+
* @param smartAccountAddress - The address of the smart account
|
|
214
|
+
*/
|
|
215
|
+
initialize(_a) {
|
|
216
|
+
return __awaiter(this, arguments, void 0, function* ({ eoaConnector, smartWalletAddress, }) {
|
|
217
|
+
this.initializedDeferredPromise = this.initializedDeferredPromise
|
|
218
|
+
? this.initializedDeferredPromise
|
|
219
|
+
: new DeferredPromise();
|
|
220
|
+
this.eoaConnector = eoaConnector;
|
|
221
|
+
this.eoaAddress = (yield eoaConnector.getAddress());
|
|
222
|
+
this.smartAccountAddress = smartWalletAddress;
|
|
223
|
+
this.smartAccount = (yield this.createEcdsaClient(eoaConnector));
|
|
224
|
+
yield this.checkIsDeployed();
|
|
225
|
+
this.initializedDeferredPromise.resolve();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
createSessionClient(sessionKey, sessionConfig) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
if (!this.smartAccountAddress) {
|
|
231
|
+
throw new Error('Smart account address is not initialized');
|
|
232
|
+
}
|
|
233
|
+
if (!this.sessionKeyAddress) {
|
|
234
|
+
throw new Error('Session key address is not initialized');
|
|
235
|
+
}
|
|
236
|
+
return createZksyncSessionClient({
|
|
237
|
+
address: this.smartAccountAddress,
|
|
238
|
+
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
239
|
+
contracts: {
|
|
240
|
+
session: this.sessionKeyAddress,
|
|
241
|
+
},
|
|
242
|
+
sessionConfig,
|
|
243
|
+
sessionKey,
|
|
244
|
+
transport: http(),
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Creates a passkey client for ZKsync authentication
|
|
250
|
+
*
|
|
251
|
+
* This method initializes a passkey client using stored credentials and
|
|
252
|
+
* configures it with the necessary contract addresses and chain information.
|
|
253
|
+
*
|
|
254
|
+
*/
|
|
255
|
+
createPasskeyClient() {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
if (!this.smartAccountAddress) {
|
|
258
|
+
throw new Error('Smart account address is not initialized');
|
|
259
|
+
}
|
|
260
|
+
if (!this.passkeyAddress) {
|
|
261
|
+
throw new Error('Passkey address is not initialized');
|
|
262
|
+
}
|
|
263
|
+
const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
|
|
264
|
+
if (!storedCredentialPublicKey) {
|
|
265
|
+
throw new Error('Credential public key not found');
|
|
266
|
+
}
|
|
267
|
+
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
268
|
+
const publicClient = yield this.getTypedPublicClient();
|
|
269
|
+
const { chain } = publicClient;
|
|
270
|
+
if (!chain) {
|
|
271
|
+
throw new Error('Chain information not available');
|
|
272
|
+
}
|
|
273
|
+
const contractAddresses = {
|
|
274
|
+
accountFactory: this.factoryAddress,
|
|
275
|
+
passkey: this.passkeyAddress,
|
|
276
|
+
recovery: this.recoveryAddress,
|
|
277
|
+
session: this.sessionKeyAddress,
|
|
278
|
+
};
|
|
279
|
+
this.passkeyClient = createZksyncPasskeyClient({
|
|
280
|
+
address: this.smartAccountAddress,
|
|
281
|
+
chain,
|
|
282
|
+
contracts: contractAddresses,
|
|
283
|
+
credentialPublicKey,
|
|
284
|
+
transport: http(),
|
|
285
|
+
userDisplayName: this.smartAccountAddress,
|
|
286
|
+
userName: this.smartAccountAddress,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
registerPasskeyAndDeploy() {
|
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
if (!this.smartAccountAddress) {
|
|
293
|
+
throw new Error('Smart account address is not initialized');
|
|
294
|
+
}
|
|
295
|
+
const { credentialPublicKey, credentialId } = yield registerNewPasskey({
|
|
296
|
+
attestationType: 'none',
|
|
297
|
+
authenticatorSelection: {
|
|
298
|
+
authenticatorAttachment: 'platform',
|
|
299
|
+
requireResidentKey: false,
|
|
300
|
+
userVerification: 'required',
|
|
301
|
+
},
|
|
302
|
+
userDisplayName: this.smartAccountAddress,
|
|
303
|
+
userName: this.smartAccountAddress,
|
|
304
|
+
});
|
|
305
|
+
StorageService.setItem('credentialPublicKey', credentialPublicKey);
|
|
306
|
+
StorageService.setItem('credentialId', credentialId);
|
|
307
|
+
yield this.deploySmartAccount({
|
|
308
|
+
withPaymaster: true,
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
deploySmartAccount(_a) {
|
|
313
|
+
return __awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
314
|
+
if (!this.chainId) {
|
|
315
|
+
throw new Error('Chain ID is not initialized');
|
|
316
|
+
}
|
|
317
|
+
if (!this.eoaConnector) {
|
|
318
|
+
throw new Error('EOA connector is not initialized');
|
|
319
|
+
}
|
|
320
|
+
yield ensureEoaConnectorNetwork(this.eoaConnector, this.chainId);
|
|
321
|
+
if (withPaymaster && this.paymasterAddress) {
|
|
322
|
+
yield this.deploySmartAccountWithPaymaster();
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
yield this.deploySmartAccountWithoutPaymaster();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
deploySmartAccountWithPaymaster() {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
if (!this.paymasterAddress) {
|
|
332
|
+
throw new Error('Paymaster address is not initialized');
|
|
333
|
+
}
|
|
334
|
+
if (!this.smartAccountAddress) {
|
|
335
|
+
throw new Error('Smart account address is not initialized');
|
|
336
|
+
}
|
|
337
|
+
if (!this.eoaAddress) {
|
|
338
|
+
throw new Error('EOA address is not initialized');
|
|
339
|
+
}
|
|
340
|
+
const paymaster = this.paymasterAddress;
|
|
341
|
+
const publicClient = yield this.getTypedPublicClient();
|
|
342
|
+
const walletClient = yield this.getTypedWalletClient();
|
|
343
|
+
const deploymentParams = yield getDeploymentParameters({
|
|
344
|
+
enablePasskeys: this.enablePasskeys,
|
|
345
|
+
eoaAddress: this.eoaAddress,
|
|
346
|
+
passkeyAddress: this.passkeyAddress,
|
|
347
|
+
saltText: this.saltText,
|
|
348
|
+
sessionKeyAddress: this.sessionKeyAddress,
|
|
349
|
+
});
|
|
350
|
+
const { request } = yield simulateAccountDeployment(publicClient, walletClient, deploymentParams, this.factoryAddress, false);
|
|
351
|
+
const paymasterInput = getGeneralPaymasterInput({
|
|
352
|
+
innerInput: new Uint8Array(),
|
|
353
|
+
});
|
|
354
|
+
const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
|
|
355
|
+
paymasterInput });
|
|
356
|
+
yield executeAccountDeployment(walletClient, publicClient, requestWithPaymaster, this.smartAccountAddress);
|
|
357
|
+
this._isSmartAccountDeployed = true;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Deploys a new smart account contract
|
|
362
|
+
* @throws {ZkSyncConnectorError} If deployment fails
|
|
363
|
+
* @testable This method can be mocked in tests
|
|
364
|
+
*/
|
|
365
|
+
deploySmartAccountWithoutPaymaster() {
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
if (!this.eoaConnector) {
|
|
368
|
+
throw new Error('EOA connector is not initialized');
|
|
369
|
+
}
|
|
370
|
+
if (!this.smartAccountAddress) {
|
|
371
|
+
throw new Error('Smart account address is not initialized');
|
|
372
|
+
}
|
|
373
|
+
const walletClient = yield this.getTypedWalletClient();
|
|
374
|
+
const publicClient = yield this.getTypedPublicClient();
|
|
375
|
+
const deploymentParams = yield this.getDeploymentParameters();
|
|
376
|
+
// Simulate the contract deployment first
|
|
377
|
+
const { request } = yield simulateAccountDeployment(publicClient, walletClient, deploymentParams, this.factoryAddress, false);
|
|
378
|
+
// Execute the deployment transaction
|
|
379
|
+
yield executeAccountDeployment(walletClient, publicClient, request, this.smartAccountAddress);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Gets typed public client from EOA connector
|
|
384
|
+
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
385
|
+
* @testable This method can be mocked in tests
|
|
386
|
+
*/
|
|
387
|
+
getTypedPublicClient() {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
389
|
+
if (!this.eoaConnector) {
|
|
390
|
+
throw new Error('EOA connector is not initialized');
|
|
391
|
+
}
|
|
392
|
+
const publicClient = yield this.eoaConnector.getPublicClient();
|
|
393
|
+
if (!publicClient) {
|
|
394
|
+
throw new Error('Failed to get public client from EOA connector');
|
|
395
|
+
}
|
|
396
|
+
return publicClient;
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Gets typed wallet client from EOA connector on the correct chain
|
|
401
|
+
* @throws {ZkSyncConnectorError} If wallet client cannot be obtained
|
|
402
|
+
* @testable This method can be mocked in tests
|
|
403
|
+
*/
|
|
404
|
+
getTypedWalletClient() {
|
|
405
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
406
|
+
if (!this.eoaConnector) {
|
|
407
|
+
throw new Error('EOA connector is not initialized');
|
|
408
|
+
}
|
|
409
|
+
const walletClient = yield this.eoaConnector.getWalletClient();
|
|
410
|
+
if (!walletClient) {
|
|
411
|
+
throw new Error('Failed to get wallet client from EOA connector');
|
|
412
|
+
}
|
|
413
|
+
return walletClient
|
|
414
|
+
.extend(publicActions)
|
|
415
|
+
.extend(walletActions)
|
|
416
|
+
.extend(eip712WalletActions())
|
|
417
|
+
.extend(zksyncSsoEcdsaWalletActions);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Returns the parameters needed for deploying the smart account
|
|
422
|
+
* @returns Deployment parameters object
|
|
423
|
+
* @testable This method can be overridden in tests
|
|
424
|
+
*/
|
|
425
|
+
getDeploymentParameters() {
|
|
426
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
427
|
+
if (!this.eoaAddress) {
|
|
428
|
+
throw new Error('EOA address is not initialized');
|
|
429
|
+
}
|
|
430
|
+
const initialValidators = [];
|
|
431
|
+
const initialK1Owners = [this.eoaAddress];
|
|
432
|
+
// TODO: revisit this logic, maybe we should always add the passkey module data,
|
|
433
|
+
// otherwise if people active passkeys later, old accounts will not be able to use passkey module
|
|
434
|
+
if (this.enablePasskeys && this.passkeyAddress) {
|
|
435
|
+
const encodedPasskeyModuleData = yield getEncodedPasskeyModuleData({
|
|
436
|
+
passkeyAddress: this.passkeyAddress,
|
|
437
|
+
});
|
|
438
|
+
initialValidators.push(encodedPasskeyModuleData);
|
|
439
|
+
}
|
|
440
|
+
if (this.sessionKeyAddress) {
|
|
441
|
+
const encodedSessionKeyModuleData = encodeModuleData({
|
|
442
|
+
address: this.sessionKeyAddress,
|
|
443
|
+
parameters: '0x',
|
|
444
|
+
});
|
|
445
|
+
initialValidators.push(encodedSessionKeyModuleData);
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
initialK1Owners,
|
|
449
|
+
initialValidators,
|
|
450
|
+
salt: getSalt(this.saltText),
|
|
451
|
+
};
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
signMessage(message) {
|
|
455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
const walletClient = this.getWalletClient();
|
|
457
|
+
if (!walletClient) {
|
|
458
|
+
throw new Error('Error fetching signer');
|
|
459
|
+
}
|
|
460
|
+
return walletClient.signMessage({
|
|
461
|
+
account: walletClient.account,
|
|
462
|
+
message,
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Checks if a smart account is deployed
|
|
468
|
+
* @throws {ZkSyncConnectorError} If the check fails
|
|
469
|
+
* @returns Promise that resolves when the check is complete
|
|
470
|
+
*/
|
|
471
|
+
checkIsDeployed() {
|
|
472
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
if (!this.smartAccountAddress) {
|
|
474
|
+
throw new Error('Smart account address is not initialized');
|
|
475
|
+
}
|
|
476
|
+
const client = yield this.getPublicClient();
|
|
477
|
+
if (!client) {
|
|
478
|
+
throw new Error('Failed to get public client from EOA connector');
|
|
479
|
+
}
|
|
480
|
+
const code = yield client.getCode({
|
|
481
|
+
address: this.smartAccountAddress,
|
|
482
|
+
});
|
|
483
|
+
const isDeployed = Boolean(code);
|
|
484
|
+
this._isSmartAccountDeployed = isDeployed;
|
|
485
|
+
return isDeployed;
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
getAddress() {
|
|
489
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
490
|
+
var _a;
|
|
491
|
+
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
492
|
+
if (!this.smartAccount) {
|
|
493
|
+
throw new Error('Smart account is not initialized');
|
|
494
|
+
}
|
|
495
|
+
return this.smartAccountAddress;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
validateActiveWallet(expectedAddress) {
|
|
499
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
500
|
+
const currentAddress = yield this.getAddress();
|
|
501
|
+
if (currentAddress !== expectedAddress) {
|
|
502
|
+
throw new DynamicError('Invalid active wallet');
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
isSmartAccountDeployed() {
|
|
507
|
+
return __awaiter(this, arguments, void 0, function* (refetch = false) {
|
|
508
|
+
if (refetch) {
|
|
509
|
+
yield this.checkIsDeployed();
|
|
510
|
+
}
|
|
511
|
+
return this._isSmartAccountDeployed;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export { ZKsyncConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ZKsyncConnector } from './ZKsyncConnector';
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
8
|
+
var ZKsyncConnector = require('./connector/ZKsyncConnector.cjs');
|
|
9
|
+
require('viem');
|
|
10
|
+
require('../_virtual/_tslib.cjs');
|
|
11
|
+
require('zksync-sso/utils');
|
|
12
|
+
require('@dynamic-labs/utils');
|
|
13
|
+
var isZKsyncConnector = require('./utils/isZKsyncConnector.cjs');
|
|
14
|
+
|
|
15
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/ethereum-aa-zksync', _package.version);
|
|
16
|
+
const ZKsyncSmartWalletConnectors = (props) => {
|
|
17
|
+
var _a;
|
|
18
|
+
if ((_a = props.apiProviders) === null || _a === void 0 ? void 0 : _a.zksync) {
|
|
19
|
+
return [ZKsyncConnector.ZKsyncConnector];
|
|
20
|
+
}
|
|
21
|
+
return [];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.isZKsyncConnector = isZKsyncConnector.isZKsyncConnector;
|
|
25
|
+
exports.ZKsyncSmartWalletConnectors = ZKsyncSmartWalletConnectors;
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
|
+
import { version } from '../package.js';
|
|
4
|
+
import { ZKsyncConnector } from './connector/ZKsyncConnector.js';
|
|
5
|
+
import 'viem';
|
|
6
|
+
import '../_virtual/_tslib.js';
|
|
7
|
+
import 'zksync-sso/utils';
|
|
8
|
+
import '@dynamic-labs/utils';
|
|
9
|
+
export { isZKsyncConnector } from './utils/isZKsyncConnector.js';
|
|
10
|
+
|
|
11
|
+
assertPackageVersion('@dynamic-labs/ethereum-aa-zksync', version);
|
|
12
|
+
const ZKsyncSmartWalletConnectors = (props) => {
|
|
13
|
+
var _a;
|
|
14
|
+
if ((_a = props.apiProviders) === null || _a === void 0 ? void 0 : _a.zksync) {
|
|
15
|
+
return [ZKsyncConnector];
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { ZKsyncSmartWalletConnectors };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
|
|
2
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import { InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
export type AccountAbstractionConnectorProps = {
|
|
5
|
+
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
6
|
+
walletBook: WalletBookSchema;
|
|
7
|
+
evmNetworks: GenericNetwork[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
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;
|