@dynamic-labs/ethereum-aa 4.10.4-preview.0 → 4.10.4
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 +5 -6
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -11
- package/src/ZeroDevConnector.cjs +13 -17
- package/src/ZeroDevConnector.d.ts +15 -21
- 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/ZKsync/client.cjs +0 -29
- package/src/ZKsync/client.d.ts +0 -24
- package/src/ZKsync/client.js +0 -25
- package/src/ZKsync/ecdsaAccount.cjs +0 -32
- package/src/ZKsync/ecdsaAccount.d.ts +0 -13
- package/src/ZKsync/ecdsaAccount.js +0 -28
- package/src/ZKsync/getEip712Domain.cjs +0 -62
- package/src/ZKsync/getEip712Domain.d.ts +0 -2
- package/src/ZKsync/getEip712Domain.js +0 -58
- package/src/ZKsync/types.cjs +0 -52
- package/src/ZKsync/types.d.ts +0 -9
- package/src/ZKsync/types.js +0 -48
- package/src/ZKsync/walletActions.cjs +0 -93
- package/src/ZKsync/walletActions.d.ts +0 -15
- package/src/ZKsync/walletActions.js +0 -87
- package/src/ZKsyncConnector.cjs +0 -502
- package/src/ZKsyncConnector.d.ts +0 -24918
- package/src/ZKsyncConnector.js +0 -498
- 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,498 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { createPublicClient, http, publicActions, custom, createWalletClient, walletActions, toBytes, keccak256, toHex } from 'viem';
|
|
4
|
-
import { getGeneralPaymasterInput, eip712WalletActions } from 'viem/zksync';
|
|
5
|
-
import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client/passkey';
|
|
6
|
-
import { getPublicKeyBytesFromPasskeySignature, encodePasskeyModuleParameters, encodeModuleData } from 'zksync-sso/utils';
|
|
7
|
-
import { EthereumWallet, getOrMapViemChain, confirmationTransport, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
8
|
-
import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
|
|
9
|
-
import { AccountAbstractionConnector } from './AccountAbstractionConnector.js';
|
|
10
|
-
import { AAFactoryABI } from './utils/abi.js';
|
|
11
|
-
import { createZksyncEcdsaClient } from './ZKsync/client.js';
|
|
12
|
-
import { zksyncSsoEcdsaWalletActions } from './ZKsync/walletActions.js';
|
|
13
|
-
|
|
14
|
-
class ZKsyncConnector extends AccountAbstractionConnector {
|
|
15
|
-
constructor(props) {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
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 = ((_d = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress) !== null && _d !== void 0 ? _d : '0xa980E4B20354d4944de93F2a51f0a14c6E8e481d'); // Fallback if not provided
|
|
41
|
-
this.paymasterAddress = ((_f = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.paymasterAddress) !== null && _f !== void 0 ? _f : '0xD681ef8eD603F8F3b1CF9c1ef93548e698F60F0a'); // Fallback if not provided
|
|
42
|
-
this.passkeyAddress = ((_h = (_g = props.apiProviders.zksync) === null || _g === void 0 ? void 0 : _g.passkeyAddress) !== null && _h !== void 0 ? _h : '0x271546A4a3d8050610367e68040d41ee56E4BB31'); // Fallback if not provided
|
|
43
|
-
this.sessionKeyAddress = ((_k = (_j = props.apiProviders.zksync) === null || _j === void 0 ? void 0 : _j.sessionAddress) !== null && _k !== void 0 ? _k : '0xA8CC0A6bD462B44A8830bBbfB54Ce19F32815Fb7'); // Fallback if not provided
|
|
44
|
-
this.enablePasskeys =
|
|
45
|
-
(_m = (_l = props.settings.sdk.accountAbstraction) === null || _l === void 0 ? void 0 : _l.enablePasskeys) !== null && _m !== void 0 ? _m : 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
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
-
getWalletClient() {
|
|
88
|
-
if (!this.smartAccount) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
return this.smartAccount;
|
|
92
|
-
}
|
|
93
|
-
getTransport(provider) {
|
|
94
|
-
const transport = confirmationTransport({
|
|
95
|
-
getAccounts: () => __awaiter(this, void 0, void 0, function* () { return [provider.account.address]; }),
|
|
96
|
-
onPersonalSign: (_a) => __awaiter(this, [_a], void 0, function* ({ message }) {
|
|
97
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
98
|
-
if (!this._isSmartAccountDeployed) {
|
|
99
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
100
|
-
}
|
|
101
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
102
|
-
return provider.signMessage({
|
|
103
|
-
message,
|
|
104
|
-
});
|
|
105
|
-
}),
|
|
106
|
-
onSignTypedData: (_b) => __awaiter(this, [_b], void 0, function* ({ message }) {
|
|
107
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
108
|
-
const signTypedData = JSON.parse(message);
|
|
109
|
-
if (!this._isSmartAccountDeployed) {
|
|
110
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
111
|
-
}
|
|
112
|
-
this._walletUiUtils.disabledConfirmationOnce();
|
|
113
|
-
return provider.signTypedData({
|
|
114
|
-
domain: signTypedData.domain,
|
|
115
|
-
message: signTypedData.message,
|
|
116
|
-
primaryType: signTypedData.primaryType,
|
|
117
|
-
types: signTypedData.types,
|
|
118
|
-
});
|
|
119
|
-
}),
|
|
120
|
-
provider: provider.extend(publicActions),
|
|
121
|
-
transport: custom(provider, this.providersConfig.httpTransportConfig),
|
|
122
|
-
// TODO: remove this. We should not be passing references to wallet connectors
|
|
123
|
-
walletConnector: this,
|
|
124
|
-
walletUiUtils: this._walletUiUtils,
|
|
125
|
-
});
|
|
126
|
-
return transport;
|
|
127
|
-
}
|
|
128
|
-
getSigner() {
|
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
return this.getWalletClient();
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
createEcdsaClient(eoaConnector) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const eoaSigner = yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.getSigner());
|
|
136
|
-
if (!eoaSigner) {
|
|
137
|
-
throw new Error('EOA wallet client not found');
|
|
138
|
-
}
|
|
139
|
-
const transport = this.getTransport(eoaSigner);
|
|
140
|
-
const ownerWithTransport = createWalletClient(Object.assign(Object.assign({}, eoaSigner), { transport }));
|
|
141
|
-
const walletClient = yield createZksyncEcdsaClient({
|
|
142
|
-
address: this.smartAccountAddress,
|
|
143
|
-
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
144
|
-
contracts: {
|
|
145
|
-
accountFactory: this.factoryAddress,
|
|
146
|
-
session: this.sessionKeyAddress,
|
|
147
|
-
},
|
|
148
|
-
owner: ownerWithTransport,
|
|
149
|
-
transport: http(),
|
|
150
|
-
});
|
|
151
|
-
return walletClient;
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Implementation of the interface method required by IAccountAbstractionWalletConnector
|
|
156
|
-
* @param eoaConnector - The EOA connector to use for signing transactions
|
|
157
|
-
* @param smartAccountAddress - The address of the smart account
|
|
158
|
-
*/
|
|
159
|
-
initializeZksyncConnector(_a) {
|
|
160
|
-
return __awaiter(this, arguments, void 0, function* ({ eoaConnector, smartAccountAddress, }) {
|
|
161
|
-
this.initializedDeferredPromise = this.initializedDeferredPromise
|
|
162
|
-
? this.initializedDeferredPromise
|
|
163
|
-
: new DeferredPromise();
|
|
164
|
-
this.eoaConnector = eoaConnector;
|
|
165
|
-
this.eoaAddress = yield eoaConnector.getAddress();
|
|
166
|
-
this.smartAccountAddress = smartAccountAddress;
|
|
167
|
-
this.smartAccount = (yield this.createEcdsaClient(eoaConnector));
|
|
168
|
-
yield this.checkIsDeployed();
|
|
169
|
-
this.initializedDeferredPromise.resolve();
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Creates a passkey client for ZKsync authentication
|
|
174
|
-
*
|
|
175
|
-
* This method initializes a passkey client using stored credentials and
|
|
176
|
-
* configures it with the necessary contract addresses and chain information.
|
|
177
|
-
*
|
|
178
|
-
*/
|
|
179
|
-
createPasskeyClient() {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
if (!this.smartAccountAddress) {
|
|
182
|
-
throw new Error('Smart account address is not initialized');
|
|
183
|
-
}
|
|
184
|
-
const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
|
|
185
|
-
if (!storedCredentialPublicKey) {
|
|
186
|
-
throw new Error('Credential public key not found');
|
|
187
|
-
}
|
|
188
|
-
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
189
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
190
|
-
const { chain } = publicClient;
|
|
191
|
-
if (!chain) {
|
|
192
|
-
throw new Error('Chain information not available');
|
|
193
|
-
}
|
|
194
|
-
const contractAddresses = {
|
|
195
|
-
accountFactory: this.factoryAddress,
|
|
196
|
-
passkey: this.passkeyAddress,
|
|
197
|
-
session: this.sessionKeyAddress,
|
|
198
|
-
};
|
|
199
|
-
this.passkeyClient = createZksyncPasskeyClient({
|
|
200
|
-
address: this.smartAccountAddress,
|
|
201
|
-
chain,
|
|
202
|
-
contracts: contractAddresses,
|
|
203
|
-
credentialPublicKey,
|
|
204
|
-
transport: http(),
|
|
205
|
-
userDisplayName: this.smartAccountAddress,
|
|
206
|
-
userName: this.smartAccountAddress,
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
registerPasskeyAndDeploy() {
|
|
211
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
const { credentialPublicKey, credentialId } = yield registerNewPasskey({
|
|
213
|
-
attestationType: 'none',
|
|
214
|
-
authenticatorSelection: {
|
|
215
|
-
authenticatorAttachment: 'platform',
|
|
216
|
-
requireResidentKey: false,
|
|
217
|
-
userVerification: 'required',
|
|
218
|
-
},
|
|
219
|
-
userDisplayName: this.smartAccountAddress,
|
|
220
|
-
userName: this.smartAccountAddress,
|
|
221
|
-
});
|
|
222
|
-
StorageService.setItem('credentialPublicKey', credentialPublicKey);
|
|
223
|
-
StorageService.setItem('credentialId', credentialId);
|
|
224
|
-
yield this.deploySmartAccount({
|
|
225
|
-
withPaymaster: true,
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
deploySmartAccount(_a) {
|
|
230
|
-
return __awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
231
|
-
if (withPaymaster) {
|
|
232
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
yield this.deploySmartAccountWithoutPaymaster();
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
deploySmartAccountWithPaymaster() {
|
|
240
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
const paymaster = this.paymasterAddress;
|
|
242
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
243
|
-
const walletClient = yield this.getTypedWalletClient();
|
|
244
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
245
|
-
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
246
|
-
const paymasterInput = getGeneralPaymasterInput({
|
|
247
|
-
innerInput: new Uint8Array(),
|
|
248
|
-
});
|
|
249
|
-
const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
|
|
250
|
-
paymasterInput });
|
|
251
|
-
yield this.executeAccountDeployment(walletClient, requestWithPaymaster);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Deploys a new smart account contract
|
|
256
|
-
* @throws {ZkSyncConnectorError} If deployment fails
|
|
257
|
-
* @testable This method can be mocked in tests
|
|
258
|
-
*/
|
|
259
|
-
deploySmartAccountWithoutPaymaster() {
|
|
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 walletClient = yield this.getTypedWalletClient();
|
|
265
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
266
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
267
|
-
// Simulate the contract deployment first
|
|
268
|
-
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
269
|
-
// Execute the deployment transaction
|
|
270
|
-
yield this.executeAccountDeployment(walletClient, request);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Gets typed public client from EOA connector
|
|
275
|
-
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
276
|
-
* @testable This method can be mocked in tests
|
|
277
|
-
*/
|
|
278
|
-
getTypedPublicClient() {
|
|
279
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
-
if (!this.eoaConnector) {
|
|
281
|
-
throw new Error('EOA connector is not initialized');
|
|
282
|
-
}
|
|
283
|
-
const publicClient = yield this.eoaConnector.getPublicClient();
|
|
284
|
-
if (!publicClient) {
|
|
285
|
-
throw new Error('Failed to get public client from EOA connector');
|
|
286
|
-
}
|
|
287
|
-
return publicClient;
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Gets typed wallet client from EOA connector
|
|
292
|
-
* @throws {ZkSyncConnectorError} If wallet client cannot be obtained
|
|
293
|
-
* @testable This method can be mocked in tests
|
|
294
|
-
*/
|
|
295
|
-
getTypedWalletClient() {
|
|
296
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
-
if (!this.eoaConnector) {
|
|
298
|
-
throw new Error('EOA connector is not initialized');
|
|
299
|
-
}
|
|
300
|
-
const walletClient = yield this.eoaConnector.getWalletClient();
|
|
301
|
-
if (!walletClient) {
|
|
302
|
-
throw new Error('Failed to get wallet client from EOA connector');
|
|
303
|
-
}
|
|
304
|
-
return walletClient
|
|
305
|
-
.extend(publicActions)
|
|
306
|
-
.extend(walletActions)
|
|
307
|
-
.extend(eip712WalletActions())
|
|
308
|
-
.extend(zksyncSsoEcdsaWalletActions);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Returns the parameters needed for deploying the smart account
|
|
313
|
-
* @returns Deployment parameters object
|
|
314
|
-
* @testable This method can be overridden in tests
|
|
315
|
-
*/
|
|
316
|
-
getDeploymentParameters() {
|
|
317
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
const salt = `0x${Buffer.from(toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
|
|
319
|
-
const initialValidators = [];
|
|
320
|
-
const initialK1Owners = [this.eoaAddress];
|
|
321
|
-
if (this.enablePasskeys) {
|
|
322
|
-
const encodedPasskeyModuleData = yield this.getEncodedPasskeyModuleData();
|
|
323
|
-
initialValidators.push(encodedPasskeyModuleData);
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
initialK1Owners,
|
|
327
|
-
initialValidators,
|
|
328
|
-
salt,
|
|
329
|
-
};
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Retrieves and encodes passkey module data for smart account deployment
|
|
334
|
-
* @returns Encoded passkey module data as a hex string
|
|
335
|
-
* @throws {Error} If credential public key or ID is not found
|
|
336
|
-
* @private
|
|
337
|
-
*/
|
|
338
|
-
getEncodedPasskeyModuleData() {
|
|
339
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
340
|
-
const storedCredentialPublicKey = StorageService.getItem('credentialPublicKey');
|
|
341
|
-
if (!storedCredentialPublicKey) {
|
|
342
|
-
throw new Error('Credential public key not found');
|
|
343
|
-
}
|
|
344
|
-
const credentialPublicKey = new Uint8Array(Object.values(storedCredentialPublicKey));
|
|
345
|
-
const credentialId = StorageService.getItem('credentialId');
|
|
346
|
-
if (!credentialId) {
|
|
347
|
-
throw new Error('Credential ID not found');
|
|
348
|
-
}
|
|
349
|
-
const passkeyPublicKey = getPublicKeyBytesFromPasskeySignature(credentialPublicKey);
|
|
350
|
-
const encodedPasskeyParameters = encodePasskeyModuleParameters({
|
|
351
|
-
credentialId: credentialId,
|
|
352
|
-
expectedOrigin: window.location.origin, // TODO: how is this going to be set?
|
|
353
|
-
passkeyPublicKey,
|
|
354
|
-
});
|
|
355
|
-
return encodeModuleData({
|
|
356
|
-
address: this.passkeyAddress,
|
|
357
|
-
parameters: encodedPasskeyParameters,
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Simulates the smart account deployment
|
|
363
|
-
* @param publicClient - The public client to use for simulation
|
|
364
|
-
* @param walletClient - The wallet client to use for account information
|
|
365
|
-
* @param params - The deployment parameters
|
|
366
|
-
* @returns The simulation result
|
|
367
|
-
* @throws {ZkSyncConnectorError} If simulation fails
|
|
368
|
-
* @testable This method can be mocked in tests
|
|
369
|
-
*/
|
|
370
|
-
simulateAccountDeployment(publicClient_1, walletClient_1, params_1) {
|
|
371
|
-
return __awaiter(this, arguments, void 0, function* (publicClient, walletClient, params, checkBalance = true) {
|
|
372
|
-
var _a, _b, _c;
|
|
373
|
-
// this is to keep the same salt as calculated on zksync sso package
|
|
374
|
-
const salt = keccak256(toHex(params.salt));
|
|
375
|
-
const gasEstimate = yield publicClient.estimateContractGas({
|
|
376
|
-
abi: AAFactoryABI,
|
|
377
|
-
account: (_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address,
|
|
378
|
-
address: this.factoryAddress,
|
|
379
|
-
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
380
|
-
functionName: 'deployProxySsoAccount',
|
|
381
|
-
});
|
|
382
|
-
if (checkBalance) {
|
|
383
|
-
const balance = yield publicClient.getBalance({
|
|
384
|
-
address: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
385
|
-
});
|
|
386
|
-
if (balance < gasEstimate) {
|
|
387
|
-
throw new Error('Insufficient balance to deploy account');
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
// Simulate the contract call
|
|
391
|
-
return publicClient.simulateContract({
|
|
392
|
-
abi: AAFactoryABI,
|
|
393
|
-
account: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
|
|
394
|
-
address: this.factoryAddress,
|
|
395
|
-
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
396
|
-
functionName: 'deployProxySsoAccount',
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Executes the smart account deployment transaction
|
|
402
|
-
* @param walletClient - The wallet client to use for transaction execution
|
|
403
|
-
* @param request - The deployment request object containing transaction parameters
|
|
404
|
-
* @returns Promise that resolves when the deployment transaction is confirmed
|
|
405
|
-
* @throws {DynamicError} If the smart account address is not initialized
|
|
406
|
-
* @throws {Error} If transaction execution or confirmation fails
|
|
407
|
-
*/
|
|
408
|
-
executeAccountDeployment(walletClient, request) {
|
|
409
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
410
|
-
if (!this.smartAccountAddress) {
|
|
411
|
-
throw new Error('Smart account address is not initialized');
|
|
412
|
-
}
|
|
413
|
-
const tx = yield walletClient.writeContract(request);
|
|
414
|
-
const publicClient = yield this.getPublicClient();
|
|
415
|
-
yield publicClient.waitForTransactionReceipt({ hash: tx });
|
|
416
|
-
this._isSmartAccountDeployed = true;
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
signMessage(message) {
|
|
420
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
421
|
-
const walletClient = this.getWalletClient();
|
|
422
|
-
if (!walletClient) {
|
|
423
|
-
throw new Error('Wallet client not found');
|
|
424
|
-
}
|
|
425
|
-
return yield walletClient.signMessage({
|
|
426
|
-
account: walletClient.account,
|
|
427
|
-
message,
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Checks if a smart account is deployed
|
|
433
|
-
* @throws {ZkSyncConnectorError} If the check fails
|
|
434
|
-
* @returns Promise that resolves when the check is complete
|
|
435
|
-
*/
|
|
436
|
-
checkIsDeployed() {
|
|
437
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
438
|
-
const client = yield this.getPublicClient();
|
|
439
|
-
if (!client) {
|
|
440
|
-
throw new Error('Failed to get public client from EOA connector');
|
|
441
|
-
}
|
|
442
|
-
const code = yield client.getCode({
|
|
443
|
-
address: this.smartAccountAddress,
|
|
444
|
-
});
|
|
445
|
-
const isDeployed = Boolean(code);
|
|
446
|
-
this._isSmartAccountDeployed = isDeployed;
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
getAddress() {
|
|
450
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
451
|
-
var _a;
|
|
452
|
-
yield ((_a = this.initializedDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
453
|
-
if (!this.smartAccount) {
|
|
454
|
-
throw new Error('Smart account is not initialized');
|
|
455
|
-
}
|
|
456
|
-
return this.smartAccountAddress;
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
validateActiveWallet(expectedAddress) {
|
|
460
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
-
const currentAddress = yield this.getAddress();
|
|
462
|
-
if (currentAddress !== expectedAddress) {
|
|
463
|
-
throw new DynamicError('Invalid active wallet');
|
|
464
|
-
}
|
|
465
|
-
return;
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
createUiTransaction(from) {
|
|
469
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
470
|
-
yield this.validateActiveWallet(from);
|
|
471
|
-
const walletClient = this.getWalletClient();
|
|
472
|
-
const publicClient = yield this.getPublicClient();
|
|
473
|
-
if (!publicClient || !walletClient) {
|
|
474
|
-
throw new DynamicError('No public client available');
|
|
475
|
-
}
|
|
476
|
-
return createViemUiTransaction({
|
|
477
|
-
from: from,
|
|
478
|
-
publicClient: publicClient,
|
|
479
|
-
walletClient: walletClient,
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
isSmartAccountDeployed() {
|
|
484
|
-
return __awaiter(this, arguments, void 0, function* (refetch = false) {
|
|
485
|
-
if (refetch) {
|
|
486
|
-
yield this.checkIsDeployed();
|
|
487
|
-
}
|
|
488
|
-
return this._isSmartAccountDeployed;
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
registerEoa(_a) {
|
|
492
|
-
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }) {
|
|
493
|
-
throw new Error('Not implemented');
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
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;
|
package/src/utils/abi.d.ts
DELETED
|
@@ -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
|
-
}];
|