Skip to content

Commit

Permalink
updated ebsi-trusted-issuer-did policy to check for ebsi type did
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Apr 18, 2023
1 parent 0a77a28 commit 993aa7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class EbsiTrustedIssuerDidPolicy : SimpleVerificationPolicy() {
override val description: String = "Verify by trusted issuer did"
override fun doVerify(vc: VerifiableCredential): VerificationPolicyResult {
return try {
DidService.loadOrResolveAnyDid(vc.issuerId!!)?.let { VerificationPolicyResult.success() }
?: VerificationPolicyResult.failure()
if (!DidService.isDidEbsiV1(vc.issuerId!!)) VerificationPolicyResult.failure(IllegalArgumentException("Not an ebsi v1 did"))
else DidService.loadOrResolveAnyDid(vc.issuerId!!)?.let { VerificationPolicyResult.success() } ?: VerificationPolicyResult.failure()
} catch (e: ClientRequestException) {
VerificationPolicyResult.failure(
IllegalArgumentException(
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/id/walt/services/did/DidService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,14 @@ object DidService {
}
//endregion

fun isDidEbsiV2(did: String): Boolean {
fun isDidEbsiV1(did: String): Boolean = checkIsDidEbsiAndVersion(did, 1)

fun isDidEbsiV2(did: String): Boolean = checkIsDidEbsiAndVersion(did, 2)

fun checkIsDidEbsiAndVersion(did: String, version: Int): Boolean {
return DidUrl.isDidUrl(did) &&
DidUrl.from(did).let { didUrl ->
didUrl.method == DidMethod.ebsi.name && Multibase.decode(didUrl.identifier).first().toInt() == 2
didUrl.method == DidMethod.ebsi.name && Multibase.decode(didUrl.identifier).first().toInt() == version
}
}

Expand Down

0 comments on commit 993aa7b

Please sign in to comment.