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

hyperledger / identus-cloud-agent / 10833924030

12 Sep 2024 03:25PM CUT coverage: 48.864% (+0.07%) from 48.793%
10833924030

Pull #1351

CryptoKnightIOG
ATL-7660: Credential Schema as List

Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
Pull Request #1351: feat: Support Array Of Credential Schema

15 of 28 new or added lines in 3 files covered. (53.57%)

222 existing lines in 68 files now uncovered.

7530 of 15410 relevant lines covered (48.86%)

0.49 hits per line

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

75.56
/mercury/models/src/main/scala/org/hyperledger/identus/mercury/model/AttachmentDescriptor.scala
1
package org.hyperledger.identus.mercury.model
2

3
import cats.syntax.functor.*
4
import io.circe.{Decoder, Encoder, Json, JsonObject}
5
import io.circe.generic.semiauto.*
6
import io.circe.syntax.*
7

8
import java.util.Base64 as JBase64
9

10
/** @see
11
  *   data in attachments https://identity.foundation/didcomm-messaging/spec/#attachments
12
  */
13
sealed trait AttachmentData
14

15
final case class Header(kid: String)
16
object Header {
17
  given Encoder[Header] = deriveEncoder[Header]
×
18

19
  given Decoder[Header] = deriveDecoder[Header]
×
20
}
21
final case class Jws(header: Header, `protected`: String, signature: String)
22
object Jws {
23
  given Encoder[Jws] = deriveEncoder[Jws]
×
24

25
  given Decoder[Jws] = deriveDecoder[Jws]
×
26
}
27
final case class JwsData(base64: String, jws: Jws) extends AttachmentData
28
object JwsData {
29
  given Encoder[JwsData] = deriveEncoder[JwsData]
×
30

UNCOV
31
  given Decoder[JwsData] = deriveDecoder[JwsData]
×
32
}
33
final case class Base64(base64: String) extends AttachmentData
34
object Base64 {
35
  given Encoder[Base64] = deriveEncoder[Base64]
1✔
36
  given Decoder[Base64] = deriveDecoder[Base64]
1✔
37

38
}
39

40
final case class LinkData(links: Seq[String], hash: String) extends AttachmentData
41
object LinkData {
42
  given Encoder[LinkData] = deriveEncoder[LinkData]
1✔
UNCOV
43
  given Decoder[LinkData] = deriveDecoder[LinkData]
×
44

45
}
46

47
final case class JsonData(json: JsonObject) extends AttachmentData
48
object JsonData {
49
  given Encoder[JsonData] = deriveEncoder[JsonData]
1✔
50
  given Decoder[JsonData] = deriveDecoder[JsonData]
1✔
51
}
52
object AttachmentData {
53
  // given Encoder[AttachmentData] = deriveEncoder[AttachmentData]
54
  given Encoder[AttachmentData] = (a: AttachmentData) => {
55
    a match
56
      case data @ JsonData(_)    => data.asJson
1✔
57
      case data @ Base64(_)      => data.asJson
1✔
58
      case data @ JwsData(_, _)  => data.asJson
×
59
      case data @ LinkData(_, _) => data.asJson
1✔
60
  }
61

62
  given Decoder[AttachmentData] = List[Decoder[AttachmentData]](
1✔
63
    Decoder[JsonData].widen,
1✔
64
    Decoder[Base64].widen,
1✔
65
    Decoder[JwsData].widen,
1✔
66
    Decoder[LinkData].widen
1✔
67
  ).reduceLeft(_ or _)
1✔
68
}
69

70
/** https://identity.foundation/didcomm-messaging/spec/#attachments
71
  *
72
  * Example:
73
  * {{{
74
  *      {"id":"765d7fda-1b7f-4325-a828-f0c5523a6c19",
75
  *        "data":{"jws":null,"hash":null,"json":{
76
  *          "ciphertext":"c1kzLNSIZAuRILhaJg7KY3rx95czEy6VVBFVCN002OWw4D7bLK-ZuPTaTVEvwhfxlwkkwP1xuG9R22XMYlzLUIou6hx3gyeWgsUZS6OZkvuQlRqtPLh1yEZap24WH80cH4_DpX-srxsic5n7cEluuUlC0xvF5th-TLOZcmfUYySBPoKLzrSBcNIZH0GPyeePlnmLhqB5pi--mX3M17DcTpN5miQyJUNaRNv8hj3lKsKiRtGUCL_dzbV4UGRFEZ-fF-LWZtZfNco3LoEwIpX5099sqzc9ZrFi3GbgAWdyJUe075A5h89FgMHYdqdOrGp8HSQCoj4pRTv-SQJJ16APFo-u7GZOVd0kLeJvMBCQhwXlGT4DUpaeMV_52wrPj2FA9jDyqnzpUFPsb_IH7poc-VFrV32NJ6GLhzgwwc3k3vU_s16bHB3GeB-7_GgCu6hT","protected":"eyJlcGsiOnsia3R5IjoiT0tQIiwiY3J2IjoiWDI1NTE5IiwieCI6Ii1vY3RRYmFobFVYSF81aTQwOHRKN0Y3SmxHQU4yODY1Z1hvTHlHNTBNSHcifSwiYXB2IjoiYUptdEdPMHZIc3loQkpxVnRXU2dHNVN3YjMzVTJWdTRKTWhCS0ZiX0NHSSIsInNraWQiOiJkaWQ6ZXhhbXBsZTphbGljZSNrZXktYWdyZWVtZW50LTEiLCJhcHUiOiJaR2xrT21WNFlXMXdiR1U2WVd4cFkyVWphMlY1TFdGbmNtVmxiV1Z1ZEMweCIsInR5cCI6ImFwcGxpY2F0aW9uXC9kaWRjb21tLWVuY3J5cHRlZCtqc29uIiwiZW5jIjoiQTI1NkNCQy1IUzUxMiIsImFsZyI6IkVDREgtMVBVK0EyNTZLVyJ9",
77
  *          "recipients":[{
78
  *            "encrypted_key":"lWDvuQ37k6rotmnmOe7h1UF7Ao1RApL08aWmwjcijhlcH1_kvOvLYV8Dg2jXOZGsz2GsnM_W36JkLDFxM160g91ZsNAbz2rn",
79
  *            "header":{"kid":"did:example:bob#key-agreement-1"}
80
  *          }],"tag":"4pWPm37KdyRLZbWGIPJXqY9Mq55mKBHtSqBKUeHQHwc","iv":"THIgCu-Fq2aCiuwS-PcsfQ"
81
  *       }
82
  * }}}
83
  *
84
  * @see
85
  *   https://github.com/hyperledger/aries-rfcs/tree/main/concepts/0017-attachments
86
  * @param id
87
  * @param media_type
88
  * @param data
89
  * @param filename
90
  * @param lastmod_time
91
  * @param byte_count
92
  * @param description
93
  */
94
final case class AttachmentDescriptor(
95
    id: String,
96
    media_type: Option[String] = None,
×
97
    data: AttachmentData = Base64(""),
×
98
    format: Option[String] = None,
1✔
99
    filename: Option[String] = None,
1✔
100
    lastmod_time: Option[Long] = None,
1✔
101
    byte_count: Option[Long] = None,
1✔
102
    description: Option[String] = None,
1✔
103
)
104

105
object AttachmentDescriptor {
106

107
  def buildBase64Attachment(
1✔
108
      id: String = java.util.UUID.randomUUID.toString,
1✔
109
      payload: Array[Byte],
110
      mediaType: Option[String] = None,
1✔
111
      format: Option[String] = None,
1✔
112
  ): AttachmentDescriptor = {
113
    val encoded = JBase64.getUrlEncoder.encodeToString(payload)
1✔
114
    AttachmentDescriptor(id, mediaType, Base64(encoded), format = format)
1✔
115
  }
116

117
  def buildJsonAttachment[A](
1✔
118
      id: String = java.util.UUID.randomUUID.toString,
1✔
119
      payload: A,
120
      mediaType: Option[String] = Some("application/json"),
121
      format: Option[String] = None,
122
  )(using Encoder[A]): AttachmentDescriptor = {
123
    val jsonObject = payload.asJson.asObject.getOrElse(JsonObject.empty)
1✔
124
    AttachmentDescriptor(id, mediaType, JsonData(jsonObject), format = format) // use JsonData or Base64 by default?
1✔
125
  }
126

127
  given attachmentDescriptorEncoderV1: Encoder[AttachmentDescriptor] = (a: AttachmentDescriptor) => {
128
    Json.obj(
1✔
129
      "@id" -> a.id.asJson,
1✔
130
      "mime_type" -> a.media_type.asJson,
1✔
131
      "data" -> a.data.asJson
1✔
132
    )
133
  }
134

135
  given attachmentDescriptorEncoderV2: Encoder[AttachmentDescriptor] = deriveEncoder[AttachmentDescriptor]
1✔
136

137
  given Decoder[AttachmentDescriptor] = deriveDecoder[AttachmentDescriptor]
×
138

139
}
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