From ea3af44024524bc2feea7ff7603293b4717acfcf Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Mon, 3 Jul 2023 15:39:17 +0100 Subject: [PATCH] feat: process KeylistQuery and return Keylist (#30) Process a Keylist Query and return a Keylist For ATL-4208 Signed-off-by: Fabio --- build.sbt | 2 +- .../MediatorCoordinationExecuter.scala | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index b09794a9..d96fe0a2 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,7 @@ inThisBuild( /** Versions */ lazy val V = new { - val scalaDID = "0.1.0-M3" + val scalaDID = "0.1.0-M4" // val scalajsJavaSecureRandom = "1.0.0" // FIXME another bug in the test framework https://github.com/scalameta/munit/issues/554 diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MediatorCoordinationExecuter.scala b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MediatorCoordinationExecuter.scala index acbe2892..ddcfe424 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MediatorCoordinationExecuter.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MediatorCoordinationExecuter.scala @@ -75,8 +75,24 @@ object MediatorCoordinationExecuter extends ProtocolExecuterWithServices[Protoco } } yield SyncReplyOnly(m.makeKeylistResponse(updateResponse).toPlaintextMessage) case m: KeylistResponse => ZIO.logWarning("KeylistResponse") *> ZIO.succeed(NoReply) - case m: KeylistQuery => ZIO.logError("Not implemented KeylistQuery") *> ZIO.succeed(NoReply) // TODO - case m: Keylist => ZIO.logWarning("Keylist") *> ZIO.succeed(NoReply) + case m: KeylistQuery => + for { + _ <- ZIO.logInfo("KeylistQuery") + repo <- ZIO.service[UserAccountRepo] + mAccount <- repo.getDidAccount(m.from.toDID) + mResponse = mAccount.map { account => + Keylist( + thid = m.id, + from = m.to.asFROM, + to = m.from.asTO, + keys = account.alias.map(e => Keylist.RecipientDID(e)), + pagination = None, + ) + } + } yield mResponse match + case None => NoReply // TODO error report + case Some(response) => SyncReplyOnly(response.toPlaintextMessage) + case m: Keylist => ZIO.logWarning("Keylist") *> ZIO.succeed(NoReply) } match case Left(error) => ZIO.logError(error) *> ZIO.succeed(NoReply) case Right(program) => program