Skip to content

Commit

Permalink
ATL-7380: Fix Requested present proof by Holder
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <[email protected]>
  • Loading branch information
CryptoKnightIOG committed Aug 31, 2024
1 parent 5a7b950 commit e1fda19
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
None,
_,
_,
credentialsToUse,
_,
_,
_,
_,
Expand Down Expand Up @@ -970,7 +970,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
record.from.getOrElse(throw new RuntimeException("from is None is not possible"))
)
result <- for {
didOps <- ZIO.service[DidOps]
didCommAgent <- buildDIDCommAgent(
record.from.getOrElse(throw new RuntimeException("from is None is not possible"))
).provideSomeLayer(ZLayer.succeed(walletAccessContext))
Expand Down Expand Up @@ -1291,11 +1290,4 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
}
}

// val syncDIDPublicationStateFromDlt: ZIO[WalletAccessContext & ManagedDIDService, GetManagedDIDError, Unit] =
// for {
// managedDidService <- ZIO.service[ManagedDIDService]
// _ <- managedDidService.syncManagedDIDState
// _ <- managedDidService.syncUnconfirmedUpdateOperations
// } yield ()

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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.protocol.presentproof.AttachmentBasedPresentation
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)
val requestData = extractData(domain.requestPresentationData)
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,18 @@ object PresentationStatus {
)
}

private def extractData(maybePresentation: Option[AttachmentBasedPresentation]): Seq[String] = {
maybePresentation 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
}

given Conversion[PresentationRecord, PresentationStatus] = fromDomain

object annotations {
Expand Down Expand Up @@ -143,6 +153,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.hyperledger.identus.mercury.protocol.presentproof
import org.hyperledger.identus.mercury.model.AttachmentDescriptor

trait AttachmentBasedPresentation {
val attachments: Seq[AttachmentDescriptor]
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final case class Presentation(
thid: Option[String] = None,
from: DidId,
to: DidId,
) {
) extends AttachmentBasedPresentation {
assert(`type` == Presentation.`type`)

def makeMessage: Message = Message(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final case class ProposePresentation(
thid: Option[String] = None,
from: DidId,
to: DidId,
) {
) extends AttachmentBasedPresentation {
assert(`type` == ProposePresentation.`type`)

def makeMessage: Message = Message(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final case class RequestPresentation(
thid: Option[String] = None,
from: Option[DidId],
to: Option[DidId],
) {
) extends AttachmentBasedPresentation {

def makeMessage: Message = Message(
id = this.id,
Expand Down

0 comments on commit e1fda19

Please sign in to comment.