Skip to content

Commit cbb6a0b

Browse files
committed
fix: linting updates from code review
1 parent f070f0e commit cbb6a0b

File tree

3 files changed

+58
-26
lines changed
  • packages
    • auth-server
    • sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-ffi-web/src/account/modular_smart_account/session

3 files changed

+58
-26
lines changed

packages/auth-server/components/session/row/Row.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
</div>
1717
</div>
1818
<div class="session-expiry-container">
19+
<!-- TODO: created-at is hardcoded to 0 because the current session data
20+
does not include a creation timestamp. Update this when a real
21+
created-at value is available or when SessionRowExpiry is changed
22+
to not rely on created-at for active sessions. -->
1923
<SessionRowExpiry
2024
v-if="sessionState"
2125
:status="sessionState.status"
2226
:is-expired="isExpired"
23-
<!-- TODO: created-at is hardcoded to 0 because the current session data
24-
does not include a creation timestamp. Update this when a real
25-
created-at value is available or when SessionRowExpiry is changed
26-
to not rely on created-at for active sessions. -->
2727
:created-at="0"
2828
:expires-at="expiresAt"
2929
:now="now"

packages/auth-server/pages/dashboard/sessions.vue

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import { InformationCircleIcon } from "@heroicons/vue/20/solid";
5656
import type { Address, Hex } from "viem";
5757
import { listActiveSessions } from "zksync-sso-4337";
58-
import { LimitType, type SessionSpec } from "zksync-sso-4337/client";
58+
import { type ConstraintCondition, LimitType, type SessionSpec } from "zksync-sso-4337/client";
5959
6060
const { defaultChain } = useClientStore();
6161
const { address } = storeToRefs(useAccountStore());
@@ -68,7 +68,7 @@ interface WasmUsageLimit {
6868
}
6969
7070
interface WasmConstraint {
71-
condition: string;
71+
condition: string; // Will be converted to ConstraintCondition enum
7272
index: string;
7373
refValue: Hex;
7474
limit: WasmUsageLimit;
@@ -107,6 +107,7 @@ const convertSessionSpec = (wasmSpec: WasmSessionSpec): SessionSpec => {
107107
else {
108108
const numericLimitType = Number(limit.limitType);
109109
if (Number.isNaN(numericLimitType)) {
110+
// eslint-disable-next-line no-console
110111
console.warn(
111112
"Unexpected limitType value received from WASM:",
112113
limit.limitType,
@@ -118,32 +119,61 @@ const convertSessionSpec = (wasmSpec: WasmSessionSpec): SessionSpec => {
118119
}
119120
}
120121
122+
// Validate and convert BigInt values with try-catch
123+
let limitValue: bigint;
124+
let periodValue: bigint;
125+
try {
126+
limitValue = BigInt(limit.limit);
127+
} catch (e) {
128+
// eslint-disable-next-line no-console
129+
console.warn("Invalid limit value from WASM, defaulting to 0:", limit.limit, e);
130+
limitValue = 0n;
131+
}
132+
try {
133+
periodValue = BigInt(limit.period);
134+
} catch (e) {
135+
// eslint-disable-next-line no-console
136+
console.warn("Invalid period value from WASM, defaulting to 0:", limit.period, e);
137+
periodValue = 0n;
138+
}
139+
121140
return {
122141
limitType,
123-
limit: BigInt(limit.limit),
124-
period: BigInt(limit.period),
142+
limit: limitValue,
143+
period: periodValue,
125144
};
126145
};
127146
147+
// Helper to safely convert BigInt with validation
148+
const safeBigInt = (value: string, fieldName: string): bigint => {
149+
try {
150+
return BigInt(value);
151+
} catch (e) {
152+
// eslint-disable-next-line no-console
153+
console.warn(`Invalid ${fieldName} value from WASM, defaulting to 0:`, value, e);
154+
return 0n;
155+
}
156+
};
157+
128158
return {
129159
signer: wasmSpec.signer,
130-
expiresAt: BigInt(wasmSpec.expiresAt),
160+
expiresAt: safeBigInt(wasmSpec.expiresAt, "expiresAt"),
131161
feeLimit: convertLimit(wasmSpec.feeLimit),
132162
callPolicies: (wasmSpec.callPolicies || []).map((policy: WasmCallPolicy) => ({
133163
target: policy.target,
134164
selector: policy.selector,
135-
maxValuePerUse: BigInt(policy.maxValuePerUse),
165+
maxValuePerUse: safeBigInt(policy.maxValuePerUse, "maxValuePerUse"),
136166
valueLimit: convertLimit(policy.valueLimit),
137167
constraints: (policy.constraints || []).map((constraint: WasmConstraint) => ({
138-
condition: constraint.condition,
139-
index: BigInt(constraint.index),
168+
condition: constraint.condition as unknown as ConstraintCondition,
169+
index: safeBigInt(constraint.index, "constraint.index"),
140170
refValue: constraint.refValue,
141171
limit: convertLimit(constraint.limit),
142172
})),
143173
})),
144174
transferPolicies: (wasmSpec.transferPolicies || []).map((policy: WasmTransferPolicy) => ({
145175
target: policy.target,
146-
maxValuePerUse: BigInt(policy.maxValuePerUse),
176+
maxValuePerUse: safeBigInt(policy.maxValuePerUse, "transfer.maxValuePerUse"),
147177
valueLimit: convertLimit(policy.valueLimit),
148178
})),
149179
};
@@ -169,7 +199,7 @@ const {
169199
rpcUrl,
170200
contracts: {
171201
sessionValidator: contracts.sessionValidator,
172-
entryPoint: (contracts as any).entryPoint || "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
202+
entryPoint: (contracts as { entryPoint?: Address }).entryPoint || "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
173203
accountFactory: contracts.factory,
174204
webauthnValidator: contracts.webauthnValidator,
175205
eoaValidator: contracts.eoaValidator,
@@ -178,16 +208,17 @@ const {
178208
});
179209
180210
// Map snake_case properties from WASM to camelCase and convert types
181-
const filtered = activeSessions
182-
.filter((item: { session_hash?: Hex; session_spec?: WasmSessionSpec }) => {
211+
type WasmSession = { session_hash: Hex; session_spec: WasmSessionSpec };
212+
const filtered = (activeSessions as unknown as WasmSession[])
213+
.filter((item) => {
183214
const isValid = item?.session_hash && item?.session_spec && item?.session_spec?.signer;
184215
if (!isValid) {
185216
// eslint-disable-next-line no-console
186217
console.warn("[sessions.vue] Filtering out invalid session:", item);
187218
}
188219
return isValid;
189220
})
190-
.map((item: { session_hash: Hex; session_spec: WasmSessionSpec }) => ({
221+
.map((item) => ({
191222
sessionHash: item.session_hash,
192223
sessionSpec: convertSessionSpec(item.session_spec),
193224
}));

packages/sdk-platforms/rust/zksync-sso-erc4337/crates/zksync-sso-erc4337-ffi-web/src/account/modular_smart_account/session/list.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ pub fn get_active_sessions_wasm(
3737
};
3838

3939
// Parse contracts JSON
40-
let contracts: CoreContracts = match serde_json::from_str(&contracts_json) {
41-
Ok(c) => c,
42-
Err(e) => {
43-
return Err(JsValue::from_str(&format!(
44-
"Invalid contracts JSON: {}",
45-
e
46-
)));
47-
}
48-
};
40+
let contracts: CoreContracts =
41+
match serde_json::from_str(&contracts_json) {
42+
Ok(c) => c,
43+
Err(e) => {
44+
return Err(JsValue::from_str(&format!(
45+
"Invalid contracts JSON: {}",
46+
e
47+
)));
48+
}
49+
};
4950

5051
// Create transport and provider
5152
let transport = WasmHttpTransport::new(rpc_url);

0 commit comments

Comments
 (0)