Skip to content

Commit

Permalink
feat: Add Predicate and Attribute through API (#802)
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
  • Loading branch information
CryptoKnightIOG committed Dec 19, 2023
1 parent a06b861 commit c3fbcd0
Show file tree
Hide file tree
Showing 19 changed files with 732 additions and 147 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ lazy val D = new {
"com.github.dasniko" % "testcontainers-keycloak" % V.testContainersJavaKeycloak % Test

val doobiePostgres: ModuleID = "org.tpolecat" %% "doobie-postgres" % V.doobie
val doobiePostgresCirce: ModuleID = "org.tpolecat" %% "doobie-postgres-circe" % V.doobie
val doobieHikari: ModuleID = "org.tpolecat" %% "doobie-hikari" % V.doobie
val flyway: ModuleID = "org.flywaydb" % "flyway-core" % V.flyway

Expand All @@ -149,7 +150,7 @@ lazy val D = new {

// LIST of Dependencies
val doobieDependencies: Seq[ModuleID] =
Seq(doobiePostgres, doobieHikari, flyway)
Seq(doobiePostgres, doobiePostgresCirce, doobieHikari, flyway)
}

lazy val D_Shared = new {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.iohk.atala.pollux.core.model

import io.iohk.atala.mercury.protocol.presentproof.ProposePresentation
import io.iohk.atala.mercury.protocol.presentproof.RequestPresentation
import io.iohk.atala.mercury.protocol.presentproof.Presentation
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.presentproof.{Presentation, ProposePresentation, RequestPresentation}

import java.time.Instant
import java.time.temporal.ChronoUnit

type AnoncredCredentialProofs = zio.json.ast.Json

final case class PresentationRecord(
id: DidCommID,
createdAt: Instant,
Expand All @@ -23,6 +23,8 @@ final case class PresentationRecord(
proposePresentationData: Option[ProposePresentation],
presentationData: Option[Presentation],
credentialsToUse: Option[List[String]],
anoncredCredentialsToUseJsonSchemaId: Option[String],
anoncredCredentialsToUse: Option[AnoncredCredentialProofs],
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ class SchemaSerDes[S](jsonSchemaSchemaStr: String) {
def initialiseJsonSchema: IO[JsonSchemaError, JsonSchema] =
JsonSchemaUtils.jsonSchema(jsonSchemaSchemaStr)

def serialize(instance: S)(using encoder: JsonEncoder[S]): String = {
def serializeToJsonString(instance: S)(using encoder: JsonEncoder[S]): String = {
instance.toJson
}

def serialize(instance: S)(using encoder: JsonEncoder[S]): Either[String, Json] = {
instance.toJsonAST
}

def deserialize(
schema: zio.json.ast.Json
)(using decoder: JsonDecoder[S]): IO[JsonSchemaError, S] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ trait PresentationRepository {
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]

def updateAnoncredPresentationWithCredentialsToUse(
recordId: DidCommID,
anoncredCredentialsToUseJsonSchemaId: Option[String],
anoncredCredentialsToUse: Option[AnoncredCredentialProofs],
protocolState: ProtocolState
): RIO[WalletAccessContext, Int]

def updateAfterFail(
recordId: DidCommID,
failReason: Option[String]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.iohk.atala.pollux.core.repository

import io.iohk.atala.mercury.protocol.presentproof._
import io.iohk.atala.mercury.protocol.presentproof.*
import io.iohk.atala.pollux.core.model.*
import io.iohk.atala.pollux.core.model.PresentationRecord.ProtocolState
import io.iohk.atala.pollux.core.model._
import io.iohk.atala.pollux.core.model.error.PresentationError._
import io.iohk.atala.shared.models.WalletAccessContext
import io.iohk.atala.shared.models.WalletId
import io.iohk.atala.pollux.core.model.error.PresentationError.*
import io.iohk.atala.shared.models.{WalletAccessContext, WalletId}
import zio.*

import java.time.Instant
Expand Down Expand Up @@ -114,6 +113,37 @@ class PresentationRepositoryInMemory(
} yield count
}

def updateAnoncredPresentationWithCredentialsToUse(
recordId: DidCommID,
anoncredCredentialsToUseJsonSchemaId: Option[String],
anoncredCredentialsToUse: Option[AnoncredCredentialProofs],
protocolState: ProtocolState
): RIO[WalletAccessContext, Int] = {
for {
storeRef <- walletStoreRef
maybeRecord <- getPresentationRecord(recordId)
count <- maybeRecord
.map(record =>
for {
_ <- storeRef.update(r =>
r.updated(
recordId,
record.copy(
updatedAt = Some(Instant.now),
anoncredCredentialsToUseJsonSchemaId = anoncredCredentialsToUseJsonSchemaId,
anoncredCredentialsToUse = anoncredCredentialsToUse,
protocolState = protocolState,
metaRetries = maxRetries,
metaLastFailure = None,
)
)
)
} yield 1
)
.getOrElse(ZIO.succeed(0))
} yield count
}

override def updateWithPresentation(
recordId: DidCommID,
presentation: Presentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.iohk.atala.pollux.anoncreds.AnoncredPresentation
import io.iohk.atala.pollux.core.model.error.PresentationError
import io.iohk.atala.pollux.core.model.presentation.Options
import io.iohk.atala.pollux.core.model.{DidCommID, PresentationRecord}
import io.iohk.atala.pollux.core.service.serdes.AnoncredPresentationRequestV1
import io.iohk.atala.pollux.core.service.serdes.{AnoncredCredentialProofsV1, AnoncredPresentationRequestV1}
import io.iohk.atala.pollux.vc.jwt.{Issuer, PresentationPayload, W3cCredentialPayload}
import io.iohk.atala.shared.models.WalletAccessContext
import zio.mock.{Mock, Proxy}
Expand Down Expand Up @@ -45,6 +45,13 @@ object MockPresentationService extends Mock[PresentationService] {

object AcceptRequestPresentation extends Effect[(DidCommID, Seq[String]), PresentationError, PresentationRecord]

object AcceptAnoncredRequestPresentation
extends Effect[
(DidCommID, AnoncredCredentialProofsV1),
PresentationError,
PresentationRecord
]

object RejectRequestPresentation extends Effect[DidCommID, PresentationError, PresentationRecord]

object MarkPresentationGenerated extends Effect[(DidCommID, Presentation), PresentationError, PresentationRecord]
Expand Down Expand Up @@ -95,6 +102,12 @@ object MockPresentationService extends Mock[PresentationService] {
): IO[PresentationError, PresentationRecord] =
proxy(AcceptRequestPresentation, (recordId, credentialsToUse))

override def acceptAnoncredRequestPresentation(
recordId: DidCommID,
credentialsToUse: AnoncredCredentialProofsV1
): IO[PresentationError, PresentationRecord] =
proxy(AcceptAnoncredRequestPresentation, (recordId, credentialsToUse))

override def rejectRequestPresentation(recordId: DidCommID): IO[PresentationError, PresentationRecord] =
proxy(RejectRequestPresentation, recordId)

Expand Down Expand Up @@ -152,6 +165,7 @@ object MockPresentationService extends Mock[PresentationService] {
override def createAnoncredPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
anoncredCredentialProof: AnoncredCredentialProofsV1,
issuanceDate: Instant
): IO[PresentationError, AnoncredPresentation] = ???

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.iohk.atala.pollux.anoncreds.AnoncredPresentation
import io.iohk.atala.pollux.core.model.*
import io.iohk.atala.pollux.core.model.error.PresentationError
import io.iohk.atala.pollux.core.model.presentation.*
import io.iohk.atala.pollux.core.service.serdes.AnoncredPresentationRequestV1
import io.iohk.atala.pollux.core.service.serdes.{AnoncredCredentialProofsV1, AnoncredPresentationRequestV1}
import io.iohk.atala.pollux.vc.jwt.*
import io.iohk.atala.shared.models.WalletAccessContext
import zio.*
Expand All @@ -16,7 +16,6 @@ import java.util as ju
import java.util.UUID

trait PresentationService {

def extractIdFromCredential(credential: W3cCredentialPayload): Option[UUID]

def createJwtPresentationRecord(
Expand Down Expand Up @@ -49,6 +48,7 @@ trait PresentationService {
def createAnoncredPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
anoncredCredentialProof: AnoncredCredentialProofsV1,
issuanceDate: Instant
): ZIO[WalletAccessContext, PresentationError, AnoncredPresentation]

Expand Down Expand Up @@ -82,6 +82,11 @@ trait PresentationService {
credentialsToUse: Seq[String]
): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def acceptAnoncredRequestPresentation(
recordId: DidCommID,
credentialsToUse: AnoncredCredentialProofsV1
): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def rejectRequestPresentation(recordId: DidCommID): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def receiveProposePresentation(
Expand Down
Loading

0 comments on commit c3fbcd0

Please sign in to comment.