From 8ba16d51f255ae6ccd5c696c1151879a32160a06 Mon Sep 17 00:00:00 2001 From: Pat Losoponkul Date: Mon, 3 Jul 2023 12:36:19 +0700 Subject: [PATCH] fix: do not use did parser from sdk 1.4 --- .../iohk/atala/castor/core/model/did/DID.scala | 5 +++++ .../atala/castor/core/model/did/PrismDID.scala | 16 ++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/DID.scala b/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/DID.scala index 2678bc3f20..e0e5a34d85 100644 --- a/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/DID.scala +++ b/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/DID.scala @@ -30,3 +30,8 @@ final case class DID( ) { override def toString: String = s"did:${method.value}:${methodSpecificId.value}" } + +object DID { + // TODO: implement + def fromString(s: String): Either[String, DID] = ??? +} diff --git a/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/PrismDID.scala b/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/PrismDID.scala index 22324e29ec..0972fc99d6 100644 --- a/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/PrismDID.scala +++ b/castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/PrismDID.scala @@ -56,18 +56,14 @@ object PrismDID extends ProtoModelHelper { } def fromString(s: String): Either[String, PrismDID] = { - // Only reuse code in Did.fromString not PrismDid.fromString from 1.4 SDK - // because of uncertainty around keeping prism-identity up-to-date - // as the protobuf definition evolves - Try(io.iohk.atala.prism.identity.Did.Companion.fromString(s)).toEither.left - .map(_.getMessage) + DID.fromString(s) .flatMap { did => - if (did.getMethod.toString == PRISM_METHOD.value) Right(did) - else Left(s"Expected DID to have method ${PRISM_METHOD.value}, but got \"${did.getMethod.toString}\" instead") + if (did.method.toString == PRISM_METHOD.value) Right(did) + else Left(s"Expected DID to have method ${PRISM_METHOD.value}, but got \"${did.method.toString}\" instead") } - .flatMap { (did: io.iohk.atala.prism.identity.Did) => - val canonicalMatchGroups = CANONICAL_SUFFIX_REGEX.findAllMatchIn(did.getMethodSpecificId.toString).toList - val longFormMatchGroups = LONG_FORM_SUFFIX_REGEX.findAllMatchIn(did.getMethodSpecificId.toString).toList + .flatMap { did => + val canonicalMatchGroups = CANONICAL_SUFFIX_REGEX.findAllMatchIn(did.methodSpecificId.toString).toList + val longFormMatchGroups = LONG_FORM_SUFFIX_REGEX.findAllMatchIn(did.methodSpecificId.toString).toList (canonicalMatchGroups, longFormMatchGroups) match { case (Nil, longFormPattern :: Nil) =>