Skip to content

Commit

Permalink
feat(pollux): Added JWT verfication (#280)
Browse files Browse the repository at this point in the history
Signed-off-by: Shailesh Patil <[email protected]>

address the  pr comments

Signed-off-by: Shailesh Patil <[email protected]>

Signed-off-by: Shailesh Patil <[email protected]>
Co-authored-by: Shailesh Patil <[email protected]>
  • Loading branch information
mineme0110 and Shailesh Patil authored Dec 20, 2022
1 parent eda1fa3 commit a87dc17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,12 @@ private class CredentialServiceImpl(
)
// TODO: get schema when schema registry is available if schema ID is provided
credential = W3cCredentialPayload(
`@context` = Set.empty, // TODO: his information should come from Schema registry by record.schemaId
`@context` = Set(
"https://www.w3.org/2018/credentials/v1"
), // TODO: his information should come from Schema registry by record.schemaId
maybeId = None,
`type` = Set.empty, // TODO: This information should come from Schema registry by record.schemaId
`type` =
Set("VerifiableCredential"), // TODO: This information should come from Schema registry by record.schemaId
issuer = issuer.did,
issuanceDate = issuanceDate,
maybeExpirationDate = record.validityPeriod.map(sec => issuanceDate.plusSeconds(sec.toLong)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package io.iohk.atala.pollux.core.service

import com.google.protobuf.ByteString
import io.circe.Json
import io.circe.parser._
import io.circe.syntax.*
import io.circe._
import io.iohk.atala.pollux.core.model.EncodedJWTCredential
import io.iohk.atala.pollux.core.model.PresentationRecord
import io.iohk.atala.pollux.core.model.error.PresentationError
Expand All @@ -29,6 +31,7 @@ import java.security.PublicKey
import io.iohk.atala.mercury.protocol.issuecredential.IssueCredential
import io.iohk.atala.pollux.core.model.IssueCredentialRecord
import io.iohk.atala.pollux.core.repository.CredentialRepository
import org.didcommx.didcomm.message.Attachment.Data.Base64

trait PresentationService {

Expand Down Expand Up @@ -208,18 +211,23 @@ private class PresentationServiceImpl(
): IO[PresentationError, JWT] = {

val verifiableCredentials = issuedCredentials.map { issuedCredential =>
JwtVerifiableCredentialPayload(JWT(issuedCredential.signedCredential))
decode[io.iohk.atala.mercury.model.Base64](issuedCredential.signedCredential)
.map(x => new String(java.util.Base64.getDecoder().decode(x.base64)))
.map(_.drop(1).dropRight(1))
.map(x => JwtVerifiableCredentialPayload(JWT(x)))
.getOrElse(???)
}.toVector

val w3cPresentationPayload =
W3cPresentationPayload(
`@context` = IndexedSeq.empty,
`@context` = Vector("https://www.w3.org/2018/presentations/v1"),
maybeId = None,
`type` = Vector("VerifiablePresentation"),
verifiableCredential = verifiableCredentials,
holder = prover.did.value,
verifier = Vector("https://example.edu/issuers/565049"), // TODO Fix this
maybeIssuanceDate = None,
maybeExpirationDate = Some(Instant.parse("2010-01-12T00:00:00Z"))
maybeExpirationDate = None
)

val encodedJWT = JwtPresentation.toEncodedJwt(w3cPresentationPayload, prover)
Expand Down Expand Up @@ -310,6 +318,7 @@ private class PresentationServiceImpl(
record <- presentationRepository
.getPresentationRecord(record.id)
.mapError(RepositoryError.apply)

} yield record
}

Expand Down Expand Up @@ -421,14 +430,6 @@ private class PresentationServiceImpl(
} yield record
}

private[this] def verifyPresentation(
presentation: Presentation
) = {
for {
_ <- ZIO.log(s"************Verify Presentation Not Implemented*************")
} yield ()
}

private[this] def createDidCommRequestPresentation(
proofTypes: Seq[ProofType],
thid: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ object JWTVerification {
curve <- publicKeyJwk.crv
x <- publicKeyJwk.x.map(Base64URL.from)
y <- publicKeyJwk.y.map(Base64URL.from)
d <- publicKeyJwk.d.map(Base64URL.from)
} yield new ECKey.Builder(Curve.parse(curve), x, y).d(d).build().toPublicKey
} yield new ECKey.Builder(Curve.parse(curve), x, y).build().toPublicKey
Validation.fromOptionWith("Unable to parse Public Key")(maybePublicKey)
}
}

0 comments on commit a87dc17

Please sign in to comment.