Skip to content

Commit

Permalink
fix(prism-agent): fix incorrect long-form parsing behavior on resolut…
Browse files Browse the repository at this point in the history
…ion endpoint (#475)

* fix(prism-agent): update castor pollux and make it compile

* fix(prism-agent): add errorMessage to the resolution metadata

* fix(prism-agent): use released version of castor pollux
  • Loading branch information
patlo-iog committed Mar 23, 2023
1 parent 7fa2e1a commit af356d6
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 37 deletions.
4 changes: 4 additions & 0 deletions prism-agent/service/api/http/castor/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ components:
type: string
description: Resolution error constant according to [DID spec registries](https://www.w3.org/TR/did-spec-registries/#error)
example: invalidDid
errorMessage:
type: string
description: Resolution error message
example: The initialState does not match the suffix
contentType:
type: string
description: The media type of the returned DID document
Expand Down
4 changes: 2 additions & 2 deletions prism-agent/service/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ object Dependencies {
val zioMetrics = "2.0.6"
val akka = "2.6.20"
val akkaHttp = "10.2.9"
val castor = "0.8.1"
val pollux = "0.43.1"
val castor = "0.8.2"
val pollux = "0.43.2"
val connect = "0.13.0"
val bouncyCastle = "1.70"
val logback = "1.4.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
given RootJsonFormat[DIDDocumentMetadata] = jsonFormat2(DIDDocumentMetadata.apply)
given RootJsonFormat[DIDOperationResponse] = jsonFormat1(DIDOperationResponse.apply)
given RootJsonFormat[DidOperationSubmission] = jsonFormat2(DidOperationSubmission.apply)
given RootJsonFormat[DIDResolutionMetadata] = jsonFormat2(DIDResolutionMetadata.apply)
given RootJsonFormat[DIDResolutionMetadata] = jsonFormat3(DIDResolutionMetadata.apply)
given RootJsonFormat[ErrorResponse] = jsonFormat5(ErrorResponse.apply)
given RootJsonFormat[ManagedDID] = jsonFormat3(ManagedDID.apply)
given RootJsonFormat[ManagedDIDPage] = jsonFormat6(ManagedDIDPage.apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ trait OASDomainModelHelper {
`@context` = "https://w3id.org/did-resolution/v1",
didDocument = None,
didDocumentMetadata = DIDDocumentMetadata(),
didResolutionMetadata = DIDResolutionMetadata(error = Some(resolutionError.value))
didResolutionMetadata =
DIDResolutionMetadata(error = Some(resolutionError.value), errorMessage = resolutionError.errorMessage)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,6 @@ trait OASErrorModelHelper {
}
}

given ToErrorResponse[DIDResolutionErrorRepr] with {
override def toErrorResponse(e: DIDResolutionErrorRepr): ErrorResponse = {
import DIDResolutionErrorRepr.*
val status = e match {
case InvalidDID => 422
case InvalidDIDUrl => 422
case NotFound => 404
case RepresentationNotSupported => 422
case InternalError => 500
case InvalidPublicKeyLength => 422
case InvalidPublicKeyType => 422
case UnsupportedPublicKeyType => 422
}
ErrorResponse(
`type` = "error-type",
title = e.value,
status = status,
detail = Some(e.toString),
instance = "error-instance"
)
}
}

given ToErrorResponse[CredentialServiceError] with {
def toErrorResponse(error: CredentialServiceError): ErrorResponse = {
ErrorResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class DIDApiServiceImpl(service: DIDService)(using runtime: Runtime[Any])
resolutionError match {
case None if !isDeactivated => complete(200 -> resolutionResult)
case None => complete(410 -> resolutionResult)
case Some(InvalidDID) => complete(400 -> resolutionResult)
case Some(InvalidDIDUrl) => complete(400 -> resolutionResult)
case Some(InvalidDID(_)) => complete(400 -> resolutionResult)
case Some(InvalidDIDUrl(_)) => complete(400 -> resolutionResult)
case Some(NotFound) => complete(404 -> resolutionResult)
case Some(RepresentationNotSupported) => complete(406 -> resolutionResult)
case Some(InternalError) => complete(500 -> resolutionResult)
case Some(InternalError(_)) => complete(500 -> resolutionResult)
case Some(_) => complete(500 -> resolutionResult)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ object OperationFactory {
CreateManagedDIDError.KeyGenerationError.apply
)
operation = PrismDIDOperation.Create(
publicKeys = keys.map(_._2),
internalKeys = Seq(masterKey._2),
publicKeys = keys.map(_._2) ++ Seq(masterKey._2),
services = didTemplate.services
)
secret = CreateDIDSecret(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import io.iohk.atala.agent.walletapi.model.{DIDPublicKeyTemplate, ManagedDIDStat
import io.iohk.atala.castor.core.model.did.{
DIDData,
DIDMetadata,
InternalPublicKey,
PrismDID,
PrismDIDOperation,
ScheduleDIDOperationOutcome,
PublicKey,
ScheduledDIDOperationDetail,
ScheduledDIDOperationStatus,
ScheduleDIDOperationOutcome,
Service,
SignedPrismDIDOperation,
VerificationRelationship
Expand Down Expand Up @@ -137,7 +139,7 @@ object ManagedDIDServiceSpec extends ZIOSpecDefault, PostgresTestContainerSuppor
assert(opsAfter.map(_.operation))(hasSameElements(Seq(createOp)))
},
test("fail when publish non-existing DID") {
val did = PrismDID.buildLongFormFromOperation(PrismDIDOperation.Create(Nil, Nil, Nil)).asCanonical
val did = PrismDID.buildLongFormFromOperation(PrismDIDOperation.Create(Nil, Nil)).asCanonical
val result = ZIO.serviceWithZIO[ManagedDIDService](_.publishStoredDID(did))
assertZIO(result.exit)(fails(isSubtype[PublishManagedDIDError.DIDNotFound](anything)))
},
Expand Down Expand Up @@ -201,7 +203,7 @@ object ManagedDIDServiceSpec extends ZIOSpecDefault, PostgresTestContainerSuppor
did <- svc.createAndStoreDID(template).map(_.asCanonical)
state <- svc.nonSecretStorage.getManagedDIDState(did)
createOperation <- ZIO.fromOption(state.collect { case ManagedDIDState.Created(operation) => operation })
publicKeys = createOperation.publicKeys
publicKeys = createOperation.publicKeys.collect { case pk: PublicKey => pk }
} yield assert(publicKeys.map(i => i.id -> i.purpose))(
hasSameElements(
Seq(
Expand All @@ -218,7 +220,7 @@ object ManagedDIDServiceSpec extends ZIOSpecDefault, PostgresTestContainerSuppor
did <- svc.createAndStoreDID(generateDIDTemplate()).map(_.asCanonical)
state <- svc.nonSecretStorage.getManagedDIDState(did)
createOperation <- ZIO.fromOption(state.collect { case ManagedDIDState.Created(operation) => operation })
internalKeys = createOperation.internalKeys
internalKeys = createOperation.publicKeys.collect { case pk: InternalPublicKey => pk }
} yield assert(internalKeys.map(_.purpose))(contains(InternalKeyPurpose.Master))
},
test("validate DID before persisting it in storage") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import zio.*
import io.iohk.atala.agent.walletapi.model.ManagedDIDState

trait StorageSpecHelper {
protected val didExample = PrismDID.buildLongFormFromOperation(PrismDIDOperation.Create(Nil, Nil, Nil))
protected val didExample = PrismDID.buildLongFormFromOperation(PrismDIDOperation.Create(Nil, Nil))

protected def updateLineage(
operationId: Array[Byte] = Array.fill(32)(0),
Expand Down

0 comments on commit af356d6

Please sign in to comment.