@dynamic-labs/ethereum-aa-zksync 4.18.7 → 4.18.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/connector/ZKsyncConnector.cjs +41 -1
- package/src/connector/ZKsyncConnector.d.ts +13 -18
- package/src/connector/ZKsyncConnector.js +42 -2
- package/src/types/index.d.ts +18 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/session.cjs +52 -0
- package/src/utils/session.d.ts +11 -0
- package/src/utils/session.js +44 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.18.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.7...v4.18.8) (2025-05-22)
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* 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))
|
|
7
|
+
* 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))
|
|
8
|
+
|
|
2
9
|
### [4.18.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.6...v4.18.7) (2025-05-21)
|
|
3
10
|
|
|
4
11
|
|
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.8",
|
|
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.
|
|
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.8",
|
|
24
|
+
"@dynamic-labs/ethereum-aa-core": "4.18.8",
|
|
25
|
+
"@dynamic-labs/ethereum-core": "4.18.8",
|
|
26
|
+
"@dynamic-labs/types": "4.18.8",
|
|
27
|
+
"@dynamic-labs/utils": "4.18.8",
|
|
28
|
+
"@dynamic-labs/wallet-book": "4.18.8",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "4.18.8"
|
|
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,7 @@ 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');
|
|
22
24
|
|
|
23
25
|
class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
24
26
|
constructor(props) {
|
|
@@ -532,7 +534,7 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
532
534
|
}))
|
|
533
535
|
.filter((log) => log.args.sessionHash)
|
|
534
536
|
.map((log) => log.args.sessionHash);
|
|
535
|
-
|
|
537
|
+
const activeSessions = createSessionLogs
|
|
536
538
|
.filter((log) => log.args.sessionHash &&
|
|
537
539
|
// filter out the sessions that have been revoked
|
|
538
540
|
!revokedSessionHashes.includes(log.args.sessionHash))
|
|
@@ -552,6 +554,10 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
552
554
|
return -1;
|
|
553
555
|
return 0;
|
|
554
556
|
});
|
|
557
|
+
return activeSessions.map((session$1) => {
|
|
558
|
+
var _a;
|
|
559
|
+
return (Object.assign(Object.assign({}, session$1), { origin: (_a = session.retrieveSessionFromStorage(session$1.sessionId)) === null || _a === void 0 ? void 0 : _a.origin }));
|
|
560
|
+
});
|
|
555
561
|
}
|
|
556
562
|
catch (error) {
|
|
557
563
|
walletConnectorCore.logger.error('[ZKsyncConnector] Error listing sessions: ', error);
|
|
@@ -586,6 +592,40 @@ class ZKsyncConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
586
592
|
};
|
|
587
593
|
}
|
|
588
594
|
yield this.smartAccount.revokeSession(params);
|
|
595
|
+
utils.StorageService.removeItem(`zksync-session-${sessionId}`);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
createSession(_a) {
|
|
599
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ sessionConfig, origin, }) {
|
|
600
|
+
if (!this.smartAccount) {
|
|
601
|
+
throw new Error('Smart account is not initialized');
|
|
602
|
+
}
|
|
603
|
+
const safeSessionConfig = session.enforceSessionConfigRestrictions(sessionConfig);
|
|
604
|
+
const privateKey = accounts.generatePrivateKey();
|
|
605
|
+
const signer = accounts.privateKeyToAccount(privateKey);
|
|
606
|
+
const params = {
|
|
607
|
+
sessionConfig: Object.assign(Object.assign({}, safeSessionConfig), { signer: signer.address }),
|
|
608
|
+
};
|
|
609
|
+
if (this.paymasterAddress) {
|
|
610
|
+
params.paymaster = {
|
|
611
|
+
address: this.paymasterAddress,
|
|
612
|
+
paymasterInput: zksync.getGeneralPaymasterInput({
|
|
613
|
+
innerInput: new Uint8Array(),
|
|
614
|
+
}),
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
yield this.smartAccount.createSession(params);
|
|
618
|
+
const sessionHash = session.getSessionHash(params.sessionConfig);
|
|
619
|
+
const serializedSessionConfig = session.stringifySessionConfig(params.sessionConfig);
|
|
620
|
+
const originURI = origin
|
|
621
|
+
? new URL(origin).hostname
|
|
622
|
+
: utils.PlatformService.getHostname();
|
|
623
|
+
utils.StorageService.setItem(`zksync-session-${sessionHash}`, {
|
|
624
|
+
origin: originURI,
|
|
625
|
+
sessionConfig: serializedSessionConfig,
|
|
626
|
+
sessionKey: privateKey,
|
|
627
|
+
});
|
|
628
|
+
return { expiresAt: safeSessionConfig.expiresAt, sessionId: sessionHash };
|
|
589
629
|
});
|
|
590
630
|
}
|
|
591
631
|
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;
|
|
@@ -161,11 +161,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
161
161
|
ReturnType: `0x${string}`;
|
|
162
162
|
}, {
|
|
163
163
|
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
|
-
*/
|
|
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];
|
|
169
165
|
ReturnType: {
|
|
170
166
|
accessList: import("viem").AccessList;
|
|
171
167
|
gasUsed: `0x${string}`;
|
|
@@ -16534,7 +16530,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
16534
16530
|
sourceId?: number | undefined;
|
|
16535
16531
|
testnet?: boolean | undefined;
|
|
16536
16532
|
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account, chainOverride_9>) => Promise<`0x${string}`>;
|
|
16537
|
-
createSession: (args: Omit<
|
|
16533
|
+
createSession: (args: Omit<CreateSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").CreateSessionReturnType>;
|
|
16538
16534
|
revokeSession: (args: Omit<RevokeSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").RevokeSessionReturnType>;
|
|
16539
16535
|
extend: <const client extends {
|
|
16540
16536
|
[x: string]: unknown;
|
|
@@ -16710,11 +16706,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
16710
16706
|
ReturnType: `0x${string}`;
|
|
16711
16707
|
}, {
|
|
16712
16708
|
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
|
-
*/
|
|
16709
|
+
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
16710
|
ReturnType: {
|
|
16719
16711
|
accessList: import("viem").AccessList;
|
|
16720
16712
|
gasUsed: `0x${string}`;
|
|
@@ -17221,11 +17213,7 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
17221
17213
|
ReturnType: `0x${string}`;
|
|
17222
17214
|
}, {
|
|
17223
17215
|
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
|
-
*/
|
|
17216
|
+
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
17217
|
ReturnType: {
|
|
17230
17218
|
accessList: import("viem").AccessList;
|
|
17231
17219
|
gasUsed: `0x${string}`;
|
|
@@ -17711,6 +17699,13 @@ export declare class ZKsyncConnector extends AccountAbstractionBaseConnector imp
|
|
|
17711
17699
|
listSessions(): Promise<SessionInformation[]>;
|
|
17712
17700
|
getAddress(): Promise<string | undefined>;
|
|
17713
17701
|
revokeSession(sessionId: `0x${string}`): Promise<void>;
|
|
17702
|
+
createSession({ sessionConfig, origin, }: {
|
|
17703
|
+
sessionConfig: SessionConfigWithoutSigner;
|
|
17704
|
+
origin?: string;
|
|
17705
|
+
}): Promise<{
|
|
17706
|
+
expiresAt: bigint;
|
|
17707
|
+
sessionId: `0x${string}`;
|
|
17708
|
+
}>;
|
|
17714
17709
|
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
17715
17710
|
isSmartAccountDeployed(refetch?: boolean): Promise<boolean>;
|
|
17716
17711
|
}
|
|
@@ -7,14 +7,16 @@ import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client
|
|
|
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 { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
10
11
|
import { EthereumWallet, chainsMap, confirmationTransport, getOrMapViemChain } from '@dynamic-labs/ethereum-core';
|
|
11
|
-
import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
|
|
12
|
+
import { parseEvmNetworks, DeferredPromise, StorageService, PlatformService, 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 { retrieveSessionFromStorage, enforceSessionConfigRestrictions, getSessionHash, stringifySessionConfig } from '../utils/session.js';
|
|
18
20
|
|
|
19
21
|
class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
20
22
|
constructor(props) {
|
|
@@ -528,7 +530,7 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
528
530
|
}))
|
|
529
531
|
.filter((log) => log.args.sessionHash)
|
|
530
532
|
.map((log) => log.args.sessionHash);
|
|
531
|
-
|
|
533
|
+
const activeSessions = createSessionLogs
|
|
532
534
|
.filter((log) => log.args.sessionHash &&
|
|
533
535
|
// filter out the sessions that have been revoked
|
|
534
536
|
!revokedSessionHashes.includes(log.args.sessionHash))
|
|
@@ -548,6 +550,10 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
548
550
|
return -1;
|
|
549
551
|
return 0;
|
|
550
552
|
});
|
|
553
|
+
return activeSessions.map((session) => {
|
|
554
|
+
var _a;
|
|
555
|
+
return (Object.assign(Object.assign({}, session), { origin: (_a = retrieveSessionFromStorage(session.sessionId)) === null || _a === void 0 ? void 0 : _a.origin }));
|
|
556
|
+
});
|
|
551
557
|
}
|
|
552
558
|
catch (error) {
|
|
553
559
|
logger.error('[ZKsyncConnector] Error listing sessions: ', error);
|
|
@@ -582,6 +588,40 @@ class ZKsyncConnector extends AccountAbstractionBaseConnector {
|
|
|
582
588
|
};
|
|
583
589
|
}
|
|
584
590
|
yield this.smartAccount.revokeSession(params);
|
|
591
|
+
StorageService.removeItem(`zksync-session-${sessionId}`);
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
createSession(_a) {
|
|
595
|
+
return __awaiter(this, arguments, void 0, function* ({ sessionConfig, origin, }) {
|
|
596
|
+
if (!this.smartAccount) {
|
|
597
|
+
throw new Error('Smart account is not initialized');
|
|
598
|
+
}
|
|
599
|
+
const safeSessionConfig = enforceSessionConfigRestrictions(sessionConfig);
|
|
600
|
+
const privateKey = generatePrivateKey();
|
|
601
|
+
const signer = privateKeyToAccount(privateKey);
|
|
602
|
+
const params = {
|
|
603
|
+
sessionConfig: Object.assign(Object.assign({}, safeSessionConfig), { signer: signer.address }),
|
|
604
|
+
};
|
|
605
|
+
if (this.paymasterAddress) {
|
|
606
|
+
params.paymaster = {
|
|
607
|
+
address: this.paymasterAddress,
|
|
608
|
+
paymasterInput: getGeneralPaymasterInput({
|
|
609
|
+
innerInput: new Uint8Array(),
|
|
610
|
+
}),
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
yield this.smartAccount.createSession(params);
|
|
614
|
+
const sessionHash = getSessionHash(params.sessionConfig);
|
|
615
|
+
const serializedSessionConfig = stringifySessionConfig(params.sessionConfig);
|
|
616
|
+
const originURI = origin
|
|
617
|
+
? new URL(origin).hostname
|
|
618
|
+
: PlatformService.getHostname();
|
|
619
|
+
StorageService.setItem(`zksync-session-${sessionHash}`, {
|
|
620
|
+
origin: originURI,
|
|
621
|
+
sessionConfig: serializedSessionConfig,
|
|
622
|
+
sessionKey: privateKey,
|
|
623
|
+
});
|
|
624
|
+
return { expiresAt: safeSessionConfig.expiresAt, sessionId: sessionHash };
|
|
585
625
|
});
|
|
586
626
|
}
|
|
587
627
|
validateActiveWallet(expectedAddress) {
|
package/src/types/index.d.ts
CHANGED
|
@@ -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
|
};
|
package/src/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
var utils$1 = require('@dynamic-labs/utils');
|
|
9
|
+
|
|
10
|
+
const DEFAULT_EXPIRATION_TIME = 86400; // 1 day
|
|
11
|
+
const enforceSessionConfigRestrictions = (sessionConfig) => {
|
|
12
|
+
const now = Math.floor(Date.now() / 1000);
|
|
13
|
+
const maxExpirationTime = now + DEFAULT_EXPIRATION_TIME;
|
|
14
|
+
if (!sessionConfig.expiresAt ||
|
|
15
|
+
Number(sessionConfig.expiresAt) > maxExpirationTime) {
|
|
16
|
+
sessionConfig.expiresAt = BigInt(maxExpirationTime);
|
|
17
|
+
}
|
|
18
|
+
return sessionConfig;
|
|
19
|
+
};
|
|
20
|
+
const getSessionHash = (sessionConfig) => {
|
|
21
|
+
const sessionHash = utils.encodeSession(sessionConfig);
|
|
22
|
+
return viem.keccak256(sessionHash);
|
|
23
|
+
};
|
|
24
|
+
const parseSessionConfigJSON = (sessionConfig) => {
|
|
25
|
+
const serializeLimit = (limit) => ({
|
|
26
|
+
limit: BigInt(limit.limit),
|
|
27
|
+
limitType: limit.limitType,
|
|
28
|
+
period: BigInt(limit.period),
|
|
29
|
+
});
|
|
30
|
+
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) }))) });
|
|
31
|
+
};
|
|
32
|
+
const stringifySessionConfig = (sessionConfig) => {
|
|
33
|
+
const stringifyLimit = (limit) => ({
|
|
34
|
+
limit: limit.limit.toString(),
|
|
35
|
+
limitType: limit.limitType,
|
|
36
|
+
period: limit.period.toString(),
|
|
37
|
+
});
|
|
38
|
+
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) }))) });
|
|
39
|
+
};
|
|
40
|
+
const retrieveSessionFromStorage = (sessionId) => {
|
|
41
|
+
const session = utils$1.StorageService.getItem(`zksync-session-${sessionId}`);
|
|
42
|
+
if (!session) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return Object.assign(Object.assign({}, session), { sessionConfig: parseSessionConfigJSON(session.sessionConfig) });
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.enforceSessionConfigRestrictions = enforceSessionConfigRestrictions;
|
|
49
|
+
exports.getSessionHash = getSessionHash;
|
|
50
|
+
exports.parseSessionConfigJSON = parseSessionConfigJSON;
|
|
51
|
+
exports.retrieveSessionFromStorage = retrieveSessionFromStorage;
|
|
52
|
+
exports.stringifySessionConfig = stringifySessionConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
7
|
+
export declare const retrieveSessionFromStorage: (sessionId: string) => {
|
|
8
|
+
sessionConfig: SessionConfig;
|
|
9
|
+
origin?: string | undefined;
|
|
10
|
+
sessionKey: string;
|
|
11
|
+
} | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { keccak256 } from 'viem';
|
|
3
|
+
import { encodeSession } from 'zksync-sso/utils';
|
|
4
|
+
import { StorageService } from '@dynamic-labs/utils';
|
|
5
|
+
|
|
6
|
+
const DEFAULT_EXPIRATION_TIME = 86400; // 1 day
|
|
7
|
+
const enforceSessionConfigRestrictions = (sessionConfig) => {
|
|
8
|
+
const now = Math.floor(Date.now() / 1000);
|
|
9
|
+
const maxExpirationTime = now + DEFAULT_EXPIRATION_TIME;
|
|
10
|
+
if (!sessionConfig.expiresAt ||
|
|
11
|
+
Number(sessionConfig.expiresAt) > maxExpirationTime) {
|
|
12
|
+
sessionConfig.expiresAt = BigInt(maxExpirationTime);
|
|
13
|
+
}
|
|
14
|
+
return sessionConfig;
|
|
15
|
+
};
|
|
16
|
+
const getSessionHash = (sessionConfig) => {
|
|
17
|
+
const sessionHash = encodeSession(sessionConfig);
|
|
18
|
+
return keccak256(sessionHash);
|
|
19
|
+
};
|
|
20
|
+
const parseSessionConfigJSON = (sessionConfig) => {
|
|
21
|
+
const serializeLimit = (limit) => ({
|
|
22
|
+
limit: BigInt(limit.limit),
|
|
23
|
+
limitType: limit.limitType,
|
|
24
|
+
period: BigInt(limit.period),
|
|
25
|
+
});
|
|
26
|
+
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) }))) });
|
|
27
|
+
};
|
|
28
|
+
const stringifySessionConfig = (sessionConfig) => {
|
|
29
|
+
const stringifyLimit = (limit) => ({
|
|
30
|
+
limit: limit.limit.toString(),
|
|
31
|
+
limitType: limit.limitType,
|
|
32
|
+
period: limit.period.toString(),
|
|
33
|
+
});
|
|
34
|
+
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) }))) });
|
|
35
|
+
};
|
|
36
|
+
const retrieveSessionFromStorage = (sessionId) => {
|
|
37
|
+
const session = StorageService.getItem(`zksync-session-${sessionId}`);
|
|
38
|
+
if (!session) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return Object.assign(Object.assign({}, session), { sessionConfig: parseSessionConfigJSON(session.sessionConfig) });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { enforceSessionConfigRestrictions, getSessionHash, parseSessionConfigJSON, retrieveSessionFromStorage, stringifySessionConfig };
|