Skip to content

Commit

Permalink
feat(prism-agent): add 'GET /present-proof/presentations/{id}' endpoi…
Browse files Browse the repository at this point in the history
…nt (#282)
  • Loading branch information
bvoiturier authored Dec 20, 2022
1 parent e39daf5 commit 030a257
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
25 changes: 25 additions & 0 deletions prism-agent/service/api/http/prism-agent-openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,31 @@ paths:
application/json:
schema:
$ref: "./castor/schemas.yaml#/components/schemas/ErrorResponse"
get:
tags: [ "Present Proof" ]
operationId: getPresentation
parameters:
- in: path
name: id
schema:
type: string
required: true
description: Unique identifier of the presentation
example: "06e126d1-fa44-4882-a243-1e326fbe21db"
summary: Returns an existing presentation record by id.
responses:
"200":
description: Presentation state record
content:
application/json:
schema:
$ref: "./pollux/schemas.yaml#/components/schemas/PresentationStatus"
"404":
description: There is no presentation record matching the given 'id'.
content:
application/json:
schema:
$ref: "./castor/schemas.yaml#/components/schemas/ErrorResponse"

# ----------------------------------
# Connect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ object PresentProofApiMarshallerImpl extends JsonSupport {
implicit def fromEntityUnmarshallerRequestPresentationInput: FromEntityUnmarshaller[RequestPresentationInput] =
summon[RootJsonFormat[RequestPresentationInput]]

implicit def toEntityMarshallerPresentationStatus: ToEntityMarshaller[PresentationStatus] =
summon[RootJsonFormat[PresentationStatus]]

implicit def toEntityMarshallerPresentationStatusarray: ToEntityMarshaller[Seq[PresentationStatus]] =
summon[RootJsonFormat[Seq[PresentationStatus]]]
implicit def toEntityMarshallerRequestPresentationOutput: ToEntityMarshaller[RequestPresentationOutput] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import io.iohk.atala.castor.core.model.did.{LongFormPrismDID, PrismDID}

import java.util.UUID
import io.iohk.atala.connect.core.model.ConnectionRecord.Role
import io.iohk.atala.agent.openapi.model.PresentationStatus

trait OASDomainModelHelper {

Expand Down Expand Up @@ -145,6 +146,29 @@ trait OASDomainModelHelper {
)
}

extension (domain: polluxdomain.PresentationRecord) {
def toOAS: PresentationStatus = {
val connectionId = domain.connectionId
val data = domain.presentationData match
case Some(p) =>
p.attachments.head.data match {
case Base64(data) =>
val base64Decoded = new String(java.util.Base64.getDecoder().decode(data)).drop(1).dropRight(1)
println(s"Base64decode:\n\n ${base64Decoded} \n\n")
Seq(base64Decoded)
case any => ???
}
case None => Seq.empty
PresentationStatus(
presentationId = domain.id.toString,
status = domain.protocolState.toString,
proofs = Seq.empty,
data = data,
connectionId = connectionId
)
}
}

extension (str: String) {
def toUUID: ZIO[Any, InvalidPayload, UUID] =
ZIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,9 @@ class PresentProofApiServiceImpl(
records <- presentationService
.getPresentationRecords()
.mapError(HttpServiceError.DomainError[PresentationError].apply)
} yield records

presentationStatus = records.map { record =>
val connectionId = record.connectionId
val data = record.presentationData match
case Some(p) =>
p.attachments.head.data match {
case Base64(data) =>
val base64Decoded = new String(java.util.Base64.getDecoder().decode(data)).drop(1).dropRight(1)
println(s"Base64decode:\n\n ${base64Decoded} \n\n")
Seq(base64Decoded)
case any => ???
}
case None => Seq.empty

PresentationStatus(record.id.toString, record.protocolState.toString, Seq.empty, data, connectionId)
}
} yield presentationStatus

onZioSuccess(result.mapError(_.toOAS).either) {
onZioSuccess(result.mapBoth(_.toOAS, _.map(_.toOAS)).either) {
case Left(error) => complete(error.status -> error)
case Right(results) => {

Expand All @@ -112,6 +96,24 @@ class PresentProofApiServiceImpl(
}
}

def getPresentation(id: String)(implicit
toEntityMarshallerPresentationStatus: ToEntityMarshaller[PresentationStatus],
toEntityMarshallerErrorResponse: ToEntityMarshaller[ErrorResponse]
): Route = {
val result = for {
presentationId <- id.toUUID
outcome <- presentationService
.getPresentationRecord(presentationId)
.mapError(HttpServiceError.DomainError[PresentationError].apply)
} yield outcome

onZioSuccess(result.mapBoth(_.toOAS, _.map(_.toOAS)).either) {
case Left(error) => complete(error.status -> error)
case Right(Some(result)) => getPresentation200(result)
case Right(None) => getPresentation404(notFoundErrorResponse(Some("Presentation record not found")))
}
}

override def updatePresentation(id: String, requestPresentationAction: RequestPresentationAction)(implicit
toEntityMarshallerErrorResponse: ToEntityMarshaller[ErrorResponse]
): Route = {
Expand Down

0 comments on commit 030a257

Please sign in to comment.