Verify Presentation
Using the verifiable credentials library to verify verifiable presentations signed as JWT (JWT-VPs).
We will be using the verifyPresentation()
function on the Verifier
class. The function can be configured to apply
verification policies, you can find here, to the verifiable presentation, all credentials in the presentation or specific
credentials as shown in the example below.
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.
Kotlin
import id.walt.credentials.verification.Verifier
import id.walt.credentials.verification.models.PolicyRequest
import id.walt.credentials.verification.policies.ExpirationDatePolicy
import id.walt.credentials.verification.policies.JwtSignaturePolicy
import id.walt.credentials.verification.policies.vp.HolderBindingPolicy
import id.walt.did.dids.DidService
suspend fun main() {
// Initialise DID Service to be able to resolve DIDs
DidService.minimalInit()
val verifier = Verifier
// JWT of the presentation to verify
val presentationJwt = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDprZXk6ejZNa2hmcGNjV2JaS1J1cUZ2RkxwWmh5ZUI0WVl0VjhiSnkzN2pMNmlpRTdOZjdiI3o2TWtoZnBjY1diWktSdXFGdkZMcFpoeWVCNFlZdFY4Ykp5MzdqTDZpaUU3TmY3YiJ9.eyJzdWIiOiJkaWQ6a2V5Ono2TWtoZnBjY1diWktSdXFGdkZMcFpoeWVCNFlZdFY4Ykp5MzdqTDZpaUU3TmY3YiIsIm5iZiI6MTcwNTUwMzE2NCwiaWF0IjoxNzA1NTAzMjI0LCJqdGkiOiJ1cm46dXVpZDo5YWI2YTMzNi03MTFlLTQwMWEtOWQ3NS1mMGNkM2EzMWFkMTAiLCJpc3MiOiJkaWQ6a2V5Ono2TWtoZnBjY1diWktSdXFGdkZMcFpoeWVCNFlZdFY4Ykp5MzdqTDZpaUU3TmY3YiIsIm5vbmNlIjoiMjAzOTQwMjkzNDAiLCJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXS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VzUwWlhKdmNHVnlZV0pwYkdsMGVTSjlmUS5BS1RsUW5INUZUb3EyZ0hHdGxoc1NscHp6TGZfdU12ZmhxbV80OWhsMTBpN0N3MnBOWkhJYjMyTi1QV2lWOFVTcmVZZmJ2MklkTC1NcGFLWF9IekNDdyJdfX0.U0MEUTd6OfCXXO3PPMnywpytEQoeCuPqkqJ2fhBQlPr0SPVAM7R9_SiFr54urKknD73YSWlZ_73gfxE0zNnxAA"
// Policies that should be applied to Verifiable Presentation.
val vpPolicies = listOf(
PolicyRequest(HolderBindingPolicy())
// other policies ...
)
// Global policies that are applied to ALL verifiable credentials in the Verifiable Presentation.
val globalVcPolicies = listOf(
PolicyRequest(JwtSignaturePolicy())
// other policies ...
)
// Specify policies for specific credential types.
val specificCredentialPolicies = mapOf(
"OpenBadgeCredential" to listOf(PolicyRequest(ExpirationDatePolicy()))
// other policies ...
)
// Context is optional and it's an empty map by default.
val presentationContext = mapOf<String, Any>()
// Verify the presentation
val result = verifier.verifyPresentation(
presentationJwt,
vpPolicies,
globalVcPolicies,
specificCredentialPolicies,
presentationContext
)
println(result.overallSuccess())
}
Arguments:
- vpTokenJwt: Provide the full VP Token
- vpPolicies: Provide the policies you'd like to run over the full VP (execute once with the VP as argument)
- globalVcPolicies: Provide the policies you'd like to run for every VC (executed for every VC in the VP)
- specificCredentialPolicies: Provide a mapping of a credential Type to a list of policies to run on the specific credential type
- A specific type mapping executes the list of policies mapped for the specific type for every VC in the VP that has that specific type
- presentationContext: Optionally provide context to the verification policies, e.g.
presentationDefinition
for the PresentationDefinitionPolicy,challenge
to compare the required nonce, etc.