From b0542642ce2df796ca3c9a32b21a7d4b69951edb Mon Sep 17 00:00:00 2001 From: Matej Feder Date: Fri, 26 Nov 2021 16:57:13 +0100 Subject: [PATCH 1/3] Add GaiaxSD template Signed-off-by: Matej Feder --- build.gradle.kts | 2 +- .../kotlin/id/walt/auditor/PolicyRegistry.kt | 1 + .../id/walt/auditor/VerificationPolicy.kt | 8 +++++ .../id/walt/signatory/CLIDataProvider.kt | 29 +++++++++++++++++++ .../walt/signatory/SignatoryDataProvider.kt | 14 +++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 466dc4e1..92559954 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,7 +40,7 @@ dependencies { implementation("com.google.guava:guava:31.0.1-jre") // VC - implementation("id.walt:waltid-ssikit-vclib:1.5-SNAPSHOT") + implementation("id.walt:waltid-ssikit-vclib:1.6-SNAPSHOT") // JSON implementation("org.json:json:20210307") diff --git a/src/main/kotlin/id/walt/auditor/PolicyRegistry.kt b/src/main/kotlin/id/walt/auditor/PolicyRegistry.kt index dd7ff1be..4198bb20 100644 --- a/src/main/kotlin/id/walt/auditor/PolicyRegistry.kt +++ b/src/main/kotlin/id/walt/auditor/PolicyRegistry.kt @@ -22,5 +22,6 @@ object PolicyRegistry { register(ValidFromBeforePolicy()) register(ExpirationDateAfterPolicy()) register(GaiaxTrustedPolicy()) + register(GaiaxSDPolicy()) } } diff --git a/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt b/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt index 67ca91dd..18a794a9 100644 --- a/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt +++ b/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt @@ -11,6 +11,7 @@ import id.walt.vclib.Helpers.encode import id.walt.vclib.VcUtils import id.walt.vclib.credentials.GaiaxCredential import id.walt.vclib.credentials.VerifiablePresentation +import id.walt.vclib.credentials.GaiaxSD import id.walt.vclib.model.VerifiableCredential import id.walt.vclib.schema.SchemaService import kotlinx.serialization.Serializable @@ -200,6 +201,13 @@ class GaiaxTrustedPolicy : VerificationPolicy { } } +class GaiaxSDPolicy : VerificationPolicy { + override val description: String = "Verify Gaiax SD fields" + override fun verify(vc: VerifiableCredential): Boolean { + return true + } +} + private fun parseDate(date: String?) = try { dateFormatter.parse(date) } catch (e: Exception) { diff --git a/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt b/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt index 7532a219..dbdd373b 100644 --- a/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt +++ b/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt @@ -1,6 +1,7 @@ package id.walt.signatory import id.walt.vclib.model.VerifiableCredential +import id.walt.vclib.credentials.GaiaxSD import id.walt.vclib.credentials.GaiaxCredential import id.walt.vclib.credentials.VerifiableDiploma import id.walt.vclib.credentials.VerifiableId @@ -12,6 +13,7 @@ object CLIDataProviders { "VerifiableDiploma" -> VerifiableDiplomaCLIDataProvider() "VerifiableId" -> VerifiableIDCLIDataProvider() "GaiaxCredential" -> GaiaxCLIDataProvider() + "GaiaxSD" -> GaiaxSDProvider() else -> null } } @@ -183,6 +185,33 @@ class GaiaxCLIDataProvider : CLIDataProvider() { } } + +class GaiaxSDProvider : CLIDataProvider() { + override fun populate(template: VerifiableCredential, proofConfig: ProofConfig): VerifiableCredential { + (template as GaiaxSD).apply { + println() + println("> Subject information") + println() + issuer = proofConfig.issuerDid + credentialSubject.apply { + if (proofConfig.subjectDid != null) id = proofConfig.subjectDid + type = prompt("Type", "Service") ?: "" + hasName = prompt("Name", "AIS") ?: "" + description = prompt("Description", "AIS demonstrates machine learning application use case.") ?:"" + hasVersion = prompt("Version", "0.1.0") ?: "" + providedBy = prompt("Provided by", "GAIA-X") ?: "" + hasMarketingImage = prompt("Marketing Image", "https://www.data-infrastructure.eu/GAIAX/Redaktion/EN/Bilder/UseCases/ai-marketplace-for-product-development.jpg?__blob=normal") ?: "" + hasCertifications = listOf(prompt("Certifications", hasCertifications?.get(0)) ?: "") + utilizes = listOf(prompt("Utilizes", utilizes?.get(0)) ?: "") + dependsOn = listOf(prompt("Depends on", dependsOn?.get(0)) ?: "") + } + } + + return template + } +} + + class VerifiableIDCLIDataProvider : CLIDataProvider() { override fun populate(template : VerifiableCredential, proofConfig: ProofConfig): VerifiableCredential { template as VerifiableId diff --git a/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt b/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt index 4c0c93cb..5a8b2e66 100644 --- a/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt +++ b/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt @@ -32,6 +32,7 @@ object DataProviderRegistry { register(VerifiableId::class, VerifiableIdDataProvider()) register(Europass::class, EuropassDataProvider()) register(GaiaxCredential::class, DeltaDaoDataProvider()) + register(GaiaxSD::class, SdDataProvider()) register(PermanentResidentCard::class, PermanentResidentCardDataProvider()) } } @@ -118,6 +119,19 @@ class NoSuchDataProviderException(credentialType: KClass Date: Tue, 30 Nov 2021 08:51:10 +0100 Subject: [PATCH 2/3] Updated docs for issuing credentials --- .../id/walt/signatory/rest/SignatoryController.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/id/walt/signatory/rest/SignatoryController.kt b/src/main/kotlin/id/walt/signatory/rest/SignatoryController.kt index 64890fb1..5739c911 100644 --- a/src/main/kotlin/id/walt/signatory/rest/SignatoryController.kt +++ b/src/main/kotlin/id/walt/signatory/rest/SignatoryController.kt @@ -39,6 +39,17 @@ object SignatoryController { } fun issueCredentialDocs() = document().operation { - it.summary("Issue a credential").operationId("issue").addTagsItem("Credentials") + it.summary("Issue a credential").operationId("issue").addTagsItem("Credentials").description("Based on a template (maintained in the VcLib), this call creates a W3C Verifiable Credential. Note that the 'templateId, issuerDid, and the subjectDid, are mandatory parameters. All other parameters are optional.

This is a example request, that also demonstrates how to populate the credential with custom data: the

{
" + + " \"templateId\": \"VerifiableId\",
" + + " \"config\": {
" + + "      \"issuerDid\": \"did:ebsi:zuathxHtXTV8psijTjtuZD7\",
" + + "      \"subjectDid\": \"did:key:z6MkwfgBDSMRqXaJtw5DjhkJdDsDmRNSrvrM1L6UMBDtvaSX\"
" + + "      },
" + + " \"credentialData\": {
" + + "      \"credentialSubject\": {
" + + "          \"firstName\": \"Severin\"
" + + "          }
" + + "      }
" + + "}
") }.body().json("200") } From 2c42b356d3d7deaa5d9fdfdd403355bcc46cb124 Mon Sep 17 00:00:00 2001 From: Philipp Potisk Date: Tue, 30 Nov 2021 19:22:07 +0100 Subject: [PATCH 3/3] Included GaiaxSelfDescription cred --- CHANGELOG.md | 3 +++ src/main/kotlin/id/walt/auditor/VerificationPolicy.kt | 11 +++++------ src/main/kotlin/id/walt/signatory/CLIDataProvider.kt | 6 +++--- .../kotlin/id/walt/signatory/SignatoryDataProvider.kt | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8e38f14..3734331c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Notable changes since the last release of the [SSI Kit](https://github.com/walt- ## [Unreleased] +- Features + - Added GaiaxSelfDecription credential https://github.com/dNationCloud/waltid-ssikit/pull/1 thx to https://github.com/dNationCloud & https://github.com/matofeder + ## [1.1.0] - 2021-11-25 - Features diff --git a/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt b/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt index 18a794a9..590d2837 100644 --- a/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt +++ b/src/main/kotlin/id/walt/auditor/VerificationPolicy.kt @@ -11,7 +11,6 @@ import id.walt.vclib.Helpers.encode import id.walt.vclib.VcUtils import id.walt.vclib.credentials.GaiaxCredential import id.walt.vclib.credentials.VerifiablePresentation -import id.walt.vclib.credentials.GaiaxSD import id.walt.vclib.model.VerifiableCredential import id.walt.vclib.schema.SchemaService import kotlinx.serialization.Serializable @@ -69,11 +68,11 @@ class JsonSchemaPolicy : VerificationPolicy { override fun verify(vc: VerifiableCredential): Boolean { SchemaService.validateSchema(vc.json!!).apply { - if(valid) + if (valid) return true log.error { "Credential not valid according the json-schema of type ${vc.type}. The validation errors are:" } - errors?.forEach{ error -> log.error { error }} + errors?.forEach { error -> log.error { error } } } return false } @@ -128,7 +127,7 @@ class TrustedIssuerRegistryPolicy : VerificationPolicy { private fun isValidTrustedIssuerRecord(tirRecord: TrustedIssuer): Boolean { for (attribute in tirRecord.attributes) { val attributeInfo = AttributeInfo.from(attribute.body) - if(TIR_TYPE_ATTRIBUTE.equals(attributeInfo?.type) && TIR_NAME_ISSUER.equals(attributeInfo?.name)) { + if (TIR_TYPE_ATTRIBUTE.equals(attributeInfo?.type) && TIR_NAME_ISSUER.equals(attributeInfo?.name)) { return true } } @@ -187,12 +186,12 @@ class GaiaxTrustedPolicy : VerificationPolicy { val gaiaxVc = vc as GaiaxCredential // TODO: validate trusted fields properly - if (gaiaxVc.credentialSubject.DNSpublicKey.length < 0) { + if (gaiaxVc.credentialSubject.DNSpublicKey.length < 1) { log.debug { "DNS Public key not valid." } return false } - if (gaiaxVc.credentialSubject.ethereumAddress.id.length < 0) { + if (gaiaxVc.credentialSubject.ethereumAddress.id.length < 1) { log.debug { "ETH address not valid." } return false } diff --git a/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt b/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt index dbdd373b..414eff01 100644 --- a/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt +++ b/src/main/kotlin/id/walt/signatory/CLIDataProvider.kt @@ -1,7 +1,7 @@ package id.walt.signatory import id.walt.vclib.model.VerifiableCredential -import id.walt.vclib.credentials.GaiaxSD +import id.walt.vclib.credentials.GaiaxSelfDescription import id.walt.vclib.credentials.GaiaxCredential import id.walt.vclib.credentials.VerifiableDiploma import id.walt.vclib.credentials.VerifiableId @@ -13,7 +13,7 @@ object CLIDataProviders { "VerifiableDiploma" -> VerifiableDiplomaCLIDataProvider() "VerifiableId" -> VerifiableIDCLIDataProvider() "GaiaxCredential" -> GaiaxCLIDataProvider() - "GaiaxSD" -> GaiaxSDProvider() + "GaiaxSelfDescription" -> GaiaxSDProvider() else -> null } } @@ -188,7 +188,7 @@ class GaiaxCLIDataProvider : CLIDataProvider() { class GaiaxSDProvider : CLIDataProvider() { override fun populate(template: VerifiableCredential, proofConfig: ProofConfig): VerifiableCredential { - (template as GaiaxSD).apply { + (template as GaiaxSelfDescription).apply { println() println("> Subject information") println() diff --git a/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt b/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt index 5a8b2e66..a65a9dfa 100644 --- a/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt +++ b/src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt @@ -32,7 +32,7 @@ object DataProviderRegistry { register(VerifiableId::class, VerifiableIdDataProvider()) register(Europass::class, EuropassDataProvider()) register(GaiaxCredential::class, DeltaDaoDataProvider()) - register(GaiaxSD::class, SdDataProvider()) + register(GaiaxSelfDescription::class, SdDataProvider()) register(PermanentResidentCard::class, PermanentResidentCardDataProvider()) } } @@ -122,11 +122,11 @@ class NoSuchDataProviderException(credentialType: KClass