@dynamic-labs/ethereum-aa-zksync 4.18.5 → 4.18.7
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 +34 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -9
- package/src/connector/ZKsyncConnector.cjs +136 -47
- package/src/connector/ZKsyncConnector.d.ts +21 -11
- package/src/connector/ZKsyncConnector.js +136 -47
- package/src/index.d.ts +1 -0
- package/src/types/index.d.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.18.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.6...v4.18.7) (2025-05-21)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add zero dev kernel migration to v3.3 ([#8747](https://github.com/dynamic-labs/dynamic-auth/issues/8747)) ([ce10ef8](https://github.com/dynamic-labs/dynamic-auth/commit/ce10ef85d12452c2c21758c909f1e28f9fa5fbae))
|
|
8
|
+
* bump [@dynamic-labs-wallet](https://github.com/dynamic-labs-wallet) to v0.0.74 ([#8746](https://github.com/dynamic-labs/dynamic-auth/issues/8746)) ([98e3a0b](https://github.com/dynamic-labs/dynamic-auth/commit/98e3a0b845e7d6c34a2c748597198825713f4bcf))
|
|
9
|
+
* support kernel versio 0.3.2 and 0.3.3 ([#8738](https://github.com/dynamic-labs/dynamic-auth/issues/8738)) ([1115830](https://github.com/dynamic-labs/dynamic-auth/commit/1115830966318960d39a497c8b29188d9d9a447f))
|
|
10
|
+
* v3 solana confirmation ui ([#8731](https://github.com/dynamic-labs/dynamic-auth/issues/8731)) ([cfa5ba0](https://github.com/dynamic-labs/dynamic-auth/commit/cfa5ba07a946b847e60388c80afbd8aa233e9ebf))
|
|
11
|
+
* v3 svm send balance ([#8726](https://github.com/dynamic-labs/dynamic-auth/issues/8726)) ([236ec48](https://github.com/dynamic-labs/dynamic-auth/commit/236ec4843152f4b720aa7332e650db68c2d111b2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **alex/qntm-3201:** send empty data field when using zksync sendbalance ([#8733](https://github.com/dynamic-labs/dynamic-auth/issues/8733)) ([4c42035](https://github.com/dynamic-labs/dynamic-auth/commit/4c420350cf7404ac80db8b552594233a3de9fb57))
|
|
17
|
+
* allow for continuing signing if zksync account exists while attempting to deploy ([#8736](https://github.com/dynamic-labs/dynamic-auth/issues/8736)) ([1ff82e4](https://github.com/dynamic-labs/dynamic-auth/commit/1ff82e418e14300b9dec662fba517c5533c1caac))
|
|
18
|
+
* api kernel version on react native extension ([#8754](https://github.com/dynamic-labs/dynamic-auth/issues/8754)) ([c2f0bb4](https://github.com/dynamic-labs/dynamic-auth/commit/c2f0bb4ac86214f4e3bbdac5cf4b481a7a304449))
|
|
19
|
+
* CTRL wallet eip6963 detection ([#8727](https://github.com/dynamic-labs/dynamic-auth/issues/8727)) ([194334f](https://github.com/dynamic-labs/dynamic-auth/commit/194334f7fd541917d9a7f6b452145a47cf7ae853))
|
|
20
|
+
* **QNTM-3249:** fix mobile layout alignment in send view ([#8740](https://github.com/dynamic-labs/dynamic-auth/issues/8740)) ([7d8e02c](https://github.com/dynamic-labs/dynamic-auth/commit/7d8e02c11830f547b6fcfbc7b518ee3f045df41a))
|
|
21
|
+
|
|
22
|
+
### [4.18.6](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.5...v4.18.6) (2025-05-16)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* remove alert on wallet icon fail errors ([#8719](https://github.com/dynamic-labs/dynamic-auth/issues/8719)) ([3257160](https://github.com/dynamic-labs/dynamic-auth/commit/3257160ec2ce422e76ccf5e5adc10f92e73c3c61))
|
|
28
|
+
* evm export waas ([#8669](https://github.com/dynamic-labs/dynamic-auth/issues/8669)) ([c8f6199](https://github.com/dynamic-labs/dynamic-auth/commit/c8f6199914c5c0791996e0dfad1ac5642c327bea))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* onramps hook ([#8700](https://github.com/dynamic-labs/dynamic-auth/issues/8700)) ([33d0fb5](https://github.com/dynamic-labs/dynamic-auth/commit/33d0fb5e83db627aeea5ce2f07871cd4029c118a))
|
|
34
|
+
* use mainnet as default SVM cluster ([#8721](https://github.com/dynamic-labs/dynamic-auth/issues/8721)) ([5408f9a](https://github.com/dynamic-labs/dynamic-auth/commit/5408f9afbd2b4c6dfaf041c661cc3fb4802b6c05))
|
|
35
|
+
|
|
2
36
|
### [4.18.5](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.4...v4.18.5) (2025-05-15)
|
|
3
37
|
|
|
4
38
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-aa-zksync",
|
|
3
|
-
"version": "4.18.
|
|
3
|
+
"version": "4.18.7",
|
|
4
4
|
"description": "Core package for Ethereum Account Abstraction utilities and types",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.0.672",
|
|
22
22
|
"zksync-sso": "0.1.0",
|
|
23
|
-
"@dynamic-labs/assert-package-version": "4.18.
|
|
24
|
-
"@dynamic-labs/ethereum-aa-core": "4.18.
|
|
25
|
-
"@dynamic-labs/ethereum-core": "4.18.
|
|
26
|
-
"@dynamic-labs/types": "4.18.
|
|
27
|
-
"@dynamic-labs/utils": "4.18.
|
|
28
|
-
"@dynamic-labs/wallet-book": "4.18.
|
|
29
|
-
"@dynamic-labs/wallet-connector-core": "4.18.
|
|
23
|
+
"@dynamic-labs/assert-package-version": "4.18.7",
|
|
24
|
+
"@dynamic-labs/ethereum-aa-core": "4.18.7",
|
|
25
|
+
"@dynamic-labs/ethereum-core": "4.18.7",
|
|
26
|
+
"@dynamic-labs/types": "4.18.7",
|
|
27
|
+
"@dynamic-labs/utils": "4.18.7",
|
|
28
|
+
"@dynamic-labs/wallet-book": "4.18.7",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "4.18.7"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"viem": "^2.21.60"
|
|
@@ -6,12 +6,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var viem = require('viem');
|
|
8
8
|
var zksync = require('viem/zksync');
|
|
9
|
+
var abi = require('zksync-sso/abi');
|
|
9
10
|
var passkey = require('zksync-sso/client/passkey');
|
|
10
11
|
var utils$1 = require('zksync-sso/utils');
|
|
11
12
|
var client = require('zksync-sso/client');
|
|
12
13
|
var ecdsa = require('zksync-sso/client/ecdsa');
|
|
13
14
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
14
15
|
var utils = require('@dynamic-labs/utils');
|
|
16
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
15
17
|
var ethereumAaCore = require('@dynamic-labs/ethereum-aa-core');
|
|
16
18
|
var getSalt = require('../utils/getSalt.cjs');
|
|
17
19
|
var passkeys = require('../utils/passkeys.cjs');
|
|
@@ -315,33 +317,18 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
315
317
|
}
|
|
316
318
|
deploySmartAccount(_a) {
|
|
317
319
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
320
|
+
var _b, _c;
|
|
318
321
|
if (!this.chainId) {
|
|
319
322
|
throw new Error('Chain ID is not initialized');
|
|
320
323
|
}
|
|
321
|
-
if (!this.eoaConnector) {
|
|
324
|
+
if (!this.eoaConnector || !this.eoaAddress) {
|
|
322
325
|
throw new Error('EOA connector is not initialized');
|
|
323
326
|
}
|
|
324
|
-
yield network.ensureEoaConnectorNetwork(this.eoaConnector, this.chainId);
|
|
325
|
-
if (withPaymaster && this.paymasterAddress) {
|
|
326
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
yield this.deploySmartAccountWithoutPaymaster();
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
deploySmartAccountWithPaymaster() {
|
|
334
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
335
|
-
if (!this.paymasterAddress) {
|
|
336
|
-
throw new Error('Paymaster address is not initialized');
|
|
337
|
-
}
|
|
338
327
|
if (!this.smartAccountAddress) {
|
|
339
328
|
throw new Error('Smart account address is not initialized');
|
|
340
329
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
const paymaster = this.paymasterAddress;
|
|
330
|
+
yield network.ensureEoaConnectorNetwork(this.eoaConnector, this.chainId);
|
|
331
|
+
const deployWithPaymaster = withPaymaster && this.paymasterAddress;
|
|
345
332
|
const publicClient = yield this.getTypedPublicClient();
|
|
346
333
|
const walletClient = yield this.getTypedWalletClient();
|
|
347
334
|
const deploymentParams = yield deployment.getDeploymentParameters({
|
|
@@ -351,36 +338,23 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
351
338
|
saltText: this.saltText,
|
|
352
339
|
sessionKeyAddress: this.sessionKeyAddress,
|
|
353
340
|
});
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Deploys a new smart account contract
|
|
366
|
-
* @throws {ZkSyncConnectorError} If deployment fails
|
|
367
|
-
* @testable This method can be mocked in tests
|
|
368
|
-
*/
|
|
369
|
-
deploySmartAccountWithoutPaymaster() {
|
|
370
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
371
|
-
if (!this.eoaConnector) {
|
|
372
|
-
throw new Error('EOA connector is not initialized');
|
|
341
|
+
try {
|
|
342
|
+
let { request } = yield deployment.simulateAccountDeployment(publicClient, walletClient, deploymentParams, this.factoryAddress, !deployWithPaymaster);
|
|
343
|
+
if (deployWithPaymaster) {
|
|
344
|
+
const paymasterInput = zksync.getGeneralPaymasterInput({
|
|
345
|
+
innerInput: new Uint8Array(),
|
|
346
|
+
});
|
|
347
|
+
request = Object.assign(Object.assign({}, request), { paymaster: this.paymasterAddress, paymasterInput });
|
|
348
|
+
}
|
|
349
|
+
yield deployment.executeAccountDeployment(walletClient, publicClient, request, this.smartAccountAddress);
|
|
373
350
|
}
|
|
374
|
-
|
|
375
|
-
|
|
351
|
+
catch (error) {
|
|
352
|
+
// If the account already exists, we don't want to throw an error and continue
|
|
353
|
+
if (((_c = (_b = error === null || error === void 0 ? void 0 : error.cause) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.errorName) !== 'ACCOUNT_ALREADY_EXISTS') {
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
376
356
|
}
|
|
377
|
-
|
|
378
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
379
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
380
|
-
// Simulate the contract deployment first
|
|
381
|
-
const { request } = yield deployment.simulateAccountDeployment(publicClient, walletClient, deploymentParams, this.factoryAddress, false);
|
|
382
|
-
// Execute the deployment transaction
|
|
383
|
-
yield deployment.executeAccountDeployment(walletClient, publicClient, request, this.smartAccountAddress);
|
|
357
|
+
this._isSmartAccountDeployed = true;
|
|
384
358
|
});
|
|
385
359
|
}
|
|
386
360
|
/**
|
|
@@ -489,6 +463,102 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
489
463
|
return isDeployed;
|
|
490
464
|
});
|
|
491
465
|
}
|
|
466
|
+
getSmartAccountCreationBlock() {
|
|
467
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
468
|
+
if (!this.smartAccountAddress) {
|
|
469
|
+
throw new Error('Smart account address is not initialized');
|
|
470
|
+
}
|
|
471
|
+
// check cache first
|
|
472
|
+
const cachedBlock = utils.StorageService.getItem(`smart-account-creation-block-${this.smartAccountAddress}`);
|
|
473
|
+
if (cachedBlock) {
|
|
474
|
+
return Number(cachedBlock);
|
|
475
|
+
}
|
|
476
|
+
const publicClient = yield this.getPublicClient();
|
|
477
|
+
try {
|
|
478
|
+
const createAccountLogs = yield publicClient.getContractEvents({
|
|
479
|
+
abi: abi.AAFactoryAbi,
|
|
480
|
+
address: this.factoryAddress,
|
|
481
|
+
args: {
|
|
482
|
+
accountAddress: this.smartAccountAddress,
|
|
483
|
+
},
|
|
484
|
+
eventName: 'AccountCreated',
|
|
485
|
+
fromBlock: BigInt(0),
|
|
486
|
+
});
|
|
487
|
+
if (createAccountLogs.length === 0) {
|
|
488
|
+
return 0;
|
|
489
|
+
}
|
|
490
|
+
// cache the block number
|
|
491
|
+
utils.StorageService.setItem(`smart-account-creation-block-${this.smartAccountAddress}`, createAccountLogs[0].blockNumber.toString());
|
|
492
|
+
return Number(createAccountLogs[0].blockNumber);
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
walletConnectorCore.logger.error('[ZKsyncConnector] Error getting smart account creation block: ', error);
|
|
496
|
+
return 0;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
listSessions() {
|
|
501
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
if (!this.smartAccount) {
|
|
503
|
+
throw new Error('Smart account is not initialized');
|
|
504
|
+
}
|
|
505
|
+
if (!this._isSmartAccountDeployed) {
|
|
506
|
+
return [];
|
|
507
|
+
}
|
|
508
|
+
const smartAccountCreationBlock = yield this.getSmartAccountCreationBlock();
|
|
509
|
+
const publicClient = yield this.getPublicClient();
|
|
510
|
+
try {
|
|
511
|
+
// Get all created session information
|
|
512
|
+
const createSessionLogs = (yield publicClient.getContractEvents({
|
|
513
|
+
abi: abi.SessionKeyValidatorAbi,
|
|
514
|
+
address: this.sessionKeyAddress,
|
|
515
|
+
args: {
|
|
516
|
+
account: this.smartAccountAddress,
|
|
517
|
+
},
|
|
518
|
+
eventName: 'SessionCreated',
|
|
519
|
+
// only get sessions from the block when the smart account was created
|
|
520
|
+
fromBlock: BigInt(smartAccountCreationBlock),
|
|
521
|
+
})).filter((log) => log.args.sessionSpec && log.args.sessionHash);
|
|
522
|
+
// Get all revoked session hashes
|
|
523
|
+
const revokedSessionHashes = (yield publicClient.getContractEvents({
|
|
524
|
+
abi: abi.SessionKeyValidatorAbi,
|
|
525
|
+
address: this.sessionKeyAddress,
|
|
526
|
+
args: {
|
|
527
|
+
account: this.smartAccountAddress,
|
|
528
|
+
},
|
|
529
|
+
eventName: 'SessionRevoked',
|
|
530
|
+
// only get sessions from the block when the smart account was created
|
|
531
|
+
fromBlock: BigInt(smartAccountCreationBlock),
|
|
532
|
+
}))
|
|
533
|
+
.filter((log) => log.args.sessionHash)
|
|
534
|
+
.map((log) => log.args.sessionHash);
|
|
535
|
+
return createSessionLogs
|
|
536
|
+
.filter((log) => log.args.sessionHash &&
|
|
537
|
+
// filter out the sessions that have been revoked
|
|
538
|
+
!revokedSessionHashes.includes(log.args.sessionHash))
|
|
539
|
+
.map((log) => ({
|
|
540
|
+
blockNumber: log.blockNumber,
|
|
541
|
+
session: log.args.sessionSpec,
|
|
542
|
+
sessionId: log.args.sessionHash,
|
|
543
|
+
timestamp: new Date(
|
|
544
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
545
|
+
parseInt(log.blockTimestamp, 16) * 1000).getTime(),
|
|
546
|
+
transactionHash: log.transactionHash,
|
|
547
|
+
}))
|
|
548
|
+
.sort((a, b) => {
|
|
549
|
+
if (a.blockNumber < b.blockNumber)
|
|
550
|
+
return 1;
|
|
551
|
+
if (a.blockNumber > b.blockNumber)
|
|
552
|
+
return -1;
|
|
553
|
+
return 0;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
walletConnectorCore.logger.error('[ZKsyncConnector] Error listing sessions: ', error);
|
|
558
|
+
return [];
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
492
562
|
getAddress() {
|
|
493
563
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
494
564
|
var _a;
|
|
@@ -499,6 +569,25 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
499
569
|
return this.smartAccountAddress;
|
|
500
570
|
});
|
|
501
571
|
}
|
|
572
|
+
revokeSession(sessionId) {
|
|
573
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
574
|
+
if (!this.smartAccount) {
|
|
575
|
+
throw new Error('Smart account is not initialized');
|
|
576
|
+
}
|
|
577
|
+
const params = {
|
|
578
|
+
sessionId,
|
|
579
|
+
};
|
|
580
|
+
if (this.paymasterAddress) {
|
|
581
|
+
params.paymaster = {
|
|
582
|
+
address: this.paymasterAddress,
|
|
583
|
+
paymasterInput: zksync.getGeneralPaymasterInput({
|
|
584
|
+
innerInput: new Uint8Array(),
|
|
585
|
+
}),
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
yield this.smartAccount.revokeSession(params);
|
|
589
|
+
});
|
|
590
|
+
}
|
|
502
591
|
validateActiveWallet(expectedAddress) {
|
|
503
592
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
504
593
|
const currentAddress = yield this.getAddress();
|
|
@@ -3,6 +3,7 @@ import { ZksyncSsoPasskeyClient } from 'zksync-sso/client/passkey';
|
|
|
3
3
|
import { SessionConfig } from 'zksync-sso/utils';
|
|
4
4
|
import { ZksyncSsoSessionClient } from 'zksync-sso/client';
|
|
5
5
|
import { ZksyncSsoEcdsaClient } from 'zksync-sso/client/ecdsa';
|
|
6
|
+
import { RevokeSessionArgs } from 'node_modules/zksync-sso/dist/_types/client/session/actions/session';
|
|
6
7
|
import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
|
|
7
8
|
import { ProjectSettings, Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
8
9
|
import { EvmNetwork, GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
|
|
@@ -10,6 +11,7 @@ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
|
10
11
|
import { Chain, IAccountAbstractionWalletConnector, InternalWalletConnector, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
11
12
|
import { AccountAbstractionBaseConnector, AccountAbstractionConnectorProps } from '@dynamic-labs/ethereum-aa-core';
|
|
12
13
|
import { DeploymentParams } from '../utils';
|
|
14
|
+
import { SessionInformation } from '../types';
|
|
13
15
|
type ZKsyncConnectorProps = AccountAbstractionConnectorProps & {
|
|
14
16
|
apiProviders: {
|
|
15
17
|
[key in ProviderEnum]?: Provider;
|
|
@@ -159,7 +161,11 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
159
161
|
ReturnType: `0x${string}`;
|
|
160
162
|
}, {
|
|
161
163
|
Method: "eth_createAccessList";
|
|
162
|
-
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
|
|
164
|
+
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier]; /**
|
|
165
|
+
* Gets typed public client from EOA connector
|
|
166
|
+
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
167
|
+
* @testable This method can be mocked in tests
|
|
168
|
+
*/
|
|
163
169
|
ReturnType: {
|
|
164
170
|
accessList: import("viem").AccessList;
|
|
165
171
|
gasUsed: `0x${string}`;
|
|
@@ -16529,7 +16535,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
16529
16535
|
testnet?: boolean | undefined;
|
|
16530
16536
|
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account, chainOverride_9>) => Promise<`0x${string}`>;
|
|
16531
16537
|
createSession: (args: Omit<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").CreateSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").CreateSessionReturnType>;
|
|
16532
|
-
revokeSession: (args: Omit<
|
|
16538
|
+
revokeSession: (args: Omit<RevokeSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").RevokeSessionReturnType>;
|
|
16533
16539
|
extend: <const client extends {
|
|
16534
16540
|
[x: string]: unknown;
|
|
16535
16541
|
account?: undefined;
|
|
@@ -16704,7 +16710,11 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
16704
16710
|
ReturnType: `0x${string}`;
|
|
16705
16711
|
}, {
|
|
16706
16712
|
Method: "eth_createAccessList";
|
|
16707
|
-
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
|
|
16713
|
+
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier]; /**
|
|
16714
|
+
* Gets typed public client from EOA connector
|
|
16715
|
+
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
16716
|
+
* @testable This method can be mocked in tests
|
|
16717
|
+
*/
|
|
16708
16718
|
ReturnType: {
|
|
16709
16719
|
accessList: import("viem").AccessList;
|
|
16710
16720
|
gasUsed: `0x${string}`;
|
|
@@ -17211,7 +17221,11 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
17211
17221
|
ReturnType: `0x${string}`;
|
|
17212
17222
|
}, {
|
|
17213
17223
|
Method: "eth_createAccessList";
|
|
17214
|
-
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
|
|
17224
|
+
Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier]; /**
|
|
17225
|
+
* Gets typed public client from EOA connector
|
|
17226
|
+
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
17227
|
+
* @testable This method can be mocked in tests
|
|
17228
|
+
*/
|
|
17215
17229
|
ReturnType: {
|
|
17216
17230
|
accessList: import("viem").AccessList;
|
|
17217
17231
|
gasUsed: `0x${string}`;
|
|
@@ -17668,13 +17682,6 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
17668
17682
|
deploySmartAccount({ withPaymaster, }: {
|
|
17669
17683
|
withPaymaster: boolean;
|
|
17670
17684
|
}): Promise<void>;
|
|
17671
|
-
private deploySmartAccountWithPaymaster;
|
|
17672
|
-
/**
|
|
17673
|
-
* Deploys a new smart account contract
|
|
17674
|
-
* @throws {ZkSyncConnectorError} If deployment fails
|
|
17675
|
-
* @testable This method can be mocked in tests
|
|
17676
|
-
*/
|
|
17677
|
-
private deploySmartAccountWithoutPaymaster;
|
|
17678
17685
|
/**
|
|
17679
17686
|
* Gets typed public client from EOA connector
|
|
17680
17687
|
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
@@ -17700,7 +17707,10 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
17700
17707
|
* @returns Promise that resolves when the check is complete
|
|
17701
17708
|
*/
|
|
17702
17709
|
protected checkIsDeployed(): Promise<boolean>;
|
|
17710
|
+
private getSmartAccountCreationBlock;
|
|
17711
|
+
listSessions(): Promise<SessionInformation[]>;
|
|
17703
17712
|
getAddress(): Promise<string | undefined>;
|
|
17713
|
+
revokeSession(sessionId: `0x${string}`): Promise<void>;
|
|
17704
17714
|
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
17705
17715
|
isSmartAccountDeployed(refetch?: boolean): Promise<boolean>;
|
|
17706
17716
|
}
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { createWalletClient, custom, publicActions, createPublicClient, http, walletActions, toHex } from 'viem';
|
|
4
4
|
import { getGeneralPaymasterInput, eip712WalletActions } from 'viem/zksync';
|
|
5
|
+
import { AAFactoryAbi, SessionKeyValidatorAbi } from 'zksync-sso/abi';
|
|
5
6
|
import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client/passkey';
|
|
6
7
|
import { encodeModuleData } from 'zksync-sso/utils';
|
|
7
8
|
import { createZksyncSessionClient } from 'zksync-sso/client';
|
|
8
9
|
import { createZksyncEcdsaClient, zksyncSsoEcdsaWalletActions } from 'zksync-sso/client/ecdsa';
|
|
9
10
|
import { EthereumWallet, chainsMap, confirmationTransport, getOrMapViemChain } from '@dynamic-labs/ethereum-core';
|
|
10
11
|
import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
|
|
12
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
11
13
|
import { AccountAbstractionBaseConnector } from '@dynamic-labs/ethereum-aa-core';
|
|
12
14
|
import { getSalt } from '../utils/getSalt.js';
|
|
13
15
|
import { getEncodedPasskeyModuleData } from '../utils/passkeys.js';
|
|
@@ -311,33 +313,18 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
311
313
|
}
|
|
312
314
|
deploySmartAccount(_a) {
|
|
313
315
|
return __awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
316
|
+
var _b, _c;
|
|
314
317
|
if (!this.chainId) {
|
|
315
318
|
throw new Error('Chain ID is not initialized');
|
|
316
319
|
}
|
|
317
|
-
if (!this.eoaConnector) {
|
|
320
|
+
if (!this.eoaConnector || !this.eoaAddress) {
|
|
318
321
|
throw new Error('EOA connector is not initialized');
|
|
319
322
|
}
|
|
320
|
-
yield ensureEoaConnectorNetwork(this.eoaConnector, this.chainId);
|
|
321
|
-
if (withPaymaster && this.paymasterAddress) {
|
|
322
|
-
yield this.deploySmartAccountWithPaymaster();
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
yield this.deploySmartAccountWithoutPaymaster();
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
deploySmartAccountWithPaymaster() {
|
|
330
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
-
if (!this.paymasterAddress) {
|
|
332
|
-
throw new Error('Paymaster address is not initialized');
|
|
333
|
-
}
|
|
334
323
|
if (!this.smartAccountAddress) {
|
|
335
324
|
throw new Error('Smart account address is not initialized');
|
|
336
325
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
const paymaster = this.paymasterAddress;
|
|
326
|
+
yield ensureEoaConnectorNetwork(this.eoaConnector, this.chainId);
|
|
327
|
+
const deployWithPaymaster = withPaymaster && this.paymasterAddress;
|
|
341
328
|
const publicClient = yield this.getTypedPublicClient();
|
|
342
329
|
const walletClient = yield this.getTypedWalletClient();
|
|
343
330
|
const deploymentParams = yield getDeploymentParameters({
|
|
@@ -347,36 +334,23 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
347
334
|
saltText: this.saltText,
|
|
348
335
|
sessionKeyAddress: this.sessionKeyAddress,
|
|
349
336
|
});
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Deploys a new smart account contract
|
|
362
|
-
* @throws {ZkSyncConnectorError} If deployment fails
|
|
363
|
-
* @testable This method can be mocked in tests
|
|
364
|
-
*/
|
|
365
|
-
deploySmartAccountWithoutPaymaster() {
|
|
366
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
-
if (!this.eoaConnector) {
|
|
368
|
-
throw new Error('EOA connector is not initialized');
|
|
337
|
+
try {
|
|
338
|
+
let { request } = yield simulateAccountDeployment(publicClient, walletClient, deploymentParams, this.factoryAddress, !deployWithPaymaster);
|
|
339
|
+
if (deployWithPaymaster) {
|
|
340
|
+
const paymasterInput = getGeneralPaymasterInput({
|
|
341
|
+
innerInput: new Uint8Array(),
|
|
342
|
+
});
|
|
343
|
+
request = Object.assign(Object.assign({}, request), { paymaster: this.paymasterAddress, paymasterInput });
|
|
344
|
+
}
|
|
345
|
+
yield executeAccountDeployment(walletClient, publicClient, request, this.smartAccountAddress);
|
|
369
346
|
}
|
|
370
|
-
|
|
371
|
-
|
|
347
|
+
catch (error) {
|
|
348
|
+
// If the account already exists, we don't want to throw an error and continue
|
|
349
|
+
if (((_c = (_b = error === null || error === void 0 ? void 0 : error.cause) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.errorName) !== 'ACCOUNT_ALREADY_EXISTS') {
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
372
352
|
}
|
|
373
|
-
|
|
374
|
-
const publicClient = yield this.getTypedPublicClient();
|
|
375
|
-
const deploymentParams = yield this.getDeploymentParameters();
|
|
376
|
-
// Simulate the contract deployment first
|
|
377
|
-
const { request } = yield simulateAccountDeployment(publicClient, walletClient, deploymentParams, this.factoryAddress, false);
|
|
378
|
-
// Execute the deployment transaction
|
|
379
|
-
yield executeAccountDeployment(walletClient, publicClient, request, this.smartAccountAddress);
|
|
353
|
+
this._isSmartAccountDeployed = true;
|
|
380
354
|
});
|
|
381
355
|
}
|
|
382
356
|
/**
|
|
@@ -485,6 +459,102 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
485
459
|
return isDeployed;
|
|
486
460
|
});
|
|
487
461
|
}
|
|
462
|
+
getSmartAccountCreationBlock() {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
464
|
+
if (!this.smartAccountAddress) {
|
|
465
|
+
throw new Error('Smart account address is not initialized');
|
|
466
|
+
}
|
|
467
|
+
// check cache first
|
|
468
|
+
const cachedBlock = StorageService.getItem(`smart-account-creation-block-${this.smartAccountAddress}`);
|
|
469
|
+
if (cachedBlock) {
|
|
470
|
+
return Number(cachedBlock);
|
|
471
|
+
}
|
|
472
|
+
const publicClient = yield this.getPublicClient();
|
|
473
|
+
try {
|
|
474
|
+
const createAccountLogs = yield publicClient.getContractEvents({
|
|
475
|
+
abi: AAFactoryAbi,
|
|
476
|
+
address: this.factoryAddress,
|
|
477
|
+
args: {
|
|
478
|
+
accountAddress: this.smartAccountAddress,
|
|
479
|
+
},
|
|
480
|
+
eventName: 'AccountCreated',
|
|
481
|
+
fromBlock: BigInt(0),
|
|
482
|
+
});
|
|
483
|
+
if (createAccountLogs.length === 0) {
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
// cache the block number
|
|
487
|
+
StorageService.setItem(`smart-account-creation-block-${this.smartAccountAddress}`, createAccountLogs[0].blockNumber.toString());
|
|
488
|
+
return Number(createAccountLogs[0].blockNumber);
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
logger.error('[ZKsyncConnector] Error getting smart account creation block: ', error);
|
|
492
|
+
return 0;
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
listSessions() {
|
|
497
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
498
|
+
if (!this.smartAccount) {
|
|
499
|
+
throw new Error('Smart account is not initialized');
|
|
500
|
+
}
|
|
501
|
+
if (!this._isSmartAccountDeployed) {
|
|
502
|
+
return [];
|
|
503
|
+
}
|
|
504
|
+
const smartAccountCreationBlock = yield this.getSmartAccountCreationBlock();
|
|
505
|
+
const publicClient = yield this.getPublicClient();
|
|
506
|
+
try {
|
|
507
|
+
// Get all created session information
|
|
508
|
+
const createSessionLogs = (yield publicClient.getContractEvents({
|
|
509
|
+
abi: SessionKeyValidatorAbi,
|
|
510
|
+
address: this.sessionKeyAddress,
|
|
511
|
+
args: {
|
|
512
|
+
account: this.smartAccountAddress,
|
|
513
|
+
},
|
|
514
|
+
eventName: 'SessionCreated',
|
|
515
|
+
// only get sessions from the block when the smart account was created
|
|
516
|
+
fromBlock: BigInt(smartAccountCreationBlock),
|
|
517
|
+
})).filter((log) => log.args.sessionSpec && log.args.sessionHash);
|
|
518
|
+
// Get all revoked session hashes
|
|
519
|
+
const revokedSessionHashes = (yield publicClient.getContractEvents({
|
|
520
|
+
abi: SessionKeyValidatorAbi,
|
|
521
|
+
address: this.sessionKeyAddress,
|
|
522
|
+
args: {
|
|
523
|
+
account: this.smartAccountAddress,
|
|
524
|
+
},
|
|
525
|
+
eventName: 'SessionRevoked',
|
|
526
|
+
// only get sessions from the block when the smart account was created
|
|
527
|
+
fromBlock: BigInt(smartAccountCreationBlock),
|
|
528
|
+
}))
|
|
529
|
+
.filter((log) => log.args.sessionHash)
|
|
530
|
+
.map((log) => log.args.sessionHash);
|
|
531
|
+
return createSessionLogs
|
|
532
|
+
.filter((log) => log.args.sessionHash &&
|
|
533
|
+
// filter out the sessions that have been revoked
|
|
534
|
+
!revokedSessionHashes.includes(log.args.sessionHash))
|
|
535
|
+
.map((log) => ({
|
|
536
|
+
blockNumber: log.blockNumber,
|
|
537
|
+
session: log.args.sessionSpec,
|
|
538
|
+
sessionId: log.args.sessionHash,
|
|
539
|
+
timestamp: new Date(
|
|
540
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
541
|
+
parseInt(log.blockTimestamp, 16) * 1000).getTime(),
|
|
542
|
+
transactionHash: log.transactionHash,
|
|
543
|
+
}))
|
|
544
|
+
.sort((a, b) => {
|
|
545
|
+
if (a.blockNumber < b.blockNumber)
|
|
546
|
+
return 1;
|
|
547
|
+
if (a.blockNumber > b.blockNumber)
|
|
548
|
+
return -1;
|
|
549
|
+
return 0;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
logger.error('[ZKsyncConnector] Error listing sessions: ', error);
|
|
554
|
+
return [];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
}
|
|
488
558
|
getAddress() {
|
|
489
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
490
560
|
var _a;
|
|
@@ -495,6 +565,25 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
495
565
|
return this.smartAccountAddress;
|
|
496
566
|
});
|
|
497
567
|
}
|
|
568
|
+
revokeSession(sessionId) {
|
|
569
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
570
|
+
if (!this.smartAccount) {
|
|
571
|
+
throw new Error('Smart account is not initialized');
|
|
572
|
+
}
|
|
573
|
+
const params = {
|
|
574
|
+
sessionId,
|
|
575
|
+
};
|
|
576
|
+
if (this.paymasterAddress) {
|
|
577
|
+
params.paymaster = {
|
|
578
|
+
address: this.paymasterAddress,
|
|
579
|
+
paymasterInput: getGeneralPaymasterInput({
|
|
580
|
+
innerInput: new Uint8Array(),
|
|
581
|
+
}),
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
yield this.smartAccount.revokeSession(params);
|
|
585
|
+
});
|
|
586
|
+
}
|
|
498
587
|
validateActiveWallet(expectedAddress) {
|
|
499
588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
500
589
|
const currentAddress = yield this.getAddress();
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
2
|
export { isZKsyncConnector } from './utils';
|
|
3
|
+
export { type SessionInformation } from './types';
|
|
3
4
|
export declare const ZKsyncSmartWalletConnectors: (props: any) => WalletConnectorConstructor[];
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SessionConfig } from 'zksync-sso/utils';
|
|
1
2
|
import { GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
|
|
2
3
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
4
|
import { InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
@@ -6,3 +7,10 @@ export type AccountAbstractionConnectorProps = {
|
|
|
6
7
|
walletBook: WalletBookSchema;
|
|
7
8
|
evmNetworks: GenericNetwork[];
|
|
8
9
|
};
|
|
10
|
+
export type SessionInformation = {
|
|
11
|
+
blockNumber: bigint;
|
|
12
|
+
session: SessionConfig;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
transactionHash: string;
|
|
16
|
+
};
|