@dynamic-labs/ethereum-aa-zksync 4.18.7 → 4.19.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 CHANGED
@@ -1,4 +1,27 @@
1
1
 
2
+ ## [4.19.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.8...v4.19.0) (2025-05-23)
3
+
4
+
5
+ ### Features
6
+
7
+ * expose 7702 kernel and add viem controller ([#8786](https://github.com/dynamic-labs/dynamic-auth/issues/8786)) ([eea710e](https://github.com/dynamic-labs/dynamic-auth/commit/eea710e238ccbc36e6be37d8f7493954b99858ef))
8
+ * use browser wallet client & iframe for waas operations ([#8697](https://github.com/dynamic-labs/dynamic-auth/issues/8697)) ([13a47b1](https://github.com/dynamic-labs/dynamic-auth/commit/13a47b1c9a2984f08682e833ca8c87605a3a872f))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **global-wallet:** close popup when page unloads to prevent orphaned popup windows ([#8787](https://github.com/dynamic-labs/dynamic-auth/issues/8787)) ([441b04c](https://github.com/dynamic-labs/dynamic-auth/commit/441b04ca04a02feb37473e43bca0e66c5d772ce2))
14
+ * override network when requesting BTC networks in useTokenBalances ([#8773](https://github.com/dynamic-labs/dynamic-auth/issues/8773)) ([fd07d09](https://github.com/dynamic-labs/dynamic-auth/commit/fd07d09de970c7e6f85b251a88854e8eca57e249))
15
+ * remove libmpc executor dependency global wallet ([#8792](https://github.com/dynamic-labs/dynamic-auth/issues/8792)) ([7502585](https://github.com/dynamic-labs/dynamic-auth/commit/75025859d2f952915322cf65504117ec2506152b))
16
+ * standardize font on headers ([#8734](https://github.com/dynamic-labs/dynamic-auth/issues/8734)) ([9f0900c](https://github.com/dynamic-labs/dynamic-auth/commit/9f0900cb7c4294201cc952ae7538648bdea83ff5))
17
+
18
+ ### [4.18.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.7...v4.18.8) (2025-05-22)
19
+
20
+ ### Bug Fixes
21
+
22
+ * allow closing widget right after login ([#8760](https://github.com/dynamic-labs/dynamic-auth/issues/8760)) ([a9afff0](https://github.com/dynamic-labs/dynamic-auth/commit/a9afff0ab2a685853b39aed88e10bf1e700e4c8c))
23
+ * user wallets turning empty when linking new wallets ([#8775](https://github.com/dynamic-labs/dynamic-auth/issues/8775)) ([04215f5](https://github.com/dynamic-labs/dynamic-auth/commit/04215f5307e16ec4e1a7ff235a0d7df2340c3447))
24
+
2
25
  ### [4.18.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.6...v4.18.7) (2025-05-21)
3
26
 
4
27
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.18.7";
6
+ var version = "4.19.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.18.7";
2
+ var version = "4.19.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa-zksync",
3
- "version": "4.18.7",
3
+ "version": "4.19.0",
4
4
  "description": "Core package for Ethereum Account Abstraction utilities and types",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -20,13 +20,13 @@
20
20
  "dependencies": {
21
21
  "@dynamic-labs/sdk-api-core": "0.0.672",
22
22
  "zksync-sso": "0.1.0",
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"
23
+ "@dynamic-labs/assert-package-version": "4.19.0",
24
+ "@dynamic-labs/ethereum-aa-core": "4.19.0",
25
+ "@dynamic-labs/ethereum-core": "4.19.0",
26
+ "@dynamic-labs/types": "4.19.0",
27
+ "@dynamic-labs/utils": "4.19.0",
28
+ "@dynamic-labs/wallet-book": "4.19.0",
29
+ "@dynamic-labs/wallet-connector-core": "4.19.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "viem": "^2.21.60"
@@ -11,6 +11,7 @@ var passkey = require('zksync-sso/client/passkey');
11
11
  var utils$1 = require('zksync-sso/utils');
12
12
  var client = require('zksync-sso/client');
13
13
  var ecdsa = require('zksync-sso/client/ecdsa');
14
+ var accounts = require('viem/accounts');
14
15
  var ethereumCore = require('@dynamic-labs/ethereum-core');
15
16
  var utils = require('@dynamic-labs/utils');
16
17
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
@@ -19,6 +20,8 @@ var getSalt = require('../utils/getSalt.cjs');
19
20
  var passkeys = require('../utils/passkeys.cjs');
20
21
  var deployment = require('../utils/deployment.cjs');
21
22
  var network = require('../utils/network.cjs');
23
+ var session = require('../utils/session.cjs');
24
+ var storage = require('../utils/storage.cjs');
22
25
 
23
26
  class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
24
27
  constructor(props) {
@@ -90,7 +93,33 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
90
93
  return false;
91
94
  });
92
95
  }
93
- getAccountAbstractionProvider() {
96
+ getSessionFromStorage(sessionId) {
97
+ return storage.retrieveSessionFromStorage(sessionId);
98
+ }
99
+ setSession(sessionId, session) {
100
+ return storage.saveSessionToStorage(sessionId, session);
101
+ }
102
+ deleteSession(sessionId) {
103
+ return storage.deleteSessionFromStorage(sessionId);
104
+ }
105
+ getAccountAbstractionProvider({ sessionId } = {}) {
106
+ if (sessionId && this.sessionKeyAddress) {
107
+ const session = this.getSessionFromStorage(sessionId);
108
+ const isSessionRequestValid = session &&
109
+ (!session.origin || utils.PlatformService.getHostname() === session.origin);
110
+ if (isSessionRequestValid) {
111
+ return client.createZksyncSessionClient({
112
+ address: this.smartAccountAddress,
113
+ chain: ethereumCore.getOrMapViemChain(this.evmNetworks[0]),
114
+ contracts: {
115
+ session: this.sessionKeyAddress,
116
+ },
117
+ sessionConfig: session.sessionConfig,
118
+ sessionKey: session.sessionKey,
119
+ transport: viem.http(),
120
+ });
121
+ }
122
+ }
94
123
  return this.smartAccount;
95
124
  }
96
125
  getWalletClient(chainId) {
@@ -532,7 +561,7 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
532
561
  }))
533
562
  .filter((log) => log.args.sessionHash)
534
563
  .map((log) => log.args.sessionHash);
535
- return createSessionLogs
564
+ const activeSessions = createSessionLogs
536
565
  .filter((log) => log.args.sessionHash &&
537
566
  // filter out the sessions that have been revoked
538
567
  !revokedSessionHashes.includes(log.args.sessionHash))
@@ -552,6 +581,10 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
552
581
  return -1;
553
582
  return 0;
554
583
  });
584
+ return activeSessions.map((session) => {
585
+ var _a;
586
+ return (Object.assign(Object.assign({}, session), { origin: (_a = this.getSessionFromStorage(session.sessionId)) === null || _a === void 0 ? void 0 : _a.origin }));
587
+ });
555
588
  }
556
589
  catch (error) {
557
590
  walletConnectorCore.logger.error('[ZKsyncConnector] Error listing sessions: ', error);
@@ -586,6 +619,40 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
586
619
  };
587
620
  }
588
621
  yield this.smartAccount.revokeSession(params);
622
+ this.deleteSession(sessionId);
623
+ });
624
+ }
625
+ createSession(_a) {
626
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ sessionConfig, origin, }) {
627
+ if (!this.smartAccount) {
628
+ throw new Error('Smart account is not initialized');
629
+ }
630
+ const safeSessionConfig = session.enforceSessionConfigRestrictions(sessionConfig);
631
+ const privateKey = accounts.generatePrivateKey();
632
+ const signer = accounts.privateKeyToAccount(privateKey);
633
+ const params = {
634
+ sessionConfig: Object.assign(Object.assign({}, safeSessionConfig), { signer: signer.address }),
635
+ };
636
+ if (this.paymasterAddress) {
637
+ params.paymaster = {
638
+ address: this.paymasterAddress,
639
+ paymasterInput: zksync.getGeneralPaymasterInput({
640
+ innerInput: new Uint8Array(),
641
+ }),
642
+ };
643
+ }
644
+ yield this.smartAccount.createSession(params);
645
+ const sessionHash = session.getSessionHash(params.sessionConfig);
646
+ const serializedSessionConfig = session.stringifySessionConfig(params.sessionConfig);
647
+ const originURI = origin
648
+ ? new URL(origin).hostname
649
+ : utils.PlatformService.getHostname();
650
+ this.setSession(sessionHash, {
651
+ origin: originURI,
652
+ sessionConfig: serializedSessionConfig,
653
+ sessionKey: privateKey,
654
+ });
655
+ return { expiresAt: safeSessionConfig.expiresAt, sessionId: sessionHash };
589
656
  });
590
657
  }
591
658
  validateActiveWallet(expectedAddress) {
@@ -3,7 +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
+ import { CreateSessionArgs, RevokeSessionArgs } from 'node_modules/zksync-sso/dist/_types/client/session/actions/session';
7
7
  import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
8
8
  import { ProjectSettings, Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
9
9
  import { EvmNetwork, GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
@@ -11,7 +11,7 @@ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
11
11
  import { Chain, IAccountAbstractionWalletConnector, InternalWalletConnector, WalletConnector } from '@dynamic-labs/wallet-connector-core';
12
12
  import { AccountAbstractionBaseConnector, AccountAbstractionConnectorProps } from '@dynamic-labs/ethereum-aa-core';
13
13
  import { DeploymentParams } from '../utils';
14
- import { SessionInformation } from '../types';
14
+ import { SessionInformation, SessionConfigWithoutSigner } from '../types';
15
15
  type ZKsyncConnectorProps = AccountAbstractionConnectorProps & {
16
16
  apiProviders: {
17
17
  [key in ProviderEnum]?: Provider;
@@ -65,7 +65,13 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
65
65
  getNetwork(): Promise<number | undefined>;
66
66
  getPublicClient(): Promise<PublicClient>;
67
67
  canSponsorTransactionGas(): Promise<boolean>;
68
- getAccountAbstractionProvider<T = ZksyncSsoEcdsaClient<Transport, ViemChain, RpcSchema>>(): T;
68
+ private getSessionFromStorage;
69
+ private setSession;
70
+ private deleteSession;
71
+ getAccountAbstractionProvider<T = ZksyncSsoEcdsaClient<Transport, ViemChain, RpcSchema> | ZksyncSsoSessionClient<Transport, ViemChain, RpcSchema>>({ sessionId }?: {
72
+ sessionId?: string;
73
+ withSponsorship?: boolean;
74
+ }): T;
69
75
  getWalletClient(chainId?: string): WalletClient<Transport, ViemChain, Account> | undefined;
70
76
  private getWalletClientTransport;
71
77
  private getTransport;
@@ -161,11 +167,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
161
167
  ReturnType: `0x${string}`;
162
168
  }, {
163
169
  Method: "eth_createAccessList";
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
- */
170
+ Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
169
171
  ReturnType: {
170
172
  accessList: import("viem").AccessList;
171
173
  gasUsed: `0x${string}`;
@@ -16534,7 +16536,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
16534
16536
  sourceId?: number | undefined;
16535
16537
  testnet?: boolean | undefined;
16536
16538
  } & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account, chainOverride_9>) => Promise<`0x${string}`>;
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>;
16539
+ createSession: (args: Omit<CreateSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").CreateSessionReturnType>;
16538
16540
  revokeSession: (args: Omit<RevokeSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").RevokeSessionReturnType>;
16539
16541
  extend: <const client extends {
16540
16542
  [x: string]: unknown;
@@ -16710,11 +16712,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
16710
16712
  ReturnType: `0x${string}`;
16711
16713
  }, {
16712
16714
  Method: "eth_createAccessList";
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
- */
16715
+ Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
16718
16716
  ReturnType: {
16719
16717
  accessList: import("viem").AccessList;
16720
16718
  gasUsed: `0x${string}`;
@@ -17221,11 +17219,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
17221
17219
  ReturnType: `0x${string}`;
17222
17220
  }, {
17223
17221
  Method: "eth_createAccessList";
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
- */
17222
+ Parameters: [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>] | [transaction: import("viem").ExactPartial<import("viem").RpcTransactionRequest>, block: `0x${string}` | import("viem").BlockTag | import("viem").RpcBlockIdentifier];
17229
17223
  ReturnType: {
17230
17224
  accessList: import("viem").AccessList;
17231
17225
  gasUsed: `0x${string}`;
@@ -17711,6 +17705,13 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
17711
17705
  listSessions(): Promise<SessionInformation[]>;
17712
17706
  getAddress(): Promise<string | undefined>;
17713
17707
  revokeSession(sessionId: `0x${string}`): Promise<void>;
17708
+ createSession({ sessionConfig, origin, }: {
17709
+ sessionConfig: SessionConfigWithoutSigner;
17710
+ origin?: string;
17711
+ }): Promise<{
17712
+ expiresAt: bigint;
17713
+ sessionId: `0x${string}`;
17714
+ }>;
17714
17715
  validateActiveWallet(expectedAddress: string): Promise<void>;
17715
17716
  isSmartAccountDeployed(refetch?: boolean): Promise<boolean>;
17716
17717
  }
@@ -1,20 +1,23 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
- import { createWalletClient, custom, publicActions, createPublicClient, http, walletActions, toHex } from 'viem';
3
+ import { http, createWalletClient, custom, publicActions, createPublicClient, walletActions, toHex } from 'viem';
4
4
  import { getGeneralPaymasterInput, eip712WalletActions } from 'viem/zksync';
5
5
  import { AAFactoryAbi, SessionKeyValidatorAbi } from 'zksync-sso/abi';
6
6
  import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client/passkey';
7
7
  import { encodeModuleData } from 'zksync-sso/utils';
8
8
  import { createZksyncSessionClient } from 'zksync-sso/client';
9
9
  import { createZksyncEcdsaClient, zksyncSsoEcdsaWalletActions } from 'zksync-sso/client/ecdsa';
10
- import { EthereumWallet, chainsMap, confirmationTransport, getOrMapViemChain } from '@dynamic-labs/ethereum-core';
11
- import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
10
+ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
11
+ import { EthereumWallet, getOrMapViemChain, chainsMap, confirmationTransport } from '@dynamic-labs/ethereum-core';
12
+ import { parseEvmNetworks, PlatformService, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
12
13
  import { logger } from '@dynamic-labs/wallet-connector-core';
13
14
  import { AccountAbstractionBaseConnector } from '@dynamic-labs/ethereum-aa-core';
14
15
  import { getSalt } from '../utils/getSalt.js';
15
16
  import { getEncodedPasskeyModuleData } from '../utils/passkeys.js';
16
17
  import { getDeploymentParameters, simulateAccountDeployment, executeAccountDeployment } from '../utils/deployment.js';
17
18
  import { ensureEoaConnectorNetwork } from '../utils/network.js';
19
+ import { enforceSessionConfigRestrictions, getSessionHash, stringifySessionConfig } from '../utils/session.js';
20
+ import { retrieveSessionFromStorage, saveSessionToStorage, deleteSessionFromStorage } from '../utils/storage.js';
18
21
 
19
22
  class ZKsyncConnector extends AccountAbstractionBaseConnector {
20
23
  constructor(props) {
@@ -86,7 +89,33 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
86
89
  return false;
87
90
  });
88
91
  }
89
- getAccountAbstractionProvider() {
92
+ getSessionFromStorage(sessionId) {
93
+ return retrieveSessionFromStorage(sessionId);
94
+ }
95
+ setSession(sessionId, session) {
96
+ return saveSessionToStorage(sessionId, session);
97
+ }
98
+ deleteSession(sessionId) {
99
+ return deleteSessionFromStorage(sessionId);
100
+ }
101
+ getAccountAbstractionProvider({ sessionId } = {}) {
102
+ if (sessionId && this.sessionKeyAddress) {
103
+ const session = this.getSessionFromStorage(sessionId);
104
+ const isSessionRequestValid = session &&
105
+ (!session.origin || PlatformService.getHostname() === session.origin);
106
+ if (isSessionRequestValid) {
107
+ return createZksyncSessionClient({
108
+ address: this.smartAccountAddress,
109
+ chain: getOrMapViemChain(this.evmNetworks[0]),
110
+ contracts: {
111
+ session: this.sessionKeyAddress,
112
+ },
113
+ sessionConfig: session.sessionConfig,
114
+ sessionKey: session.sessionKey,
115
+ transport: http(),
116
+ });
117
+ }
118
+ }
90
119
  return this.smartAccount;
91
120
  }
92
121
  getWalletClient(chainId) {
@@ -528,7 +557,7 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
528
557
  }))
529
558
  .filter((log) => log.args.sessionHash)
530
559
  .map((log) => log.args.sessionHash);
531
- return createSessionLogs
560
+ const activeSessions = createSessionLogs
532
561
  .filter((log) => log.args.sessionHash &&
533
562
  // filter out the sessions that have been revoked
534
563
  !revokedSessionHashes.includes(log.args.sessionHash))
@@ -548,6 +577,10 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
548
577
  return -1;
549
578
  return 0;
550
579
  });
580
+ return activeSessions.map((session) => {
581
+ var _a;
582
+ return (Object.assign(Object.assign({}, session), { origin: (_a = this.getSessionFromStorage(session.sessionId)) === null || _a === void 0 ? void 0 : _a.origin }));
583
+ });
551
584
  }
552
585
  catch (error) {
553
586
  logger.error('[ZKsyncConnector] Error listing sessions: ', error);
@@ -582,6 +615,40 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
582
615
  };
583
616
  }
584
617
  yield this.smartAccount.revokeSession(params);
618
+ this.deleteSession(sessionId);
619
+ });
620
+ }
621
+ createSession(_a) {
622
+ return __awaiter(this, arguments, void 0, function* ({ sessionConfig, origin, }) {
623
+ if (!this.smartAccount) {
624
+ throw new Error('Smart account is not initialized');
625
+ }
626
+ const safeSessionConfig = enforceSessionConfigRestrictions(sessionConfig);
627
+ const privateKey = generatePrivateKey();
628
+ const signer = privateKeyToAccount(privateKey);
629
+ const params = {
630
+ sessionConfig: Object.assign(Object.assign({}, safeSessionConfig), { signer: signer.address }),
631
+ };
632
+ if (this.paymasterAddress) {
633
+ params.paymaster = {
634
+ address: this.paymasterAddress,
635
+ paymasterInput: getGeneralPaymasterInput({
636
+ innerInput: new Uint8Array(),
637
+ }),
638
+ };
639
+ }
640
+ yield this.smartAccount.createSession(params);
641
+ const sessionHash = getSessionHash(params.sessionConfig);
642
+ const serializedSessionConfig = stringifySessionConfig(params.sessionConfig);
643
+ const originURI = origin
644
+ ? new URL(origin).hostname
645
+ : PlatformService.getHostname();
646
+ this.setSession(sessionHash, {
647
+ origin: originURI,
648
+ sessionConfig: serializedSessionConfig,
649
+ sessionKey: privateKey,
650
+ });
651
+ return { expiresAt: safeSessionConfig.expiresAt, sessionId: sessionHash };
585
652
  });
586
653
  }
587
654
  validateActiveWallet(expectedAddress) {
@@ -2,6 +2,11 @@ import { SessionConfig } from 'zksync-sso/utils';
2
2
  import { GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
3
3
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
4
4
  import { InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
5
+ export type SessionConfigWithoutSigner = Omit<SessionConfig, 'signer'>;
6
+ export type ConvertBigIntToString<T> = T extends bigint ? string : T extends Array<infer U> ? Array<ConvertBigIntToString<U>> : T extends object ? {
7
+ [K in keyof T]: ConvertBigIntToString<T[K]>;
8
+ } : T;
9
+ export type SessionConfigJSON = ConvertBigIntToString<SessionConfig>;
5
10
  export type AccountAbstractionConnectorProps = {
6
11
  walletUiUtils: WalletUiUtils<InternalWalletConnector>;
7
12
  walletBook: WalletBookSchema;
@@ -13,4 +18,17 @@ export type SessionInformation = {
13
18
  sessionId: string;
14
19
  timestamp: number;
15
20
  transactionHash: string;
21
+ origin?: string;
22
+ };
23
+ export type ChainSessionInformation = {
24
+ blockNumber: bigint;
25
+ session: SessionConfig;
26
+ sessionId: `0x${string}`;
27
+ timestamp: number;
28
+ transactionHash: `0x${string}`;
29
+ };
30
+ export type SessionStorageItem = {
31
+ origin?: string;
32
+ sessionConfig: SessionConfigJSON;
33
+ sessionKey: string;
16
34
  };
@@ -3,3 +3,5 @@ export * from './passkeys';
3
3
  export * from './deployment';
4
4
  export * from './network';
5
5
  export * from './isZKsyncConnector';
6
+ export * from './session';
7
+ export * from './storage';
@@ -0,0 +1,43 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var viem = require('viem');
7
+ var utils = require('zksync-sso/utils');
8
+
9
+ const DEFAULT_EXPIRATION_TIME = 86400; // 1 day
10
+ const enforceSessionConfigRestrictions = (sessionConfig) => {
11
+ const now = Math.floor(Date.now() / 1000);
12
+ const maxExpirationTime = now + DEFAULT_EXPIRATION_TIME;
13
+ if (!sessionConfig.expiresAt ||
14
+ Number(sessionConfig.expiresAt) > maxExpirationTime) {
15
+ sessionConfig.expiresAt = BigInt(maxExpirationTime);
16
+ }
17
+ return sessionConfig;
18
+ };
19
+ const getSessionHash = (sessionConfig) => {
20
+ const sessionHash = utils.encodeSession(sessionConfig);
21
+ return viem.keccak256(sessionHash);
22
+ };
23
+ const parseSessionConfigJSON = (sessionConfig) => {
24
+ const serializeLimit = (limit) => ({
25
+ limit: BigInt(limit.limit),
26
+ limitType: limit.limitType,
27
+ period: BigInt(limit.period),
28
+ });
29
+ return Object.assign(Object.assign({}, sessionConfig), { callPolicies: sessionConfig.callPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { constraints: policy.constraints.map((constraint) => (Object.assign(Object.assign({}, constraint), { index: BigInt(constraint.index), limit: serializeLimit(constraint.limit) }))), maxValuePerUse: BigInt(policy.maxValuePerUse), valueLimit: serializeLimit(policy.valueLimit) }))), expiresAt: BigInt(sessionConfig.expiresAt), feeLimit: serializeLimit(sessionConfig.feeLimit), transferPolicies: sessionConfig.transferPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { maxValuePerUse: BigInt(policy.maxValuePerUse), valueLimit: serializeLimit(policy.valueLimit) }))) });
30
+ };
31
+ const stringifySessionConfig = (sessionConfig) => {
32
+ const stringifyLimit = (limit) => ({
33
+ limit: limit.limit.toString(),
34
+ limitType: limit.limitType,
35
+ period: limit.period.toString(),
36
+ });
37
+ return Object.assign(Object.assign({}, sessionConfig), { callPolicies: sessionConfig.callPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { constraints: policy.constraints.map((constraint) => (Object.assign(Object.assign({}, constraint), { index: constraint.index.toString(), limit: stringifyLimit(constraint.limit) }))), maxValuePerUse: policy.maxValuePerUse.toString(), valueLimit: stringifyLimit(policy.valueLimit) }))), expiresAt: sessionConfig.expiresAt.toString(), feeLimit: stringifyLimit(sessionConfig.feeLimit), transferPolicies: sessionConfig.transferPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { maxValuePerUse: policy.maxValuePerUse.toString(), valueLimit: stringifyLimit(policy.valueLimit) }))) });
38
+ };
39
+
40
+ exports.enforceSessionConfigRestrictions = enforceSessionConfigRestrictions;
41
+ exports.getSessionHash = getSessionHash;
42
+ exports.parseSessionConfigJSON = parseSessionConfigJSON;
43
+ exports.stringifySessionConfig = stringifySessionConfig;
@@ -0,0 +1,6 @@
1
+ import { SessionConfig } from 'zksync-sso/utils';
2
+ import { SessionConfigJSON, SessionConfigWithoutSigner } from '../types';
3
+ export declare const enforceSessionConfigRestrictions: (sessionConfig: SessionConfigWithoutSigner) => SessionConfigWithoutSigner;
4
+ export declare const getSessionHash: (sessionConfig: SessionConfig) => `0x${string}`;
5
+ export declare const parseSessionConfigJSON: (sessionConfig: SessionConfigJSON) => SessionConfig;
6
+ export declare const stringifySessionConfig: (sessionConfig: SessionConfig) => SessionConfigJSON;
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ import { keccak256 } from 'viem';
3
+ import { encodeSession } from 'zksync-sso/utils';
4
+
5
+ const DEFAULT_EXPIRATION_TIME = 86400; // 1 day
6
+ const enforceSessionConfigRestrictions = (sessionConfig) => {
7
+ const now = Math.floor(Date.now() / 1000);
8
+ const maxExpirationTime = now + DEFAULT_EXPIRATION_TIME;
9
+ if (!sessionConfig.expiresAt ||
10
+ Number(sessionConfig.expiresAt) > maxExpirationTime) {
11
+ sessionConfig.expiresAt = BigInt(maxExpirationTime);
12
+ }
13
+ return sessionConfig;
14
+ };
15
+ const getSessionHash = (sessionConfig) => {
16
+ const sessionHash = encodeSession(sessionConfig);
17
+ return keccak256(sessionHash);
18
+ };
19
+ const parseSessionConfigJSON = (sessionConfig) => {
20
+ const serializeLimit = (limit) => ({
21
+ limit: BigInt(limit.limit),
22
+ limitType: limit.limitType,
23
+ period: BigInt(limit.period),
24
+ });
25
+ return Object.assign(Object.assign({}, sessionConfig), { callPolicies: sessionConfig.callPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { constraints: policy.constraints.map((constraint) => (Object.assign(Object.assign({}, constraint), { index: BigInt(constraint.index), limit: serializeLimit(constraint.limit) }))), maxValuePerUse: BigInt(policy.maxValuePerUse), valueLimit: serializeLimit(policy.valueLimit) }))), expiresAt: BigInt(sessionConfig.expiresAt), feeLimit: serializeLimit(sessionConfig.feeLimit), transferPolicies: sessionConfig.transferPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { maxValuePerUse: BigInt(policy.maxValuePerUse), valueLimit: serializeLimit(policy.valueLimit) }))) });
26
+ };
27
+ const stringifySessionConfig = (sessionConfig) => {
28
+ const stringifyLimit = (limit) => ({
29
+ limit: limit.limit.toString(),
30
+ limitType: limit.limitType,
31
+ period: limit.period.toString(),
32
+ });
33
+ return Object.assign(Object.assign({}, sessionConfig), { callPolicies: sessionConfig.callPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { constraints: policy.constraints.map((constraint) => (Object.assign(Object.assign({}, constraint), { index: constraint.index.toString(), limit: stringifyLimit(constraint.limit) }))), maxValuePerUse: policy.maxValuePerUse.toString(), valueLimit: stringifyLimit(policy.valueLimit) }))), expiresAt: sessionConfig.expiresAt.toString(), feeLimit: stringifyLimit(sessionConfig.feeLimit), transferPolicies: sessionConfig.transferPolicies.map((policy) => (Object.assign(Object.assign({}, policy), { maxValuePerUse: policy.maxValuePerUse.toString(), valueLimit: stringifyLimit(policy.valueLimit) }))) });
34
+ };
35
+
36
+ export { enforceSessionConfigRestrictions, getSessionHash, parseSessionConfigJSON, stringifySessionConfig };
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var utils = require('@dynamic-labs/utils');
7
+ var session = require('./session.cjs');
8
+
9
+ const getZksyncSessionStorageKey = (sessionId) => `zksync-session-${sessionId}`;
10
+ const retrieveSessionFromStorage = (sessionId) => {
11
+ const session$1 = utils.StorageService.getItem(getZksyncSessionStorageKey(sessionId));
12
+ if (!session$1) {
13
+ return undefined;
14
+ }
15
+ return Object.assign(Object.assign({}, session$1), { sessionConfig: session.parseSessionConfigJSON(session$1.sessionConfig) });
16
+ };
17
+ const saveSessionToStorage = (sessionId, session) => {
18
+ utils.StorageService.setItem(getZksyncSessionStorageKey(sessionId), session);
19
+ };
20
+ const deleteSessionFromStorage = (sessionId) => {
21
+ utils.StorageService.removeItem(getZksyncSessionStorageKey(sessionId));
22
+ };
23
+
24
+ exports.deleteSessionFromStorage = deleteSessionFromStorage;
25
+ exports.getZksyncSessionStorageKey = getZksyncSessionStorageKey;
26
+ exports.retrieveSessionFromStorage = retrieveSessionFromStorage;
27
+ exports.saveSessionToStorage = saveSessionToStorage;
@@ -0,0 +1,9 @@
1
+ import { SessionStorageItem } from '../types';
2
+ export declare const getZksyncSessionStorageKey: (sessionId: string) => string;
3
+ export declare const retrieveSessionFromStorage: (sessionId: string) => {
4
+ sessionConfig: import("zksync-sso/utils").SessionConfig;
5
+ origin?: string | undefined;
6
+ sessionKey: string;
7
+ } | undefined;
8
+ export declare const saveSessionToStorage: (sessionId: string, session: SessionStorageItem) => void;
9
+ export declare const deleteSessionFromStorage: (sessionId: string) => void;
@@ -0,0 +1,20 @@
1
+ 'use client'
2
+ import { StorageService } from '@dynamic-labs/utils';
3
+ import { parseSessionConfigJSON } from './session.js';
4
+
5
+ const getZksyncSessionStorageKey = (sessionId) => `zksync-session-${sessionId}`;
6
+ const retrieveSessionFromStorage = (sessionId) => {
7
+ const session = StorageService.getItem(getZksyncSessionStorageKey(sessionId));
8
+ if (!session) {
9
+ return undefined;
10
+ }
11
+ return Object.assign(Object.assign({}, session), { sessionConfig: parseSessionConfigJSON(session.sessionConfig) });
12
+ };
13
+ const saveSessionToStorage = (sessionId, session) => {
14
+ StorageService.setItem(getZksyncSessionStorageKey(sessionId), session);
15
+ };
16
+ const deleteSessionFromStorage = (sessionId) => {
17
+ StorageService.removeItem(getZksyncSessionStorageKey(sessionId));
18
+ };
19
+
20
+ export { deleteSessionFromStorage, getZksyncSessionStorageKey, retrieveSessionFromStorage, saveSessionToStorage };