From 1bba75f26b2e4c630bc2cc7b399c731705805abf Mon Sep 17 00:00:00 2001 From: Shailesh Patil <53746241+mineme0110@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:41:43 +0100 Subject: [PATCH] fix: mediator db not storing the orignal value for protected header (#15) fix: meadiator db bson implicits to store the orginal Signed-off-by: Shailesh Patil <53746241+mineme0110@users.noreply.github.com> Signed-off-by: Shailesh Patil --- .../io/iohk/atala/mediator/db/BsonImplicits.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/db/BsonImplicits.scala b/mediator/src/main/scala/io/iohk/atala/mediator/db/BsonImplicits.scala index dae90cb1..3976f093 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/db/BsonImplicits.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/db/BsonImplicits.scala @@ -69,17 +69,23 @@ given BSONReader[IV] with { given BSONWriter[Base64Obj[ProtectedHeader]] with { import Base64Obj.* - def writeTry(obj: Base64Obj[ProtectedHeader]): Try[BSONValue] = Try(BSONString(obj.base64url)) + def writeTry(obj: Base64Obj[ProtectedHeader]): Try[BSONValue] = { + val protectedHeader: String = (obj.obj, obj.original) match { + case (_, Some(op)) => op.urlBase64 + case (p, None) => obj.base64url + } + Try(BSONString(protectedHeader)) + } } given BSONReader[Base64Obj[ProtectedHeader]] with { def readTry(bson: BSONValue): Try[Base64Obj[ProtectedHeader]] = bson .asTry[String] - .flatMap{v => + .flatMap { v => s""""$v"""".fromJson[Base64Obj[ProtectedHeader]] match // TODO with a new methods from ScalaDid case Left(value) => Failure(RuntimeException(value)) case Right(value) => Try(value) -} + } } given BSONWriter[Base64] with {