Skip to content

Commit

Permalink
Merge pull request #780 from walt-id/wal-203-verification-policies-fo…
Browse files Browse the repository at this point in the history
…r-non-w3c

Wal 203 verification policies for non w3c
  • Loading branch information
severinstampler authored Oct 1, 2024
2 parents f076e0c + 58f08b3 commit 0e2cda1
Show file tree
Hide file tree
Showing 81 changed files with 715 additions and 349 deletions.
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ val modules = listOf(
* "$libraries:credentials".group(
"waltid-verifiable-credentials",
"waltid-mdoc-credentials",
"waltid-dif-definitions-parser"
"waltid-dif-definitions-parser",
"waltid-verification-policies"
),

* "$libraries:protocols".group(
Expand Down
1 change: 1 addition & 0 deletions waltid-applications/waltid-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ kotlin {
api(project(":waltid-libraries:crypto:waltid-crypto"))
api(project(":waltid-libraries:waltid-did"))
api(project(":waltid-libraries:credentials:waltid-verifiable-credentials"))
api(project(":waltid-libraries:credentials:waltid-verification-policies"))
api(project(":waltid-libraries:sdjwt:waltid-sdjwt"))
api(project(":waltid-libraries:protocols:waltid-openid4vc"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import com.github.ajalt.clikt.parameters.types.file
import id.walt.cli.util.PrettyPrinter
import id.walt.cli.util.VCUtil
import id.walt.cli.util.WaltIdCmdHelpOptionMessage
import id.walt.credentials.verification.ExpirationDatePolicyException
import id.walt.credentials.verification.JsonSchemaVerificationException
import id.walt.credentials.verification.NotBeforePolicyException
import id.walt.credentials.verification.models.PolicyResult
import id.walt.policies.ExpirationDatePolicyException
import id.walt.policies.JsonSchemaVerificationException
import id.walt.policies.NotBeforePolicyException
import id.walt.policies.models.PolicyResult
import id.walt.crypto.utils.JsonUtils.toJsonElement
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -102,7 +102,7 @@ class VCVerifyCmd : CliktCommand(
private fun handleFailure(it: PolicyResult) {
when (val exception = it.result.exceptionOrNull()) {

is JsonSchemaVerificationException -> {
is id.walt.policies.JsonSchemaVerificationException -> {
exception.validationErrors.forEach { err ->
print.dim("${it.request.policy.name}: ", false)
print.red("Fail! ", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import com.github.ajalt.clikt.parameters.types.path
import id.walt.cli.util.JsonUtils.toJsonPrimitive
import id.walt.cli.util.PrettyPrinter
import id.walt.cli.util.WaltIdCmdHelpOptionMessage
import id.walt.credentials.verification.*
import id.walt.credentials.verification.models.PolicyRequest
import id.walt.credentials.verification.models.PolicyResult
import id.walt.credentials.verification.models.PresentationVerificationResponse
import id.walt.policies.models.PolicyRequest
import id.walt.policies.models.PolicyResult
import id.walt.policies.models.PresentationVerificationResponse
import id.walt.crypto.utils.JsonUtils.toJsonElement
import id.walt.did.dids.DidService
import id.walt.oid4vc.data.dif.PresentationDefinition
import id.walt.oid4vc.data.dif.PresentationSubmission
import id.walt.policies.ExpirationDatePolicyException
import id.walt.policies.NotBeforePolicyException
import id.walt.policies.PolicyManager
import id.walt.policies.Verifier
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
Expand Down Expand Up @@ -263,8 +266,10 @@ class VPVerifyCmd : CliktCommand(
private fun verify(params: VpVerifyParameters): PresentationVerificationResponse {
try {
return runBlocking {
val presentationFormat = params.presentationSubmission.descriptorMap.firstOrNull()?.format ?: throw IllegalArgumentException("No presentation submission or presentation format found.")
Verifier.verifyPresentation(
vpTokenJwt = params.vp,
presentationFormat,
vpToken = params.vp,
vpPolicies = params.vpPolicyRequests,
globalVcPolicies = params.globalVcPolicyRequests,
specificCredentialPolicies = emptyMap(),
Expand Down Expand Up @@ -296,7 +301,7 @@ class VPVerifyCmd : CliktCommand(
private fun handleFailure(it: PolicyResult) {
when (val exception = it.result.exceptionOrNull()) {

is JsonSchemaVerificationException -> {
is id.walt.policies.JsonSchemaVerificationException -> {
exception.validationErrors.forEach { err ->
print.dim("${it.request.policy.name}: ", false)
print.red("Fail! ", false)
Expand Down Expand Up @@ -336,4 +341,4 @@ class VPVerifyCmd : CliktCommand(
print.dim("${it.request.policy.name}: ", false)
print.green("Success!", linebreak = true)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package id.walt.cli.presexch

import id.walt.cli.models.Credential
import id.walt.credentials.utils.VCFormat
import id.walt.crypto.utils.JwsUtils.decodeJws
import id.walt.oid4vc.data.dif.*
import kotlinx.serialization.json.*
Expand Down Expand Up @@ -51,4 +52,4 @@ class PresentationSubmissionBuilder(
presentationDefinition?.inputDescriptors?.find {
(it.name ?: it.id) == type
}?.id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package id.walt.cli.util

import id.walt.credentials.issuance.Issuer.mergingJwtIssue
import id.walt.credentials.vc.vcs.W3CVC
import id.walt.credentials.verification.PolicyManager
import id.walt.credentials.verification.Verifier
import id.walt.credentials.verification.models.PolicyRequest
import id.walt.credentials.verification.models.PolicyResult
import id.walt.policies.PolicyManager
import id.walt.policies.Verifier
import id.walt.policies.models.PolicyRequest
import id.walt.policies.models.PolicyResult
import id.walt.crypto.keys.jwk.JWKKey
import id.walt.did.dids.DidService
import kotlinx.coroutines.runBlocking
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package id.walt.cli.verifiers

import id.walt.credentials.verification.ExpirationDatePolicyException
import id.walt.credentials.verification.PolicyManager
import id.walt.credentials.verification.Verifier
import id.walt.credentials.verification.models.PolicyRequest
import id.walt.credentials.verification.policies.ExpirationDatePolicy
import id.walt.policies.ExpirationDatePolicyException
import id.walt.policies.PolicyManager
import id.walt.policies.Verifier
import id.walt.policies.models.PolicyRequest
import id.walt.policies.policies.ExpirationDatePolicy
import id.walt.crypto.utils.JwsUtils.decodeJws
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package id.walt.credentials.utils

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class VCFormat(val value: String) {
jwt("jwt"),
jwt_vc("jwt_vc"),
jwt_vp("jwt_vp"),
ldp_vc("ldp_vc"),
ldp_vp("ldp_vp"),
ldp("ldp"),
jwt_vc_json("jwt_vc_json"),
jwt_vp_json("jwt_vp_json"),
mso_mdoc("mso_mdoc"),
@SerialName("vc+sd-jwt") sd_jwt_vc("vc+sd-jwt")
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import love.forte.plugin.suspendtrans.ClassInfo
import love.forte.plugin.suspendtrans.SuspendTransformConfiguration
import love.forte.plugin.suspendtrans.TargetPlatform
import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants
import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("maven-publish")
id("dev.petuska.npm.publish") version "3.4.3"
id("love.forte.plugin.suspend-transform") version "2.0.20-0.9.2"
id("com.github.ben-manes.versions")
}

group = "id.walt.policies"

repositories {
mavenCentral()
}

suspendTransform {
enabled = true
includeRuntime = true
useDefault()

includeAnnotation = false // Required in the current version to avoid "compileOnly" warning
}

kotlin {
jvmToolchain(17)

jvm {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget = JvmTarget.JVM_17
}
withJava()
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
}

js(IR) {
moduleName = "verification-policies"
nodejs {
generateTypeScriptDefinitions()
}
binaries.library()
}
val ktor_version = "2.3.12"
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.eygraber:jsonpathkt-kotlinx:3.0.2")
// JSON
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("io.github.optimumcode:json-schema-validator:0.2.2")

implementation(project(":waltid-libraries:credentials:waltid-verifiable-credentials"))
implementation(project(":waltid-libraries:sdjwt:waltid-sdjwt"))

// Kotlinx
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0")

// Ktor client
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("io.ktor:ktor-client-json:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")

// Loggin
implementation("io.github.oshai:kotlin-logging:7.0.0")

// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")

// suspend-transform plugin annotations (required in the current version to avoid "compileOnly" warning)
implementation("${SuspendTransPluginConstants.ANNOTATION_GROUP}:${SuspendTransPluginConstants.ANNOTATION_NAME}:${SuspendTransPluginConstants.ANNOTATION_VERSION}")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
}
}
val jvmTest by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("org.slf4j:slf4j-simple:2.0.13")
implementation("org.junit.jupiter:junit-jupiter-params:5.11.0-M2")
}
}
}
}

extensions.getByType<SuspendTransformGradleExtension>().apply {
transformers[TargetPlatform.JS] = mutableListOf(
SuspendTransformConfiguration.jsPromiseTransformer.copy(
copyAnnotationExcludes = listOf(
ClassInfo("kotlin.js", "JsExport.Ignore")
)
)
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package id.walt.credentials.verification
package id.walt.policies

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package id.walt.credentials.verification
package id.walt.policies

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package id.walt.credentials.verification
package id.walt.policies

import id.walt.credentials.Claims
import kotlinx.datetime.Instant
Expand Down Expand Up @@ -30,4 +30,4 @@ object DatePolicyUtils {

private fun epochInstantConverter(value: String) = value.toLongOrNull()?.let { Instant.fromEpochSeconds(it) }
?: throw IllegalArgumentException("Couldn't parse epoch seconds from: $value")
}
}
Loading

0 comments on commit 0e2cda1

Please sign in to comment.