Verify Credential

To verify a W3C credential we will be using the verifiable credentials library.

By using the verifyCredential function on the Verifier class we can provide a credential signed as JWT and apply a list of policies on it to verify the credential. You can find all available policies here.

We also need to initialise the DID service so that the Verifier class can resolve the DID present in the to be verified credential. Learn more about DIDs and how they can be managed here.

Example

import id.walt.credentials.verification.Verifier
import id.walt.credentials.verification.models.PolicyRequest
import id.walt.credentials.verification.policies.JwtSignaturePolicy
import id.walt.did.dids.DidService

suspend fun main() {
    // Initialise DID Service to be able to resolve DIDs 
    DidService.minimalInit()

    // W3C JWT Credential
    val signedCredential: String = "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3B5ZWYxdXpidnc2RzY2N1hhc3ZvQXR3UUJjb3Rlcm9SNXBWZGVhcEo4c2tDIn0.eyJpc3MiOiJkaWQ6a2V5Ono2TWtweWVmMXV6YnZ3Nkc2NjdYYXN2b0F0d1FCY290ZXJvUjVwVmRlYXBKOHNrQyIsInN1YiI6ImRpZDprZXk6ejZNa2V4ZzdHVVluMXpaSEtFUm5vUlBqWjM2YVVQdkFqb3g2MW1Vcmljelh6MmJNIiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiLCJodHRwczovL3B1cmwuaW1zZ2xvYmFsLm9yZy9zcGVjL29iL3YzcDAvY29udGV4dC0zLjAuMi5qc29uIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJPcGVuQmFkZ2VDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InR5cGUiOlsiQWNoaWV2ZW1lbnRTdWJqZWN0Il0sImFjaGlldmVtZW50Ijp7ImlkIjoidXJuOnV1aWQ6YWMyNTRiZDUtOGZhZC00YmIxLTlkMjktZWZkOTM4NTM2OTI2IiwidHlwZSI6WyJBY2hpZXZlbWVudCJdLCJuYW1lIjoiSkZGIHggdmMtZWR1IFBsdWdGZXN0IDMgSW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wiaWQiOiJkaWQ6a2V5Ono2TWtzRm5heDZ4Q0JXZG82aGhmWjdwRXNieWFxOU1NTmRtQUJTMU5yY0NEWkpyMyJ9LCJpZCI6InVybjp1dWlkOjQxNzdlMDQ4LTlhNGEtNDc0ZS05ZGM2LWFlZDRlNjFhNjQzOSIsImlzc3VlciI6ImRpZDprZXk6ejZNa3NGbmF4NnhDQldkbzZoaGZaN3BFc2J5YXE5TU1OZG1BQlMxTnJjQ0RaSnIzIiwiaXNzdWFuY2VEYXRlIjoiMjAyNC0wMS0xN1QxMzo1OToyNS44MjM4NzZaIiwiZXhwaXJhdGlvbkRhdGUiOiIyMDI0LTAxLTE5VDEzOjU5OjI1LjgyNDQ0MloiLCJuYW1lIjoiSkZGIHggdmMtZWR1IFBsdWdGZXN0IDMgSW50ZXJvcGVyYWJpbGl0eSJ9fQ.GXkviEo6ma3YnRjmoPVM1v_hsvMJoOf4TU8MDDmPxnXwBogBsE11vs1pNjZ0Mx8EcqoYo5INYp_uoNcsY2sZDw"

    /// Verify the JWT Credential:
    val results = Verifier.verifyCredential(
            signedCredential,
            listOf(
                    PolicyRequest(JwtSignaturePolicy())
                    // other policies ...
            )
    )

    results.forEach { verification ->
        println("[${verification.request.policy.name}] -> Success=${verification.isSuccess()}, Result=${verification.result}")
    }
}