Skip to content

Commit

Permalink
fix: OutOfBand qrcode with base url (#133)
Browse files Browse the repository at this point in the history
* fix: OutOfBand qrcode with base url

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>

* flaky test fix moving the affect to zio

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>

---------

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>
Signed-off-by: Shailesh Patil <53746241+mineme0110@users.noreply.github.com>

Signed-off-by: Shailesh Patil <shailesh.patil@iohk.io>
  • Loading branch information
mineme0110 committed May 1, 2024
1 parent 1e6f824 commit 28df290
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ object EmbeddedMongoDBInstance {
val port = 27777
val hostIp = "localhost"
val connectionString = s"mongodb://$hostIp:$port/messages"
val index = Index(
key = Seq("alias" -> IndexType.Ascending),
name = Some("alias_did"),
unique = true,
background = true,
partialFilter = Some(BSONDocument("alias.0" -> BSONDocument("$exists" -> true)))
)

def layer(
port: Int = 27077,
hostIp: String = "localhost"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import zio.json.*
import zio.test.*
import zio.test.Assertion.*
import io.iohk.atala.mediator.db.EmbeddedMongoDBInstance.*
import io.iohk.atala.mediator.protocols.MessageSetup

import scala.concurrent.ExecutionContext.Implicits.global
object UserAccountRepoSpec extends ZIOSpecDefault with DidAccountStubSetup {
object UserAccountRepoSpec extends ZIOSpecDefault with DidAccountStubSetup with MessageSetup {

override def spec = suite("UserAccountRepoSpec")(
test("insert new Did Account") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ object ForwardMessageExecutorSpec extends ZIOSpecDefault with DidAccountStubSetu
.provideSomeLayer(AgentStub.agentLayer)
.provideLayerShared(dataAccessLayer) @@ TestAspect.sequential

def setupAndClean = {
for {
userAccount <- ZIO.service[UserAccountRepo]
col <- userAccount.collection
_ = col.indexesManager.create(index)
_ = col.delete.one(BSONDocument())
} yield {}
}


val dataAccessLayer = EmbeddedMongoDBInstance.layer(port, hostIp)
>>> AsyncDriverResource.layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,6 @@ object MediatorCoordinationExecuterSpec extends ZIOSpecDefault with DidAccountSt
.provideLayerShared(dataAccessLayer) @@ TestAspect.sequential
}

def setupAndClean = {
for {
userAccount <- ZIO.service[UserAccountRepo]
col <- userAccount.collection
_ <- ZIO.fromFuture { implicit ec =>
col.indexesManager.create(index)
}
_ <- ZIO.fromFuture { implicit ec =>
col.delete.one(BSONDocument())
}
} yield {}
}

val dataAccessLayer = EmbeddedMongoDBInstance.layer(port, hostIp)
>>> AsyncDriverResource.layer
>>> ReactiveMongoApi.layer(connectionString)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
package io.iohk.atala.mediator.protocols

import fmgp.did.comm.{EncryptedMessage, PlaintextMessage}
import io.iohk.atala.mediator.db.UserAccountRepo
import reactivemongo.api.bson.BSONDocument
import zio.ZIO
import zio.json.*
import reactivemongo.api.indexes.{Index, IndexType}
trait MessageSetup {

val index = Index(
key = Seq("alias" -> IndexType.Ascending),
name = Some("alias_did"),
unique = true,
background = true,
partialFilter = Some(BSONDocument("alias.0" -> BSONDocument("$exists" -> true)))
)
def setupAndClean = {
for {
userAccount <- ZIO.service[UserAccountRepo]
col <- userAccount.collection
_ <- ZIO.fromFuture { implicit ec =>
col.indexesManager.create(index)
}
_ <- ZIO.fromFuture { implicit ec =>
col.delete.one(BSONDocument())
}
} yield {}
}

val mediatorDid =
"did:peer:2.Ez6LSkGy3e2z54uP4U9HyXJXRpaF2ytsnTuVgh6SNNmCyGZQZ.Vz6Mkjdwvf9hWc6ibZndW9B97si92DSk9hWAhGYBgP9kUFk8Z.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9ib2IuZGlkLmZtZ3AuYXBwLyIsInIiOltdLCJhIjpbImRpZGNvbW0vdjIiXX0"
val plaintextForwardNotEnrolledDidMessage: Either[String, PlaintextMessage] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,6 @@ object PickupExecuterSpec extends ZIOSpecDefault with DidAccountStubSetup with M
.provideLayerShared(dataAccessLayer) @@ TestAspect.sequential
}

def setupAndClean = {
for {
userAccount <- ZIO.service[UserAccountRepo]
col <- userAccount.collection
_ <- ZIO.fromFuture { implicit ec =>
col.indexesManager.create(index)
}
_ <- ZIO.fromFuture { implicit ec =>
col.delete.one(BSONDocument())
}
} yield {}
}

val dataAccessLayer = EmbeddedMongoDBInstance.layer(port, hostIp)
>>> AsyncDriverResource.layer
>>> ReactiveMongoApi.layer(connectionString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ object MediatorInfo {
goal = Some("RequestMediate"),
accept = Some(Seq("didcomm/v2")),
)
val qrCodeData = OutOfBandPlaintext.from(invitation.toPlaintextMessage).makeURI("#/")
val host = dom.window.location.host
val scheme = dom.window.location.protocol
val fullPath = s"${scheme}//${host}"
val qrCodeData = OutOfBandPlaintext.from(invitation.toPlaintextMessage).makeURI(s"$fullPath")

val divQRCode = div()
{
Expand All @@ -35,7 +38,7 @@ object MediatorInfo {
code(invitation.from.value),
),
h3("Plaintext out of band invitation:"),
p(a(href := qrCodeData, target := "_blank", code(qrCodeData))), // FIXME make it a link to the mobile app
p(a(href := fullPath, target := "_blank", code(qrCodeData))), // FIXME make it a link to the mobile app
pre(code(invitation.toPlaintextMessage.toJsonPretty)),
p(
"To facilitate the integration with other systems you can get the plain text invitation and the out-of-band invitation on the following endpoints:",
Expand Down

0 comments on commit 28df290

Please sign in to comment.