@dynamic-labs/ethereum-aa 4.10.4-preview.2 → 4.11.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 +7 -18
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -10
- package/src/ZeroDevConnector.cjs +13 -17
- package/src/ZeroDevConnector.d.ts +16 -17
- package/src/ZeroDevConnector.js +14 -18
- package/src/index.cjs +0 -11
- package/src/index.d.ts +0 -2
- package/src/index.js +1 -10
- package/src/AccountAbstractionConnector.cjs +0 -75
- package/src/AccountAbstractionConnector.d.ts +0 -56
- package/src/AccountAbstractionConnector.js +0 -71
- package/src/ZKsyncConnector.cjs +0 -590
- package/src/ZKsyncConnector.d.ts +0 -24921
- package/src/ZKsyncConnector.js +0 -586
- package/src/utils/abi.cjs +0 -88
- package/src/utils/abi.d.ts +0 -102
- package/src/utils/abi.js +0 -84
- package/src/utils/isZKsyncConnector.cjs +0 -8
- package/src/utils/isZKsyncConnector.d.ts +0 -3
- package/src/utils/isZKsyncConnector.js +0 -4
package/src/ZKsyncConnector.js
DELETED
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { createPublicClient, http, createWalletClient, custom, publicActions, 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 { createZksyncEcdsaClient, zksyncSsoEcdsaWalletActions } from 'zksync-sso/client/ecdsa';
|
|
9
|
-
import { EthereumWallet, getOrMapViemChain, confirmationTransport, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
10
|
-
import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
|
|
11
|
-
import { AccountAbstractionConnector } from './AccountAbstractionConnector.js';
|
|
12
|
-
import { AAFactoryABI } from './utils/abi.js';
|
|
13
|
-
|
|
14
|
-
class ZKsyncConnector extends AccountAbstractionConnector {
|
|
15
|
-
constructor(props) {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
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._isSmartAccountDeployed = false;
|
|
27
|
-
this.enablePasskeys = true;
|
|
28
|
-
this.enableEIP7702Mode = false;
|
|
29
|
-
this.walletFallback = {
|
|
30
|
-
brand: {
|
|
31
|
-
alt: 'Smart Wallet',
|
|
32
|
-
spriteId: 'smartwallet',
|
|
33
|
-
},
|
|
34
|
-
name: 'ZKsync',
|
|
35
|
-
};
|
|
36
|
-
this._walletUiUtils = props.walletUiUtils;
|
|
37
|
-
this.providersConfig = (_a = props.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
38
|
-
this.chainId = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.defaultChainId;
|
|
39
|
-
this.evmNetworks = parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
|
|
40
|
-
this.factoryAddress = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress; // Fallback if not provided
|
|
41
|
-
this.paymasterAddress = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress; // Fallback if not provided
|
|
42
|
-
this.passkeyAddress = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.passkeyAddress; // Fallback if not provided
|
|
43
|
-
this.sessionKeyAddress = (_f = props.apiProviders.zksync) === null || _f === void 0 ? void 0 : _f.sessionAddress; // Fallback if not provided
|
|
44
|
-
this.enablePasskeys =
|
|
45
|
-
(_h = (_g = props.settings.sdk.accountAbstraction) === null || _g === void 0 ? void 0 : _g.enablePasskeys) !== null && _h !== void 0 ? _h : false;
|
|
46
|
-
}
|
|
47
|
-
getEnabledNetworks() {
|
|
48
|
-
return this.evmNetworks;
|
|
49
|
-
}
|
|
50
|
-
getConnectedAccounts() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
var _a;
|
|
53
|
-
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
54
|
-
if (!this.smartAccountAddress) {
|
|
55
|
-
throw new Error('Smart account address is not initialized');
|
|
56
|
-
}
|
|
57
|
-
return [this.smartAccountAddress];
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
getNetwork() {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
var _a;
|
|
63
|
-
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
64
|
-
if (!this.smartAccountAddress) {
|
|
65
|
-
throw new Error('Smart account address is not initialized');
|
|
66
|
-
}
|
|
67
|
-
return this.chainId;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
getPublicClient() {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
return createPublicClient({
|
|
73
|
-
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
74
|
-
transport: http(),
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
canSponsorTransactionGas() {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
return false;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
getAccountAbstractionProvider() {
|
|
84
|
-
return this.smartAccount;
|
|
85
|
-
}
|
|
86
|
-
getWalletClient() {
|
|
87
|
-
const smartAccountClient = this.smartAccount;
|
|
88
|
-
if (!smartAccountClient) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
const transport = this.getWalletClientTransport(smartAccountClient);
|
|
92
|
-
return createWalletClient({
|
|
93
|
-
account: smartAccountClient.account,
|
|
94
|
-
chain: smartAccountClient.chain,
|
|
95
|
-
transport,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
getWalletClientTransport(smartAccountClient) {
|
|
99
|
-
return custom({
|
|
100
|
-
request: (_a) => __awaiter(this, [_a], void 0, function* ({ method, params, }) {
|
|
101
|
-
const handleRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
var _b;
|
|
103
|
-
switch (method) {
|
|
104
|
-
case 'personal_sign':
|
|
105
|
-
// Delegate signing to the smart account client instance
|
|
106
|
-
return smartAccountClient.signMessage({ message: params[0] });
|
|
107
|
-
case 'eth_signTypedData_v4': {
|
|
108
|
-
// Delegate typed data signing to the smart account client instance
|
|
109
|
-
// Note: ZKsync usually expects JSON string for EIP712, but viem standard passes object.
|
|
110
|
-
// The smartAccountClient's signTypedData should handle the expected format internally.
|
|
111
|
-
const signTypedDataParams = params[1]; // Assuming standard viem format
|
|
112
|
-
return smartAccountClient.signTypedData(signTypedDataParams);
|
|
113
|
-
}
|
|
114
|
-
case 'eth_sendTransaction':
|
|
115
|
-
// Delegate transaction sending to the smart account client instance.
|
|
116
|
-
// This ensures deployment checks, paymaster logic, etc., are handled.
|
|
117
|
-
return smartAccountClient.sendTransaction(params[0]);
|
|
118
|
-
case 'eth_accounts':
|
|
119
|
-
case 'eth_requestAccounts':
|
|
120
|
-
// Return the smart account address
|
|
121
|
-
return ((_b = smartAccountClient.account) === null || _b === void 0 ? void 0 : _b.address)
|
|
122
|
-
? [smartAccountClient.account.address]
|
|
123
|
-
: [];
|
|
124
|
-
case 'eth_chainId': {
|
|
125
|
-
// Return chainId from the smart account client
|
|
126
|
-
const chainId = yield smartAccountClient.getChainId();
|
|
127
|
-
return toHex(chainId);
|
|
128
|
-
}
|
|
129
|
-
default: {
|
|
130
|
-
// For other read-only methods, delegate to a basic public client transport.
|
|
131
|
-
// Avoid creating a new client/transport on every call if possible,
|
|
132
|
-
// but for simplicity here, we create it transiently.
|
|
133
|
-
// Consider caching this public client if performance becomes an issue.
|
|
134
|
-
const publicClient = createPublicClient({
|
|
135
|
-
chain: smartAccountClient.chain,
|
|
136
|
-
transport: http(undefined, this.providersConfig.httpTransportConfig), // Use configured transport if available
|
|
137
|
-
});
|
|
138
|
-
return publicClient.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
|
-
// TODO: remove this. We should not be passing references to wallet connectors
|
|
182
|
-
walletConnector: this,
|
|
183
|
-
walletUiUtils: this._walletUiUtils,
|
|
184
|
-
});
|
|
185
|
-
return transport;
|
|
186
|
-
}
|
|
187
|
-
getSigner() {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
return this.getWalletClient();
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
createEcdsaClient(eoaConnector) {
|
|
193
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
const eoaSigner = yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.getSigner());
|
|
195
|
-
if (!eoaSigner) {
|
|
196
|
-
throw new Error('EOA wallet client not found');
|
|
197
|
-
}
|
|
198
|
-
const transport = this.getTransport(eoaSigner);
|
|
199
|
-
const ownerWithTransport = createWalletClient(Object.assign(Object.assign({}, eoaSigner), { transport }));
|
|
200
|
-
const walletClient = yield createZksyncEcdsaClient({
|
|
201
|
-
address: this.smartAccountAddress,
|
|
202
|
-
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
203
|
-
contracts: {
|
|
204
|
-
accountFactory: this.factoryAddress,
|
|
205
|
-
session: this.sessionKeyAddress,
|
|
206
|
-
},
|
|
207
|
-
owner: ownerWithTransport,
|
|
208
|
-
transport: custom(ownerWithTransport),
|
|
209
|
-
});
|
|
210
|
-
return walletClient;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Implementation of the interface method required by IAccountAbstractionWalletConnector
|
|
215
|
-
* @param eoaConnector - The EOA connector to use for signing transactions
|
|
216
|
-
* @param smartAccountAddress - The address of the smart account
|
|
217
|
-
*/
|
|
218
|
-
initializeZksyncConnector(_a) {
|
|
219
|
-
return __awaiter(this, arguments, void 0, function* ({ eoaConnector, smartAccountAddress, }) {
|
|
220
|
-
this.initializedDeferredPromise = this.initializedDeferredPromise
|
|
221
|
-
? this.initializedDeferredPromise
|
|
222
|
-
: new DeferredPromise();
|
|
223
|
-
this.eoaConnector = eoaConnector;
|
|
224
|
-
this.eoaAddress = yield eoaConnector.getAddress();
|
|
225
|
-
this.smartAccountAddress = smartAccountAddress;
|
|
226
|
-
this.smartAccount = (yield this.createEcdsaClient(eoaConnector));
|
|
227
|
-
yield this.checkIsDeployed();
|
|
228
|
-
this.initializedDeferredPromise.resolve();
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
createSessionClient(sessionKey, sessionConfig) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
if (!this.smartAccountAddress) {
|
|
234
|
-
throw new Error('Smart account 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
|
-
const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
|
|
261
|
-
if (!storedCredentialPublicKey) {
|
|
262
|
-
throw new Error('Credential public key not found');
|
|
263
|
-
}
|
|
264
|
-
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
265
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
266
|
-
const { chain } = publicClient;
|
|
267
|
-
if (!chain) {
|
|
268
|
-
throw new Error('Chain information not available');
|
|
269
|
-
}
|
|
270
|
-
const contractAddresses = {
|
|
271
|
-
accountFactory: this.factoryAddress,
|
|
272
|
-
passkey: this.passkeyAddress,
|
|
273
|
-
session: this.sessionKeyAddress,
|
|
274
|
-
};
|
|
275
|
-
this.passkeyClient = createZksyncPasskeyClient({
|
|
276
|
-
address: this.smartAccountAddress,
|
|
277
|
-
chain,
|
|
278
|
-
contracts: contractAddresses,
|
|
279
|
-
credentialPublicKey,
|
|
280
|
-
transport: http(),
|
|
281
|
-
userDisplayName: this.smartAccountAddress,
|
|
282
|
-
userName: this.smartAccountAddress,
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
registerPasskeyAndDeploy() {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
const { credentialPublicKey, credentialId } = yield registerNewPasskey({
|
|
289
|
-
attestationType: 'none',
|
|
290
|
-
authenticatorSelection: {
|
|
291
|
-
authenticatorAttachment: 'platform',
|
|
292
|
-
requireResidentKey: false,
|
|
293
|
-
userVerification: 'required',
|
|
294
|
-
},
|
|
295
|
-
userDisplayName: this.smartAccountAddress,
|
|
296
|
-
userName: this.smartAccountAddress,
|
|
297
|
-
});
|
|
298
|
-
StorageService.setItem('credentialPublicKey', credentialPublicKey);
|
|
299
|
-
StorageService.setItem('credentialId', credentialId);
|
|
300
|
-
yield this.deploySmartAccount({
|
|
301
|
-
withPaymaster: true,
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
deploySmartAccount(_a) {
|
|
306
|
-
return __awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
307
|
-
if (withPaymaster && this.paymasterAddress) {
|
|
308
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
yield this.deploySmartAccountWithoutPaymaster();
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
deploySmartAccountWithPaymaster() {
|
|
316
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
if (!this.paymasterAddress) {
|
|
318
|
-
throw new Error('Paymaster address is not initialized');
|
|
319
|
-
}
|
|
320
|
-
const paymaster = this.paymasterAddress;
|
|
321
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
322
|
-
const walletClient = yield this.getTypedWalletClient();
|
|
323
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
324
|
-
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
325
|
-
const paymasterInput = getGeneralPaymasterInput({
|
|
326
|
-
innerInput: new Uint8Array(),
|
|
327
|
-
});
|
|
328
|
-
const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
|
|
329
|
-
paymasterInput });
|
|
330
|
-
yield this.executeAccountDeployment(walletClient, requestWithPaymaster);
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Deploys a new smart account contract
|
|
335
|
-
* @throws {ZkSyncConnectorError} If deployment fails
|
|
336
|
-
* @testable This method can be mocked in tests
|
|
337
|
-
*/
|
|
338
|
-
deploySmartAccountWithoutPaymaster() {
|
|
339
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
340
|
-
if (!this.eoaConnector) {
|
|
341
|
-
throw new Error('EOA connector is not initialized');
|
|
342
|
-
}
|
|
343
|
-
const walletClient = yield this.getTypedWalletClient();
|
|
344
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
345
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
346
|
-
// Simulate the contract deployment first
|
|
347
|
-
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
348
|
-
// Execute the deployment transaction
|
|
349
|
-
yield this.executeAccountDeployment(walletClient, request);
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Gets typed public client from EOA connector
|
|
354
|
-
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
355
|
-
* @testable This method can be mocked in tests
|
|
356
|
-
*/
|
|
357
|
-
getTypedPublicClient() {
|
|
358
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
-
if (!this.eoaConnector) {
|
|
360
|
-
throw new Error('EOA connector is not initialized');
|
|
361
|
-
}
|
|
362
|
-
const publicClient = yield this.eoaConnector.getPublicClient();
|
|
363
|
-
if (!publicClient) {
|
|
364
|
-
throw new Error('Failed to get public client from EOA connector');
|
|
365
|
-
}
|
|
366
|
-
return publicClient;
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Gets typed wallet client from EOA connector
|
|
371
|
-
* @throws {ZkSyncConnectorError} If wallet client cannot be obtained
|
|
372
|
-
* @testable This method can be mocked in tests
|
|
373
|
-
*/
|
|
374
|
-
getTypedWalletClient() {
|
|
375
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
-
if (!this.eoaConnector) {
|
|
377
|
-
throw new Error('EOA connector is not initialized');
|
|
378
|
-
}
|
|
379
|
-
const walletClient = yield this.eoaConnector.getWalletClient();
|
|
380
|
-
if (!walletClient) {
|
|
381
|
-
throw new Error('Failed to get wallet client from EOA connector');
|
|
382
|
-
}
|
|
383
|
-
return walletClient
|
|
384
|
-
.extend(publicActions)
|
|
385
|
-
.extend(walletActions)
|
|
386
|
-
.extend(eip712WalletActions())
|
|
387
|
-
.extend(zksyncSsoEcdsaWalletActions);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Returns the parameters needed for deploying the smart account
|
|
392
|
-
* @returns Deployment parameters object
|
|
393
|
-
* @testable This method can be overridden in tests
|
|
394
|
-
*/
|
|
395
|
-
getDeploymentParameters() {
|
|
396
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
397
|
-
const salt = `0x${Buffer.from(toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
|
|
398
|
-
const initialValidators = [];
|
|
399
|
-
const initialK1Owners = [this.eoaAddress];
|
|
400
|
-
// TODO: revisit this logic, maybe we should always add the passkey module data,
|
|
401
|
-
// otherwise if people active passkeys later, old accounts will not be able to use passkey module
|
|
402
|
-
if (this.enablePasskeys && this.passkeyAddress) {
|
|
403
|
-
const encodedPasskeyModuleData = yield this.getEncodedPasskeyModuleData();
|
|
404
|
-
initialValidators.push(encodedPasskeyModuleData);
|
|
405
|
-
}
|
|
406
|
-
if (this.sessionKeyAddress) {
|
|
407
|
-
const encodedSessionKeyModuleData = encodeModuleData({
|
|
408
|
-
address: this.sessionKeyAddress,
|
|
409
|
-
parameters: '0x',
|
|
410
|
-
});
|
|
411
|
-
initialValidators.push(encodedSessionKeyModuleData);
|
|
412
|
-
}
|
|
413
|
-
return {
|
|
414
|
-
initialK1Owners,
|
|
415
|
-
initialValidators,
|
|
416
|
-
salt,
|
|
417
|
-
};
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Retrieves and encodes passkey module data for smart account deployment
|
|
422
|
-
* @returns Encoded passkey module data as a hex string
|
|
423
|
-
* @throws {Error} If credential public key or ID is not found
|
|
424
|
-
* @private
|
|
425
|
-
*/
|
|
426
|
-
getEncodedPasskeyModuleData() {
|
|
427
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
428
|
-
const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
|
|
429
|
-
if (!storedCredentialPublicKey) {
|
|
430
|
-
throw new Error('Credential public key not found');
|
|
431
|
-
}
|
|
432
|
-
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
433
|
-
const credentialId = StorageService.getItem('credentialId');
|
|
434
|
-
if (!credentialId) {
|
|
435
|
-
throw new Error('Credential ID not found');
|
|
436
|
-
}
|
|
437
|
-
const passkeyPublicKey = getPublicKeyBytesFromPasskeySignature(credentialPublicKey);
|
|
438
|
-
const encodedPasskeyParameters = encodePasskeyModuleParameters({
|
|
439
|
-
credentialId: credentialId,
|
|
440
|
-
expectedOrigin: window.location.origin, // TODO: how is this going to be set?
|
|
441
|
-
passkeyPublicKey,
|
|
442
|
-
});
|
|
443
|
-
return encodeModuleData({
|
|
444
|
-
address: this.passkeyAddress,
|
|
445
|
-
parameters: encodedPasskeyParameters,
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Simulates the smart account deployment
|
|
451
|
-
* @param publicClient - The public client to use for simulation
|
|
452
|
-
* @param walletClient - The wallet client to use for account information
|
|
453
|
-
* @param params - The deployment parameters
|
|
454
|
-
* @returns The simulation result
|
|
455
|
-
* @throws {ZkSyncConnectorError} If simulation fails
|
|
456
|
-
* @testable This method can be mocked in tests
|
|
457
|
-
*/
|
|
458
|
-
simulateAccountDeployment(publicClient_1, walletClient_1, params_1) {
|
|
459
|
-
return __awaiter(this, arguments, void 0, function* (publicClient, walletClient, params, checkBalance = true) {
|
|
460
|
-
var _a, _b, _c;
|
|
461
|
-
// this is to keep the same salt as calculated on zksync sso package
|
|
462
|
-
const salt = keccak256(toHex(params.salt));
|
|
463
|
-
const gasEstimate = yield publicClient.estimateContractGas({
|
|
464
|
-
abi: AAFactoryABI,
|
|
465
|
-
account: (_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address,
|
|
466
|
-
address: this.factoryAddress,
|
|
467
|
-
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
468
|
-
functionName: 'deployProxySsoAccount',
|
|
469
|
-
});
|
|
470
|
-
if (checkBalance) {
|
|
471
|
-
const balance = yield publicClient.getBalance({
|
|
472
|
-
address: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
473
|
-
});
|
|
474
|
-
if (balance < gasEstimate) {
|
|
475
|
-
throw new Error('Insufficient balance to deploy account');
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
// Simulate the contract call
|
|
479
|
-
return publicClient.simulateContract({
|
|
480
|
-
abi: AAFactoryABI,
|
|
481
|
-
account: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
|
|
482
|
-
address: this.factoryAddress,
|
|
483
|
-
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
484
|
-
functionName: 'deployProxySsoAccount',
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Executes the smart account deployment transaction
|
|
490
|
-
* @param walletClient - The wallet client to use for transaction execution
|
|
491
|
-
* @param request - The deployment request object containing transaction parameters
|
|
492
|
-
* @returns Promise that resolves when the deployment transaction is confirmed
|
|
493
|
-
* @throws {DynamicError} If the smart account address is not initialized
|
|
494
|
-
* @throws {Error} If transaction execution or confirmation fails
|
|
495
|
-
*/
|
|
496
|
-
executeAccountDeployment(walletClient, request) {
|
|
497
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
498
|
-
if (!this.smartAccountAddress) {
|
|
499
|
-
throw new Error('Smart account address is not initialized');
|
|
500
|
-
}
|
|
501
|
-
const tx = yield walletClient.writeContract(request);
|
|
502
|
-
const publicClient = yield this.getPublicClient();
|
|
503
|
-
yield publicClient.waitForTransactionReceipt({ hash: tx });
|
|
504
|
-
this._isSmartAccountDeployed = true;
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
signMessage(message) {
|
|
508
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
509
|
-
const walletClient = this.getWalletClient();
|
|
510
|
-
if (!walletClient) {
|
|
511
|
-
throw new Error('Wallet client not found');
|
|
512
|
-
}
|
|
513
|
-
return yield walletClient.signMessage({
|
|
514
|
-
account: walletClient.account,
|
|
515
|
-
message,
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Checks if a smart account is deployed
|
|
521
|
-
* @throws {ZkSyncConnectorError} If the check fails
|
|
522
|
-
* @returns Promise that resolves when the check is complete
|
|
523
|
-
*/
|
|
524
|
-
checkIsDeployed() {
|
|
525
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
526
|
-
const client = yield this.getPublicClient();
|
|
527
|
-
if (!client) {
|
|
528
|
-
throw new Error('Failed to get public client from EOA connector');
|
|
529
|
-
}
|
|
530
|
-
const code = yield client.getCode({
|
|
531
|
-
address: this.smartAccountAddress,
|
|
532
|
-
});
|
|
533
|
-
const isDeployed = Boolean(code);
|
|
534
|
-
this._isSmartAccountDeployed = isDeployed;
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
getAddress() {
|
|
538
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
539
|
-
var _a;
|
|
540
|
-
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
541
|
-
if (!this.smartAccount) {
|
|
542
|
-
throw new Error('Smart account is not initialized');
|
|
543
|
-
}
|
|
544
|
-
return this.smartAccountAddress;
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
validateActiveWallet(expectedAddress) {
|
|
548
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
549
|
-
const currentAddress = yield this.getAddress();
|
|
550
|
-
if (currentAddress !== expectedAddress) {
|
|
551
|
-
throw new DynamicError('Invalid active wallet');
|
|
552
|
-
}
|
|
553
|
-
return;
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
createUiTransaction(from) {
|
|
557
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
558
|
-
yield this.validateActiveWallet(from);
|
|
559
|
-
const walletClient = this.getWalletClient();
|
|
560
|
-
const publicClient = yield this.getPublicClient();
|
|
561
|
-
if (!publicClient || !walletClient) {
|
|
562
|
-
throw new DynamicError('No public client available');
|
|
563
|
-
}
|
|
564
|
-
return createViemUiTransaction({
|
|
565
|
-
from: from,
|
|
566
|
-
publicClient: publicClient,
|
|
567
|
-
walletClient: walletClient,
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
isSmartAccountDeployed() {
|
|
572
|
-
return __awaiter(this, arguments, void 0, function* (refetch = false) {
|
|
573
|
-
if (refetch) {
|
|
574
|
-
yield this.checkIsDeployed();
|
|
575
|
-
}
|
|
576
|
-
return this._isSmartAccountDeployed;
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
registerEoa(_a) {
|
|
580
|
-
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }) {
|
|
581
|
-
throw new Error('Not implemented');
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
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;
|