Skip to content

Commit 0f5070d

Browse files
authored
fix: upgrade zio http, update reactive mongo driver RC15 and scala version to 3.6.4 (#472)
Signed-off-by: mineme0110 <shailesh.patil@iohk.io>
1 parent e83f121 commit 0f5070d

File tree

17 files changed

+131
-96
lines changed

17 files changed

+131
-96
lines changed

build.sbt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ resolvers ++= Resolver.sonatypeOssRepos("snapshots")
44

55
inThisBuild(
66
Seq(
7-
scalaVersion := "3.3.3", // Also update docs/publishWebsite.sh and any ref to scala-3.3.3
7+
scalaVersion := "3.6.4", // Also update docs/publishWebsite.sh and any ref to scala-3.6.3
88
versionScheme := Some("semver-spec"), // https://www.scala-sbt.org/1.x/docs/Publishing.html#Version+scheme
99
)
1010
)
1111

1212
/** Versions */
1313
lazy val V = new {
14-
val scalaDID = "0.1.0-M19"
14+
val scalaDID = "0.1.0-M26"
1515

1616
// FIXME another bug in the test framework https://github.com/scalameta/munit/issues/554
1717
val munit = "1.0.0" // "0.7.29"
@@ -21,16 +21,16 @@ lazy val V = new {
2121

2222
// // https://mvnrepository.com/artifact/dev.zio/zio
2323
val zio = "2.1.5"
24-
val zioJson = "0.7.1"
24+
val zioJson = "0.7.42"
2525
// val zioMunitTest = "0.1.1"
26-
val zioHttp = "3.0.0-RC6"
27-
val zioConfig = "4.0.1"
26+
val zioHttp = "3.3.3"
27+
val zioConfig = "4.0.4"
2828
val zioLogging = "2.2.4"
2929
val zioSl4j = "2.2.2"
3030
val logback = "1.5.6"
3131
val logstash = "7.4"
3232
val jansi = "2.4.1"
33-
val mongo = "1.1.0-RC10"
33+
val mongo = "1.1.0-RC15"
3434
val embedMongo = "4.14.0"
3535
val munitZio = "0.1.1"
3636
val zioTest = "2.1.5"
@@ -51,6 +51,7 @@ lazy val D = new {
5151
val scalaDID_imp = Def.setting("app.fmgp" %%% "did-imp" % V.scalaDID)
5252
val scalaDID_peer = Def.setting("app.fmgp" %%% "did-method-peer" % V.scalaDID)
5353
val scalaDID_framework = Def.setting("app.fmgp" %%% "did-framework" % V.scalaDID)
54+
val scalaDID_protocols = Def.setting("app.fmgp" %%% "did-comm-protocols" % V.scalaDID)
5455

5556
// /** The [[java.security.SecureRandom]] is used by the [[java.util.UUID.randomUUID()]] method in [[MsgId]].
5657
// *
@@ -207,6 +208,7 @@ lazy val mediator = project
207208
libraryDependencies += D.scalaDID_imp.value,
208209
libraryDependencies += D.scalaDID_peer.value,
209210
libraryDependencies += D.scalaDID_framework.value,
211+
libraryDependencies += D.scalaDID_protocols.value,
210212
libraryDependencies += D.zioHttp.value,
211213
libraryDependencies ++= Seq(
212214
D.zioConfig.value,
@@ -272,7 +274,7 @@ lazy val webapp = project
272274
.settings(
273275
libraryDependencies ++= Seq(D.laminar.value, D.waypoint.value, D.upickle.value),
274276
libraryDependencies ++= Seq(D.zio.value, D.zioJson.value),
275-
libraryDependencies ++= Seq(D.scalaDID.value, D.scalaDID_peer.value),
277+
libraryDependencies ++= Seq(D.scalaDID.value, D.scalaDID_peer.value, D.scalaDID_protocols.value),
276278
Compile / npmDependencies ++= NPM.qrcode ++ NPM.materialDesign ++ NPM.sha256,
277279
)
278280
.settings(

mediator/src/main/scala/org/hyperledger/identus/mediator/AgentExecutorMediator.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import fmgp.did.framework._
1313
import org.hyperledger.identus.mediator.db.{UserAccountRepo, MessageItemRepo}
1414
import org.hyperledger.identus.mediator.protocols.Problems
1515
import fmgp.did.comm.protocol.reportproblem2.ProblemReport
16+
import fmgp.did.method.peer.DIDPeer.AgentDIDPeer
17+
import fmgp.did.framework.AgentProgram
1618

1719
case class AgentExecutorMediator(
1820
agent: Agent,
@@ -21,7 +23,7 @@ case class AgentExecutorMediator(
2123
userAccountRepo: UserAccountRepo,
2224
messageItemRepo: MessageItemRepo,
2325
scope: Scope,
24-
) extends AgentExecutar {
26+
) extends AgentProgram {
2527
val indentityLayer = ZLayer.succeed(agent)
2628
val userAccountRepoLayer = ZLayer.succeed(userAccountRepo)
2729
val messageItemRepoLayer = ZLayer.succeed(messageItemRepo)
@@ -261,7 +263,7 @@ object AgentExecutorMediator {
261263
userAccountRepo: UserAccountRepo,
262264
messageItemRepo: MessageItemRepo,
263265
scope: Scope,
264-
): ZIO[TransportFactory, Nothing, AgentExecutar] =
266+
): ZIO[TransportFactory, Nothing, AgentProgram] =
265267
for {
266268
_ <- ZIO.logInfo(s"Make Madiator AgentExecutor for ${agent.id}")
267269
transportManager <- MediatorTransportManager.make

mediator/src/main/scala/org/hyperledger/identus/mediator/DIDCommRoutes.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package org.hyperledger.identus.mediator
22

3-
import zio._
4-
import zio.json._
5-
import zio.stream._
6-
import zio.http._
7-
import zio.http.Header.{AccessControlAllowOrigin, AccessControlAllowMethods}
8-
9-
import fmgp.crypto._
10-
import fmgp.crypto.error._
11-
import fmgp.did._
12-
import fmgp.did.comm._
13-
import fmgp.did.framework._
14-
import fmgp.did.method.peer.DidPeerResolver
3+
import fmgp.crypto.*
4+
import fmgp.crypto.error.*
5+
import fmgp.did.*
6+
import fmgp.did.comm.*
7+
import fmgp.did.framework.*
158
import fmgp.did.method.peer.DIDPeer.AgentDIDPeer
9+
import fmgp.did.method.peer.DidPeerResolver
10+
import zio.*
11+
import zio.http.*
12+
import zio.http.Header.AccessControlAllowMethods
13+
import zio.http.Header.AccessControlAllowOrigin
14+
import zio.json.*
15+
import zio.stream.*
1616

1717
object DIDCommRoutes {
1818

19-
def app: HttpApp[Operator & Operations & Resolver & Scope] = routes.@@(TraceIdMiddleware.addTraceId).toHttpApp
20-
19+
def app: Routes[Operator & Operations & Resolver, Nothing] =
20+
routes @@ TraceIdMiddleware.addTraceId
2121
def routes: Routes[Operator & Operations & Resolver, Nothing] = Routes(
2222
Method.GET / "ws" -> handler { (req: Request) =>
2323
for {
@@ -74,7 +74,8 @@ object DIDCommRoutes {
7474
} yield ret)
7575
.tapErrorCause(ZIO.logErrorCause("Error", _))
7676
.catchAllCause(cause => ZIO.succeed(Response.fromCause(cause)))
77-
case Some(_) | None => ZIO.succeed(Response.badRequest(s"The content-type must be $SignedTyp or $EncryptedTyp"))
77+
case Some(_) | None =>
78+
ZIO.succeed(Response.badRequest(s"The content-type must be $SignedTyp or $EncryptedTyp"))
7879
},
7980
)
8081
}

mediator/src/main/scala/org/hyperledger/identus/mediator/MediatorAgent.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ import fmgp.did.comm.*
77
import fmgp.did.comm.protocol.*
88
import fmgp.did.comm.protocol.oobinvitation.OOBInvitation
99
import fmgp.did.comm.protocol.reportproblem2.ProblemReport
10+
import io.netty.handler.codec.http.HttpHeaderNames
1011
import org.hyperledger.identus.mediator.*
1112
import org.hyperledger.identus.mediator.db.*
1213
import org.hyperledger.identus.mediator.protocols.*
13-
import io.netty.handler.codec.http.HttpHeaderNames
1414
import reactivemongo.api.bson.{*, given}
1515
import zio.*
1616
import zio.http.*
17+
import zio.http.*
18+
import zio.http.Header.AccessControlAllowMethods
19+
import zio.http.Header.AccessControlAllowOrigin
20+
import zio.http.Header.HeaderType
1721
import zio.json.*
1822

1923
import scala.concurrent.ExecutionContext.Implicits.global
20-
import scala.util.Try
2124
import scala.io.Source
22-
import zio.http.Header.AccessControlAllowOrigin
23-
import zio.http.Header.AccessControlAllowMethods
24-
import zio.http.Header.HeaderType
25+
import scala.util.Try
2526

2627
case class MediatorAgent(
2728
override val id: DID,
@@ -30,7 +31,8 @@ case class MediatorAgent(
3031

3132
object MediatorAgent {
3233

33-
def didCommApp = didCommAppAux.@@(TraceIdMiddleware.addTraceId).toHttpApp
34+
def didCommApp =
35+
didCommAppAux @@ TraceIdMiddleware.addTraceId
3436

3537
def make(id: DID, keyStore: KeyStore): ZIO[Any, Nothing, MediatorAgent] = ZIO.succeed(MediatorAgent(id, keyStore))
3638

mediator/src/main/scala/org/hyperledger/identus/mediator/MediatorStandalone.scala

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package org.hyperledger.identus.mediator
22

33
import fmgp.crypto.*
4+
import fmgp.crypto.OKPPrivateKey.*
5+
import fmgp.crypto.OKPPrivateKeyWithKid.*
46
import fmgp.crypto.error.*
57
import fmgp.did.*
68
import fmgp.did.comm.*
79
import fmgp.did.comm.protocol.*
8-
import fmgp.did.method.peer.*
910
import fmgp.did.framework.TransportFactoryImp
11+
import fmgp.did.method.peer.*
1012
import org.hyperledger.identus.mediator.db.*
1113
import org.hyperledger.identus.mediator.protocols.*
1214
import zio.*
13-
import zio.stream.*
1415
import zio.config.*
1516
import zio.config.magnolia.*
1617
import zio.config.typesafe.*
@@ -19,10 +20,39 @@ import zio.json.*
1920
import zio.logging.*
2021
import zio.logging.LogFormat.*
2122
import zio.logging.backend.SLF4J
23+
import zio.stream.*
2224

2325
import java.time.format.DateTimeFormatter
2426
import scala.io.Source
25-
case class MediatorConfig(endpoints: String, keyAgreement: OKPPrivateKey, keyAuthentication: OKPPrivateKey) {
27+
28+
object CurveConfig:
29+
30+
// Config for OKPCurve union type
31+
given okpCurveConfig: Config[OKPCurve] =
32+
Config.string.mapOrFail:
33+
case "X25519" => Right(Curve.X25519)
34+
case "Ed25519" => Right(Curve.Ed25519)
35+
case other => Left(Config.Error.InvalidData(message = s"Invalid OKP curve: $other. Expected X25519 or Ed25519"))
36+
37+
// Config for ECCurve union type
38+
given ecCurveConfig: Config[ECCurve] =
39+
Config.string.mapOrFail:
40+
case "P-256" => Right(Curve.`P-256`)
41+
case "P-384" => Right(Curve.`P-384`)
42+
case "P-521" => Right(Curve.`P-521`)
43+
case "secp256k1" => Right(Curve.secp256k1)
44+
case other =>
45+
Left(
46+
Config.Error.InvalidData(message = s"Invalid EC curve: $other. Expected P-256, P-384, P-521, or secp256k1")
47+
)
48+
49+
import CurveConfig.given
50+
51+
case class MediatorConfig(
52+
endpoints: String,
53+
keyAgreement: OKPPrivateKeyWithoutKid,
54+
keyAuthentication: OKPPrivateKeyWithoutKid
55+
) {
2656
val did = DIDPeer2.makeAgent(
2757
Seq(keyAgreement, keyAuthentication),
2858
endpoints
@@ -34,6 +64,7 @@ case class MediatorConfig(endpoints: String, keyAgreement: OKPPrivateKey, keyAut
3464
val agentLayer: ZLayer[Any, Nothing, MediatorAgent] =
3565
ZLayer(MediatorAgent.make(id = did.id, keyStore = did.keyStore))
3666
}
67+
3768
case class DataBaseConfig(
3869
protocol: String,
3970
host: String,
@@ -97,9 +128,8 @@ object MediatorStandalone extends ZIOAppDefault {
97128
.provideSomeLayer(DidPeerResolver.layerDidPeerResolver)
98129
.provideSomeLayer(agentLayer)
99130
.provideSomeLayer(repos)
100-
.provideSomeLayer((agentLayer ++ transportFactory ++ repos ++ Scope.default) >>> OperatorImp.layer)
101-
.provideSomeLayer(Operations.layerDefault)
102-
.provideSomeLayer(Scope.default)
131+
.provideSomeLayer(Scope.default >>> ((agentLayer ++ transportFactory ++ repos) >>> OperatorImp.layer))
132+
.provideSomeLayer(Operations.layerOperations)
103133
.provide(Server.defaultWithPort(port))
104134
.debug
105135
.fork

mediator/src/main/scala/org/hyperledger/identus/mediator/TraceIdMiddleware.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ object TraceIdMiddleware {
1414
.map(h => LogAnnotation(NAME_TRACE_ID, h.renderedValue))
1515
)
1616

17-
def addTraceId = {
18-
HandlerAspect.interceptHandler(
17+
def addTraceId[R] = {
18+
HandlerAspect.interceptHandler[R, Unit](
1919
Handler.fromFunctionZIO[Request] { request =>
20-
val effect = requestId(request)
21-
effect.map(_ => (request, ()))
20+
ZIO.scoped {
21+
requestId(request).map(_ => (request, ()))
22+
}
2223
}
2324
)(Handler.identity)
2425
}

mediator/src/main/scala/org/hyperledger/identus/mediator/db/BsonImplicits.scala

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import fmgp.did.*
55
import fmgp.did.comm.*
66
import fmgp.did.comm.extension.*
77
import fmgp.util.*
8+
import reactivemongo.api.bson.*
89
import zio.json.*
910
import zio.json.ast.Json
10-
import reactivemongo.api.bson.*
1111

1212
import scala.util.*
1313

@@ -160,25 +160,24 @@ given BSONReader[MediaTypes] with {
160160
given BSONDocumentWriter[PublicKey] with {
161161
override def writeTry(obj: PublicKey): Try[BSONDocument] =
162162
obj match {
163-
case ECPublicKey(kty, crv, x, y, kid) =>
163+
case key: ECPublicKey =>
164164
Try(
165165
BSONDocument(
166-
"kty" -> kty,
167-
"crv" -> crv,
168-
"x" -> x,
169-
"y" -> y,
170-
"kid" -> kid,
166+
"kty" -> key.kty,
167+
"crv" -> key.crv,
168+
"x" -> key.x,
169+
"y" -> key.y
171170
)
172171
)
173-
case OKPPublicKey(kty, crv, x, kid) =>
172+
case key: OKPPublicKey =>
174173
Try(
175174
BSONDocument(
176-
"kty" -> kty,
177-
"crv" -> crv,
178-
"x" -> x,
179-
"kid" -> kid,
175+
"kty" -> key.kty,
176+
"crv" -> key.crv,
177+
"x" -> key.x
180178
)
181179
)
180+
case null => Failure(new RuntimeException("PublicKey cannot be null"))
182181
}
183182
}
184183
given BSONDocumentReader[PublicKey] with {
@@ -195,9 +194,9 @@ given BSONDocumentReader[PublicKey] with {
195194
Success(
196195
OKPPublicKey(
197196
kty = KTY.OKP,
198-
crv = crv,
197+
crv = crv.asOKPCurve,
199198
x = x,
200-
kid = doc.getAsOpt[String]("kid")
199+
kid = doc.getAsOpt[String]("kid").orNull
201200
)
202201
)
203202
case (Failure(ex), _) => Failure(ex)
@@ -212,10 +211,10 @@ given BSONDocumentReader[PublicKey] with {
212211
Success(
213212
ECPublicKey(
214213
kty = KTY.EC,
215-
crv = crv,
214+
crv = crv.asECCurve,
216215
x = x,
217216
y = y,
218-
kid = doc.getAsOpt[String]("kid")
217+
kid = doc.getAsOpt[String]("kid").orNull
219218
)
220219
)
221220
case (Failure(ex), _, _) => Failure(ex)
@@ -264,11 +263,11 @@ given BSONReader[Payload] with {
264263
def readTry(bson: BSONValue): Try[Payload] = bson.asTry[String].map(v => Payload.fromBase64url(v))
265264
}
266265

267-
given BSONWriter[SigningAlgorithm] with {
268-
def writeTry(obj: SigningAlgorithm): Try[BSONValue] = Try(BSONString(obj.toString()))
266+
given BSONWriter[JWAAlgorithm] with {
267+
def writeTry(obj: JWAAlgorithm): Try[BSONValue] = Try(BSONString(obj.toString()))
269268
}
270-
given BSONReader[SigningAlgorithm] with {
271-
def readTry(bson: BSONValue): Try[SigningAlgorithm] = bson.asTry[String].map(v => SigningAlgorithm.valueOf(v))
269+
given BSONReader[JWAAlgorithm] with {
270+
def readTry(bson: BSONValue): Try[JWAAlgorithm] = bson.asTry[String].map(v => JWAAlgorithm.valueOf(v))
272271
}
273272

274273
given BSONDocumentWriter[SignProtectedHeader] = Macros.writer[SignProtectedHeader]
@@ -364,7 +363,7 @@ given BSONReader[FROM] with {
364363
}
365364

366365
//JSON_RFC7159
367-
def sequenceTrys[T](trySequence: Seq[_ <: Try[_ <: T]]): Try[Seq[T]] = {
366+
def sequenceTrys[T](trySequence: Seq[? <: Try[? <: T]]): Try[Seq[T]] = {
368367
trySequence.foldLeft(Try(Seq.empty[T])) { (acc, tryElement) =>
369368
acc.flatMap(accSeq => tryElement.map(success => accSeq :+ success))
370369
}
@@ -380,8 +379,8 @@ def toBSON(j: Json): Try[BSONValue] = j match
380379

381380
def toJson(b: BSONValue): Try[Json] = b match
382381
case doc: BSONDocument =>
383-
sequenceTrys(doc.toMap.toSeq.map(e => toJson(e._2).map(e2 => (e._1, e2)))).map(Json.Obj(_: _*))
384-
case array: BSONArray => sequenceTrys(array.values.map(toJson(_))).map(Json.Arr(_: _*))
382+
sequenceTrys(doc.toMap.toSeq.map(e => toJson(e._2).map(e2 => (e._1, e2)))).map(Json.Obj(_*))
383+
case array: BSONArray => sequenceTrys(array.values.map(toJson(_))).map(Json.Arr(_*))
385384
case e: BSONDouble => e.toDouble.map(Json.Num(_))
386385
case e: BSONInteger => e.toDouble.map(Json.Num(_))
387386
case e: BSONLong => e.toDouble.map(Json.Num(_))
@@ -408,7 +407,7 @@ given BSONWriter[JSON_RFC7159] with {
408407
given BSONReader[JSON_RFC7159] with {
409408
def readTry(bson: BSONValue): Try[JSON_RFC7159] =
410409
bson.asTry[BSONDocument].flatMap { doc =>
411-
sequenceTrys(doc.toMap.toSeq.map(e => toJson(e._2).map(e2 => (e._1, e2)))).map(Json.Obj(_: _*))
410+
sequenceTrys(doc.toMap.toSeq.map(e => toJson(e._2).map(e2 => (e._1, e2)))).map(Json.Obj(_*))
412411
}
413412
}
414413

0 commit comments

Comments
 (0)