@@ -62,30 +62,41 @@ worldId.post('/verify', authMiddleware(), async (c) => {
6262 return c . json ( { error : 'World ID not configured' } , 500 ) ;
6363 }
6464
65+ // Log incoming payload for debugging
66+ console . log ( 'World ID verify incoming payload:' , JSON . stringify ( body ) . slice ( 0 , 2000 ) ) ;
67+
6568 // Forward IDKit result to World ID v4 verify API
66- const verifyRes = await fetch (
67- `https://developer.worldcoin.org/api/v4/verify/${ RP_ID } ` ,
68- {
69- method : 'POST' ,
70- headers : { 'Content-Type' : 'application/json' } ,
71- body : JSON . stringify ( body ) ,
72- } ,
73- ) ;
69+ const verifyUrl = `https://developer.worldcoin.org/api/v4/verify/${ RP_ID } ` ;
70+ console . log ( 'Forwarding to:' , verifyUrl ) ;
71+
72+ const verifyRes = await fetch ( verifyUrl , {
73+ method : 'POST' ,
74+ headers : { 'Content-Type' : 'application/json' } ,
75+ body : JSON . stringify ( body ) ,
76+ } ) ;
77+
78+ const responseText = await verifyRes . text ( ) ;
79+ console . log ( 'World ID response:' , verifyRes . status , responseText . slice ( 0 , 2000 ) ) ;
7480
7581 if ( ! verifyRes . ok ) {
76- const err = await verifyRes . text ( ) ;
77- console . error ( 'World ID v4 verify failed:' , verifyRes . status , err ) ;
7882 let parsed : any = { } ;
79- try { parsed = JSON . parse ( err ) ; } catch ( _ ) { }
83+ try { parsed = JSON . parse ( responseText ) ; } catch ( _ ) { }
8084 return c . json ( {
8185 error : 'World ID verification failed' ,
82- detail : parsed . detail || parsed . message || err . slice ( 0 , 500 ) ,
86+ detail : parsed . detail || parsed . message || responseText . slice ( 0 , 500 ) ,
8387 code : parsed . code ,
8488 world_id_status : verifyRes . status ,
89+ // Debug: include truncated payload info
90+ _debug_payload_keys : Object . keys ( body ) ,
91+ _debug_protocol : body . protocol_version ,
92+ _debug_responses_count : body . responses ?. length ,
8593 } , 400 ) ;
8694 }
8795
88- const verifyData = await verifyRes . json < any > ( ) ;
96+ let verifyData : any ;
97+ try { verifyData = JSON . parse ( responseText ) ; } catch ( _ ) {
98+ return c . json ( { error : 'Invalid JSON from World ID API' , raw : responseText . slice ( 0 , 500 ) } , 500 ) ;
99+ }
89100
90101 // Extract nullifier from response
91102 // v3 legacy: responses[0].nullifier
@@ -187,4 +198,35 @@ worldId.delete('/verify', authMiddleware(), async (c) => {
187198 return c . json ( { ok : true , message : 'World ID verification removed' } ) ;
188199} ) ;
189200
201+ /**
202+ * GET /api/world-id/debug
203+ * Temporary: test World ID v4 API connectivity
204+ */
205+ worldId . get ( '/debug' , async ( c ) => {
206+ const RP_ID = c . env . WORLD_ID_RP_ID ;
207+ const HAS_SIGNING_KEY = ! ! c . env . WORLD_ID_SIGNING_KEY ;
208+
209+ // Test connectivity to World ID API
210+ let apiTest = 'untested' ;
211+ try {
212+ const res = await fetch ( `https://developer.worldcoin.org/api/v4/verify/${ RP_ID } ` , {
213+ method : 'POST' ,
214+ headers : { 'Content-Type' : 'application/json' } ,
215+ body : JSON . stringify ( { protocol_version : '3.0' , nonce : 'test' , action : 'verify-human' , responses : [ ] } ) ,
216+ } ) ;
217+ const text = await res . text ( ) ;
218+ apiTest = `${ res . status } : ${ text . slice ( 0 , 300 ) } ` ;
219+ } catch ( e : any ) {
220+ apiTest = `Error: ${ e . message } ` ;
221+ }
222+
223+ return c . json ( {
224+ rp_id : RP_ID ,
225+ has_signing_key : HAS_SIGNING_KEY ,
226+ app_id : c . env . WORLD_ID_APP_ID ,
227+ action : c . env . WORLD_ID_ACTION ,
228+ api_test : apiTest ,
229+ } ) ;
230+ } ) ;
231+
190232export { worldId as worldIdRoutes } ;
0 commit comments