Skip to content

Commit

Permalink
chore(prism-agent): pr diff cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Losoponkul committed Nov 21, 2022
1 parent d5063b7 commit 1dcbd6e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import akka.actor.BootstrapSetup
import akka.actor.setup.ActorSystemSetup
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.server.Route
import doobie.util.transactor.Transactor
import io.iohk.atala.agent.server.http.{HttpRoutes, HttpServer}
import io.iohk.atala.castor.core.service.{DIDService, DIDServiceImpl}
import io.iohk.atala.castor.core.util.DIDOperationValidator
import io.iohk.atala.agent.server.http.marshaller.{
Expand All @@ -23,17 +20,13 @@ import io.iohk.atala.agent.server.http.service.{
DIDRegistrarApiServiceImpl,
IssueCredentialsApiServiceImpl
}
import io.iohk.atala.castor.core.repository.DIDOperationRepository
import io.iohk.atala.agent.openapi.api.{
DIDApi,
DIDAuthenticationApi,
DIDOperationsApi,
DIDRegistrarApi,
IssueCredentialsApi
}
import io.iohk.atala.castor.sql.repository.{JdbcDIDOperationRepository, TransactorLayer}
import zio.*
import zio.interop.catz.*
import cats.effect.std.Dispatcher
import com.typesafe.config.ConfigFactory
import doobie.util.transactor.Transactor
Expand All @@ -44,11 +37,7 @@ import io.iohk.atala.agent.walletapi.service.ManagedDIDService
import io.iohk.atala.agent.server.http.marshaller.*
import io.iohk.atala.agent.server.http.service.*
import io.iohk.atala.agent.server.http.{HttpRoutes, HttpServer}
import io.iohk.atala.castor.core.repository.DIDOperationRepository
import io.iohk.atala.castor.core.service.{DIDService, DIDServiceImpl}
import io.iohk.atala.pollux.core.service.CredentialServiceImpl
import io.iohk.atala.castor.sql.repository.{JdbcDIDOperationRepository, TransactorLayer}
import io.iohk.atala.castor.sql.repository.DbConfig as CastorDbConfig
import io.iohk.atala.iris.proto.service.IrisServiceGrpc
import io.iohk.atala.iris.proto.service.IrisServiceGrpc.IrisServiceStub
import io.iohk.atala.pollux.core.repository.CredentialRepository
Expand Down Expand Up @@ -230,13 +219,13 @@ object SystemModule {
}

object AppModule {
val didOperationValidatorLayer: ULayer[DIDOperationValidator] = DIDOperationValidator.layer()
val didOpValidatorLayer: ULayer[DIDOperationValidator] = DIDOperationValidator.layer()

val didServiceLayer: TaskLayer[DIDService] =
(didOperationValidatorLayer ++ GrpcModule.layers) >>> DIDServiceImpl.layer
(didOpValidatorLayer ++ GrpcModule.layers) >>> DIDServiceImpl.layer

val manageDIDServiceLayer: TaskLayer[ManagedDIDService] =
(didOperationValidatorLayer ++ didServiceLayer) >>> ManagedDIDService.inMemoryStorage
(didOpValidatorLayer ++ didServiceLayer) >>> ManagedDIDService.inMemoryStorage

val credentialServiceLayer: TaskLayer[CredentialService] =
(GrpcModule.layers ++ RepoModule.layers) >>> CredentialServiceImpl.layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package io.iohk.atala.agent.walletapi.model.error
import io.iohk.atala.castor.core.model.did.PrismDID
import io.iohk.atala.castor.core.model.error.DIDOperationError

import scala.collection.immutable.ArraySeq

sealed trait PublishManagedDIDError

object PublishManagedDIDError {
final case class DIDNotFound(did: PrismDID) extends PublishManagedDIDError
final case class WalletStorageError(cause: Throwable) extends PublishManagedDIDError
final case class OperationError(cause: DIDOperationError) extends PublishManagedDIDError
final case class CryptographicError(cause: Throwable) extends PublishManagedDIDError
final case class CryptographyError(cause: Throwable) extends PublishManagedDIDError
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ final class ManagedDIDService private[walletapi] (
private val CURVE = EllipticCurve.SECP256K1

def publishStoredDID(did: CanonicalPrismDID): IO[PublishManagedDIDError, ScheduleDIDOperationOutcome] = {
def syncStateAndPersist =
def syncDLTStateAndPersist =
nonSecretStorage
.getManagedDIDState(did)
.mapError(PublishManagedDIDError.WalletStorageError.apply)
.flatMap(op => ZIO.fromOption(op).mapError(_ => PublishManagedDIDError.DIDNotFound(did)))
.flatMap(state => ZIO.fromOption(state).mapError(_ => PublishManagedDIDError.DIDNotFound(did)))
.flatMap(state => syncDIDStateFromDLT(state).mapError(PublishManagedDIDError.OperationError.apply))
.tap(state =>
nonSecretStorage.setManagedDIDState(did, state).mapError(PublishManagedDIDError.WalletStorageError.apply)
Expand All @@ -71,14 +71,14 @@ final class ManagedDIDService private[walletapi] (
ZIO
.fromOption(maybeKey)
.orDieWith(_ =>
new Exception("master-key must exists in the wallet for create DID publication signature")
new Exception("master-key must exists in the wallet for DID publication operation signature")
)
)
signedAtalaOperation <- ZIO
.fromTry(
ECWrapper.signBytes(CURVE, operation.toAtalaOperation.toByteArray, masterKeyPair.privateKey)
)
.mapError(PublishManagedDIDError.CryptographicError.apply)
.mapError(PublishManagedDIDError.CryptographyError.apply)
.map(signature =>
SignedPrismDIDOperation.Create(
operation = operation,
Expand All @@ -95,7 +95,7 @@ final class ManagedDIDService private[walletapi] (
} yield outcome

for {
didState <- syncStateAndPersist
didState <- syncDLTStateAndPersist
outcome <- didState match {
case ManagedDIDState.Created(operation) => submitOperation(operation)
case ManagedDIDState.PublicationPending(operation, operationId) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private[walletapi] class InMemoryDIDNonSecretStorage private (
override def setManagedDIDState(did: PrismDID, state: ManagedDIDState): Task[Unit] =
store.update(_.updated(did, state))

def listManagedDID: Task[Map[PrismDID, ManagedDIDState]] = store.get
override def listManagedDID: Task[Map[PrismDID, ManagedDIDState]] = store.get

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ object ManagedDIDTemplateValidator {
def validate(template: ManagedDIDTemplate): Either[String, Unit] = {
for {
_ <- validateReservedKeyId(template)
_ <- validateUniqueKeyId(template)
} yield ()
}

Expand All @@ -20,10 +19,4 @@ object ManagedDIDTemplateValidator {
else Right(())
}

private def validateUniqueKeyId(template: ManagedDIDTemplate): Either[String, Unit] = {
val keyIds = template.publicKeys.map(_.id)
if (keyIds.distinct.length == keyIds.length) Right(())
else Left("Public key for creating a DID id must be unique")
}

}

0 comments on commit 1dcbd6e

Please sign in to comment.