Skip to content

Commit

Permalink
Merge pull request #77 from walt-id/feat-gaiax-self-decription
Browse files Browse the repository at this point in the history
Feat gaiax self decription
  • Loading branch information
philpotisk authored Nov 30, 2021
2 parents 5885e7f + 2c42b35 commit eeffc5a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
implementation("com.google.guava:guava:31.0.1-jre")

// VC
implementation("id.walt:waltid-ssikit-vclib:1.6.0")
implementation("id.walt:waltid-ssikit-vclib:1.6.1")

// JSON
implementation("org.json:json:20210307")
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/id/walt/auditor/PolicyRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ object PolicyRegistry {
register(ValidFromBeforePolicy())
register(ExpirationDateAfterPolicy())
register(GaiaxTrustedPolicy())
register(GaiaxSDPolicy())
}
}
17 changes: 12 additions & 5 deletions src/main/kotlin/id/walt/auditor/VerificationPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,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
}
Expand Down Expand Up @@ -127,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
}
}
Expand Down Expand Up @@ -186,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
}
Expand All @@ -200,6 +200,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) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/kotlin/id/walt/signatory/CLIDataProvider.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package id.walt.signatory

import id.walt.vclib.model.VerifiableCredential
import id.walt.vclib.credentials.GaiaxSelfDescription
import id.walt.vclib.credentials.GaiaxCredential
import id.walt.vclib.credentials.VerifiableDiploma
import id.walt.vclib.credentials.VerifiableId
Expand All @@ -12,6 +13,7 @@ object CLIDataProviders {
"VerifiableDiploma" -> VerifiableDiplomaCLIDataProvider()
"VerifiableId" -> VerifiableIDCLIDataProvider()
"GaiaxCredential" -> GaiaxCLIDataProvider()
"GaiaxSelfDescription" -> GaiaxSDProvider()
else -> null
}
}
Expand Down Expand Up @@ -183,6 +185,33 @@ class GaiaxCLIDataProvider : CLIDataProvider() {
}
}


class GaiaxSDProvider : CLIDataProvider() {
override fun populate(template: VerifiableCredential, proofConfig: ProofConfig): VerifiableCredential {
(template as GaiaxSelfDescription).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
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/id/walt/signatory/SignatoryDataProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object DataProviderRegistry {
register(VerifiableId::class, VerifiableIdDataProvider())
register(Europass::class, EuropassDataProvider())
register(GaiaxCredential::class, DeltaDaoDataProvider())
register(GaiaxSelfDescription::class, SdDataProvider())
register(PermanentResidentCard::class, PermanentResidentCardDataProvider())
}
}
Expand Down Expand Up @@ -118,6 +119,19 @@ class NoSuchDataProviderException(credentialType: KClass<out VerifiableCredentia
Exception("No data provider is registered for ${credentialType.simpleName}")



class SdDataProvider : SignatoryDataProvider {

override fun populate(template: VerifiableCredential, proofConfig: ProofConfig): GaiaxSelfDescription {
val vc = template as GaiaxSelfDescription
vc.id = proofConfig.credentialId
vc.issuer = proofConfig.issuerDid
vc.credentialSubject.id = proofConfig.subjectDid!!
return vc
}
}


class DeltaDaoDataProvider : SignatoryDataProvider {
override fun populate(template: VerifiableCredential, proofConfig: ProofConfig): VerifiableCredential {
if (template is GaiaxCredential) {
Expand Down
13 changes: 12 additions & 1 deletion src/main/kotlin/id/walt/signatory/rest/SignatoryController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<b>templateId</b>, <b>issuerDid</b>, and the <b>subjectDid</b>, are mandatory parameters. All other parameters are optional. <br><br> This is a example request, that also demonstrates how to populate the credential with custom data: the <br><br>{<br>" +
" \"templateId\": \"VerifiableId\",<br>" +
" \"config\": {<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp; \"issuerDid\": \"did:ebsi:zuathxHtXTV8psijTjtuZD7\",<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp; \"subjectDid\": \"did:key:z6MkwfgBDSMRqXaJtw5DjhkJdDsDmRNSrvrM1L6UMBDtvaSX\"<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp; },<br>" +
" \"credentialData\": {<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp; \"credentialSubject\": {<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"firstName\": \"Severin\"<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>" +
" &nbsp;&nbsp;&nbsp;&nbsp; }<br>" +
"}<br>")
}.body<IssueCredentialRequest>().json<String>("200")
}

0 comments on commit eeffc5a

Please sign in to comment.