@@ -344,13 +344,15 @@ export class IdentityClient {
344344 badgeIconURL = 'XUUV39HVPkpmMzYNTx7rpKzJvXfeiVyQWg2vfSpjBAuhunTCA9uG'
345345 badgeClickURL = 'https://projectbabbage.com/docs/self-identity' // TODO: Make this doc page exist
346346 break
347- default :
348- name = defaultIdentity . name
349- avatarURL = decryptedFields . profilePhoto
350- badgeLabel = defaultIdentity . badgeLabel
351- badgeIconURL = defaultIdentity . badgeIconURL
352- badgeClickURL = defaultIdentity . badgeClickURL // TODO: Make this doc page exist
347+ default : {
348+ const parsed = IdentityClient . tryToParseGenericIdentity ( type , decryptedFields , certifierInfo )
349+ name = parsed . name
350+ avatarURL = parsed . avatarURL
351+ badgeLabel = parsed . badgeLabel
352+ badgeIconURL = parsed . badgeIconURL
353+ badgeClickURL = parsed . badgeClickURL
353354 break
355+ }
354356 }
355357
356358 return {
@@ -363,4 +365,59 @@ export class IdentityClient {
363365 badgeClickURL
364366 }
365367 }
368+
369+ /**
370+ * Helper to check if a value is a non-empty string
371+ */
372+ private static hasValue ( value : any ) : value is string {
373+ return value !== undefined && value !== null && value !== ''
374+ }
375+
376+ /**
377+ * Try to parse identity information from unknown certificate types
378+ * by checking common field names
379+ */
380+ private static tryToParseGenericIdentity (
381+ type : string ,
382+ decryptedFields : Record < string , any > ,
383+ certifierInfo : any
384+ ) : { name : string , avatarURL : string , badgeLabel : string , badgeIconURL : string , badgeClickURL : string } {
385+ // Try to construct a name from common field patterns
386+ const firstName = decryptedFields . firstName
387+ const lastName = decryptedFields . lastName
388+ const fullName = IdentityClient . hasValue ( firstName ) && IdentityClient . hasValue ( lastName )
389+ ? `${ firstName } ${ lastName } `
390+ : IdentityClient . hasValue ( firstName )
391+ ? firstName
392+ : IdentityClient . hasValue ( lastName )
393+ ? lastName
394+ : undefined
395+
396+ const name = IdentityClient . hasValue ( decryptedFields . name )
397+ ? decryptedFields . name
398+ : IdentityClient . hasValue ( decryptedFields . userName )
399+ ? decryptedFields . userName
400+ : fullName ?? ( IdentityClient . hasValue ( decryptedFields . email ) ? decryptedFields . email : defaultIdentity . name )
401+
402+ // Try to find an avatar/photo from common field names
403+ const avatarURL = IdentityClient . hasValue ( decryptedFields . profilePhoto )
404+ ? decryptedFields . profilePhoto
405+ : IdentityClient . hasValue ( decryptedFields . avatar )
406+ ? decryptedFields . avatar
407+ : IdentityClient . hasValue ( decryptedFields . icon )
408+ ? decryptedFields . icon
409+ : IdentityClient . hasValue ( decryptedFields . photo )
410+ ? decryptedFields . photo
411+ : defaultIdentity . avatarURL
412+
413+ // Generate badge information
414+ const badgeLabel = IdentityClient . hasValue ( certifierInfo ?. name )
415+ ? `${ type } certified by ${ String ( certifierInfo . name ) } `
416+ : defaultIdentity . badgeLabel
417+
418+ const badgeIconURL = IdentityClient . hasValue ( certifierInfo ?. iconUrl ) ? certifierInfo . iconUrl : defaultIdentity . badgeIconURL
419+ const badgeClickURL = defaultIdentity . badgeClickURL
420+
421+ return { name, avatarURL, badgeLabel, badgeIconURL, badgeClickURL }
422+ }
366423}
0 commit comments