5555import { InformationCircleIcon } from " @heroicons/vue/20/solid" ;
5656import type { Address , Hex } from " viem" ;
5757import { 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
6060const { defaultChain } = useClientStore ();
6161const { address } = storeToRefs (useAccountStore ());
@@ -68,7 +68,7 @@ interface WasmUsageLimit {
6868}
6969
7070interface 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 }));
0 commit comments