-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mediator rename package and refactoring (#41)
* Refactoring the package * TrustPingExecutor moved to seprated file and package * Moved all the protocols executor to protocol package
- Loading branch information
1 parent
116174b
commit c755c99
Showing
11 changed files
with
142 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
mediator/src/main/scala/io/iohk/atala/mediator/protocols/BasicMessageExecuter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.iohk.atala.mediator.protocols | ||
|
||
import fmgp.crypto.error.FailToParse | ||
import fmgp.did.comm.{PIURI, PlaintextMessage} | ||
import fmgp.did.comm.protocol.basicmessage2.BasicMessage | ||
import io.iohk.atala.mediator.{MediatorDidError, MediatorThrowable} | ||
import io.iohk.atala.mediator.actions.{NoReply, ProtocolExecuter} | ||
import zio.{Console, ZIO} | ||
|
||
object BasicMessageExecuter extends ProtocolExecuter[Any] { | ||
|
||
override def suportedPIURI: Seq[PIURI] = Seq(BasicMessage.piuri) | ||
override def program[R1 <: Any](plaintextMessage: PlaintextMessage) = for { | ||
job <- BasicMessage.fromPlaintextMessage(plaintextMessage) match | ||
case Left(error) => ZIO.fail(MediatorDidError(FailToParse(error))) | ||
case Right(bm) => Console.printLine(bm.toString).mapError(ex => MediatorThrowable(ex)) | ||
} yield NoReply | ||
} |
13 changes: 13 additions & 0 deletions
13
mediator/src/main/scala/io/iohk/atala/mediator/protocols/NullProtocolExecuter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.iohk.atala.mediator.protocols | ||
|
||
import fmgp.did.comm.PlaintextMessage | ||
import io.iohk.atala.mediator.MissingProtocolError | ||
import io.iohk.atala.mediator.actions.ProtocolExecuter | ||
import zio.ZIO | ||
|
||
object NullProtocolExecuter extends ProtocolExecuter[Any] { | ||
|
||
override def suportedPIURI = Seq() | ||
override def program[R1 <: Any](plaintextMessage: PlaintextMessage) = | ||
ZIO.fail(MissingProtocolError(plaintextMessage.`type`)) | ||
} |
46 changes: 46 additions & 0 deletions
46
mediator/src/main/scala/io/iohk/atala/mediator/protocols/TrustPingExecuter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.iohk.atala.mediator.protocols | ||
|
||
import fmgp.crypto.error.FailToParse | ||
import fmgp.did.Agent | ||
import fmgp.did.comm.{PIURI, PlaintextMessage} | ||
import fmgp.did.comm.protocol.trustping2.{ | ||
TrustPing, | ||
TrustPingResponse, | ||
TrustPingWithOutRequestedResponse, | ||
TrustPingWithRequestedResponse | ||
} | ||
import io.iohk.atala.mediator.{MediatorDidError, MediatorError} | ||
import io.iohk.atala.mediator.actions.{Action, NoReply, ProtocolExecuter, ProtocolExecuterWithServices, Reply} | ||
import zio.ZIO | ||
|
||
class TrustPingExecuter extends ProtocolExecuterWithServices[ProtocolExecuter.Services] { | ||
|
||
override def suportedPIURI: Seq[PIURI] = Seq(TrustPing.piuri, TrustPingResponse.piuri) | ||
|
||
override def program[R1 <: Agent]( | ||
plaintextMessage: PlaintextMessage | ||
): ZIO[R1, MediatorError, Action] = { | ||
// the val is from the match to be definitely stable | ||
val piuriTrustPing = TrustPing.piuri | ||
val piuriTrustPingResponse = TrustPingResponse.piuri | ||
|
||
plaintextMessage.`type` match | ||
case `piuriTrustPing` => | ||
TrustPing.fromPlaintextMessage(plaintextMessage) match | ||
case Left(error) => ZIO.fail(MediatorDidError(FailToParse(error))) | ||
case Right(ping: TrustPingWithOutRequestedResponse) => ZIO.logInfo(ping.toString()) *> ZIO.succeed(NoReply) | ||
case Right(ping: TrustPingWithRequestedResponse) => | ||
for { | ||
_ <- ZIO.logInfo(ping.toString()) | ||
agent <- ZIO.service[Agent] | ||
ret = ping.makeRespond | ||
} yield Reply(ret.toPlaintextMessage) | ||
case `piuriTrustPingResponse` => | ||
for { | ||
job <- TrustPingResponse.fromPlaintextMessage(plaintextMessage) match | ||
case Left(error) => ZIO.fail(MediatorDidError(FailToParse(error))) | ||
case Right(ping) => ZIO.logInfo(ping.toString()) | ||
} yield NoReply | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
webapp/src/main/scala/fmgp/webapp/App.scala → ...in/scala/io/iohk/atala/mediator/App.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package fmgp.webapp | ||
package io.iohk.atala.mediator | ||
|
||
import scala.scalajs.js.annotation._ | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...src/main/scala/fmgp/webapp/AppUtils.scala → ...ala/io/iohk/atala/mediator/AppUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...p/src/main/scala/fmgp/webapp/Global.scala → ...scala/io/iohk/atala/mediator/Global.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
webapp/src/main/scala/io/iohk/atala/mediator/MyRouter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.iohk.atala.mediator | ||
|
||
import com.raquo.laminar.api.L.{_, given} | ||
import com.raquo.waypoint._ | ||
import org.scalajs.dom | ||
import upickle.default._ | ||
|
||
object MyRouter { | ||
sealed abstract class Page( | ||
val title: String, | ||
val icon: String // https://fonts.google.com/icons?selected=Material+Icons+Outlined | ||
) | ||
|
||
case object MediatorPage extends Page("Mediator", "diversity_3") | ||
|
||
given mediatorPageRW: ReadWriter[MediatorPage.type] = macroRW | ||
|
||
given rw: ReadWriter[Page] = macroRW | ||
|
||
private val routes = List( | ||
// // http://localhost:8080/?_oob=eyJ0eXBlIjoiaHR0cHM6Ly9kaWRjb21tLm9yZy9vdXQtb2YtYmFuZC8yLjAvaW52aXRhdGlvbiIsImlkIjoiNTk5ZjM2MzgtYjU2My00OTM3LTk0ODctZGZlNTUwOTlkOTAwIiwiZnJvbSI6ImRpZDpleGFtcGxlOnZlcmlmaWVyIiwiYm9keSI6eyJnb2FsX2NvZGUiOiJzdHJlYW1saW5lZC12cCIsImFjY2VwdCI6WyJkaWRjb21tL3YyIl19fQ | ||
Route.static(MediatorPage, root / endOfSegments, Router.localFragmentBasePath), | ||
) | ||
|
||
val router = new Router[Page]( | ||
routes = routes, | ||
getPageTitle = _.title, // displayed in the browser tab next to favicon | ||
serializePage = page => write(page)(rw), // serialize page data for storage in History API log | ||
deserializePage = pageStr => read(pageStr)(rw), // deserialize the above | ||
// routeFallback = { (_: String) => HomePage }, | ||
routeFallback = { (_: String) => MediatorPage }, | ||
)( | ||
popStateEvents = windowEvents(_.onPopState), // this is how Waypoint avoids an explicit dependency on Laminar | ||
owner = unsafeWindowOwner // this router will live as long as the window | ||
) | ||
|
||
// Note: for fragment ('#') URLs this isn't actually needed. | ||
// See https://github.com/raquo/Waypoint docs for why this modifier is useful in general. | ||
def navigateTo(page: Page): Binder[HtmlElement] = Binder { el => | ||
|
||
val isLinkElement = el.ref.isInstanceOf[dom.html.Anchor] | ||
|
||
if (isLinkElement) { | ||
el.amend(href(router.absoluteUrlForPage(page))) | ||
} | ||
|
||
// If element is a link and user is holding a modifier while clicking: | ||
// - Do nothing, browser will open the URL in new tab / window / etc. depending on the modifier key | ||
// Otherwise: | ||
// - Perform regular pushState transition | ||
(onClick | ||
.filter(ev => !(isLinkElement && (ev.ctrlKey || ev.metaKey || ev.shiftKey || ev.altKey))) | ||
.preventDefault | ||
--> (_ => router.pushState(page))).bind(el) | ||
} | ||
} |