Skip to content

Commit

Permalink
chore: run scalafmt
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Voiturier <benjamin.voiturier@iohk.io>
  • Loading branch information
bvoiturier committed Dec 10, 2024
1 parent e0ac2f4 commit c780920
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.hyperledger.identus.iam.authentication.AuthenticationError.{
InvalidCredentials
}
import org.hyperledger.identus.shared.utils.Traverse.*
import pdi.jwt.{JwtZIOJson, JwtClaim, JwtOptions}
import pdi.jwt.{JwtClaim, JwtOptions, JwtZIOJson}
import zio.*
import zio.json.ast.Json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.networknt.schema.{JsonSchema, SpecVersion}
import org.hyperledger.identus.shared.json.{JsonPath, JsonPathError, JsonSchemaError, JsonSchemaUtils}
import zio.*
import zio.json.{JsonDecoder, JsonEncoder}
import zio.json.ast.Json as ZioJson
import zio.json.ast.Json

opaque type JsonPathValue = String

Expand All @@ -20,16 +20,16 @@ object JsonPathValue {
}
}

opaque type FieldFilter = ZioJson
opaque type FieldFilter = Json

object FieldFilter {
given Conversion[ZioJson, FieldFilter] = identity
given Conversion[Json, FieldFilter] = identity

given JsonEncoder[FieldFilter] = ZioJson.encoder
given JsonDecoder[FieldFilter] = ZioJson.decoder
given JsonEncoder[FieldFilter] = Json.encoder
given JsonDecoder[FieldFilter] = Json.decoder

extension (f: FieldFilter)
def asJsonZio: ZioJson = f
def asJsonZio: Json = f

// Json schema draft 7 must be used
// https://identity.foundation/presentation-exchange/spec/v2.1.1/#json-schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.hyperledger.identus.pollux.vc.jwt.{JWT, JwtCredential, JwtPresentatio
import org.hyperledger.identus.shared.json.{JsonPathError, JsonSchemaValidatorImpl}
import org.hyperledger.identus.shared.models.{Failure, StatusCode}
import zio.*
import zio.json.ast.Json as ZioJson
import zio.json.ast.Json
import zio.json.EncoderOps

sealed trait PresentationSubmissionError extends Failure {
Expand Down Expand Up @@ -81,7 +81,7 @@ object PresentationSubmissionVerification {
def verify(
pd: PresentationDefinition,
ps: PresentationSubmission,
rootTraversalObject: ZioJson,
rootTraversalObject: Json,
)(formatVerification: ClaimFormatVerification): IO[PresentationSubmissionError, Unit] = {
for {
_ <- verifySubmissionId(pd, ps)
Expand Down Expand Up @@ -118,7 +118,7 @@ object PresentationSubmissionVerification {

private def verifyInputConstraints(
pd: PresentationDefinition,
entries: Seq[(String, ZioJson)]
entries: Seq[(String, Json)]
): IO[PresentationSubmissionError, Unit] = {
val descriptorLookup = pd.input_descriptors.map(d => d.id -> d).toMap
val descriptorWithEntry = entries.flatMap { case (id, entry) => descriptorLookup.get(id).map(_ -> entry) }
Expand All @@ -131,7 +131,7 @@ object PresentationSubmissionVerification {

private def verifyInputConstraint(
descriptor: InputDescriptor,
entry: ZioJson
entry: Json
): IO[PresentationSubmissionError, Unit] = {
val mandatoryFields = descriptor.constraints.fields
.getOrElse(Nil)
Expand All @@ -156,9 +156,9 @@ object PresentationSubmissionVerification {
}

private def extractSubmissionEntry(
traversalObject: ZioJson,
traversalObject: Json,
descriptor: InputDescriptorMapping
)(formatVerification: ClaimFormatVerification): IO[PresentationSubmissionError, ZioJson] = {
)(formatVerification: ClaimFormatVerification): IO[PresentationSubmissionError, Json] = {
for {
path <- ZIO
.fromEither(descriptor.path.toJsonPath)
Expand All @@ -179,9 +179,9 @@ object PresentationSubmissionVerification {
}

private def verifyJwtVc(
json: ZioJson,
json: Json,
path: JsonPathValue
)(formatVerification: JWT => IO[String, Unit]): IO[PresentationSubmissionError, ZioJson] = {
)(formatVerification: JWT => IO[String, Unit]): IO[PresentationSubmissionError, Json] = {
val format = ClaimFormatValue.jwt_vc
for {
jwt <- ZIO
Expand All @@ -197,9 +197,9 @@ object PresentationSubmissionVerification {
}

private def verifyJwtVp(
json: ZioJson,
json: Json,
path: JsonPathValue
)(formatVerification: JWT => IO[String, Unit]): IO[PresentationSubmissionError, ZioJson] = {
)(formatVerification: JWT => IO[String, Unit]): IO[PresentationSubmissionError, Json] = {
val format = ClaimFormatValue.jwt_vp
for {
jwt <- ZIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.hyperledger.identus.shared.crypto.{Ed25519KeyPair, Secp256k1PrivateKe
import org.hyperledger.identus.shared.models.KeyId
import zio.*
import zio.json.{EncoderOps, JsonDecoder, JsonEncoder}
import zio.json.ast.Json as ZioJson
import zio.json.ast.Json

import java.security.*
import java.security.interfaces.ECPublicKey
Expand Down Expand Up @@ -41,9 +41,9 @@ object JwtSignerImplicits {
}

trait Signer {
def encode(claim: ZioJson): JWT
def encode(claim: Json): JWT

def generateProofForJson(payload: ZioJson, pk: PublicKey): Task[Proof]
def generateProofForJson(payload: Json, pk: PublicKey): Task[Proof]
}

// works with java 7, 8, 11 & bouncycastle provider
Expand All @@ -56,15 +56,15 @@ class ES256KSigner(privateKey: PrivateKey, keyId: Option[KeyId] = None) extends
ecdsaSigner
}

override def generateProofForJson(payload: ZioJson, pk: PublicKey): Task[Proof] = {
override def generateProofForJson(payload: Json, pk: PublicKey): Task[Proof] = {
val err = Throwable("Public key must be secp256k1 EC public key")
pk match
case pk: ECPublicKey =>
EcdsaSecp256k1Signature2019ProofGenerator.generateProof(payload, signer, pk)
case _ => ZIO.fail(err)
}

override def encode(claim: ZioJson): JWT = {
override def encode(claim: Json): JWT = {
val claimSet = JWTClaimsSet.parse(claim.toJson)
val signedJwt = SignedJWT(
keyId
Expand All @@ -84,11 +84,11 @@ class EdSigner(ed25519KeyPair: Ed25519KeyPair, keyId: Option[KeyId] = None) exte
ed25519Signer
}

override def generateProofForJson(payload: ZioJson, pk: PublicKey): Task[Proof] = {
override def generateProofForJson(payload: Json, pk: PublicKey): Task[Proof] = {
EddsaJcs2022ProofGenerator.generateProof(payload, ed25519KeyPair)
}

override def encode(claim: ZioJson): JWT = {
override def encode(claim: Json): JWT = {
val claimSet = JWTClaimsSet.parse(claim.toJson)

val signedJwt = SignedJWT(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ case class JsonWebKey(
)

object JsonWebKey {
given jsonWebKeyEncoderCirceZioJson: JsonEncoder[JsonWebKey] = DeriveJsonEncoder.gen
given jsonWebKeyDecoderCirceZioJson: JsonDecoder[JsonWebKey] = DeriveJsonDecoder.gen
given JsonEncoder[JsonWebKey] = DeriveJsonEncoder.gen
given JsonDecoder[JsonWebKey] = DeriveJsonDecoder.gen
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.hyperledger.identus.shared.json

import zio.json.ast.Json as ZioJson
import zio.json.ast.Json

object JsonOps {
extension (json: ZioJson) {
def removeNullValues: ZioJson = json match
case ZioJson.Obj(fields) =>
ZioJson.Obj(fields.collect { case (key, value) if value != ZioJson.Null => key -> value.removeNullValues })
case ZioJson.Arr(elements) =>
ZioJson.Arr(elements.map(_.removeNullValues))
extension (json: Json) {
def removeNullValues: Json = json match
case Json.Obj(fields) =>
Json.Obj(fields.collect { case (key, value) if value != Json.Null => key -> value.removeNullValues })
case Json.Arr(elements) =>
Json.Arr(elements.map(_.removeNullValues))
case other => other

def removeField(name: String): ZioJson = json match
case ZioJson.Obj(fields) =>
ZioJson.Obj(fields.filterNot { case (key, value) => key == name })
case ZioJson.Arr(elements) =>
ZioJson.Arr(elements.map(_.removeField(name)))
def removeField(name: String): Json = json match
case Json.Obj(fields) =>
Json.Obj(fields.filterNot { case (key, value) => key == name })
case Json.Arr(elements) =>
Json.Arr(elements.map(_.removeField(name)))
case other => other
}
}

0 comments on commit c780920

Please sign in to comment.