• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-cloud-agent / 10793991050

10 Sep 2024 01:56PM CUT coverage: 48.504% (-4.5%) from 52.962%
10793991050

push

web-flow
build: sbt and plugins dependency update (#1337)

Signed-off-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Co-authored-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Co-authored-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>

7406 of 15269 relevant lines covered (48.5%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.58
/mercury/resolver/src/main/scala/org/hyperledger/identus/resolvers/PeerDidResolver.scala
1
package org.hyperledger.identus.resolvers
2

3
import io.circe.{Decoder, HCursor, Json}
4
import io.circe.parser.*
5
import org.didcommx.didcomm.common.*
6
import org.didcommx.didcomm.diddoc.{DIDCommService, DIDDoc, VerificationMethod}
7
import org.didcommx.peerdid.PeerDIDResolver.resolvePeerDID
8
import org.didcommx.peerdid.VerificationMaterialFormatPeerDID
9
import zio.*
10

11
import scala.jdk.CollectionConverters.*
12

13
trait PeerDidResolver {
14
  def resolve(did: String): UIO[String]
15
  def resolveDidAsJson(did: String): UIO[Option[Json]]
16
}
17

18
case class PeerDidResolverImpl() extends PeerDidResolver {
19

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

24
  def resolveDidAsJson(did: String): UIO[Option[Json]] = {
1✔
25
    ZIO.succeed {
26
      parse(resolvePeerDID(did, VerificationMaterialFormatPeerDID.MULTIBASE)).toOption
1✔
27
    }
28
  }
29
}
30

31
object PeerDidResolver {
32
  def resolveUnsafe(didPeer: String) =
1✔
33
    parse(resolvePeerDID(didPeer, VerificationMaterialFormatPeerDID.JWK)).toOption.get
1✔
34

35
  def getDIDDoc(didPeer: String): DIDDoc = {
1✔
36
    val json = resolveUnsafe(didPeer)
1✔
37
    val cursor: HCursor = json.hcursor
1✔
38
    val did = cursor.downField("id").as[String].getOrElse(UnexpectedCodeExecutionPath)
×
39
    val service = cursor.downField("service").as[List[Json]]
1✔
40

41
    val didCommServices: List[DIDCommService] = service
42
      .map {
1✔
43
        _.map { item =>
1✔
44
          val id = item.hcursor.downField("id").as[String].getOrElse(UnexpectedCodeExecutionPath)
1✔
45
          // val typ = item.hcursor.downField("type").as[String].getOrElse(UnexpectedCodeExecutionPath)
46
          val serviceEndpointJson = item.hcursor.downField("serviceEndpoint")
1✔
47
          // val serviceEndpoint = item.hcursor.downField("serviceEndpoint").as[String].getOrElse(UnexpectedCodeExecutionPath)
48
          val uri = serviceEndpointJson.downField("uri").as[String].getOrElse(UnexpectedCodeExecutionPath)
×
49
          val routingKeys: Seq[String] =
50
            serviceEndpointJson.downField("routingKeys").as[List[String]].getOrElse(Seq.empty)
1✔
51
          val accept: Seq[String] = serviceEndpointJson.downField("accept").as[List[String]].getOrElse(Seq.empty)
1✔
52
          new DIDCommService(id, uri, routingKeys.asJava, accept.asJava)
1✔
53
        }
54
      }
55
      .getOrElse(List.empty)
×
56

57
    val authentications1 = cursor.downField("authentication").as[List[Json]]
1✔
58
    val verificationMethodList1: List[VerificationMethod] = authentications1
59
      .map {
1✔
60
        _.map(item =>
1✔
61
          val id = item.hcursor.downField("id").as[String].getOrElse(UnexpectedCodeExecutionPath)
×
62

63
          val publicKeyJwk = item.hcursor
1✔
64
            .downField("publicKeyJwk")
1✔
65
            .as[Json]
66
            .map(_.toString)
1✔
67
            .getOrElse(UnexpectedCodeExecutionPath)
×
68

69
          val controller = item.hcursor.downField("controller").as[String].getOrElse(UnexpectedCodeExecutionPath)
1✔
70
          val verificationMaterial = new VerificationMaterial(VerificationMaterialFormat.JWK, publicKeyJwk)
1✔
71
          new VerificationMethod(id, VerificationMethodType.JSON_WEB_KEY_2020, verificationMaterial, controller)
1✔
72
        )
73
      }
74
      .getOrElse(UnexpectedCodeExecutionPath)
×
75

76
    val keyIdAuthentications: List[String] = authentications1
77
      .map {
1✔
78
        _.map(item => item.hcursor.downField("id").as[String].getOrElse(UnexpectedCodeExecutionPath))
×
79
      }
80
      .getOrElse(UnexpectedCodeExecutionPath)
1✔
81

82
    val keyAgreements1 = cursor.downField("keyAgreement").as[List[Json]]
1✔
83
    val verificationMethodList: List[VerificationMethod] = keyAgreements1
84
      .map {
1✔
85
        _.map(item =>
1✔
86
          val id = item.hcursor.downField("id").as[String].getOrElse(UnexpectedCodeExecutionPath)
1✔
87

88
          val publicKeyJwk = item.hcursor
1✔
89
            .downField("publicKeyJwk")
1✔
90
            .as[Json]
91
            .map(_.toString)
1✔
92
            .getOrElse(UnexpectedCodeExecutionPath)
×
93

94
          val controller = item.hcursor.downField("controller").as[String].getOrElse(UnexpectedCodeExecutionPath)
1✔
95
          val verificationMaterial = new VerificationMaterial(VerificationMaterialFormat.JWK, publicKeyJwk)
1✔
96
          new VerificationMethod(id, VerificationMethodType.JSON_WEB_KEY_2020, verificationMaterial, controller)
1✔
97
        )
98
      }
99
      .getOrElse(UnexpectedCodeExecutionPath)
1✔
100

101
    val keyIds: List[String] = keyAgreements1
102
      .map {
1✔
103
        _.map(item => item.hcursor.downField("id").as[String].getOrElse(UnexpectedCodeExecutionPath))
×
104
      }
105
      .getOrElse(UnexpectedCodeExecutionPath)
×
106
    val mergedList = verificationMethodList ++ verificationMethodList1
1✔
107

108
    val didDoc =
109
      new DIDDoc(
1✔
110
        did,
111
        keyIds.asJava,
1✔
112
        keyIdAuthentications.asJava,
1✔
113
        mergedList.asJava,
1✔
114
        didCommServices.asJava
1✔
115
      )
116
    didDoc
117
  }
118

119
  val layer: ULayer[PeerDidResolver] = {
120
    ZLayer.succeedEnvironment(
1✔
121
      ZEnvironment(PeerDidResolverImpl())
×
122
    )
123
  }
124

125
  def resolve(did: String): URIO[PeerDidResolver, String] = {
×
126
    ZIO.serviceWithZIO(_.resolve(did))
×
127
  }
128

129
  def resolveDidAsJson(did: String): URIO[PeerDidResolver, Option[Json]] = {
×
130
    ZIO.serviceWithZIO(_.resolveDidAsJson(did))
×
131
  }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc