Think of a verification request like asking someone for their ID.
You want to confirm a specific credential of theirs, say, their email address. You send a request to the issuer of the credential (the one who "issued their ID"). The issuer can either give a thumbs-up (approve) or thumbs-down (reject).
letemailDTO=DataObject.Builder().withData("bob@test.com".data(using:.utf8)).withContentType("text/plain").build()letcodeDTO=DataObject.Builder().withData("123456".data(using:.utf8)).withContentType("text/plain").build()letproofs=[Constants.SUBJECT_EMAIL:emailDTO,Constants.SUBJECT_SECURITY_CODE:codeDTO,]letverificationRequest=VerificationRequest.Builder().withTypes([CredentialType.Email]).withProofs(proofs).build()// send the requestTask(priority:.background,operation:{tryawaitself.account.send(message:verificationRequest,onAcknowledgement:{requestId,errorinprint("sent verification request: \(requestId) with error: \(error)")})})
casemessage.TypeCredentialVerificationResponse:response,err:=message.DecodeCredentialVerificationResponse(msg)iferr!=nil{// handle error}// Check the statuslog.Info("Response received with status","status",response.Status())// Validate each credentialfor_,c:=rangeresponse.Credentials(){err=c.Validate()iferr!=nil{// handle errorcontinue}claims,err:=c.CredentialSubjectClaims()iferr!=nil{// handle errorcontinue}// Access specific claimsprintln(claims["email"])}
ContentType.CREDENTIAL_VERIFICATION_RESPONSE->{valresponse=CredentialVerificationResponse.decode(content)println("Response received with status: ${response.status().name}")// Validate each credentialresponse.credentials().forEach{credential->try{credential.validate()valclaims=credential.credentialSubjectClaims()// Access specific claimsprintln("Email: ${claims["email"]}")}catch(ex:Exception){println("Failed to validate credential: ${ex.message}")}}}
account.setOnResponseListener{msg->when(msg){isVerificationResponse->{println("Response received with status:${msg.status().name}")msg.credentials().forEach{credential->println("credential types: ${credential.types()}")credential.claims().forEach{claim->println("email value ${claim.value()}")}}}}}
account.setOnResponseListener{messageinprint("setOnResponseListener: \(message)")switchmessage{caseisVerificationResponse:letresponse=messageas!VerificationResponseprint("Handle verification response: \(response)")default:print("TODO: Handle For other response: \(message)")break;}}