diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala index 559b6c7c23..772c3f31a4 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatus.scala @@ -1,7 +1,8 @@ package org.hyperledger.identus.presentproof.controller.http import org.hyperledger.identus.api.http.{Annotation, ErrorResponse} -import org.hyperledger.identus.mercury.model.Base64 +import org.hyperledger.identus.mercury.model.{AttachmentDescriptor, Base64, JsonData} +import org.hyperledger.identus.mercury.protocol.presentproof.{Presentation, RequestPresentation} import org.hyperledger.identus.pollux.core.model.PresentationRecord import org.hyperledger.identus.presentproof.controller.http.PresentationStatus.annotations import org.hyperledger.identus.shared.models.{FailureInfo, StatusCode} @@ -30,6 +31,9 @@ final case class PresentationStatus( @description(annotations.data.description) @encodedExample(annotations.data.example) data: Seq[String], + @description(annotations.requestData.description) + @encodedExample(annotations.requestData.example) + requestData: Seq[String], @description(annotations.connectionId.description) @encodedExample(annotations.connectionId.example) connectionId: Option[String] = None, @@ -54,15 +58,8 @@ final case class PresentationStatus( object PresentationStatus { def fromDomain(domain: PresentationRecord): PresentationStatus = { - val data = domain.presentationData match - case Some(p) => - p.attachments.head.data match { - case Base64(data) => - val base64Decoded = new String(java.util.Base64.getUrlDecoder.decode(data)) - Seq(base64Decoded) - case any => FeatureNotImplemented - } - case None => Seq.empty + val data = extractData(domain.presentationData, (p: Presentation) => p.attachments) + val requestData = extractData(domain.requestPresentationData, (p: RequestPresentation) => p.attachments) PresentationStatus( domain.id.value, thid = domain.thid.value, @@ -70,6 +67,7 @@ object PresentationStatus { status = domain.protocolState.toString, proofs = Seq.empty, data = data, + requestData = requestData, connectionId = domain.connectionId, invitation = domain.invitation.map(invitation => OOBPresentationInvitation.fromDomain(invitation)), goalCode = domain.invitation.flatMap(_.body.goal_code), @@ -80,6 +78,23 @@ object PresentationStatus { ) } + private def extractData[A]( + maybePresentation: Option[A], + extractAttachments: A => Seq[AttachmentDescriptor] + ): Seq[String] = { + maybePresentation match + case Some(p) => + extractAttachments(p).head.data match { + case Base64(data) => + val base64Decoded = new String(java.util.Base64.getUrlDecoder.decode(data)) + Seq(base64Decoded) + case JsonData(jsonData) => + Seq(jsonData.toJson.toString) + case any => FeatureNotImplemented + } + case None => Seq.empty + } + given Conversion[PresentationRecord, PresentationStatus] = fromDomain object annotations { @@ -143,6 +158,11 @@ object PresentationStatus { description = "The list of proofs presented by the prover to the verifier.", example = Seq.empty ) + object requestData + extends Annotation[Seq[String]]( + description = "The list of request presented by the verifier to the prover.", + example = Seq.empty + ) object connectionId extends Annotation[String]( description = "The unique identifier of an established connection between the verifier and the prover.", diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatusPage.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatusPage.scala index e7c34c1689..d9cf2d1986 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatusPage.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/PresentationStatusPage.scala @@ -71,6 +71,7 @@ object PresentationStatusPage { status = "RequestSent", proofs = Seq.empty, data = Seq.empty, + requestData = Seq.empty, connectionId = Some("e0d81be9-47ca-4e0b-b8a7-325e8c3abc2f"), invitation = None, metaRetries = 5 @@ -81,6 +82,7 @@ object PresentationStatusPage { role = "Prover", status = "RequestReceived", proofs = Seq.empty, + requestData = Seq.empty, data = Seq.empty, metaRetries = 5 ), @@ -90,6 +92,7 @@ object PresentationStatusPage { role = "Prover", status = "PresentationPending", proofs = Seq.empty, + requestData = Seq.empty, data = Seq.empty, metaRetries = 5 ), @@ -99,6 +102,7 @@ object PresentationStatusPage { role = "Verifier", status = "PresentationVerified", proofs = Seq.empty, + requestData = Seq.empty, data = Seq( "{\"claimsToDisclose\":{\"emailAddress\":{},\"givenName\":{}},\"presentation\":\"{\\\"protected\\\":\\\"eyJhbGciOiJFZERTQSJ9\\\",\\\"payload\\\":\\\"eyJfc2QiOlsiMGl4d0tIV0dzbzFvZThFR0hQd2tGYW9EZE1TRFQ3SmgyNkZGSm1ZbGRnRSIsIjQ4VlFXZS1tcjBibHMyOWpicHFKeDNxX2dYY0k5N3dHcEpsZnRoNXQwMGciLCI0Wk9xanFNZVNUVHRKQTNJRExsc3ZXN0dTNzRIemNxY3N2NVFoZk1valE4IiwiUjhGRE0ydXB1V09mNmVJMVA5ckNPdG12c3puVWFFYXpncVNuN0JfeTE0MCIsIlU5MmpfUHlpcHN2TERNQTlDaVRWbnl3bUFzYTM4S2lDWm5TeVhyUE5mNG8iLCJldFB1Mmc5ajdRd01rZ3g5VnpEX1RnNTNUV3UydVpadk1KeHRnNEJ1WGJBIiwidGV3RG1LWklNcS10bUNrMkpqZU0wajNYbU1aUUFLN01heENVNlF4dm9OMCJdLCJfc2RfYWxnIjoic2hhLTI1NiIsImlzcyI6ImRpZDpwcmlzbToxMmEzOWI1YWEwZTcxODI3ZmMxYzYwMjg1ZDVlZWJjMTk0Yjg2NzFhYTJmY2QxZDM2NDBkMGYwMTBlMzliZmVlIiwiaWF0IjoxNzE3NDEwMzgzLCJleHAiOjE3MjAwMDIzODN9\\\",\\\"signature\\\":\\\"953FfSRU_0Y2q0ERrFPzbXJ_hkF0YQe5efwESaZwtXDCn8aanD3MUstp3lzqGZkhvcWRdtCCpIxzhy0zgKwLBg\\\",\\\"disclosures\\\":[\\\"WyI0SHF6MDZCeG5fRlJMb2hWX2lWNXp3IiwgImdpdmVuTmFtZSIsICJBbGljZSJd\\\",\\\"WyJLUnNYYU01c3NXZTl4UEhqQnNjT213IiwgImVtYWlsQWRkcmVzcyIsICJhbGljZUB3b25kZXJsYW5kLmNvbSJd\\\"],\\\"kb_jwt\\\":null}\"}" ), @@ -112,6 +116,7 @@ object PresentationStatusPage { status = "InvitationGenerated", proofs = Seq.empty, data = Seq.empty, + requestData = Seq.empty, connectionId = None, myDid = Some("did:peer:veriferPeerDID1234567890"), invitation = Some(