@@ -287,13 +287,15 @@ async fn challenge_route_handler(
287287 trace ! ( "Challenge route: {} {} {}" , challenge_id, method, path) ;
288288
289289 // Check if challenge has registered routes
290- // Clone the routes while holding the lock , then drop it
290+ // First try handler.challenge_routes , then fallback to chain_state.challenge_routes
291291 let challenge_routes = {
292292 let routes = handler. challenge_routes . read ( ) ;
293293 let result = routes. get ( & challenge_id) . cloned ( ) ;
294294
295- if result. is_none ( ) {
296- // Try to find by name
295+ if result. is_some ( ) {
296+ result
297+ } else {
298+ // Try to find by name in legacy challenges
297299 let chain = handler. chain_state . read ( ) ;
298300 let actual_id = chain
299301 . challenges
@@ -302,9 +304,43 @@ async fn challenge_route_handler(
302304 . map ( |c| c. id . to_string ( ) ) ;
303305 drop ( chain) ;
304306
305- actual_id. and_then ( |id| routes. get ( & id) . cloned ( ) )
306- } else {
307- result
307+ if let Some ( id) = actual_id {
308+ routes. get ( & id) . cloned ( )
309+ } else {
310+ // Fallback: Try chain_state.challenge_routes (for WASM challenges)
311+ drop ( routes) ;
312+ let chain = handler. chain_state . read ( ) ;
313+ let challenge_uuid = uuid:: Uuid :: parse_str ( & challenge_id) . ok ( ) . map ( ChallengeId ) ;
314+
315+ challenge_uuid
316+ . as_ref ( )
317+ . and_then ( |id| chain. challenge_routes . get ( id) )
318+ . map ( |chain_routes| {
319+ use platform_challenge_sdk:: HttpMethod ;
320+ chain_routes
321+ . iter ( )
322+ . map ( |r| {
323+ let method = match r. method . to_uppercase ( ) . as_str ( ) {
324+ "GET" => HttpMethod :: Get ,
325+ "POST" => HttpMethod :: Post ,
326+ "PUT" => HttpMethod :: Put ,
327+ "DELETE" => HttpMethod :: Delete ,
328+ "PATCH" => HttpMethod :: Patch ,
329+ _ => HttpMethod :: Get ,
330+ } ;
331+ let mut route = platform_challenge_sdk:: ChallengeRoute :: new (
332+ method,
333+ r. path . clone ( ) ,
334+ r. description . clone ( ) ,
335+ ) ;
336+ if r. requires_auth {
337+ route = route. with_auth ( ) ;
338+ }
339+ route
340+ } )
341+ . collect :: < Vec < _ > > ( )
342+ } )
343+ }
308344 }
309345 } ;
310346
0 commit comments