Skip to content

Commit

Permalink
ATL-1893-DidPeerResolver (#36)
Browse files Browse the repository at this point in the history
* ATL-1893-DidPeerResolver

* added test
  • Loading branch information
mineme0110 authored Sep 22, 2022
1 parent 6f25f4c commit c0fb7aa
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mercury/prism-mediator/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ lazy val D = new {

// Test DID comm
val didcommx = Def.setting("org.didcommx" % "didcomm" % "0.3.1")
val peerDidcommx = Def.setting("org.didcommx" % "peerdid" % "0.3.0")
val didScala = Def.setting("app.fmgp" %% "did" % "0.0.0+74-691ada28+20220902-0934-SNAPSHOT")

// For munit https://scalameta.org/munit/docs/getting-started.html#scalajs-setup
Expand Down Expand Up @@ -124,9 +125,13 @@ lazy val resolver = project // maybe merge into models
.settings(
libraryDependencies ++= Seq(
D.didcommx.value,
D.peerDidcommx.value,
D.munit.value,
D.munitZio.value,
"org.jetbrains.kotlin" % "kotlin-runtime" % "1.2.71",
"org.jetbrains.kotlin" % "kotlin-stdlib" % "1.7.10",
)
),
testFrameworks += new TestFramework("munit.Framework")
)
.dependsOn(models)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.iohk.atala.resolvers

import io.iohk.atala.resolvers.UniversalDidResolver.diddocs
import org.didcommx.didcomm.diddoc.{DIDDoc, DIDDocResolver, DIDDocResolverInMemory}
import org.didcommx.peerdid.PeerDIDResolver.resolvePeerDID
import org.didcommx.peerdid.VerificationMaterialFormatPeerDID
import io.circe.Json
import io.circe.generic.auto._
import io.circe.parser._
import zio._
import zio.{Console, Task, UIO, URLayer, ZIO}

trait PeerDidResolver {
def resolve(did: String): UIO[String]
def resolveDidAsJson(did: String): UIO[Option[Json]]
}

case class PeerDidResolverImpl() extends PeerDidResolver {

def resolve(did: String): UIO[String] = {
ZIO.succeed { resolvePeerDID(did, VerificationMaterialFormatPeerDID.MULTIBASE) }
}

def resolveDidAsJson(did: String): UIO[Option[Json]] = {
ZIO.succeed {
parse(resolvePeerDID(did, VerificationMaterialFormatPeerDID.MULTIBASE)).toOption
}
}
}

object PeerDidResolver {

val layer: ULayer[PeerDidResolver] = {
ZLayer.succeedEnvironment(
ZEnvironment(PeerDidResolverImpl())
)
}

def resolve(did: String): URIO[PeerDidResolver, String] = {
ZIO.serviceWithZIO(_.resolve(did))
}

def resolveDidAsJson(did: String): URIO[PeerDidResolver, Option[Json]] = {
ZIO.serviceWithZIO(_.resolveDidAsJson(did))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.iohk.atala.resolvers
import zio.*
import munit.*
import io.circe.parser.*

class PeerDidResolverSpec extends ZSuite {

testZ("peer did") {
val a =
"did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0"
val expectedDidDocJson = parse("""{
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "authentication": [
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V",
| "type": "Ed25519VerificationKey2020",
| "controller": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "publicKeyMultibase": "z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V"
| },
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg",
| "type": "Ed25519VerificationKey2020",
| "controller": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "publicKeyMultibase": "z6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg"
| }
| ],
| "keyAgreement": [
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc",
| "type": "X25519KeyAgreementKey2020",
| "controller": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0",
| "publicKeyMultibase": "z6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc"
| }
| ],
| "service": [
| {
| "id": "did:peer:2.Ez6LSbysY2xFMRpGMhb7tFTLMpeuPRaqaWM1yECx2AtzE3KCc.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.Vz6MkgoLTnTypo3tDRwCkZXSccTPHRLhF4ZnjhueYAFpEX6vg.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludCIsInIiOlsiZGlkOmV4YW1wbGU6c29tZW1lZGlhdG9yI3NvbWVrZXkiXSwiYSI6WyJkaWRjb21tL3YyIiwiZGlkY29tbS9haXAyO2Vudj1yZmM1ODciXX0#didcommmessaging-0",
| "type": "DIDCommMessaging",
| "serviceEndpoint": "https://example.com/endpoint",
| "routingKeys": [
| "did:example:somemediator#somekey"
| ],
| "accept": [
| "didcomm/v2", "didcomm/aip2;env=rfc587"
| ]
| }
| ]
|}""".stripMargin).toOption
val peerDidResolver = PeerDidResolverImpl()
val didDocJson = peerDidResolver.resolveDidAsJson(a)
didDocJson.map(assertEquals(_, expectedDidDocJson))
// assertEqualsZ(didDocJson,expectedDidDocJson) // this fails need find why
}

}

0 comments on commit c0fb7aa

Please sign in to comment.