Skip to content

Commit

Permalink
chore: pr cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
Pat Losoponkul committed Sep 10, 2024
1 parent f9d6880 commit cfe0144
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inThisBuild(
"-unchecked",
),
scalacOptions += "-Wunused:all",
// scalacOptions += "-Wconf:cat=deprecation:warning,any:error", // "-Wconf:help", // TODO: revert before pr
scalacOptions += "-Wconf:cat=deprecation:warning,any:error", // "-Wconf:help",
// scalacOptions += "-Yexplicit-nulls",
// scalacOptions += "-Ysafe-init",
// scalacOptions += "-Werror", // <=> "-Xfatal-warnings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ case class ClaimFormatVerification(
jwtVc: JWT => IO[String, Unit],
)

// Known issues
// 1. does not respect jwt format alg in presentation_definition
object PresentationSubmissionVerification {

def verify(
Expand Down Expand Up @@ -114,8 +116,8 @@ object PresentationSubmissionVerification {
else ZIO.fail(InvalidSubmissionId(pd.id, ps.id))
}

// This is not yet fully supported as in https://identity.foundation/presentation-exchange/spec/v2.1.1/#submission-requirement-feature
// It is now a simple check that submission satisties all input descriptors
// This is not yet fully supported as described in https://identity.foundation/presentation-exchange/spec/v2.1.1/#submission-requirement-feature
// It is now a simple check that submission descriptor_map satisfies all input_descriptors
private def verifySubmissionRequirement(
pd: PresentationDefinition,
ps: PresentationSubmission
Expand Down Expand Up @@ -144,29 +146,23 @@ object PresentationSubmissionVerification {
descriptor: InputDescriptor,
entry: ZioJson
): IO[PresentationSubmissionError, Unit] = {
val fields = descriptor.constraints.fields.getOrElse(Nil)
val mandatoryFields = descriptor.constraints.fields
.getOrElse(Nil)
.filterNot(_.optional.getOrElse(false)) // optional field doesn't have to pass contraints

// all fields need to be valid
ZIO
.foreach(fields) { field =>
.foreach(mandatoryFields) { field =>
// only one of the paths need to be valid
ZIO
.validateFirst(field.path) { p =>
for {
jsonPath <- ZIO.fromEither(p.toJsonPath)
jsonAtPath <- ZIO.fromEither(jsonPath.read(entry))
maybeFilter <- ZIO.foreach(field.filter)(_.toJsonSchema)
_ <- ZIO.foreach(maybeFilter) { filter =>
JsonSchemaValidatorImpl(filter).validate(jsonAtPath.toString())
}
_ <- ZIO.foreach(maybeFilter)(JsonSchemaValidatorImpl(_).validate(jsonAtPath.toString()))
} yield ()
}
.catchAll { errors =>
// if all paths don't satisfy constraints, but optional, then the field is still valid
// https://identity.foundation/presentation-exchange/spec/v2.1.1/#input-evaluation
if field.optional.getOrElse(false)
then ZIO.unit
else ZIO.fail(errors)
}
.mapError(_ => ClaimNotSatisfyInputConstraint(descriptor.id))
}
.unit
Expand All @@ -184,10 +180,8 @@ object PresentationSubmissionVerification {
.fromEither(path.read(traversalObject))
.mapError(_ => JsonPathNotFound(descriptor.path))
currentNode <- descriptor.format match {
case ClaimFormatValue.jwt_vc =>
verifyJwtVc(jsonAtPath, descriptor.path)(formatVerification.jwtVc)
case ClaimFormatValue.jwt_vp =>
verifyJwtVp(jsonAtPath, descriptor.path)(formatVerification.jwtVp)
case ClaimFormatValue.jwt_vc => verifyJwtVc(jsonAtPath, descriptor.path)(formatVerification.jwtVc)
case ClaimFormatValue.jwt_vp => verifyJwtVp(jsonAtPath, descriptor.path)(formatVerification.jwtVp)
}
leafNode <- descriptor.path_nested.fold(ZIO.succeed(currentNode)) { nestedDescriptor =>
if descriptor.id != nestedDescriptor.id
Expand Down

0 comments on commit cfe0144

Please sign in to comment.