Skip to content

Commit

Permalink
fix(pollux): ATL-3971 Fix all Deprecation Warning (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoKnightIOG authored Apr 12, 2023
1 parent f624feb commit e5225b7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,32 @@
package io.iohk.atala.pollux.core.service

import com.google.protobuf.ByteString
import com.squareup.okhttp.Protocol
import io.circe.Json
import io.circe.syntax.*
import io.iohk.atala.castor.core.model.did.{CanonicalPrismDID, PrismDID, VerificationRelationship}
import io.iohk.atala.iris.proto.dlt.IrisOperation
import io.iohk.atala.iris.proto.service.IrisOperationId
import io.iohk.atala.iris.proto.service.IrisServiceGrpc.IrisServiceStub
import io.iohk.atala.iris.proto.vc_operations.IssueCredentialsBatch
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.issuecredential.Attribute
import io.iohk.atala.mercury.protocol.issuecredential.CredentialPreview
import io.iohk.atala.mercury.protocol.issuecredential.IssueCredential
import io.iohk.atala.mercury.protocol.issuecredential.OfferCredential
import io.iohk.atala.mercury.protocol.issuecredential.RequestCredential
import io.iohk.atala.pollux.core.model._
import io.iohk.atala.mercury.model.{AttachmentDescriptor, Base64, DidId, JsonData}
import io.iohk.atala.mercury.protocol.issuecredential.*
import io.iohk.atala.pollux.core.model.*
import io.iohk.atala.pollux.core.model.error.CredentialServiceError
import io.iohk.atala.pollux.core.model.error.CredentialServiceError._
import io.iohk.atala.pollux.core.model.error.CredentialServiceError.*
import io.iohk.atala.pollux.core.model.presentation.*
import io.iohk.atala.pollux.core.repository.CredentialRepository
import io.iohk.atala.pollux.vc.jwt.Issuer
import io.iohk.atala.pollux.vc.jwt.JwtCredentialPayload
import io.iohk.atala.pollux.vc.jwt.W3CCredential
import io.iohk.atala.pollux.vc.jwt.W3cCredentialPayload
import io.iohk.atala.pollux.vc.jwt.W3cPresentationPayload
import io.iohk.atala.pollux.vc.jwt.DidResolver
import io.iohk.atala.prism.crypto.MerkleInclusionProof
import io.iohk.atala.prism.crypto.MerkleTreeKt
import io.iohk.atala.prism.crypto.Sha256
import io.iohk.atala.pollux.vc.jwt.*
import io.iohk.atala.prism.crypto.{MerkleInclusionProof, MerkleTreeKt, Sha256}
import io.iohk.atala.resolvers.DidValidator
import zio.*
import zio.prelude.ZValidation

import java.rmi.UnexpectedException
import java.security.KeyPairGenerator
import java.security.SecureRandom
import java.security.spec.ECGenParameterSpec
import java.time.Instant
import java.security.{KeyPairGenerator, SecureRandom}
import java.time.{Instant, ZoneId}
import java.util.UUID
import io.iohk.atala.castor.core.model.did.CanonicalPrismDID
import io.iohk.atala.mercury.model.AttachmentDescriptor
import io.iohk.atala.pollux.core.model._
import io.iohk.atala.pollux.core.model.presentation.PresentationAttachment
import io.iohk.atala.pollux.core.model.presentation.Options
import io.iohk.atala.pollux.core.model.presentation.PresentationDefinition
import io.iohk.atala.pollux.core.model.presentation.ClaimFormat
import io.iohk.atala.pollux.core.model.presentation.Ldp
import io.iohk.atala.pollux.vc.jwt.{PresentationPayload, JWT, JwtVerifiableCredentialPayload, JwtPresentation}
import io.iohk.atala.mercury.model.{JsonData, Base64}
import io.iohk.atala.castor.core.model.did.PrismDID
import zio.prelude.ZValidation
import io.iohk.atala.castor.core.model.did.VerificationRelationship
import io.iohk.atala.pollux.vc.jwt.CredentialVerification
import java.time.ZoneId
import com.squareup.okhttp.Protocol
import io.iohk.atala.pollux.core.model.presentation.Jwt

object CredentialServiceImpl {
val layer: URLayer[IrisServiceStub & CredentialRepository[Task] & DidResolver, CredentialService] =
Expand All @@ -65,7 +40,7 @@ private class CredentialServiceImpl(
maxRetries: Int = 5 // TODO move to config
) extends CredentialService {

import IssueCredentialRecord._
import IssueCredentialRecord.*

override def extractIdFromCredential(credential: W3cCredentialPayload): Option[DidCommID] =
credential.maybeId.map(_.split("/").last).map(DidCommID(_))
Expand Down Expand Up @@ -769,7 +744,7 @@ private class CredentialServiceImpl(
credentials: Seq[W3cCredentialPayload],
issuer: Issuer
): IO[CredentialServiceError, PublishedBatchData] = {
import collection.JavaConverters.*
import scala.jdk.CollectionConverters.*

val hashes = credentials
.map { c =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,35 @@ case class CredentialSchema(
`type`: String
)

sealed trait CredentialPayload(
val maybeSub: Option[String],
val `@context`: Set[String],
val `type`: Set[String],
val maybeJti: Option[String],
val nbf: Instant,
val aud: Set[String],
val maybeExp: Option[Instant],
val iss: String,
val maybeCredentialStatus: Option[CredentialStatus],
val maybeRefreshService: Option[RefreshService],
val maybeEvidence: Option[Json],
val maybeTermsOfUse: Option[Json],
val maybeCredentialSchema: Option[CredentialSchema],
val credentialSubject: Json
) {
sealed trait CredentialPayload {
def maybeSub: Option[String]

def `@context`: Set[String]

def `type`: Set[String]

def maybeJti: Option[String]

def nbf: Instant

def aud: Set[String]

def maybeExp: Option[Instant]

def iss: String

def maybeCredentialStatus: Option[CredentialStatus]

def maybeRefreshService: Option[RefreshService]

def maybeEvidence: Option[Json]

def maybeTermsOfUse: Option[Json]

def maybeCredentialSchema: Option[CredentialSchema]

def credentialSubject: Json

def toJwtCredentialPayload: JwtCredentialPayload =
JwtCredentialPayload(
iss = iss,
Expand Down Expand Up @@ -229,22 +242,16 @@ case class JwtCredentialPayload(
override val aud: Set[String],
override val maybeExp: Option[Instant],
override val maybeJti: Option[String]
) extends CredentialPayload(
maybeSub = maybeSub.orElse(vc.credentialSubject.hcursor.downField("id").as[String].toOption),
`@context` = vc.`@context`,
`type` = vc.`type`,
maybeJti = maybeJti,
nbf = nbf,
aud = aud,
maybeExp = maybeExp,
iss = iss,
maybeCredentialStatus = vc.maybeCredentialStatus,
maybeRefreshService = vc.maybeRefreshService,
maybeEvidence = vc.maybeEvidence,
maybeTermsOfUse = vc.maybeTermsOfUse,
maybeCredentialSchema = vc.maybeCredentialSchema,
credentialSubject = vc.credentialSubject
)
) extends CredentialPayload {
override val `@context` = vc.`@context`
override val `type` = vc.`type`
override val maybeCredentialStatus = vc.maybeCredentialStatus
override val maybeRefreshService = vc.maybeRefreshService
override val maybeEvidence = vc.maybeEvidence
override val maybeTermsOfUse = vc.maybeTermsOfUse
override val maybeCredentialSchema = vc.maybeCredentialSchema
override val credentialSubject = vc.credentialSubject
}

case class W3cCredentialPayload(
override val `@context`: Set[String],
Expand All @@ -259,25 +266,14 @@ case class W3cCredentialPayload(
override val maybeRefreshService: Option[RefreshService],
override val maybeEvidence: Option[Json],
override val maybeTermsOfUse: Option[Json],

/** Not part of W3C Credential but included to preserve in case of conversion from JWT. */
override val aud: Set[String] = Set.empty
) extends CredentialPayload(
maybeSub = credentialSubject.hcursor.downField("id").as[String].toOption,
`@context` = `@context`,
`type` = `type`,
maybeJti = maybeId,
nbf = issuanceDate,
aud = aud,
maybeExp = maybeExpirationDate,
iss = issuer.value,
maybeCredentialStatus = maybeCredentialStatus,
maybeRefreshService = maybeRefreshService,
maybeEvidence = maybeEvidence,
maybeTermsOfUse = maybeTermsOfUse,
maybeCredentialSchema = maybeCredentialSchema,
credentialSubject = credentialSubject
)
) extends CredentialPayload {
override val maybeSub = credentialSubject.hcursor.downField("id").as[String].toOption
override val maybeJti = maybeId
override val nbf = issuanceDate
override val maybeExp = maybeExpirationDate
override val iss = issuer.value
}

object CredentialPayload {
object Implicits {
Expand Down

0 comments on commit e5225b7

Please sign in to comment.