Skip to content

Commit

Permalink
feat(agent): add CredentialIssuerService mock and get walletId by pri…
Browse files Browse the repository at this point in the history
…sm DID method

Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
  • Loading branch information
yshyn-iohk authored and patlo-iog committed Apr 29, 2024
1 parent a881c16 commit b826ac3
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ package object error {
final case class ValidationError(cause: OperationValidationError) extends DIDOperationError
}

sealed trait DIDResolutionError
sealed trait DIDResolutionError {
def message: String
}

object DIDResolutionError {
final case class DLTProxyError(cause: Throwable) extends DIDResolutionError
final case class UnexpectedDLTResult(msg: String) extends DIDResolutionError
final case class ValidationError(cause: OperationValidationError) extends DIDResolutionError
final case class DLTProxyError(cause: Throwable) extends DIDResolutionError {
override def message: String = cause.getMessage
}
final case class UnexpectedDLTResult(msg: String) extends DIDResolutionError {
override def message: String = msg
}
final case class ValidationError(cause: OperationValidationError) extends DIDResolutionError {
override def message: String = cause.toString
}
}

sealed trait OperationValidationError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ import org.hyperledger.identus.mercury.*
import org.hyperledger.identus.pollux.core.service.*
import org.hyperledger.identus.pollux.core.service.verification.VcVerificationServiceImpl
import org.hyperledger.identus.pollux.credentialdefinition.controller.CredentialDefinitionControllerImpl
import io.iohk.atala.agent.walletapi.sql.{JdbcDIDNonSecretStorage, JdbcEntityRepository, JdbcWalletNonSecretStorage}
import io.iohk.atala.agent.walletapi.storage.GenericSecretStorage
import io.iohk.atala.castor.controller.{DIDControllerImpl, DIDRegistrarControllerImpl}
import io.iohk.atala.castor.core.service.DIDServiceImpl
import io.iohk.atala.castor.core.util.DIDOperationValidator
import io.iohk.atala.connect.controller.ConnectionControllerImpl
import io.iohk.atala.connect.core.service.{ConnectionServiceImpl, ConnectionServiceNotifier}
import io.iohk.atala.connect.sql.repository.{JdbcConnectionRepository, Migrations as ConnectMigrations}
import io.iohk.atala.credentialstatus.controller.CredentialStatusControllerImpl
import io.iohk.atala.event.controller.EventControllerImpl
import io.iohk.atala.event.notification.EventNotificationServiceImpl
import io.iohk.atala.iam.authentication.DefaultAuthenticator
import io.iohk.atala.iam.authentication.apikey.JdbcAuthenticationRepository
import io.iohk.atala.iam.authorization.DefaultPermissionManagementService
import io.iohk.atala.iam.authorization.core.EntityPermissionManagementService
import io.iohk.atala.iam.entity.http.controller.{EntityController, EntityControllerImpl}
import io.iohk.atala.iam.oidc.controller.CredentialIssuerControllerImpl
import io.iohk.atala.iam.oidc.domain.{CredentialIssuerService, CredentialIssuerServiceImpl}
import io.iohk.atala.iam.wallet.http.controller.WalletManagementControllerImpl
import io.iohk.atala.issue.controller.IssueControllerImpl
import io.iohk.atala.mercury.*
import io.iohk.atala.pollux.core.service.*
import io.iohk.atala.pollux.credentialdefinition.controller.CredentialDefinitionControllerImpl
import org.hyperledger.identus.pollux.credentialschema.controller.{
CredentialSchemaController,
CredentialSchemaControllerImpl,
Expand Down Expand Up @@ -197,6 +220,8 @@ object MainApp extends ZIOAppDefault {
RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcCredentialDefinitionRepository.layer,
RepoModule.polluxContextAwareTransactorLayer ++ RepoModule.polluxTransactorLayer >>> JdbcPresentationRepository.layer,
RepoModule.polluxContextAwareTransactorLayer >>> JdbcVerificationPolicyRepository.layer,
// oidc
DIDServiceImpl.layer ++ CredentialIssuerServiceImpl.layer >>> CredentialIssuerControllerImpl.layer,
// event notification service
ZLayer.succeed(500) >>> EventNotificationServiceImpl.layer,
// HTTP client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ import org.hyperledger.identus.pollux.credentialschema.controller.{
import org.hyperledger.identus.presentproof.controller.PresentProofController
import org.hyperledger.identus.system.controller.SystemController
import org.hyperledger.identus.verification.controller.VcVerificationController
import io.iohk.atala.agent.server.AgentHttpServer
import io.iohk.atala.agent.server.http.DocModels
import io.iohk.atala.castor.controller.{DIDController, DIDRegistrarController}
import io.iohk.atala.connect.controller.ConnectionController
import io.iohk.atala.credentialstatus.controller.CredentialStatusController
import io.iohk.atala.event.controller.EventController
import io.iohk.atala.iam.authentication.DefaultAuthenticator
import io.iohk.atala.iam.entity.http.controller.EntityController
import io.iohk.atala.iam.oidc.controller.CredentialIssuerController
import io.iohk.atala.iam.wallet.http.controller.WalletManagementController
import io.iohk.atala.issue.controller.IssueController
import io.iohk.atala.pollux.credentialdefinition.controller.CredentialDefinitionController
import io.iohk.atala.pollux.credentialschema.controller.{CredentialSchemaController, VerificationPolicyController}
import io.iohk.atala.presentproof.controller.PresentProofController
import io.iohk.atala.system.controller.SystemController
import org.scalatestplus.mockito.MockitoSugar.*
import sttp.tapir.docs.openapi.OpenAPIDocsInterpreter
import zio.{Scope, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer}
Expand Down Expand Up @@ -55,7 +70,8 @@ object Tapir2StaticOAS extends ZIOAppDefault {
ZLayer.succeed(mock[EntityController]) ++
ZLayer.succeed(mock[WalletManagementController]) ++
ZLayer.succeed(mock[DefaultAuthenticator]) ++
ZLayer.succeed(mock[EventController])
ZLayer.succeed(mock[EventController]) ++
ZLayer.succeed(mock[CredentialIssuerController])
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,20 @@ class JdbcDIDNonSecretStorage(xa: Transactor[ContextAwareTask], xb: Transactor[T
cnxIO.transact(xb)
}

override def getPrismDidWalletId(prismDid: PrismDID): Task[Option[WalletId]] = {
val cnxIO = sql"""
| SELECT
| wallet_id
| FROM public.prism_did_wallet_state
| WHERE
| did = ${prismDid.toString}
""".stripMargin
.query[WalletId]
.option

cnxIO.transact(xb)
}

}

object JdbcDIDNonSecretStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import org.hyperledger.identus.agent.walletapi.model.*
import org.hyperledger.identus.castor.core.model.did.{PrismDID, ScheduledDIDOperationStatus}
import org.hyperledger.identus.mercury.model.DidId
import org.hyperledger.identus.shared.models.WalletAccessContext
import io.iohk.atala.agent.walletapi.model.*
import io.iohk.atala.castor.core.model.did.{PrismDID, ScheduledDIDOperationStatus}
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.shared.models.{WalletAccessContext, WalletId}
import zio.*

import scala.collection.immutable.ArraySeq
Expand Down Expand Up @@ -58,4 +62,6 @@ trait DIDNonSecretStorage {

def getPeerDIDRecord(did: DidId): Task[Option[PeerDIDRecord]]

def getPrismDidWalletId(prismDid: PrismDID): Task[Option[WalletId]]

}
1 change: 1 addition & 0 deletions infrastructure/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ fi

PORT=${PORT} NETWORK=${NETWORK} DOCKERHOST=${DOCKERHOST} docker compose \
-p ${NAME} \
${DEBUG} \
-f ${SCRIPT_DIR}/../shared/docker-compose.yml \
--env-file ${ENV_FILE} ${DEBUG} up ${BACKGROUND} ${WAIT}
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,3 @@ class DidCommX() extends DidOps /* with DidAgent with DIDResolver */ {
} yield (ret)

}

// object AgentService {
// val alice = ZLayer.succeed(
// AgentService[Agent.Alice.type](
// new DIDComm(UniversalDidResolver, AliceSecretResolver.secretResolver),
// Agent.Alice
// )
// )
// val bob = ZLayer.succeed(
// AgentService[Agent.Bob.type](
// new DIDComm(UniversalDidResolver, BobSecretResolver.secretResolver),
// Agent.Bob
// )
// )

// // val charlie = ZLayer.succeed(
// // AgentService[Agent.Charlie.type](
// // new DIDComm(UniversalDidResolver, CharlieSecretResolver.secretResolver),
// // Agent.Charlie
// // )
// // )

// }
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
package io.iohk.atala.iam.oidc

import io.iohk.atala.api.http.{EndpointOutputs, ErrorResponse, RequestContext}
import io.iohk.atala.api.http.{ErrorResponse, RequestContext}
import io.iohk.atala.castor.controller.http.DIDInput
import io.iohk.atala.castor.controller.http.DIDInput.didRefPathSegment
import io.iohk.atala.iam.authentication.apikey.ApiKeyCredentials
import io.iohk.atala.iam.authentication.apikey.ApiKeyEndpointSecurityLogic.apiKeyHeader
import io.iohk.atala.iam.authentication.oidc.JwtCredentials
import io.iohk.atala.iam.authentication.oidc.JwtSecurityLogic.jwtAuthHeader
import io.iohk.atala.iam.oidc.http.{
CredentialErrorResponse,
CredentialRequest,
CredentialResponse,
DeferredCredentialResponse,
ImmediateCredentialResponse,
JwtCredentialRequest,
NonceResponse
}
import io.iohk.atala.iam.oidc.http.{CredentialErrorResponse, CredentialRequest, CredentialResponse, NonceResponse}
import sttp.apispec.Tag
import sttp.tapir.{
Endpoint,
EndpointInput,
endpoint,
extractFromRequest,
model,
oneOf,
oneOfVariantValueMatcher,
path,
query,
statusCode,
stringToPath
}
import sttp.model.StatusCode
import sttp.tapir.json.zio.jsonBody
import sttp.tapir.{Endpoint, endpoint, extractFromRequest, oneOf, oneOfVariantValueMatcher, statusCode, stringToPath}

object CredentialIssuerEndpoints {

Expand All @@ -47,6 +25,8 @@ object CredentialIssuerEndpoints {

val tag = Tag(tagName, Some(tagDescription))

type ExtendedErrorResponse = Either[ErrorResponse, CredentialErrorResponse]

private val baseEndpoint = endpoint
.tag(tagName)
.securityIn(jwtAuthHeader)
Expand All @@ -71,7 +51,7 @@ object CredentialIssuerEndpoints {
val credentialEndpoint: Endpoint[
JwtCredentials,
(RequestContext, String, CredentialRequest),
Either[ErrorResponse, CredentialErrorResponse],
ExtendedErrorResponse,
CredentialResponse,
Any
] = baseEndpoint.post
Expand All @@ -91,7 +71,7 @@ object CredentialIssuerEndpoints {
val nonceEndpoint: Endpoint[
JwtCredentials,
(RequestContext, String),
Either[ErrorResponse, CredentialErrorResponse],
ExtendedErrorResponse,
NonceResponse,
Any
] = baseEndpoint.get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.iohk.atala.iam.oidc
import io.iohk.atala.agent.walletapi.model.BaseEntity
import io.iohk.atala.api.http.{ErrorResponse, RequestContext}
import io.iohk.atala.iam.authentication.{Authenticator, DefaultAuthenticator, SecurityLogic}
import io.iohk.atala.iam.oidc.controller.CredentialIssuerController
import io.iohk.atala.iam.oidc.http.{
CredentialErrorResponse,
CredentialRequest,
Expand All @@ -15,8 +16,9 @@ import zio.*
import java.time.Instant
import java.util.UUID

class CredentialIssuerServerEndpoints(
authenticator: Authenticator[BaseEntity]
case class CredentialIssuerServerEndpoints(
authenticator: Authenticator[BaseEntity],
credentialIssuerController: CredentialIssuerController
) {
val credentialServerEndpoint: ZServerEndpoint[Any, Any] =
CredentialIssuerEndpoints.credentialEndpoint
Expand All @@ -27,7 +29,7 @@ class CredentialIssuerServerEndpoints(
)
.serverLogic { wac =>
{ case (ctx: RequestContext, didRef: String, request: CredentialRequest) =>
ZIO.succeed(ImmediateCredentialResponse("credential"))
credentialIssuerController.issueCredential(ctx, didRef, request)
}
}

Expand All @@ -48,10 +50,11 @@ class CredentialIssuerServerEndpoints(
}

object CredentialIssuerServerEndpoints {
def all: URIO[DefaultAuthenticator, List[ZServerEndpoint[Any, Any]]] = {
def all: URIO[DefaultAuthenticator & CredentialIssuerController, List[ZServerEndpoint[Any, Any]]] = {
for {
authenticator <- ZIO.service[DefaultAuthenticator]
oidcEndpoints = new CredentialIssuerServerEndpoints(authenticator)
credentialIssuerController <- ZIO.service[CredentialIssuerController]
oidcEndpoints = CredentialIssuerServerEndpoints(authenticator, credentialIssuerController)
} yield oidcEndpoints.all
}
}

0 comments on commit b826ac3

Please sign in to comment.