Skip to content

Commit

Permalink
fix: GET Requested present proof by Holder (#1316)
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <[email protected]>
  • Loading branch information
CryptoKnightIOG authored Sep 3, 2024
1 parent 11ee9df commit 3b3da2c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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,
Expand All @@ -54,22 +58,16 @@ 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,
role = domain.role.toString,
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),
Expand All @@ -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 {
Expand Down Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -81,6 +82,7 @@ object PresentationStatusPage {
role = "Prover",
status = "RequestReceived",
proofs = Seq.empty,
requestData = Seq.empty,
data = Seq.empty,
metaRetries = 5
),
Expand All @@ -90,6 +92,7 @@ object PresentationStatusPage {
role = "Prover",
status = "PresentationPending",
proofs = Seq.empty,
requestData = Seq.empty,
data = Seq.empty,
metaRetries = 5
),
Expand All @@ -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}\"}"
),
Expand All @@ -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(
Expand Down

0 comments on commit 3b3da2c

Please sign in to comment.