Skip to content

Commit

Permalink
Added GaiaxTrustedPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
philpotisk committed Nov 11, 2021
1 parent 9af565b commit 0d97840
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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 @@ -20,5 +20,6 @@ object PolicyRegistry {
register(IssuanceDateBeforePolicy())
register(ValidFromBeforePolicy())
register(ExpirationDateAfterPolicy())
register(GaiaxTrustedPolicy())
}
}
26 changes: 26 additions & 0 deletions src/main/kotlin/id/walt/auditor/VerificationPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import id.walt.services.vc.JwtCredentialService
import id.walt.services.vc.VcUtils
import id.walt.vclib.Helpers.encode
import id.walt.vclib.model.VerifiableCredential
import id.walt.vclib.vclist.GaiaxCredential
import id.walt.vclib.vclist.VerifiablePresentation
import kotlinx.serialization.Serializable
import mu.KotlinLogging
Expand Down Expand Up @@ -161,6 +162,31 @@ class ExpirationDateAfterPolicy : VerificationPolicy {
}
}

class GaiaxTrustedPolicy : VerificationPolicy {
override val description: String = "Verify Gaiax trusted fields"
override fun verify(vc: VerifiableCredential): Boolean {
// VPs are not considered
if (vc is VerifiablePresentation) {
return true
}

val gaiaxVc = vc as GaiaxCredential

// TODO: validate trusted fields properly
if (gaiaxVc.credentialSubject.DNSpublicKey.length < 0) {
log.debug { "DNS Public key not valid." }
return false
}

if (gaiaxVc.credentialSubject.ethereumAddress.id.length < 0) {
log.debug { "ETH address not valid." }
return false
}

return true
}
}

private fun parseDate(date: String?) = try {
dateFormatter.parse(date)
} catch (e: Exception) {
Expand Down

0 comments on commit 0d97840

Please sign in to comment.