Skip to content

Commit

Permalink
feat: ATL-6019 Create/Store Presentation
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <[email protected]>
  • Loading branch information
CryptoKnightIOG committed Nov 18, 2023
1 parent 08939e1 commit 911e2e6
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ object AnoncredLib {
linkSecret: LinkSecret,
schemas: Map[SchemaId, SchemaDef],
credentialDefinitions: Map[CredentialDefinitionId, CredentialDefinition],
): Presentation = {
): AnoncredPresentation = {
anoncreds
.Prover()
.createPresentation(
Expand All @@ -173,7 +173,7 @@ object AnoncredLib {

// FIXME its always return false ....
def verifyPresentation(
presentation: Presentation,
presentation: AnoncredPresentation,
presentationRequest: PresentationRequest,
schemas: Map[SchemaId, SchemaDef],
credentialDefinitions: Map[CredentialDefinitionId, CredentialDefinition],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ object PresentationRequest {

// ****************************************************************************

case class Presentation(data: String)
object Presentation {
given Conversion[Presentation, UniffiPresentation] with {
def apply(presentation: Presentation): UniffiPresentation =
case class AnoncredPresentation(data: String)
object AnoncredPresentation {
given Conversion[AnoncredPresentation, UniffiPresentation] with {
def apply(presentation: AnoncredPresentation): UniffiPresentation =
UniffiPresentation(presentation.data)
}

given Conversion[UniffiPresentation, Presentation] with {
def apply(presentation: UniffiPresentation): Presentation =
Presentation(presentation.getJson())
given Conversion[UniffiPresentation, AnoncredPresentation] with {
def apply(presentation: UniffiPresentation): AnoncredPresentation =
AnoncredPresentation(presentation.getJson())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ final case class ValidIssuedCredentialRecord(
subjectId: Option[String]
)

final case class ValidFullIssuedCredentialRecord(
id: DidCommID,
issuedCredential: Option[IssueCredential],
credentialFormat: CredentialFormat,
schemaId: Option[String],
credentialDefinitionId: Option[UUID],
subjectId: Option[String]
)

object IssueCredentialRecord {

enum Role:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ object PresentationError {
final case class UnsupportedCredentialFormat(vcFormat: String) extends PresentationError
final case class InvalidAnoncredPresentationRequest(error: String) extends PresentationError
final case class MissingAnoncredPresentationRequest(error: String) extends PresentationError

final case class AnoncredPresentationCreationError(cause: Throwable) extends PresentationError
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ trait CredentialRepository {

def getValidIssuedCredentials(recordId: Seq[DidCommID]): RIO[WalletAccessContext, Seq[ValidIssuedCredentialRecord]]

def getValidAnoncredIssuedCredentials(
recordIds: Seq[DidCommID]
): RIO[WalletAccessContext, Seq[ValidFullIssuedCredentialRecord]]

def updateAfterFail(
recordId: DidCommID,
failReason: Option[String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ class CredentialRepositoryInMemory(
.toSeq
}

override def getValidAnoncredIssuedCredentials(
recordId: Seq[DidCommID]
): RIO[WalletAccessContext, Seq[ValidFullIssuedCredentialRecord]] = {
for {
storeRef <- walletStoreRef
store <- storeRef.get
} yield store.values
.filter(rec =>
recordId.contains(
rec.id
) && rec.issueCredentialData.isDefined
&& rec.schemaId.isDefined
&& rec.credentialDefinitionId.isDefined
&& rec.credentialFormat == CredentialFormat.AnonCreds
)
.map(rec =>
ValidFullIssuedCredentialRecord(
rec.id,
rec.issueCredentialData,
rec.credentialFormat,
rec.schemaId,
rec.credentialDefinitionId,
rec.subjectId
)
)
.toSeq
}

override def deleteIssueCredentialRecord(recordId: DidCommID): RIO[WalletAccessContext, Int] = {
for {
storeRef <- walletStoreRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.iohk.atala.pollux.core.service

import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.presentproof.{Presentation, ProofType, ProposePresentation, RequestPresentation}
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}
Expand Down Expand Up @@ -142,12 +143,18 @@ object MockPresentationService extends Mock[PresentationService] {
ignoreWithZeroRetries: Boolean
): IO[PresentationError, Seq[PresentationRecord]] = ???

override def createPresentationPayloadFromRecord(
override def createJwtPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
issuanceDate: Instant
): IO[PresentationError, PresentationPayload] = ???

override def createAnoncredPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
issuanceDate: Instant
): IO[PresentationError, AnoncredPresentation] = ???

override def getPresentationRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.iohk.atala.pollux.core.service

import io.iohk.atala.mercury.model.*
import io.iohk.atala.mercury.protocol.presentproof.*
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.*
Expand Down Expand Up @@ -39,12 +40,18 @@ trait PresentationService {
ignoreWithZeroRetries: Boolean
): ZIO[WalletAccessContext, PresentationError, Seq[PresentationRecord]]

def createPresentationPayloadFromRecord(
def createJwtPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
issuanceDate: Instant
): ZIO[WalletAccessContext, PresentationError, PresentationPayload]

def createAnoncredPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
issuanceDate: Instant
): ZIO[WalletAccessContext, PresentationError, AnoncredPresentation]

def getPresentationRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
Expand Down
Loading

0 comments on commit 911e2e6

Please sign in to comment.