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

hyperledger / identus-cloud-agent / 10807284826

11 Sep 2024 07:46AM UTC coverage: 48.663% (+0.1%) from 48.554%
10807284826

Pull #1332

patlo-iog
test: make test work again

Signed-off-by: Pat Losoponkul <pat.losoponkul@iohk.io>
Pull Request #1332: feat: presentation_submission validation logic [WIP]

92 of 134 new or added lines in 5 files covered. (68.66%)

248 existing lines in 65 files now uncovered.

7478 of 15367 relevant lines covered (48.66%)

0.49 hits per line

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

73.33
/mercury/agent-didcommx/src/main/scala/org/hyperledger/identus/mercury/PeerDID.scala
1
package org.hyperledger.identus.mercury
2

3
import com.nimbusds.jose.jwk.*
4
import com.nimbusds.jose.jwk.gen.*
5
import io.circe.*
6
import io.circe.generic.semiauto.*
7
import io.circe.syntax.*
8
import org.didcommx.peerdid.*
9
import org.hyperledger.identus.mercury.model.DidId
10

11
import scala.jdk.CollectionConverters.*
12

13
final case class PeerDID(
14
    did: DidId,
15
    jwkForKeyAgreement: OctetKeyPair,
16
    jwkForKeyAuthentication: OctetKeyPair,
17
) {
18
  // def keyAgreement = PeerDID.keyAgreemenFromPublicJWK(jwkForKeyAgreement)
19
  // def keyAuthentication = PeerDID.keyAuthenticationFromPublicJWK(jwkForKeyAuthentication)
20

21
  // def getSecretResolverInMemory: SecretResolverInMemory = {
22
  //   val keyIdAgreement = PeerDIDUtils.createMultibaseEncnumbasis(keyAgreement).drop(1)
23
  //   val keyIdAuthentication = PeerDIDUtils.createMultibaseEncnumbasis(keyAuthentication).drop(1)
24

25
  //   val secretKeyAgreement = new Secret(
26
  //     s"${did.value}#$keyIdAgreement",
27
  //     VerificationMethodType.JSON_WEB_KEY_2020,
28
  //     new VerificationMaterial(VerificationMaterialFormat.JWK, jwkForKeyAgreement.toJSONString)
29
  //   )
30
  //   val secretKeyAuthentication = new Secret(
31
  //     s"${did.value}#$keyIdAuthentication",
32
  //     VerificationMethodType.JSON_WEB_KEY_2020,
33
  //     new VerificationMaterial(VerificationMaterialFormat.JWK, jwkForKeyAuthentication.toJSONString)
34
  //   )
35

36
  //   new SecretResolverInMemory(
37
  //     Map(
38
  //       s"${did.value}#$keyIdAgreement" -> secretKeyAgreement,
39
  //       s"${did.value}#$keyIdAuthentication" -> secretKeyAuthentication,
40
  //     ).asJava
41
  //   )
42
  // }
43

44
  def getDIDDocument = org.didcommx.peerdid.PeerDIDResolver
×
45
    .resolvePeerDID(did.value, VerificationMaterialFormatPeerDID.JWK)
×
46
}
47

48
object PeerDID {
49

50
  /** PeerDidServiceEndpoint
51
    *
52
    * @param r
53
    *   routingKeys are OPTIONAL. An ordered array of strings referencing keys to be used when preparing the message for
54
    *   transmission as specified in Sender Process to Enable Forwarding, above.
55
    */
56

57
  case class ServiceEndpoint(uri: String, r: Seq[String] = Seq.empty, a: Seq[String] = Seq("didcomm/v2"))
1✔
58
  object ServiceEndpoint {
59
    implicit val encoder: Encoder[ServiceEndpoint] = deriveEncoder[ServiceEndpoint]
1✔
UNCOV
60
    implicit val decoder: Decoder[ServiceEndpoint] = deriveDecoder[ServiceEndpoint]
×
61
    def apply(endpoint: String) = new ServiceEndpoint(uri = endpoint)
1✔
62
  }
63

64
  case class Service(
65
      t: String = "dm",
1✔
66
      s: ServiceEndpoint
67
  ) {
68
    def `type` = t
×
69
    def serviceEndpoint = s
×
70
    def routingKeys = s.r
×
71
    def accept = s.a
×
72
  }
73
  object Service {
74
    implicit val encoder: Encoder[Service] = deriveEncoder[Service]
1✔
UNCOV
75
    implicit val decoder: Decoder[Service] = deriveDecoder[Service]
×
76
    def apply(endpoint: String) = new Service(s = ServiceEndpoint(endpoint))
1✔
77
  }
78

79
  def makeNewJwkKeyX25519: OctetKeyPair = new OctetKeyPairGenerator(Curve.X25519).generate()
1✔
80

81
  def makeNewJwkKeyEd25519: OctetKeyPair = new OctetKeyPairGenerator(Curve.Ed25519).generate()
1✔
82

83
  def keyAgreemenFromPublicJWK(key: OctetKeyPair) = VerificationMaterialPeerDID[VerificationMethodTypeAgreement](
1✔
84
    VerificationMaterialFormatPeerDID.JWK,
85
    key.toPublicJWK,
1✔
86
    VerificationMethodTypeAgreement.JSON_WEB_KEY_2020.INSTANCE
87
  )
88

89
  def keyAuthenticationFromPublicJWK(key: OctetKeyPair) =
1✔
90
    VerificationMaterialPeerDID[VerificationMethodTypeAuthentication](
1✔
91
      VerificationMaterialFormatPeerDID.JWK,
92
      key.toPublicJWK,
1✔
93
      VerificationMethodTypeAuthentication.JSON_WEB_KEY_2020.INSTANCE
94
    )
95

96
  def makePeerDid(
1✔
97
      jwkForKeyAgreement: OctetKeyPair = makeNewJwkKeyX25519,
1✔
98
      jwkForKeyAuthentication: OctetKeyPair = makeNewJwkKeyEd25519,
1✔
99
      serviceEndpoint: Option[String] = None
1✔
100
  ): PeerDID = {
101
    val did = org.didcommx.peerdid.PeerDIDCreator.createPeerDIDNumalgo2(
1✔
102
      List(keyAgreemenFromPublicJWK(jwkForKeyAgreement)).asJava,
1✔
103
      List(keyAuthenticationFromPublicJWK(jwkForKeyAuthentication)).asJava,
1✔
104
      serviceEndpoint match {
105
        case Some(endpoint) => Service(endpoint).asJson.noSpaces
1✔
106
        case None           => null
1✔
107
      }
108
    )
109
    PeerDID(DidId(did), jwkForKeyAgreement, jwkForKeyAuthentication)
110
  }
111
}
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