@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.cjs
DELETED
|
@@ -1,590 +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 passkey = require('zksync-sso/client/passkey');
|
|
10
|
-
var utils$1 = require('zksync-sso/utils');
|
|
11
|
-
var client = require('zksync-sso/client');
|
|
12
|
-
var ecdsa = require('zksync-sso/client/ecdsa');
|
|
13
|
-
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
14
|
-
var utils = require('@dynamic-labs/utils');
|
|
15
|
-
var AccountAbstractionConnector = require('./AccountAbstractionConnector.cjs');
|
|
16
|
-
var abi = require('./utils/abi.cjs');
|
|
17
|
-
|
|
18
|
-
class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConnector {
|
|
19
|
-
constructor(props) {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
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._isSmartAccountDeployed = false;
|
|
31
|
-
this.enablePasskeys = true;
|
|
32
|
-
this.enableEIP7702Mode = false;
|
|
33
|
-
this.walletFallback = {
|
|
34
|
-
brand: {
|
|
35
|
-
alt: 'Smart Wallet',
|
|
36
|
-
spriteId: 'smartwallet',
|
|
37
|
-
},
|
|
38
|
-
name: 'ZKsync',
|
|
39
|
-
};
|
|
40
|
-
this._walletUiUtils = props.walletUiUtils;
|
|
41
|
-
this.providersConfig = (_a = props.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
42
|
-
this.chainId = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.defaultChainId;
|
|
43
|
-
this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
|
|
44
|
-
this.factoryAddress = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress; // Fallback if not provided
|
|
45
|
-
this.paymasterAddress = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress; // Fallback if not provided
|
|
46
|
-
this.passkeyAddress = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.passkeyAddress; // Fallback if not provided
|
|
47
|
-
this.sessionKeyAddress = (_f = props.apiProviders.zksync) === null || _f === void 0 ? void 0 : _f.sessionAddress; // Fallback if not provided
|
|
48
|
-
this.enablePasskeys =
|
|
49
|
-
(_h = (_g = props.settings.sdk.accountAbstraction) === null || _g === void 0 ? void 0 : _g.enablePasskeys) !== null && _h !== void 0 ? _h : false;
|
|
50
|
-
}
|
|
51
|
-
getEnabledNetworks() {
|
|
52
|
-
return this.evmNetworks;
|
|
53
|
-
}
|
|
54
|
-
getConnectedAccounts() {
|
|
55
|
-
return _tslib.__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 _tslib.__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 _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
return viem.createPublicClient({
|
|
77
|
-
chain: ethereumCore.getOrMapViemChain(this.evmNetworks[0]),
|
|
78
|
-
transport: viem.http(),
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
canSponsorTransactionGas() {
|
|
83
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
return false;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
getAccountAbstractionProvider() {
|
|
88
|
-
return this.smartAccount;
|
|
89
|
-
}
|
|
90
|
-
getWalletClient() {
|
|
91
|
-
const smartAccountClient = this.smartAccount;
|
|
92
|
-
if (!smartAccountClient) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
const transport = this.getWalletClientTransport(smartAccountClient);
|
|
96
|
-
return viem.createWalletClient({
|
|
97
|
-
account: smartAccountClient.account,
|
|
98
|
-
chain: smartAccountClient.chain,
|
|
99
|
-
transport,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
getWalletClientTransport(smartAccountClient) {
|
|
103
|
-
return viem.custom({
|
|
104
|
-
request: (_a) => _tslib.__awaiter(this, [_a], void 0, function* ({ method, params, }) {
|
|
105
|
-
const handleRequest = () => _tslib.__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 viem.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 this public client if performance becomes an issue.
|
|
138
|
-
const publicClient = viem.createPublicClient({
|
|
139
|
-
chain: smartAccountClient.chain,
|
|
140
|
-
transport: viem.http(undefined, this.providersConfig.httpTransportConfig), // Use configured transport if available
|
|
141
|
-
});
|
|
142
|
-
return publicClient.request({ method, params });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
// The internal confirmationTransport used by smartAccountClient via its 'owner'
|
|
147
|
-
// should handle the UI prompts. We don't need to add extra prompts here.
|
|
148
|
-
return handleRequest();
|
|
149
|
-
}),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
getTransport(provider) {
|
|
153
|
-
const transport = ethereumCore.confirmationTransport({
|
|
154
|
-
getAccounts: () => _tslib.__awaiter(this, void 0, void 0, function* () { return [provider.account.address]; }),
|
|
155
|
-
onPersonalSign: (_a) => _tslib.__awaiter(this, [_a], void 0, function* ({ message }) {
|
|
156
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
157
|
-
if (!this._isSmartAccountDeployed) {
|
|
158
|
-
yield this.deploySmartAccount({
|
|
159
|
-
withPaymaster: true,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
163
|
-
return provider.signMessage({
|
|
164
|
-
message,
|
|
165
|
-
});
|
|
166
|
-
}),
|
|
167
|
-
onSignTypedData: (_b) => _tslib.__awaiter(this, [_b], void 0, function* ({ message }) {
|
|
168
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
169
|
-
const signTypedData = JSON.parse(message);
|
|
170
|
-
if (!this._isSmartAccountDeployed) {
|
|
171
|
-
yield this.deploySmartAccount({
|
|
172
|
-
withPaymaster: true,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
176
|
-
return provider.signTypedData({
|
|
177
|
-
domain: signTypedData.domain,
|
|
178
|
-
message: signTypedData.message,
|
|
179
|
-
primaryType: signTypedData.primaryType,
|
|
180
|
-
types: signTypedData.types,
|
|
181
|
-
});
|
|
182
|
-
}),
|
|
183
|
-
provider: provider.extend(viem.publicActions),
|
|
184
|
-
transport: viem.custom(provider, this.providersConfig.httpTransportConfig),
|
|
185
|
-
// TODO: remove this. We should not be passing references to wallet connectors
|
|
186
|
-
walletConnector: this,
|
|
187
|
-
walletUiUtils: this._walletUiUtils,
|
|
188
|
-
});
|
|
189
|
-
return transport;
|
|
190
|
-
}
|
|
191
|
-
getSigner() {
|
|
192
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
return this.getWalletClient();
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
createEcdsaClient(eoaConnector) {
|
|
197
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
const eoaSigner = yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.getSigner());
|
|
199
|
-
if (!eoaSigner) {
|
|
200
|
-
throw new Error('EOA wallet client not found');
|
|
201
|
-
}
|
|
202
|
-
const transport = this.getTransport(eoaSigner);
|
|
203
|
-
const ownerWithTransport = viem.createWalletClient(Object.assign(Object.assign({}, eoaSigner), { transport }));
|
|
204
|
-
const walletClient = yield ecdsa.createZksyncEcdsaClient({
|
|
205
|
-
address: this.smartAccountAddress,
|
|
206
|
-
chain: ethereumCore.getOrMapViemChain(this.evmNetworks[0]),
|
|
207
|
-
contracts: {
|
|
208
|
-
accountFactory: this.factoryAddress,
|
|
209
|
-
session: this.sessionKeyAddress,
|
|
210
|
-
},
|
|
211
|
-
owner: ownerWithTransport,
|
|
212
|
-
transport: viem.custom(ownerWithTransport),
|
|
213
|
-
});
|
|
214
|
-
return walletClient;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Implementation of the interface method required by IAccountAbstractionWalletConnector
|
|
219
|
-
* @param eoaConnector - The EOA connector to use for signing transactions
|
|
220
|
-
* @param smartAccountAddress - The address of the smart account
|
|
221
|
-
*/
|
|
222
|
-
initializeZksyncConnector(_a) {
|
|
223
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaConnector, smartAccountAddress, }) {
|
|
224
|
-
this.initializedDeferredPromise = this.initializedDeferredPromise
|
|
225
|
-
? this.initializedDeferredPromise
|
|
226
|
-
: new utils.DeferredPromise();
|
|
227
|
-
this.eoaConnector = eoaConnector;
|
|
228
|
-
this.eoaAddress = yield eoaConnector.getAddress();
|
|
229
|
-
this.smartAccountAddress = smartAccountAddress;
|
|
230
|
-
this.smartAccount = (yield this.createEcdsaClient(eoaConnector));
|
|
231
|
-
yield this.checkIsDeployed();
|
|
232
|
-
this.initializedDeferredPromise.resolve();
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
createSessionClient(sessionKey, sessionConfig) {
|
|
236
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
if (!this.smartAccountAddress) {
|
|
238
|
-
throw new Error('Smart account address is not initialized');
|
|
239
|
-
}
|
|
240
|
-
return client.createZksyncSessionClient({
|
|
241
|
-
address: this.smartAccountAddress,
|
|
242
|
-
chain: ethereumCore.getOrMapViemChain(this.evmNetworks[0]),
|
|
243
|
-
contracts: {
|
|
244
|
-
session: this.sessionKeyAddress,
|
|
245
|
-
},
|
|
246
|
-
sessionConfig,
|
|
247
|
-
sessionKey,
|
|
248
|
-
transport: viem.http(),
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Creates a passkey client for ZKsync authentication
|
|
254
|
-
*
|
|
255
|
-
* This method initializes a passkey client using stored credentials and
|
|
256
|
-
* configures it with the necessary contract addresses and chain information.
|
|
257
|
-
*
|
|
258
|
-
*/
|
|
259
|
-
createPasskeyClient() {
|
|
260
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
261
|
-
if (!this.smartAccountAddress) {
|
|
262
|
-
throw new Error('Smart account address is not initialized');
|
|
263
|
-
}
|
|
264
|
-
const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
|
|
265
|
-
if (!storedCredentialPublicKey) {
|
|
266
|
-
throw new Error('Credential public key not found');
|
|
267
|
-
}
|
|
268
|
-
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
269
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
270
|
-
const { chain } = publicClient;
|
|
271
|
-
if (!chain) {
|
|
272
|
-
throw new Error('Chain information not available');
|
|
273
|
-
}
|
|
274
|
-
const contractAddresses = {
|
|
275
|
-
accountFactory: this.factoryAddress,
|
|
276
|
-
passkey: this.passkeyAddress,
|
|
277
|
-
session: this.sessionKeyAddress,
|
|
278
|
-
};
|
|
279
|
-
this.passkeyClient = passkey.createZksyncPasskeyClient({
|
|
280
|
-
address: this.smartAccountAddress,
|
|
281
|
-
chain,
|
|
282
|
-
contracts: contractAddresses,
|
|
283
|
-
credentialPublicKey,
|
|
284
|
-
transport: viem.http(),
|
|
285
|
-
userDisplayName: this.smartAccountAddress,
|
|
286
|
-
userName: this.smartAccountAddress,
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
registerPasskeyAndDeploy() {
|
|
291
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
const { credentialPublicKey, credentialId } = yield passkey.registerNewPasskey({
|
|
293
|
-
attestationType: 'none',
|
|
294
|
-
authenticatorSelection: {
|
|
295
|
-
authenticatorAttachment: 'platform',
|
|
296
|
-
requireResidentKey: false,
|
|
297
|
-
userVerification: 'required',
|
|
298
|
-
},
|
|
299
|
-
userDisplayName: this.smartAccountAddress,
|
|
300
|
-
userName: this.smartAccountAddress,
|
|
301
|
-
});
|
|
302
|
-
utils.StorageService.setItem('credentialPublicKey', credentialPublicKey);
|
|
303
|
-
utils.StorageService.setItem('credentialId', credentialId);
|
|
304
|
-
yield this.deploySmartAccount({
|
|
305
|
-
withPaymaster: true,
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
deploySmartAccount(_a) {
|
|
310
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
311
|
-
if (withPaymaster && this.paymasterAddress) {
|
|
312
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
yield this.deploySmartAccountWithoutPaymaster();
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
deploySmartAccountWithPaymaster() {
|
|
320
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
if (!this.paymasterAddress) {
|
|
322
|
-
throw new Error('Paymaster address is not initialized');
|
|
323
|
-
}
|
|
324
|
-
const paymaster = this.paymasterAddress;
|
|
325
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
326
|
-
const walletClient = yield this.getTypedWalletClient();
|
|
327
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
328
|
-
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
329
|
-
const paymasterInput = zksync.getGeneralPaymasterInput({
|
|
330
|
-
innerInput: new Uint8Array(),
|
|
331
|
-
});
|
|
332
|
-
const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
|
|
333
|
-
paymasterInput });
|
|
334
|
-
yield this.executeAccountDeployment(walletClient, requestWithPaymaster);
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Deploys a new smart account contract
|
|
339
|
-
* @throws {ZkSyncConnectorError} If deployment fails
|
|
340
|
-
* @testable This method can be mocked in tests
|
|
341
|
-
*/
|
|
342
|
-
deploySmartAccountWithoutPaymaster() {
|
|
343
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
344
|
-
if (!this.eoaConnector) {
|
|
345
|
-
throw new Error('EOA connector is not initialized');
|
|
346
|
-
}
|
|
347
|
-
const walletClient = yield this.getTypedWalletClient();
|
|
348
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
349
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
350
|
-
// Simulate the contract deployment first
|
|
351
|
-
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
352
|
-
// Execute the deployment transaction
|
|
353
|
-
yield this.executeAccountDeployment(walletClient, request);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Gets typed public client from EOA connector
|
|
358
|
-
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
359
|
-
* @testable This method can be mocked in tests
|
|
360
|
-
*/
|
|
361
|
-
getTypedPublicClient() {
|
|
362
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
if (!this.eoaConnector) {
|
|
364
|
-
throw new Error('EOA connector is not initialized');
|
|
365
|
-
}
|
|
366
|
-
const publicClient = yield this.eoaConnector.getPublicClient();
|
|
367
|
-
if (!publicClient) {
|
|
368
|
-
throw new Error('Failed to get public client from EOA connector');
|
|
369
|
-
}
|
|
370
|
-
return publicClient;
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Gets typed wallet client from EOA connector
|
|
375
|
-
* @throws {ZkSyncConnectorError} If wallet client cannot be obtained
|
|
376
|
-
* @testable This method can be mocked in tests
|
|
377
|
-
*/
|
|
378
|
-
getTypedWalletClient() {
|
|
379
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
380
|
-
if (!this.eoaConnector) {
|
|
381
|
-
throw new Error('EOA connector is not initialized');
|
|
382
|
-
}
|
|
383
|
-
const walletClient = yield this.eoaConnector.getWalletClient();
|
|
384
|
-
if (!walletClient) {
|
|
385
|
-
throw new Error('Failed to get wallet client from EOA connector');
|
|
386
|
-
}
|
|
387
|
-
return walletClient
|
|
388
|
-
.extend(viem.publicActions)
|
|
389
|
-
.extend(viem.walletActions)
|
|
390
|
-
.extend(zksync.eip712WalletActions())
|
|
391
|
-
.extend(ecdsa.zksyncSsoEcdsaWalletActions);
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Returns the parameters needed for deploying the smart account
|
|
396
|
-
* @returns Deployment parameters object
|
|
397
|
-
* @testable This method can be overridden in tests
|
|
398
|
-
*/
|
|
399
|
-
getDeploymentParameters() {
|
|
400
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
401
|
-
const salt = `0x${Buffer.from(viem.toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
|
|
402
|
-
const initialValidators = [];
|
|
403
|
-
const initialK1Owners = [this.eoaAddress];
|
|
404
|
-
// TODO: revisit this logic, maybe we should always add the passkey module data,
|
|
405
|
-
// otherwise if people active passkeys later, old accounts will not be able to use passkey module
|
|
406
|
-
if (this.enablePasskeys && this.passkeyAddress) {
|
|
407
|
-
const encodedPasskeyModuleData = yield this.getEncodedPasskeyModuleData();
|
|
408
|
-
initialValidators.push(encodedPasskeyModuleData);
|
|
409
|
-
}
|
|
410
|
-
if (this.sessionKeyAddress) {
|
|
411
|
-
const encodedSessionKeyModuleData = utils$1.encodeModuleData({
|
|
412
|
-
address: this.sessionKeyAddress,
|
|
413
|
-
parameters: '0x',
|
|
414
|
-
});
|
|
415
|
-
initialValidators.push(encodedSessionKeyModuleData);
|
|
416
|
-
}
|
|
417
|
-
return {
|
|
418
|
-
initialK1Owners,
|
|
419
|
-
initialValidators,
|
|
420
|
-
salt,
|
|
421
|
-
};
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Retrieves and encodes passkey module data for smart account deployment
|
|
426
|
-
* @returns Encoded passkey module data as a hex string
|
|
427
|
-
* @throws {Error} If credential public key or ID is not found
|
|
428
|
-
* @private
|
|
429
|
-
*/
|
|
430
|
-
getEncodedPasskeyModuleData() {
|
|
431
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
432
|
-
const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
|
|
433
|
-
if (!storedCredentialPublicKey) {
|
|
434
|
-
throw new Error('Credential public key not found');
|
|
435
|
-
}
|
|
436
|
-
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
437
|
-
const credentialId = utils.StorageService.getItem('credentialId');
|
|
438
|
-
if (!credentialId) {
|
|
439
|
-
throw new Error('Credential ID not found');
|
|
440
|
-
}
|
|
441
|
-
const passkeyPublicKey = utils$1.getPublicKeyBytesFromPasskeySignature(credentialPublicKey);
|
|
442
|
-
const encodedPasskeyParameters = utils$1.encodePasskeyModuleParameters({
|
|
443
|
-
credentialId: credentialId,
|
|
444
|
-
expectedOrigin: window.location.origin, // TODO: how is this going to be set?
|
|
445
|
-
passkeyPublicKey,
|
|
446
|
-
});
|
|
447
|
-
return utils$1.encodeModuleData({
|
|
448
|
-
address: this.passkeyAddress,
|
|
449
|
-
parameters: encodedPasskeyParameters,
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Simulates the smart account deployment
|
|
455
|
-
* @param publicClient - The public client to use for simulation
|
|
456
|
-
* @param walletClient - The wallet client to use for account information
|
|
457
|
-
* @param params - The deployment parameters
|
|
458
|
-
* @returns The simulation result
|
|
459
|
-
* @throws {ZkSyncConnectorError} If simulation fails
|
|
460
|
-
* @testable This method can be mocked in tests
|
|
461
|
-
*/
|
|
462
|
-
simulateAccountDeployment(publicClient_1, walletClient_1, params_1) {
|
|
463
|
-
return _tslib.__awaiter(this, arguments, void 0, function* (publicClient, walletClient, params, checkBalance = true) {
|
|
464
|
-
var _a, _b, _c;
|
|
465
|
-
// this is to keep the same salt as calculated on zksync sso package
|
|
466
|
-
const salt = viem.keccak256(viem.toHex(params.salt));
|
|
467
|
-
const gasEstimate = yield publicClient.estimateContractGas({
|
|
468
|
-
abi: abi.AAFactoryABI,
|
|
469
|
-
account: (_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address,
|
|
470
|
-
address: this.factoryAddress,
|
|
471
|
-
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
472
|
-
functionName: 'deployProxySsoAccount',
|
|
473
|
-
});
|
|
474
|
-
if (checkBalance) {
|
|
475
|
-
const balance = yield publicClient.getBalance({
|
|
476
|
-
address: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
477
|
-
});
|
|
478
|
-
if (balance < gasEstimate) {
|
|
479
|
-
throw new Error('Insufficient balance to deploy account');
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
// Simulate the contract call
|
|
483
|
-
return publicClient.simulateContract({
|
|
484
|
-
abi: abi.AAFactoryABI,
|
|
485
|
-
account: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
|
|
486
|
-
address: this.factoryAddress,
|
|
487
|
-
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
488
|
-
functionName: 'deployProxySsoAccount',
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Executes the smart account deployment transaction
|
|
494
|
-
* @param walletClient - The wallet client to use for transaction execution
|
|
495
|
-
* @param request - The deployment request object containing transaction parameters
|
|
496
|
-
* @returns Promise that resolves when the deployment transaction is confirmed
|
|
497
|
-
* @throws {DynamicError} If the smart account address is not initialized
|
|
498
|
-
* @throws {Error} If transaction execution or confirmation fails
|
|
499
|
-
*/
|
|
500
|
-
executeAccountDeployment(walletClient, request) {
|
|
501
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
502
|
-
if (!this.smartAccountAddress) {
|
|
503
|
-
throw new Error('Smart account address is not initialized');
|
|
504
|
-
}
|
|
505
|
-
const tx = yield walletClient.writeContract(request);
|
|
506
|
-
const publicClient = yield this.getPublicClient();
|
|
507
|
-
yield publicClient.waitForTransactionReceipt({ hash: tx });
|
|
508
|
-
this._isSmartAccountDeployed = true;
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
signMessage(message) {
|
|
512
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
513
|
-
const walletClient = this.getWalletClient();
|
|
514
|
-
if (!walletClient) {
|
|
515
|
-
throw new Error('Wallet client not found');
|
|
516
|
-
}
|
|
517
|
-
return yield walletClient.signMessage({
|
|
518
|
-
account: walletClient.account,
|
|
519
|
-
message,
|
|
520
|
-
});
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Checks if a smart account is deployed
|
|
525
|
-
* @throws {ZkSyncConnectorError} If the check fails
|
|
526
|
-
* @returns Promise that resolves when the check is complete
|
|
527
|
-
*/
|
|
528
|
-
checkIsDeployed() {
|
|
529
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
530
|
-
const client = yield this.getPublicClient();
|
|
531
|
-
if (!client) {
|
|
532
|
-
throw new Error('Failed to get public client from EOA connector');
|
|
533
|
-
}
|
|
534
|
-
const code = yield client.getCode({
|
|
535
|
-
address: this.smartAccountAddress,
|
|
536
|
-
});
|
|
537
|
-
const isDeployed = Boolean(code);
|
|
538
|
-
this._isSmartAccountDeployed = isDeployed;
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
getAddress() {
|
|
542
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
543
|
-
var _a;
|
|
544
|
-
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
545
|
-
if (!this.smartAccount) {
|
|
546
|
-
throw new Error('Smart account is not initialized');
|
|
547
|
-
}
|
|
548
|
-
return this.smartAccountAddress;
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
validateActiveWallet(expectedAddress) {
|
|
552
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
553
|
-
const currentAddress = yield this.getAddress();
|
|
554
|
-
if (currentAddress !== expectedAddress) {
|
|
555
|
-
throw new utils.DynamicError('Invalid active wallet');
|
|
556
|
-
}
|
|
557
|
-
return;
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
createUiTransaction(from) {
|
|
561
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
562
|
-
yield this.validateActiveWallet(from);
|
|
563
|
-
const walletClient = this.getWalletClient();
|
|
564
|
-
const publicClient = yield this.getPublicClient();
|
|
565
|
-
if (!publicClient || !walletClient) {
|
|
566
|
-
throw new utils.DynamicError('No public client available');
|
|
567
|
-
}
|
|
568
|
-
return ethereumCore.createViemUiTransaction({
|
|
569
|
-
from: from,
|
|
570
|
-
publicClient: publicClient,
|
|
571
|
-
walletClient: walletClient,
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
isSmartAccountDeployed() {
|
|
576
|
-
return _tslib.__awaiter(this, arguments, void 0, function* (refetch = false) {
|
|
577
|
-
if (refetch) {
|
|
578
|
-
yield this.checkIsDeployed();
|
|
579
|
-
}
|
|
580
|
-
return this._isSmartAccountDeployed;
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
registerEoa(_a) {
|
|
584
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }) {
|
|
585
|
-
throw new Error('Not implemented');
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
exports.ZKsyncConnector = ZKsyncConnector;
|