Skip to content

Commit

Permalink
feat: add endpoint to get the OOB mediate invitation (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Pinheiro <fabiomgpinheiro@gmail.com>

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>
  • Loading branch information
FabioPinheiro authored and mineme0110 committed May 1, 2024
1 parent dd27b27 commit 11ef6d1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mediator/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<withJansi>true</withJansi>
<encoder>
<!-- TODO include mediator release version in the logs />-->
<pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%highlight(%-5level)] %cyan(%logger{5}@[%-4.30thread]) msgHash[%X{msgHash}] - %msg%xException%n</pattern>
<pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%highlight(%-5level)] %cyan(%logger{5}@L%line:[%-4.30thread]) %mdc - %msg%xException%n</pattern>
</encoder>
</appender>
<appender name="logstash" class="ch.qos.logback.core.ConsoleAppender">
Expand All @@ -17,6 +17,6 @@
</turboFilter>
<root level="info">
<appender-ref ref="STDOUT" />
<!-- <appender-ref ref="logstash" />-->
<!-- <appender-ref ref="logstash" /> -->
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fmgp.crypto.error.*
import fmgp.did.*
import fmgp.did.comm.*
import fmgp.did.comm.protocol.*
import fmgp.did.comm.protocol.oobinvitation.OOBInvitation
import io.iohk.atala.mediator.*
import io.iohk.atala.mediator.actions.*
import io.iohk.atala.mediator.comm.*
Expand All @@ -23,6 +24,7 @@ import zio.json.*
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Try
import scala.io.Source

case class MediatorAgent(
override val id: DID,
override val keyStore: KeyStore, // Should we make it lazy with ZIO
Expand Down Expand Up @@ -233,6 +235,38 @@ object MediatorAgent {
annotationMap <- ZIO.logAnnotations.map(_.map(e => LogAnnotation(e._1, e._2)).toSeq)
ret <- agent.websocketListenerApp(annotationMap)
} yield (ret)
case Method.GET -> !! / "invitation" =>
for {
agent <- ZIO.service[MediatorAgent]
annotationMap <- ZIO.logAnnotations.map(_.map(e => LogAnnotation(e._1, e._2)).toSeq)
invitation = OOBInvitation(
from = agent.id,
goal_code = Some("request-mediate"),
goal = Some("RequestMediate"),
accept = Some(Seq("didcomm/v2")),
)
_ <- ZIO.log("New mediate invitation MsgID: " + invitation.id.value)
ret <- ZIO.succeed(Response.json(invitation.toPlaintextMessage.toJson))

} yield (ret)
case Method.GET -> !! / "invitationOOB" =>
for {
agent <- ZIO.service[MediatorAgent]
annotationMap <- ZIO.logAnnotations.map(_.map(e => LogAnnotation(e._1, e._2)).toSeq)
invitation = OOBInvitation(
from = agent.id,
goal_code = Some("request-mediate"),
goal = Some("RequestMediate"),
accept = Some(Seq("didcomm/v2")),
)
_ <- ZIO.log("New mediate invitation MsgID: " + invitation.id.value)
ret <- ZIO.succeed(
Response.text(
OutOfBandPlaintext.from(invitation.toPlaintextMessage).makeURI("")
)
)

} yield (ret)
case req @ Method.POST -> !! if req.headersAsList.exists { h =>
h.key.toString.toLowerCase == "content-type" &&
(h.value.toString.startsWith(MediaTypes.SIGNED.typ) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ object MediatorInfo {
h3("Plaintext out of band invitation:"),
p(a(href := qrCodeData, target := "_blank", code(qrCodeData))), // FIXME make it a link to the mobile app
pre(code(invitation.toPlaintextMessage.toJsonPretty)),
pre(
"To facilitate the integration with other systems you can get the plain text invitation and the out-of-band invitation on the following endpoints:",
" '/invitation' and '/invitationOOB'"
),
divQRCode,
h3("Signed out of band invitation:"),
code("TODO"),
Expand Down

0 comments on commit 11ef6d1

Please sign in to comment.