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

hyperledger / identus-cloud-agent / 10793991050

10 Sep 2024 01:56PM UTC 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

62.07
/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/DidResolver.scala
1
package org.hyperledger.identus.pollux.vc.jwt
2

3
import io.circe.Json
4
import org.hyperledger.identus.castor.core.model.did.w3c.{
5
  makeW3CResolver,
6
  DIDDocumentRepr,
7
  DIDResolutionErrorRepr,
8
  PublicKeyJwk,
9
  PublicKeyRepr,
10
  PublicKeyReprOrRef,
11
  ServiceRepr
12
}
13
import org.hyperledger.identus.castor.core.service.DIDService
14
import zio.*
15

16
import java.time.Instant
17
import scala.annotation.unused
18

19
trait DidResolver {
20
  def resolve(didUrl: String): UIO[DIDResolutionResult]
21
}
22

23
trait DIDResolutionResult
24

25
sealed case class DIDResolutionFailed(
26
    error: DIDResolutionError
27
) extends DIDResolutionResult
28

29
sealed case class DIDResolutionSucceeded(
30
    didDocument: DIDDocument,
31
    didDocumentMetadata: DIDDocumentMetadata
32
) extends DIDResolutionResult
33

34
sealed trait DIDResolutionError(@unused error: String, @unused message: String)
35
case class InvalidDid(message: String) extends DIDResolutionError("invalidDid", message)
36
case class NotFound(message: String) extends DIDResolutionError("notFound", message)
37
case class RepresentationNotSupported(message: String) extends DIDResolutionError("RepresentationNotSupported", message)
38
case class InvalidPublicKeyLength(message: String) extends DIDResolutionError("invalidPublicKeyLength", message)
39
case class InvalidPublicKeyType(message: String) extends DIDResolutionError("invalidPublicKeyType", message)
40
case class UnsupportedPublicKeyType(message: String) extends DIDResolutionError("unsupportedPublicKeyType", message)
41
case class Error(error: String, message: String) extends DIDResolutionError(error, message)
42

43
case class DIDDocumentMetadata(
44
    created: Option[Instant] = Option.empty,
1✔
45
    updated: Option[Instant] = Option.empty,
1✔
46
    deactivated: Option[Boolean] = Option.empty,
1✔
47
    versionId: Option[Instant] = Option.empty,
1✔
48
    nextUpdate: Option[Instant] = Option.empty,
1✔
49
    nextVersionId: Option[Instant] = Option.empty,
1✔
50
    equivalentId: Option[Instant] = Option.empty,
1✔
51
    canonicalId: Option[Instant] = Option.empty
1✔
52
)
53

54
case class DIDDocument(
55
    id: String,
56
    alsoKnowAs: Vector[String],
57
    controller: Vector[String],
58
    verificationMethod: Vector[VerificationMethod] = Vector.empty,
×
59
    authentication: Vector[VerificationMethodOrRef] = Vector.empty,
×
60
    assertionMethod: Vector[VerificationMethodOrRef] = Vector.empty,
×
61
    keyAgreement: Vector[VerificationMethodOrRef] = Vector.empty,
×
62
    capabilityInvocation: Vector[VerificationMethodOrRef] = Vector.empty,
×
63
    capabilityDelegation: Vector[VerificationMethodOrRef] = Vector.empty,
×
64
    service: Vector[Service] = Vector.empty
×
65
)
66

67
type VerificationMethodOrRef = VerificationMethod | String
68

69
case class VerificationMethod(
70
    id: String,
71
    `type`: String,
72
    controller: String,
73
    publicKeyBase58: Option[String] = Option.empty,
1✔
74
    publicKeyBase64: Option[String] = Option.empty,
1✔
75
    publicKeyJwk: Option[JsonWebKey] = Option.empty,
×
76
    publicKeyHex: Option[String] = Option.empty,
1✔
77
    publicKeyMultibase: Option[String] = Option.empty,
1✔
78
    blockchainAccountId: Option[String] = Option.empty,
1✔
79
    ethereumAddress: Option[String] = Option.empty
1✔
80
)
81

82
case class Service(id: String, `type`: String | Seq[String], serviceEndpoint: Json)
83

84
/** An adapter for translating Castor resolver to resolver defined in JWT library */
85
class PrismDidResolver(didService: DIDService) extends DidResolver {
86

87
  private val w3cResolver = makeW3CResolver(didService)
1✔
88

89
  override def resolve(didUrl: String): UIO[DIDResolutionResult] = {
1✔
90
    w3cResolver(didUrl)
1✔
91
      .fold(
92
        toPolluxResolutionErrorModel,
×
93
        { case (didDocumentMetadata, didDocument) =>
1✔
94
          DIDResolutionSucceeded(
95
            didDocument = toPolluxDIDDocumentModel(didDocument),
1✔
96
            didDocumentMetadata = DIDDocumentMetadata(
1✔
97
              deactivated = Some(didDocumentMetadata.deactivated)
98
            )
99
          )
100
        }
101
      )
102
  }
103

104
  private def toPolluxDIDDocumentModel(didDocument: DIDDocumentRepr): DIDDocument = {
1✔
105
    DIDDocument(
106
      id = didDocument.id,
107
      alsoKnowAs = Vector.empty,
1✔
108
      controller = Vector(didDocument.controller),
1✔
109
      verificationMethod = didDocument.verificationMethod.map(toPolluxVerificationMethodModel).toVector,
1✔
110
      authentication = didDocument.authentication.map(toPolluxVerificationMethodOrRefModel).toVector,
1✔
111
      assertionMethod = didDocument.assertionMethod.map(toPolluxVerificationMethodOrRefModel).toVector,
1✔
112
      keyAgreement = didDocument.keyAgreement.map(toPolluxVerificationMethodOrRefModel).toVector,
1✔
113
      capabilityInvocation = didDocument.capabilityInvocation.map(toPolluxVerificationMethodOrRefModel).toVector,
1✔
114
      capabilityDelegation = didDocument.capabilityDelegation.map(toPolluxVerificationMethodOrRefModel).toVector,
×
115
      service = didDocument.service.map(toPolluxServiceModel).toVector
×
116
    )
117
  }
118

119
  private def toPolluxResolutionErrorModel(error: DIDResolutionErrorRepr): DIDResolutionFailed = {
×
120
    val e = error match {
121
      case DIDResolutionErrorRepr.InvalidDID(_)              => InvalidDid(error.value)
×
122
      case DIDResolutionErrorRepr.InvalidDIDUrl(_)           => InvalidDid(error.value)
×
123
      case DIDResolutionErrorRepr.NotFound                   => NotFound(error.value)
×
124
      case DIDResolutionErrorRepr.RepresentationNotSupported => RepresentationNotSupported(error.value)
×
125
      case DIDResolutionErrorRepr.InternalError(_)           => Error(error.value, error.value)
×
126
      case DIDResolutionErrorRepr.InvalidPublicKeyLength     => InvalidPublicKeyLength(error.value)
×
127
      case DIDResolutionErrorRepr.InvalidPublicKeyType       => InvalidPublicKeyType(error.value)
×
128
      case DIDResolutionErrorRepr.UnsupportedPublicKeyType   => UnsupportedPublicKeyType(error.value)
×
129
    }
130
    DIDResolutionFailed(e)
131
  }
132

133
  private def toPolluxServiceModel(service: ServiceRepr): Service = {
×
134
    Service(
135
      id = service.id,
136
      `type` = service.`type`,
137
      serviceEndpoint = service.serviceEndpoint
138
    )
139
  }
140

141
  private def toPolluxVerificationMethodModel(verificationMethod: PublicKeyRepr): VerificationMethod = {
1✔
142
    VerificationMethod(
1✔
143
      id = verificationMethod.id,
144
      `type` = verificationMethod.`type`,
145
      controller = verificationMethod.controller,
146
      publicKeyJwk = Some(toPolluxJwtModel(verificationMethod.publicKeyJwk))
1✔
147
    )
148
  }
149

150
  private def toPolluxVerificationMethodOrRefModel(verificationMethod: PublicKeyReprOrRef): VerificationMethodOrRef = {
1✔
151
    verificationMethod match {
152
      case uri: String       => uri
1✔
153
      case pk: PublicKeyRepr => toPolluxVerificationMethodModel(pk)
×
154
    }
155
  }
156

157
  private def toPolluxJwtModel(jwk: PublicKeyJwk): JsonWebKey = {
1✔
158
    JsonWebKey(
1✔
159
      crv = Some(jwk.crv),
160
      kty = jwk.kty,
161
      x = jwk.x,
162
      y = jwk.y
163
    )
164
  }
165

166
}
167

168
object PrismDidResolver {
169
  val layer: URLayer[DIDService, DidResolver] = ZLayer.fromFunction(PrismDidResolver(_))
1✔
170
}
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