zksync-sso 0.2.0 → 0.3.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/README.md +11 -2
- package/dist/_cjs/client/session/actions/session.js +53 -1
- package/dist/_cjs/client/session/actions/session.js.map +1 -1
- package/dist/_cjs/client/session/client.js +19 -0
- package/dist/_cjs/client/session/client.js.map +1 -1
- package/dist/_cjs/client/session/decorators/wallet.js +39 -0
- package/dist/_cjs/client/session/decorators/wallet.js.map +1 -1
- package/dist/_cjs/client-auth-server/Signer.js +25 -1
- package/dist/_cjs/client-auth-server/Signer.js.map +1 -1
- package/dist/_cjs/client-auth-server/WalletProvider.js +3 -1
- package/dist/_cjs/client-auth-server/WalletProvider.js.map +1 -1
- package/dist/_cjs/utils/helpers.js +26 -0
- package/dist/_cjs/utils/helpers.js.map +1 -1
- package/dist/_cjs/utils/session.js +283 -1
- package/dist/_cjs/utils/session.js.map +1 -1
- package/dist/_esm/client/session/actions/session.js +59 -1
- package/dist/_esm/client/session/actions/session.js.map +1 -1
- package/dist/_esm/client/session/client.js +20 -0
- package/dist/_esm/client/session/client.js.map +1 -1
- package/dist/_esm/client/session/decorators/wallet.js +47 -0
- package/dist/_esm/client/session/decorators/wallet.js.map +1 -1
- package/dist/_esm/client-auth-server/Signer.js +25 -1
- package/dist/_esm/client-auth-server/Signer.js.map +1 -1
- package/dist/_esm/client-auth-server/WalletProvider.js +3 -1
- package/dist/_esm/client-auth-server/WalletProvider.js.map +1 -1
- package/dist/_esm/utils/helpers.js +24 -0
- package/dist/_esm/utils/helpers.js.map +1 -1
- package/dist/_esm/utils/session.js +296 -1
- package/dist/_esm/utils/session.js.map +1 -1
- package/dist/_types/client/session/actions/session.d.ts +26 -1
- package/dist/_types/client/session/actions/session.d.ts.map +1 -1
- package/dist/_types/client/session/client.d.ts +6 -1
- package/dist/_types/client/session/client.d.ts.map +1 -1
- package/dist/_types/client/session/decorators/wallet.d.ts.map +1 -1
- package/dist/_types/client-auth-server/Signer.d.ts +10 -1
- package/dist/_types/client-auth-server/Signer.d.ts.map +1 -1
- package/dist/_types/client-auth-server/WalletProvider.d.ts +8 -1
- package/dist/_types/client-auth-server/WalletProvider.d.ts.map +1 -1
- package/dist/_types/utils/helpers.d.ts +7 -0
- package/dist/_types/utils/helpers.d.ts.map +1 -1
- package/dist/_types/utils/session.d.ts +51 -0
- package/dist/_types/utils/session.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/session/actions/session.ts +85 -2
- package/src/client/session/client.ts +28 -1
- package/src/client/session/decorators/wallet.ts +59 -3
- package/src/client-auth-server/Signer.ts +17 -1
- package/src/client-auth-server/WalletProvider.ts +6 -1
- package/src/utils/helpers.ts +28 -0
- package/src/utils/session.ts +356 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WalletProvider.d.ts","sourceRoot":"","sources":["../../../src/client-auth-server/WalletProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAKtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAK7D,MAAM,MAAM,gCAAgC,GAAG;IAC7C,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;IAC3C,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,kBAA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C,OAAO,EAAE,CAAC;IAUtC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,SAAS,CAAC,QAAQ,CAAC,cAAc;qCACF,OAAO,EAAE;iCAGb,MAAM;MAG/B;CACH"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export declare function getWebsiteName(): string | null;
|
|
2
2
|
export declare function getFavicon(): string | null;
|
|
3
3
|
export declare function noThrow<T>(fn: () => T): T | null;
|
|
4
|
+
export declare function findSmallestBigInt(arr: bigint[]): bigint;
|
|
5
|
+
export declare function calculateMaxFee(fee: {
|
|
6
|
+
gas?: bigint;
|
|
7
|
+
gasPrice?: bigint;
|
|
8
|
+
maxFeePerGas?: bigint;
|
|
9
|
+
maxPriorityFeePerGas?: bigint;
|
|
10
|
+
}): bigint;
|
|
4
11
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAe9C;AAED,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAiB1C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAMhD"}
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAe9C;AAED,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAiB1C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAMhD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAOxD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,MAAM,CAYT"}
|
|
@@ -125,4 +125,55 @@ export declare const getPeriodIdsForTransaction: (args: {
|
|
|
125
125
|
selector?: Hex;
|
|
126
126
|
timestamp?: bigint;
|
|
127
127
|
}) => bigint[];
|
|
128
|
+
export declare enum SessionErrorType {
|
|
129
|
+
SessionInactive = "session_inactive",
|
|
130
|
+
SessionExpired = "session_expired",
|
|
131
|
+
FeeLimitExceeded = "fee_limit_exceeded",
|
|
132
|
+
NoCallPolicy = "no_call_policy",
|
|
133
|
+
NoTransferPolicy = "no_transfer_policy",
|
|
134
|
+
MaxValuePerUseExceeded = "max_value_per_use_exceeded",
|
|
135
|
+
ValueLimitExceeded = "value_limit_exceeded",
|
|
136
|
+
ConstraintIndexOutOfBounds = "constraint_index_out_of_bounds",
|
|
137
|
+
NoLimitStateFound = "no_limit_state_found",
|
|
138
|
+
ParameterLimitExceeded = "parameter_limit_exceeded",
|
|
139
|
+
ConstraintEqualViolated = "constraint_equal_violated",
|
|
140
|
+
ConstraintGreaterViolated = "constraint_greater_violated",
|
|
141
|
+
ConstraintLessViolated = "constraint_less_violated",
|
|
142
|
+
ConstraintGreaterEqualViolated = "constraint_greater_equal_violated",
|
|
143
|
+
ConstraintLessEqualViolated = "constraint_less_equal_violated",
|
|
144
|
+
ConstraintNotEqualViolated = "constraint_not_equal_violated"
|
|
145
|
+
}
|
|
146
|
+
export declare enum SessionEventType {
|
|
147
|
+
Expired = "session_expired",
|
|
148
|
+
Revoked = "session_revoked",
|
|
149
|
+
Inactive = "session_inactive"
|
|
150
|
+
}
|
|
151
|
+
export type SessionStateEvent = {
|
|
152
|
+
type: SessionEventType;
|
|
153
|
+
message: string;
|
|
154
|
+
};
|
|
155
|
+
export type SessionStateEventCallback = (event: SessionStateEvent) => void;
|
|
156
|
+
export type ValidationResult = {
|
|
157
|
+
valid: boolean;
|
|
158
|
+
error: null | {
|
|
159
|
+
type: SessionErrorType;
|
|
160
|
+
message: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
export type TransactionValidationArgs = {
|
|
164
|
+
sessionState: SessionState;
|
|
165
|
+
sessionConfig: SessionConfig;
|
|
166
|
+
transaction: {
|
|
167
|
+
to: Address;
|
|
168
|
+
value?: bigint;
|
|
169
|
+
data?: Hex;
|
|
170
|
+
gas?: bigint;
|
|
171
|
+
gasPrice?: bigint;
|
|
172
|
+
maxFeePerGas?: bigint;
|
|
173
|
+
maxPriorityFeePerGas?: bigint;
|
|
174
|
+
paymaster?: Address;
|
|
175
|
+
};
|
|
176
|
+
currentTimestamp?: bigint;
|
|
177
|
+
};
|
|
178
|
+
export declare function validateSessionTransaction(args: TransactionValidationArgs): ValidationResult;
|
|
128
179
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/utils/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/utils/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAA0B,KAAK,IAAI,EAAE,KAAK,GAAG,EAA2B,MAAM,MAAM,CAAC;AAI1G,oBAAY,SAAS;IACnB,SAAS,IAAI;IACb,QAAQ,IAAI;IACZ,SAAS,IAAI;CACd;AAED;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;CAI1B,CAAC;AAEF,eAAO,MAAM,SAAS;;;;CAIrB,CAAC;AAEF;;GAEG;AACH,oBAAY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,OAAO,CAAC;IACf,KAAK,EAAE,IAAI,GAAG;QACZ,IAAI,EAAE,gBAAgB,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE;QACX,EAAE,EAAE,OAAO,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;IACF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,yBAAyB,GAAG,gBAAgB,CA0I5F"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type Account, type Address, type Chain, type Client, encodeFunctionData, type Hash, type Hex, type Prettify, type TransactionReceipt, type Transport } from "viem";
|
|
2
|
-
import { waitForTransactionReceipt } from "viem/actions";
|
|
2
|
+
import { readContract, waitForTransactionReceipt } from "viem/actions";
|
|
3
3
|
import { getGeneralPaymasterInput, sendTransaction } from "viem/zksync";
|
|
4
4
|
|
|
5
5
|
import { SessionKeyValidatorAbi } from "../../../abi/SessionKeyValidator.js";
|
|
6
6
|
import { type CustomPaymasterHandler, getTransactionWithPaymasterData } from "../../../paymaster/index.js";
|
|
7
7
|
import { noThrow } from "../../../utils/helpers.js";
|
|
8
|
-
import type { SessionConfig } from "../../../utils/session.js";
|
|
8
|
+
import type { SessionConfig, SessionState, SessionStateEventCallback } from "../../../utils/session.js";
|
|
9
|
+
import { SessionEventType, SessionStatus } from "../../../utils/session.js";
|
|
9
10
|
|
|
10
11
|
export type CreateSessionArgs = {
|
|
11
12
|
sessionConfig: SessionConfig;
|
|
@@ -119,3 +120,85 @@ export const revokeSession = async <
|
|
|
119
120
|
transactionReceipt,
|
|
120
121
|
};
|
|
121
122
|
};
|
|
123
|
+
|
|
124
|
+
export type GetSessionStateArgs = {
|
|
125
|
+
account: Address;
|
|
126
|
+
sessionConfig: SessionConfig;
|
|
127
|
+
contracts: {
|
|
128
|
+
session: Address; // session module
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export type GetSessionStateReturnType = {
|
|
132
|
+
sessionState: SessionState;
|
|
133
|
+
};
|
|
134
|
+
export const getSessionState = async <
|
|
135
|
+
transport extends Transport,
|
|
136
|
+
chain extends Chain,
|
|
137
|
+
>(client: Client<transport, chain>, args: Prettify<GetSessionStateArgs>): Promise<Prettify<GetSessionStateReturnType>> => {
|
|
138
|
+
const sessionState = await readContract(client, {
|
|
139
|
+
address: args.contracts.session,
|
|
140
|
+
abi: SessionKeyValidatorAbi,
|
|
141
|
+
functionName: "sessionState",
|
|
142
|
+
args: [args.account, args.sessionConfig],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
sessionState: sessionState as SessionState,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type CheckSessionStateArgs = {
|
|
151
|
+
sessionConfig: SessionConfig;
|
|
152
|
+
sessionState: SessionState;
|
|
153
|
+
onSessionStateChange: SessionStateEventCallback;
|
|
154
|
+
sessionNotifyTimeout?: NodeJS.Timeout;
|
|
155
|
+
};
|
|
156
|
+
export type CheckSessionStateReturnType = {
|
|
157
|
+
newTimeout?: NodeJS.Timeout;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Checks the current session state and sets up expiry notification.
|
|
162
|
+
* This function will trigger the callback with the session state.
|
|
163
|
+
*/
|
|
164
|
+
export const sessionStateNotify = (args: Prettify<CheckSessionStateArgs>): CheckSessionStateReturnType => {
|
|
165
|
+
// Generate a session ID for tracking timeouts
|
|
166
|
+
const { sessionState } = args;
|
|
167
|
+
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
168
|
+
|
|
169
|
+
// Check session status
|
|
170
|
+
if (sessionState.status === SessionStatus.NotInitialized) { // Not initialized
|
|
171
|
+
args.onSessionStateChange({
|
|
172
|
+
type: SessionEventType.Inactive,
|
|
173
|
+
message: "Session is not initialized",
|
|
174
|
+
});
|
|
175
|
+
} else if (sessionState.status === SessionStatus.Closed) { // Closed/Revoked
|
|
176
|
+
args.onSessionStateChange({
|
|
177
|
+
type: SessionEventType.Revoked,
|
|
178
|
+
message: "Session has been revoked",
|
|
179
|
+
});
|
|
180
|
+
} else if (args.sessionConfig.expiresAt <= now) {
|
|
181
|
+
// Session has expired
|
|
182
|
+
args.onSessionStateChange({
|
|
183
|
+
type: SessionEventType.Expired,
|
|
184
|
+
message: "Session has expired",
|
|
185
|
+
});
|
|
186
|
+
} else {
|
|
187
|
+
// Session is active, set up expiry notification
|
|
188
|
+
const timeToExpiry = Number(args.sessionConfig.expiresAt - now) * 1000;
|
|
189
|
+
if (args.sessionNotifyTimeout) {
|
|
190
|
+
clearTimeout(args.sessionNotifyTimeout);
|
|
191
|
+
}
|
|
192
|
+
const newTimeout = setTimeout(() => {
|
|
193
|
+
args.onSessionStateChange({
|
|
194
|
+
type: SessionEventType.Expired,
|
|
195
|
+
message: "Session has expired",
|
|
196
|
+
});
|
|
197
|
+
}, timeToExpiry);
|
|
198
|
+
return {
|
|
199
|
+
newTimeout,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {};
|
|
204
|
+
};
|
|
@@ -4,8 +4,9 @@ import { zksyncInMemoryNode } from "viem/chains";
|
|
|
4
4
|
|
|
5
5
|
import type { CustomPaymasterHandler } from "../../paymaster/index.js";
|
|
6
6
|
import { encodeSessionTx } from "../../utils/encoding.js";
|
|
7
|
-
import type { SessionConfig } from "../../utils/session.js";
|
|
7
|
+
import type { SessionConfig, SessionStateEventCallback } from "../../utils/session.js";
|
|
8
8
|
import { toSessionAccount } from "./account.js";
|
|
9
|
+
import { getSessionState, sessionStateNotify } from "./actions/session.js";
|
|
9
10
|
import { publicActionsRewrite } from "./decorators/publicActionsRewrite.js";
|
|
10
11
|
import { type ZksyncSsoWalletActions, zksyncSsoWalletActions } from "./decorators/wallet.js";
|
|
11
12
|
|
|
@@ -90,10 +91,31 @@ export function createZksyncSessionClient<
|
|
|
90
91
|
sessionConfig: parameters.sessionConfig,
|
|
91
92
|
contracts: parameters.contracts,
|
|
92
93
|
paymasterHandler: parameters.paymasterHandler,
|
|
94
|
+
onSessionStateChange: parameters.onSessionStateChange,
|
|
95
|
+
_sessionNotifyTimeout: undefined as NodeJS.Timeout | undefined,
|
|
93
96
|
}))
|
|
94
97
|
.extend(publicActions)
|
|
95
98
|
.extend(publicActionsRewrite)
|
|
96
99
|
.extend(zksyncSsoWalletActions);
|
|
100
|
+
|
|
101
|
+
// Check session state on initialization if callback is provided
|
|
102
|
+
if (client.onSessionStateChange) {
|
|
103
|
+
getSessionState(client, {
|
|
104
|
+
account: client.account.address,
|
|
105
|
+
sessionConfig: client.sessionConfig,
|
|
106
|
+
contracts: client.contracts,
|
|
107
|
+
}).then(({ sessionState }) => {
|
|
108
|
+
sessionStateNotify({
|
|
109
|
+
sessionConfig: client.sessionConfig,
|
|
110
|
+
sessionState,
|
|
111
|
+
onSessionStateChange: client.onSessionStateChange!,
|
|
112
|
+
sessionNotifyTimeout: client._sessionNotifyTimeout,
|
|
113
|
+
});
|
|
114
|
+
}).catch((error) => {
|
|
115
|
+
console.error("Failed to get session state on initialization:", error);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
97
119
|
return client;
|
|
98
120
|
}
|
|
99
121
|
|
|
@@ -105,6 +127,9 @@ type ZksyncSsoSessionData = {
|
|
|
105
127
|
sessionConfig: SessionConfig;
|
|
106
128
|
contracts: SessionRequiredContracts;
|
|
107
129
|
paymasterHandler?: CustomPaymasterHandler;
|
|
130
|
+
onSessionStateChange?: SessionStateEventCallback;
|
|
131
|
+
skipPreTransactionStateValidation?: boolean;
|
|
132
|
+
_sessionNotifyTimeout?: NodeJS.Timeout;
|
|
108
133
|
};
|
|
109
134
|
|
|
110
135
|
export type ClientWithZksyncSsoSessionData<
|
|
@@ -143,4 +168,6 @@ export interface ZksyncSsoSessionClientConfig<
|
|
|
143
168
|
key?: string;
|
|
144
169
|
name?: string;
|
|
145
170
|
paymasterHandler?: CustomPaymasterHandler;
|
|
171
|
+
onSessionStateChange?: SessionStateEventCallback;
|
|
172
|
+
skipPreTransactionStateValidation?: boolean; // Useful if you want to send session transactions really fast
|
|
146
173
|
}
|
|
@@ -4,20 +4,51 @@ import {
|
|
|
4
4
|
type Transport, type WalletActions } from "viem";
|
|
5
5
|
import {
|
|
6
6
|
deployContract, getAddresses, getCallsStatus, getCapabilities, getChainId, prepareAuthorization, sendCalls, sendRawTransaction,
|
|
7
|
-
showCallsStatus,
|
|
8
|
-
signAuthorization,
|
|
9
|
-
signMessage, signTypedData, waitForCallsStatus, writeContract,
|
|
7
|
+
showCallsStatus, signAuthorization, signMessage, signTypedData, waitForCallsStatus, writeContract,
|
|
10
8
|
} from "viem/actions";
|
|
11
9
|
import { signTransaction, type TransactionRequestEIP712, type ZksyncEip712Meta } from "viem/zksync";
|
|
12
10
|
|
|
13
11
|
import { getTransactionWithPaymasterData } from "../../../paymaster/index.js";
|
|
12
|
+
import { SessionErrorType, SessionEventType, type SessionState, validateSessionTransaction } from "../../../utils/session.js";
|
|
14
13
|
import { sendEip712Transaction } from "../actions/sendEip712Transaction.js";
|
|
14
|
+
import { getSessionState, sessionStateNotify } from "../actions/session.js";
|
|
15
15
|
import type { ClientWithZksyncSsoSessionData } from "../client.js";
|
|
16
16
|
|
|
17
17
|
export type ZksyncSsoWalletActions<chain extends Chain, account extends Account> = Omit<
|
|
18
18
|
WalletActions<chain, account>, "addChain" | "getPermissions" | "requestAddresses" | "requestPermissions" | "switchChain" | "watchAsset" | "prepareTransactionRequest"
|
|
19
19
|
>;
|
|
20
20
|
|
|
21
|
+
const sessionErrorToSessionEventType = {
|
|
22
|
+
[SessionErrorType.SessionInactive]: SessionEventType.Inactive,
|
|
23
|
+
[SessionErrorType.SessionExpired]: SessionEventType.Expired,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper function to check session state and notify via callback
|
|
28
|
+
*/
|
|
29
|
+
async function getSessionStateAndNotify<
|
|
30
|
+
transport extends Transport,
|
|
31
|
+
chain extends Chain,
|
|
32
|
+
account extends Account,
|
|
33
|
+
>(client: ClientWithZksyncSsoSessionData<transport, chain, account>): Promise<SessionState> {
|
|
34
|
+
const { sessionState } = await getSessionState(client, {
|
|
35
|
+
account: client.account.address,
|
|
36
|
+
sessionConfig: client.sessionConfig,
|
|
37
|
+
contracts: client.contracts,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (client.onSessionStateChange) {
|
|
41
|
+
sessionStateNotify({
|
|
42
|
+
sessionConfig: client.sessionConfig,
|
|
43
|
+
sessionState,
|
|
44
|
+
onSessionStateChange: client.onSessionStateChange,
|
|
45
|
+
sessionNotifyTimeout: client._sessionNotifyTimeout,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return sessionState;
|
|
50
|
+
}
|
|
51
|
+
|
|
21
52
|
export function zksyncSsoWalletActions<
|
|
22
53
|
transport extends Transport,
|
|
23
54
|
chain extends Chain,
|
|
@@ -58,6 +89,30 @@ export function zksyncSsoWalletActions<
|
|
|
58
89
|
type: "eip712",
|
|
59
90
|
};
|
|
60
91
|
|
|
92
|
+
if (client.skipPreTransactionStateValidation !== false) {
|
|
93
|
+
// Get current session state and trigger callback if needed
|
|
94
|
+
const sessionState = await getSessionStateAndNotify(client);
|
|
95
|
+
|
|
96
|
+
// Validate transaction against session constraints
|
|
97
|
+
const validationResult = validateSessionTransaction({
|
|
98
|
+
sessionState,
|
|
99
|
+
sessionConfig: client.sessionConfig,
|
|
100
|
+
transaction: tx,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Throw error if validation fails
|
|
104
|
+
if (validationResult.error) {
|
|
105
|
+
// If validation fails due to session issues, notify via callback
|
|
106
|
+
if (client.onSessionStateChange && Object.keys(sessionErrorToSessionEventType).includes(validationResult.error.type)) {
|
|
107
|
+
client.onSessionStateChange({
|
|
108
|
+
type: sessionErrorToSessionEventType[validationResult.error.type as keyof typeof sessionErrorToSessionEventType],
|
|
109
|
+
message: validationResult.error.message,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
throw new Error(`Session validation failed: ${validationResult.error.message} (${validationResult.error.type})`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
61
116
|
return await sendEip712Transaction(client, tx);
|
|
62
117
|
},
|
|
63
118
|
signMessage: (args) => signMessage(client, args),
|
|
@@ -72,6 +127,7 @@ export function zksyncSsoWalletActions<
|
|
|
72
127
|
return signTransaction(client, {
|
|
73
128
|
...args,
|
|
74
129
|
unformattedTxWithPaymaster,
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
131
|
} as any) as any;
|
|
76
132
|
},
|
|
77
133
|
signTypedData: (args) => signTypedData(client, args),
|
|
@@ -4,6 +4,7 @@ import type { TransactionRequestEIP712 } from "viem/chains";
|
|
|
4
4
|
import { createZksyncSessionClient, type ZksyncSsoSessionClient } from "../client/index.js";
|
|
5
5
|
import type { Communicator } from "../communicator/index.js";
|
|
6
6
|
import { type CustomPaymasterHandler, getTransactionWithPaymasterData } from "../paymaster/index.js";
|
|
7
|
+
import type { SessionStateEvent } from "../utils/session.js";
|
|
7
8
|
import { StorageItem } from "../utils/storage.js";
|
|
8
9
|
import type { AppMetadata, RequestArguments } from "./interface.js";
|
|
9
10
|
import type { AuthServerRpcSchema, ExtractParams, ExtractReturnType, Method, RPCRequestMessage, RPCResponseMessage, RpcSchema } from "./rpc.js";
|
|
@@ -41,6 +42,8 @@ type SignerConstructorParams = {
|
|
|
41
42
|
transports?: Record<number, Transport>;
|
|
42
43
|
session?: () => SessionPreferences | Promise<SessionPreferences>;
|
|
43
44
|
paymasterHandler?: CustomPaymasterHandler;
|
|
45
|
+
onSessionStateChange?: (event: { address: Address; chainId: number; state: SessionStateEvent }) => void;
|
|
46
|
+
skipPreTransactionStateValidation?: boolean; // Useful if you want to send session transactions really fast
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
type ChainsInfo = ExtractReturnType<"eth_requestAccounts", AuthServerRpcSchema>["chainsInfo"];
|
|
@@ -53,12 +56,14 @@ export class Signer implements SignerInterface {
|
|
|
53
56
|
private readonly transports: Record<number, Transport> = {};
|
|
54
57
|
private readonly sessionParameters?: () => (SessionPreferences | Promise<SessionPreferences>);
|
|
55
58
|
private readonly paymasterHandler?: CustomPaymasterHandler;
|
|
59
|
+
private readonly onSessionStateChange?: SignerConstructorParams["onSessionStateChange"];
|
|
60
|
+
private readonly skipPreTransactionStateValidation?: boolean;
|
|
56
61
|
|
|
57
62
|
private _account: StorageItem<Account | null>;
|
|
58
63
|
private _chainsInfo = new StorageItem<ChainsInfo>(StorageItem.scopedStorageKey("chainsInfo"), []);
|
|
59
64
|
private client: { instance: ZksyncSsoSessionClient; type: "session" } | { instance: WalletClient; type: "auth-server" } | undefined;
|
|
60
65
|
|
|
61
|
-
constructor({ metadata, communicator, updateListener, session, chains, transports, paymasterHandler }: SignerConstructorParams) {
|
|
66
|
+
constructor({ metadata, communicator, updateListener, session, chains, transports, paymasterHandler, onSessionStateChange, skipPreTransactionStateValidation }: SignerConstructorParams) {
|
|
62
67
|
if (!chains.length) throw new Error("At least one chain must be included in the config");
|
|
63
68
|
|
|
64
69
|
this.getMetadata = metadata;
|
|
@@ -68,6 +73,8 @@ export class Signer implements SignerInterface {
|
|
|
68
73
|
this.chains = chains;
|
|
69
74
|
this.transports = transports || {};
|
|
70
75
|
this.paymasterHandler = paymasterHandler;
|
|
76
|
+
this.onSessionStateChange = onSessionStateChange;
|
|
77
|
+
this.skipPreTransactionStateValidation = skipPreTransactionStateValidation;
|
|
71
78
|
|
|
72
79
|
this._account = new StorageItem<Account | null>(StorageItem.scopedStorageKey("account"), null, {
|
|
73
80
|
onChange: (newValue) => {
|
|
@@ -142,6 +149,15 @@ export class Signer implements SignerInterface {
|
|
|
142
149
|
chain,
|
|
143
150
|
transport: this.transports[chain.id] || http(),
|
|
144
151
|
paymasterHandler: this.paymasterHandler,
|
|
152
|
+
onSessionStateChange: (event: SessionStateEvent) => {
|
|
153
|
+
if (!this.onSessionStateChange) return;
|
|
154
|
+
this.onSessionStateChange({
|
|
155
|
+
state: event,
|
|
156
|
+
address: this.account!.address,
|
|
157
|
+
chainId: chain.id,
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
skipPreTransactionStateValidation: this.skipPreTransactionStateValidation,
|
|
145
161
|
}),
|
|
146
162
|
};
|
|
147
163
|
} else {
|
|
@@ -6,6 +6,7 @@ import { PopupCommunicator } from "../communicator/PopupCommunicator.js";
|
|
|
6
6
|
import { serializeError, standardErrors } from "../errors/index.js";
|
|
7
7
|
import type { CustomPaymasterHandler } from "../paymaster/index.js";
|
|
8
8
|
import { getFavicon, getWebsiteName } from "../utils/helpers.js";
|
|
9
|
+
import type { SessionStateEvent } from "../utils/session.js";
|
|
9
10
|
import type {
|
|
10
11
|
AppMetadata,
|
|
11
12
|
ProviderInterface,
|
|
@@ -24,13 +25,15 @@ export type WalletProviderConstructorOptions = {
|
|
|
24
25
|
session?: SessionPreferences | (() => SessionPreferences | Promise<SessionPreferences>);
|
|
25
26
|
authServerUrl?: string;
|
|
26
27
|
paymasterHandler?: CustomPaymasterHandler;
|
|
28
|
+
onSessionStateChange?: (state: { address: Address; chainId: number; state: SessionStateEvent }) => void;
|
|
29
|
+
skipPreTransactionStateValidation?: boolean; // Useful if you want to send session transactions really fast
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
export class WalletProvider extends EventEmitter implements ProviderInterface {
|
|
30
33
|
readonly isZksyncSso = true;
|
|
31
34
|
private signer: Signer;
|
|
32
35
|
|
|
33
|
-
constructor({ metadata, chains, transports, session, authServerUrl, paymasterHandler }: WalletProviderConstructorOptions) {
|
|
36
|
+
constructor({ metadata, chains, transports, session, authServerUrl, paymasterHandler, onSessionStateChange, skipPreTransactionStateValidation }: WalletProviderConstructorOptions) {
|
|
34
37
|
super();
|
|
35
38
|
const communicator = new PopupCommunicator(authServerUrl || DEFAULT_AUTH_SERVER_URL);
|
|
36
39
|
this.signer = new Signer({
|
|
@@ -45,6 +48,8 @@ export class WalletProvider extends EventEmitter implements ProviderInterface {
|
|
|
45
48
|
transports,
|
|
46
49
|
session: typeof session === "object" ? () => session : session,
|
|
47
50
|
paymasterHandler,
|
|
51
|
+
onSessionStateChange,
|
|
52
|
+
skipPreTransactionStateValidation,
|
|
48
53
|
});
|
|
49
54
|
}
|
|
50
55
|
|
package/src/utils/helpers.ts
CHANGED
|
@@ -41,3 +41,31 @@ export function noThrow<T>(fn: () => T): T | null {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
export function findSmallestBigInt(arr: bigint[]): bigint {
|
|
46
|
+
if (arr.length === 0) throw new Error("Array must not be empty");
|
|
47
|
+
let smallest = arr[0];
|
|
48
|
+
for (const num of arr) {
|
|
49
|
+
if (num < smallest) smallest = num;
|
|
50
|
+
}
|
|
51
|
+
return smallest;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function calculateMaxFee(fee: {
|
|
55
|
+
gas?: bigint;
|
|
56
|
+
gasPrice?: bigint;
|
|
57
|
+
maxFeePerGas?: bigint;
|
|
58
|
+
maxPriorityFeePerGas?: bigint;
|
|
59
|
+
}): bigint {
|
|
60
|
+
if (!fee.gas) return 0n;
|
|
61
|
+
|
|
62
|
+
if (fee.gasPrice) {
|
|
63
|
+
return fee.gas * fee.gasPrice;
|
|
64
|
+
} else if (fee.maxFeePerGas) {
|
|
65
|
+
return fee.gas * fee.maxFeePerGas;
|
|
66
|
+
} else if (fee.maxPriorityFeePerGas) {
|
|
67
|
+
return fee.gas * fee.maxPriorityFeePerGas;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return 0n;
|
|
71
|
+
}
|