Skip to content

Commit

Permalink
fix: CredentialOffer not following spec (#569)
Browse files Browse the repository at this point in the history
Signed-off-by: FabioPinheiro <fabiomgpinheiro@gmail.com>
  • Loading branch information
FabioPinheiro committed Sep 1, 2023
1 parent 9426e7f commit 3d479b9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ object AttachmentDescriptor {
given attachmentDescriptorEncoderV1: Encoder[AttachmentDescriptor] = (a: AttachmentDescriptor) => {
Json.obj(
"@id" -> a.id.asJson,
"mime-type" -> a.media_type.asJson,
"mime_type" -> a.media_type.asJson,
"data" -> a.data.asJson
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.iohk.atala.mercury.protocol.issuecredential
import io.circe.generic.semiauto.*
import io.circe.{Decoder, Encoder}
final case class Attribute(name: String, value: String, mimeType: Option[String] = None)
final case class Attribute(
name: String,
value: String,
mime_type: Option[String] = None,
)
object Attribute {
given Encoder[Attribute] = deriveEncoder[Attribute]
given Decoder[Attribute] = deriveDecoder[Attribute]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ object CredentialService {
): IO[CredentialServiceError, JsonObject] = {
for {
claims <- ZIO.foldLeft(attributes)(JsonObject()) { case (jsonObject, attr) =>
attr.mimeType match
attr.mime_type match
case None =>
ZIO.succeed(jsonObject.add(attr.name, attr.value.asJson))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ object IssueController {
case CredentialServiceError.UnsupportedVCClaimsValue(error) =>
ErrorResponse.badRequest(detail = Some(error))
case CredentialServiceError.UnsupportedVCClaimsMimeType(mimeType) =>
ErrorResponse.badRequest(detail = Some(s"Unsupported mime-type for claim: $mimeType"))
ErrorResponse.badRequest(detail = Some(s"Unsupported mime_type for claim: $mimeType"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ object IssueCredentialRecord {
.map(offer =>
offer.body.credential_preview.attributes
.foldLeft(Json.Obj()) { case (jsObject, attr) =>
val jsonValue = attr.mimeType match
val jsonValue = attr.mime_type match
case Some("application/json") =>
val jsonString =
String(java.util.Base64.getUrlDecoder.decode(attr.value.getBytes(StandardCharsets.UTF_8)))
jsonString.fromJson[Json].getOrElse(Json.Str(s"Unsupported VC claims value: $jsonString"))
case Some(mime) => Json.Str(s"Unsupported 'mime-type': $mime")
case Some(mime) => Json.Str(s"Unsupported 'mime_type': $mime")
case None => Json.Str(attr.value)
jsObject.copy(fields = jsObject.fields.appended(attr.name -> jsonValue))
}
Expand Down

0 comments on commit 3d479b9

Please sign in to comment.