Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pollux): Replace UUID with String - ATL-3555 #397

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.iohk.atala.pollux.core.model

import java.util.UUID

// type DidCommID = String
opaque type DidCommID = String
object DidCommID:
def apply(value: String): DidCommID = value
def apply(): DidCommID = UUID.randomUUID.toString()
extension (id: DidCommID) def value: String = id
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.iohk.atala.pollux.core.model
import io.iohk.atala.prism.crypto.MerkleInclusionProof

import java.util.UUID
import io.iohk.atala.mercury.protocol.issuecredential.OfferCredential
import io.iohk.atala.mercury.protocol.issuecredential.RequestCredential
import io.iohk.atala.mercury.protocol.issuecredential.IssueCredential
Expand All @@ -11,10 +10,10 @@ import io.iohk.atala.pollux.vc.jwt.JwtCredential
import io.iohk.atala.castor.core.model.did.CanonicalPrismDID

final case class IssueCredentialRecord(
id: UUID,
id: DidCommID,
createdAt: Instant,
updatedAt: Option[Instant],
thid: UUID,
thid: DidCommID,
schemaId: Option[String],
role: Role,
subjectId: String,
Expand All @@ -30,7 +29,7 @@ final case class IssueCredentialRecord(
issuingDID: Option[CanonicalPrismDID]
)
final case class ValidIssuedCredentialRecord(
id: UUID,
id: DidCommID,
issuedCredentialRaw: Option[String],
subjectId: String
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package io.iohk.atala.pollux.core.model
import io.iohk.atala.prism.crypto.MerkleInclusionProof

import java.util.UUID
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 java.time.Instant
final case class PresentationRecord(
id: UUID,
id: DidCommID,
createdAt: Instant,
updatedAt: Option[Instant],
thid: UUID,
thid: DidCommID,
schemaId: Option[String],
connectionId: Option[String],
role: PresentationRecord.Role,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package io.iohk.atala.pollux.core.model.error

import java.util.UUID
import io.iohk.atala.pollux.vc.jwt.W3cCredentialPayload
import io.iohk.atala.pollux.core.model.DidCommID

sealed trait CredentialServiceError

object CredentialServiceError {
final case class RepositoryError(cause: Throwable) extends CredentialServiceError
final case class RecordIdNotFound(recordId: UUID) extends CredentialServiceError
final case class OperationNotExecuted(recordId: UUID, info: String) extends CredentialServiceError
final case class ThreadIdNotFound(thid: UUID) extends CredentialServiceError
final case class RecordIdNotFound(recordId: DidCommID) extends CredentialServiceError
final case class OperationNotExecuted(recordId: DidCommID, info: String) extends CredentialServiceError
final case class ThreadIdNotFound(thid: DidCommID) extends CredentialServiceError
final case class InvalidFlowStateError(msg: String) extends CredentialServiceError
final case class UnexpectedError(msg: String) extends CredentialServiceError
final case class UnsupportedDidFormat(did: String) extends CredentialServiceError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.iohk.atala.pollux.core.model.error

import java.util.UUID
import io.iohk.atala.pollux.core.model.DidCommID

sealed trait PresentationError

object PresentationError {
final case class RepositoryError(cause: Throwable) extends PresentationError
final case class RecordIdNotFound(recordId: UUID) extends PresentationError
final case class ThreadIdNotFound(thid: UUID) extends PresentationError
final case class RecordIdNotFound(recordId: DidCommID) extends PresentationError
final case class ThreadIdNotFound(thid: DidCommID) extends PresentationError
final case class InvalidFlowStateError(msg: String) extends PresentationError
final case class UnexpectedError(msg: String) extends PresentationError
final case class IssuedCredentialNotFoundError(cause: Throwable) extends PresentationError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@ import io.iohk.atala.pollux.core.model._
import io.iohk.atala.prism.crypto.MerkleInclusionProof
import zio.*

import java.util.UUID
import io.iohk.atala.mercury.protocol.issuecredential.RequestCredential
import io.iohk.atala.mercury.protocol.issuecredential.IssueCredential
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.ProtocolState

trait CredentialRepository[F[_]] {
def createIssueCredentialRecord(record: IssueCredentialRecord): F[Int]
def getIssueCredentialRecords(): F[Seq[IssueCredentialRecord]]
def getIssueCredentialRecord(recordId: UUID): F[Option[IssueCredentialRecord]]
def getIssueCredentialRecord(recordId: DidCommID): F[Option[IssueCredentialRecord]]
def getIssueCredentialRecordsByStates(states: IssueCredentialRecord.ProtocolState*): F[Seq[IssueCredentialRecord]]
def updateCredentialRecordStateAndProofByCredentialIdBulk(
idsStatesAndProofs: Seq[(UUID, IssueCredentialRecord.PublicationState, MerkleInclusionProof)]
idsStatesAndProofs: Seq[(DidCommID, IssueCredentialRecord.PublicationState, MerkleInclusionProof)]
): F[Int]

def getIssueCredentialRecordByThreadId(thid: UUID): F[Option[IssueCredentialRecord]]
def getIssueCredentialRecordByThreadId(thid: DidCommID): F[Option[IssueCredentialRecord]]

def updateCredentialRecordProtocolState(
recordId: UUID,
recordId: DidCommID,
from: IssueCredentialRecord.ProtocolState,
to: IssueCredentialRecord.ProtocolState
): F[Int]

def updateCredentialRecordPublicationState(
recordId: UUID,
recordId: DidCommID,
from: Option[IssueCredentialRecord.PublicationState],
to: Option[IssueCredentialRecord.PublicationState]
): F[Int]

def updateWithRequestCredential(recordId: UUID, request: RequestCredential, protocolState: ProtocolState): F[Int]
def updateWithRequestCredential(recordId: DidCommID, request: RequestCredential, protocolState: ProtocolState): F[Int]

def updateWithIssueCredential(
recordId: UUID,
recordId: DidCommID,
issue: IssueCredential,
protocolState: ProtocolState
): F[Int]

def updateWithIssuedRawCredential(
recordId: UUID,
recordId: DidCommID,
issue: IssueCredential,
issuedRawCredential: String,
protocolState: ProtocolState
): F[Int]

def deleteIssueCredentialRecord(recordId: UUID): F[Int]
def deleteIssueCredentialRecord(recordId: DidCommID): F[Int]

def getValidIssuedCredentials(recordId: Seq[UUID]): F[Seq[ValidIssuedCredentialRecord]]
def getValidIssuedCredentials(recordId: Seq[DidCommID]): F[Seq[ValidIssuedCredentialRecord]]

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ package io.iohk.atala.pollux.core.repository

import io.iohk.atala.mercury.protocol.issuecredential.IssueCredential
import io.iohk.atala.mercury.protocol.issuecredential.RequestCredential
import io.iohk.atala.pollux.core.model.IssueCredentialRecord
import io.iohk.atala.pollux.core.model._
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.ProtocolState
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.PublicationState
import io.iohk.atala.pollux.core.model.ValidIssuedCredentialRecord
import io.iohk.atala.pollux.core.model.error.CredentialRepositoryError._
import io.iohk.atala.prism.crypto.MerkleInclusionProof
import zio.*

import java.time.Instant
import java.util.UUID

class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord]]) extends CredentialRepository[Task] {
class CredentialRepositoryInMemory(storeRef: Ref[Map[DidCommID, IssueCredentialRecord]])
extends CredentialRepository[Task] {

override def updateCredentialRecordPublicationState(
recordId: UUID,
recordId: DidCommID,
from: Option[PublicationState],
to: Option[PublicationState]
): Task[Int] = {
for {
store <- storeRef.get
maybeRecord = store.find((uuid, record) => uuid == recordId && record.publicationState == from).map(_._2)
maybeRecord = store.find((id, record) => id == recordId && record.publicationState == from).map(_._2)
count <- maybeRecord
.map(record =>
for {
Expand All @@ -46,7 +46,7 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
} yield 1
}

override def getIssueCredentialRecord(recordId: UUID): Task[Option[IssueCredentialRecord]] = {
override def getIssueCredentialRecord(recordId: DidCommID): Task[Option[IssueCredentialRecord]] = {
for {
store <- storeRef.get
record = store.get(recordId)
Expand All @@ -60,13 +60,13 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
}

override def updateCredentialRecordProtocolState(
recordId: UUID,
recordId: DidCommID,
from: ProtocolState,
to: ProtocolState
): Task[Int] = {
for {
store <- storeRef.get
maybeRecord = store.find((uuid, record) => uuid == recordId && record.protocolState == from).map(_._2)
maybeRecord = store.find((id, record) => id == recordId && record.protocolState == from).map(_._2)
count <- maybeRecord
.map(record =>
for {
Expand All @@ -78,7 +78,7 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
}

override def updateWithIssuedRawCredential(
recordId: UUID,
recordId: DidCommID,
issue: IssueCredential,
issuedRawCredential: String,
protocolState: ProtocolState
Expand All @@ -105,7 +105,7 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
} yield count
}

override def getValidIssuedCredentials(recordId: Seq[UUID]): Task[Seq[ValidIssuedCredentialRecord]] = {
override def getValidIssuedCredentials(recordId: Seq[DidCommID]): Task[Seq[ValidIssuedCredentialRecord]] = {
for {
store <- storeRef.get
} yield store.values
Expand All @@ -114,7 +114,7 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
.toSeq
}

override def deleteIssueCredentialRecord(recordId: UUID): Task[Int] = {
override def deleteIssueCredentialRecord(recordId: DidCommID): Task[Int] = {
for {
maybeRecord <- getIssueCredentialRecord(recordId)
count <- maybeRecord
Expand All @@ -128,7 +128,7 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
}

override def updateWithIssueCredential(
recordId: UUID,
recordId: DidCommID,
issue: IssueCredential,
protocolState: ProtocolState
): Task[Int] = {
Expand Down Expand Up @@ -159,14 +159,14 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
} yield store.values.filter(rec => states.contains(rec.protocolState)).toSeq
}

override def getIssueCredentialRecordByThreadId(thid: UUID): Task[Option[IssueCredentialRecord]] = {
override def getIssueCredentialRecordByThreadId(thid: DidCommID): Task[Option[IssueCredentialRecord]] = {
for {
store <- storeRef.get
} yield store.values.find(_.thid == thid)
}

override def updateWithRequestCredential(
recordId: UUID,
recordId: DidCommID,
request: RequestCredential,
protocolState: ProtocolState
): Task[Int] = {
Expand All @@ -192,15 +192,15 @@ class CredentialRepositoryInMemory(storeRef: Ref[Map[UUID, IssueCredentialRecord
}

override def updateCredentialRecordStateAndProofByCredentialIdBulk(
idsStatesAndProofs: Seq[(UUID, PublicationState, MerkleInclusionProof)]
idsStatesAndProofs: Seq[(DidCommID, PublicationState, MerkleInclusionProof)]
): Task[Int] = ???

}

object CredentialRepositoryInMemory {
val layer: ULayer[CredentialRepository[Task]] = ZLayer.fromZIO(
Ref
.make(Map.empty[UUID, IssueCredentialRecord])
.make(Map.empty[DidCommID, IssueCredentialRecord])
.map(CredentialRepositoryInMemory(_))
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.iohk.atala.pollux.core.repository

import io.iohk.atala.pollux.core.model.EncodedJWTCredential
import io.iohk.atala.pollux.core.model.PresentationRecord
import io.iohk.atala.pollux.core.model._
import io.iohk.atala.prism.crypto.MerkleInclusionProof
import zio.*

Expand All @@ -12,21 +11,33 @@ import io.iohk.atala.pollux.core.model.PresentationRecord.ProtocolState
trait PresentationRepository[F[_]] {
def createPresentationRecord(record: PresentationRecord): F[Int]
def getPresentationRecords(): F[Seq[PresentationRecord]]
def getPresentationRecord(recordId: UUID): F[Option[PresentationRecord]]
def getPresentationRecord(recordId: DidCommID): F[Option[PresentationRecord]]
def getPresentationRecordsByStates(states: PresentationRecord.ProtocolState*): F[Seq[PresentationRecord]]
def getPresentationRecordByThreadId(thid: UUID): F[Option[PresentationRecord]]
def getPresentationRecordByThreadId(thid: DidCommID): F[Option[PresentationRecord]]

def updatePresentationRecordProtocolState(
recordId: UUID,
recordId: DidCommID,
from: PresentationRecord.ProtocolState,
to: PresentationRecord.ProtocolState
): F[Int]

def updateWithRequestPresentation(recordId: UUID, request: RequestPresentation, protocolState: ProtocolState): F[Int]
def updateWithProposePresentation(recordId: UUID, request: ProposePresentation, protocolState: ProtocolState): F[Int]
def updateWithPresentation(recordId: UUID, presentation: Presentation, protocolState: ProtocolState): F[Int]
def updateWithRequestPresentation(
recordId: DidCommID,
request: RequestPresentation,
protocolState: ProtocolState
): F[Int]
def updateWithProposePresentation(
recordId: DidCommID,
request: ProposePresentation,
protocolState: ProtocolState
): F[Int]
def updateWithPresentation(
recordId: DidCommID,
presentation: Presentation,
protocolState: ProtocolState
): F[Int]
def updatePresentationWithCredentialsToUse(
recordId: UUID,
recordId: DidCommID,
credentialsToUse: Option[Seq[String]],
protocolState: ProtocolState
): F[Int]
Expand Down
Loading