Skip to content

Commit

Permalink
feat(pollux): implement Issue Credential v2 Protocol (#144)
Browse files Browse the repository at this point in the history
* feat(pollux): add 'CredentialGenerated' state

* chore(pollux): disable Doobie log handler

* chore(pollux): move DIDComm message creation and storage in credential service

* mend

chore(pollux): move DIDComm message creation and storage in credential service

* chore(prism-agent): inject DidComm layer in credential service

* chore(pollux): generate DidComm IssueCredential message when accepting credential request

* chore(prism-agent): do not create DidComm messages in background job

* chore(prism-agent): wip

* chore(prism-agent): add missing import

* chore(prism-agent): bump pollux dependency version to 0.2.0-SNAPSHOT

* fix(prism-agent): fix pollux DbConfig package change

* fix(pollux): populate record claims in DB when receiving the DIDComm OfferCredential message

* chore(pollux): remove obsolete claims attribute from DB and retrieve them from the offer

* chore(pollux): reinstate 'markCredentialGenerated' method

* feat(prism-agent): return JWT credential based on issue-credential and claims based on offer-credential from REST API calls

* chore(prism-agent): get rid of 'claims' attribute and make sure whole flow is working waiting for publication to be integrated

* chore(pollux): add 'automatic-issuance' flag to support auto request acceptance by issuer

* chore(prism-agent): add 'automaticIssuance' attribute to issue REST API

* chore(prism-agent): bump pollux dependency version to 0.3.0-SNAPSHOT

* chore(pollux): bump version to 0.3.0-SNAPSHOT

* chore(pollux): introduce 'awaitConfirmation' flag in issue credential record

* chore(pollux): introduce 'awaitConfirmation' flag in issue credential protocol REST API

* chore(prism-agent): limit pollux DB transactor connection pool

* feature(pollux): add creationDateTime attribute to issue credential record

* feature(prism-agent): add creationDateTime in issue credential protocol REST API

* feature(prism-agent): add 'updateAt' field to issue credential record

* feat(pollux): Add job that publishes credentials to DLT (#92)

* Remove SNAPSHOT from versions, fix some errirs with scala version mismatch, make local docker compose runnable
* Add getCredentialRecordsByState
* Add function to make credential from issue credential record
* WIP: implement the job
* Add inclusion proof to IssueCredentialRecord
* Add serializer and decserializer for inclusion proofs
* WIP: Add updateCredentialRecordStateAndProofByCredentialIdBulk
* Add updateCredentialRecordStateAndProofByCredentialIdBulk
* Fix merge conflict erros
* Remove MockCredentialService
* Fix errors caused by conflicts
* Edit createCredentialPayloadFromRecord, get credential from requestCredential didcome message
* Revert remove "extractIdFromCredential"
* Make it compile
* Update mercyry to 0.6.0
* Finalize protocol
* remove confusing response texts
* Format
* format prism agent
* add my branch to releases
* remove my branch from release

Co-authored-by: FabioPinheiro <[email protected]>

* feat(prism-agent): return JWT credential from API call

* chore(pollux): restore prism-agent folder to main branch => 2 PRs split

Co-authored-by: shota jolbordi <[email protected]>
Co-authored-by: FabioPinheiro <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2022
1 parent e4d4a41 commit a80702f
Show file tree
Hide file tree
Showing 19 changed files with 601 additions and 181 deletions.
4 changes: 4 additions & 0 deletions castor/lib/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ val commonSettings = Seq(
// Project definitions
lazy val root = project
.in(file("."))
.settings(commonSettings)
.settings(
name := "castor-root",
)
.settings(publish / skip := true)
.aggregate(core, `sql-doobie`)

Expand Down
2 changes: 1 addition & 1 deletion castor/lib/version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "0.2.0-SNAPSHOT"
ThisBuild / version := "0.1.0"

This comment has been minimized.

Copy link
@FabioPinheiro

FabioPinheiro Nov 23, 2022

Author Contributor

=(

2 changes: 1 addition & 1 deletion infrastructure/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ services:
IRIS_DB_USER: postgres

prism-agent:
image: ghcr.io/input-output-hk/prism-agent:0.1.0-SNAPSHOT
image: ghcr.io/input-output-hk/prism-agent:0.2.0-SNAPSHOT
environment:
IRIS_HOST: iris
IRIS_PORT: 8081
Expand Down
6 changes: 6 additions & 0 deletions iris/client/scala-client/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ inThisBuild(
)
)

val commonSettings = Seq(
githubTokenSource := TokenSource.Environment("ATALA_GITHUB_TOKEN"),
resolvers += Resolver.githubPackages("input-output-hk"),
)

// Custom keys
val apiBaseDirectory = settingKey[File]("The base directory for Iris API specifications")
ThisBuild / apiBaseDirectory := baseDirectory.value / "../../api"
Expand All @@ -27,6 +32,7 @@ lazy val root = project
Compile / PB.targets := Seq(scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"),
Compile / PB.protoSources := Seq(apiBaseDirectory.value / "grpc")
)
.settings(commonSettings)

// ### ReleaseStep ###
releaseProcess := Seq[ReleaseStep](
Expand Down
3 changes: 3 additions & 0 deletions iris/service/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ inThisBuild(

def commonProject(project: Project): Project =
project.settings(
version := "0.1.0",
organization := "io.iohk.atala",
scalaVersion := "3.2.0",
githubTokenSource := TokenSource.Environment("ATALA_GITHUB_TOKEN"),
versionScheme := Some("semver-spec"),
resolvers += Resolver
Expand Down
3 changes: 2 additions & 1 deletion mercury/mercury-mediator/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ lazy val mediator = project
libraryDependencies ++= Seq(D.mercuryModels.value, D.mercuryAgent.value),
Compile / unmanagedResourceDirectories += apiBaseDirectory.value,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
githubTokenSource := TokenSource.Environment("ATALA_GITHUB_TOKEN"),
// ### Build Docker Image ###
Docker / maintainer := "[email protected]",
Docker / dockerRepository := Some("ghcr.io"),
Docker / dockerRepository := Some("atala-prism.io"),
Docker / dockerUsername := Some("input-output-hk"),
Docker / githubOwner := "atala-prism-building-blocks",
Docker / dockerUpdateLatest := true,
Expand Down
2 changes: 1 addition & 1 deletion mercury/mercury-mediator/version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / version := "0.1.0"
1 change: 1 addition & 0 deletions pollux/lib/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ publish / skip := true //Do not publish the root

lazy val vcJWT = project
.in(file("vc-jwt"))
.settings(commonSettings)
.settings(
name := "pollux-vc-jwt",
libraryDependencies ++= polluxVcJwtDependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
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
import IssueCredentialRecord._
import java.time.Instant
final case class IssueCredentialRecord(
id: UUID,
createdAt: Instant,
updatedAt: Option[Instant],
thid: UUID,
schemaId: Option[String],
role: Role,
subjectId: String,
validityPeriod: Option[Double] = None,
claims: Map[String, String],
automaticIssuance: Option[Boolean],
awaitConfirmation: Option[Boolean],
protocolState: ProtocolState,
publicationState: Option[PublicationState],
offerCredentialData: Option[OfferCredential],
Expand Down Expand Up @@ -50,6 +55,8 @@ object IssueCredentialRecord {

// Issuer has "accepted" a credential request received from a Holder (Issuer DB)
case CredentialPending extends ProtocolState
// Issuer has generated (signed) the credential and is now ready to send it to the Holder (Issuer DB)
case CredentialGenerated extends ProtocolState
// The credential has been sent to the holder (In Issuer DB)
case CredentialSent extends ProtocolState
// Holder has received the credential (In Holder DB)
Expand All @@ -58,7 +65,7 @@ object IssueCredentialRecord {
enum PublicationState:
// The credential requires on-chain publication and should therefore be included in the next Merkle Tree computation/publication
case PublicationPending extends PublicationState
// The credential publication operation has been successfuly sent to Iris and is pending publication
// The credential publication operation has been successfully sent to Iris and is pending publication
case PublicationQueued extends PublicationState
// The credential publication has been confirmed by Iris
case Published extends PublicationState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.iohk.atala.pollux.core.model.error

sealed trait CreateCredentialPayloadFromRecordError

object CreateCredentialPayloadFromRecordError {
final case class RepositoryError(cause: Throwable) extends CreateCredentialPayloadFromRecordError
final case class CouldNotExtractClaimsError(cause: Throwable) extends CreateCredentialPayloadFromRecordError
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package io.iohk.atala.pollux.core.model.error

import java.util.UUID

sealed trait IssueCredentialError

object IssueCredentialError {
final case class RepositoryError(cause: Throwable) extends IssueCredentialError
final case class RecordIdNotFound(recordId: UUID) extends IssueCredentialError
final case class ThreadIdNotFound(thid: UUID) extends IssueCredentialError
final case class InvalidFlowStateError(msg: String) extends IssueCredentialError
final case class UnexpectedError(msg: String) extends IssueCredentialError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.iohk.atala.pollux.core.model.error

import io.iohk.atala.pollux.vc.jwt.W3cCredentialPayload

sealed trait MarkCredentialRecordsAsPublishQueuedError

object MarkCredentialRecordsAsPublishQueuedError {
final case class RepositoryError(cause: Throwable) extends MarkCredentialRecordsAsPublishQueuedError
final case class CredentialIdNotDefined(credential: W3cCredentialPayload)
extends MarkCredentialRecordsAsPublishQueuedError
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
package io.iohk.atala.pollux.core.repository

import io.iohk.atala.pollux.core.model.EncodedJWTCredential
import zio.*
import io.iohk.atala.pollux.core.model.IssueCredentialRecord
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 getIssueCredentialRecordsByState(state: IssueCredentialRecord.ProtocolState): F[Seq[IssueCredentialRecord]]
def updateCredentialRecordStateAndProofByCredentialIdBulk(
idsStatesAndProofs: Seq[(UUID, IssueCredentialRecord.PublicationState, MerkleInclusionProof)]
): F[Int]

def getIssueCredentialRecord(id: UUID): F[Option[IssueCredentialRecord]]

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

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

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

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

0 comments on commit a80702f

Please sign in to comment.