Skip to content

Commit

Permalink
fix: Add disclose claims to presentation record credential type SDJWT (
Browse files Browse the repository at this point in the history
…#1487)

Signed-off-by: mineme0110 <[email protected]>
  • Loading branch information
mineme0110 authored Jan 7, 2025
1 parent 81350ea commit 5e00556
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.unit
case PresentationRecord(_, _, _, _, _, _, _, InvitationExpired, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(_, _, _, _, _, _, _, InvitationExpired, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.unit
case PresentationRecord(id, _, _, _, _, _, _, ProposalPending, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, ProposalPending, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, ProposalSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, ProposalSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, ProposalReceived, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, ProposalReceived, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, ProposalRejected, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, ProposalRejected, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(
id,
Expand All @@ -159,6 +160,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.fail(InvalidState("PresentationRecord 'RequestPending' with no Record"))
Expand All @@ -184,6 +186,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
Verifier.handleRequestPending(id, requestPresentation)
Expand All @@ -209,6 +212,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.logDebug("PresentationRecord: RequestSent") *> ZIO.unit
Expand All @@ -234,6 +238,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.logDebug("PresentationRecord: RequestReceived") *> ZIO.unit
Expand All @@ -259,6 +264,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.logDebug("PresentationRecord: RequestRejected") *> ZIO.unit
Expand All @@ -284,10 +290,11 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, ProblemReportSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, ProblemReportSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(
id,
Expand All @@ -311,6 +318,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.fail(NotImplemented)
Expand All @@ -336,6 +344,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.fail(InvalidState("PresentationRecord 'RequestPending' with no Record"))
Expand All @@ -362,6 +371,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
Prover.PresentationPending.handle(
Expand Down Expand Up @@ -394,6 +404,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.fail(InvalidState("PresentationRecord in 'PresentationGenerated' with no Presentation"))
Expand All @@ -420,12 +431,13 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.logDebug("PresentationRecord: PresentationGenerated") *> ZIO.unit
Prover.handlePresentationGenerated(id, presentation)

case PresentationRecord(id, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.logDebug("PresentationRecord: PresentationSent") *> ZIO.unit
case PresentationRecord(
id,
Expand All @@ -449,6 +461,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.fail(InvalidState("PresentationRecord in 'PresentationReceived' with no Presentation"))
Expand All @@ -474,6 +487,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.fail(InvalidState("PresentationRecord in 'PresentationReceived' with no Presentation Request"))
Expand All @@ -499,6 +513,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.logDebug("PresentationRecord: PresentationReceived") *> ZIO.unit
Expand Down Expand Up @@ -526,6 +541,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationVerificationFailed") *> ZIO.unit
Expand All @@ -551,6 +567,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationVerifiedAccepted") *> ZIO.unit
Expand All @@ -576,6 +593,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationVerified") *> ZIO.unit
Expand All @@ -601,6 +619,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationRejected") *> ZIO.unit
Expand Down Expand Up @@ -1224,12 +1243,16 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
verifiedClaims.mapError(error => PresentationReceivedError(error.toString))
case any => ZIO.fail(PresentationReceivedError("Only Base64 Supported"))
}
service <- ZIO.service[PresentationService]
_ <- credentialsClaimsValidationResult match
case valid: SDJWT.Valid =>
ZIO.logInfo(s"CredentialsClaimsValidationResult: $valid")
val jsonObj = valid.asInstanceOf[SDJWT.ValidClaims].claims
service
.updateWithSDJWTDisclosedClaims(id, jsonObj)
.provideSomeLayer(ZLayer.succeed(walletAccessContext))
case invalid: SDJWT.Invalid =>
ZIO.logError(s"CredentialsClaimsValidationResult: $invalid")
service <- ZIO.service[PresentationService]
presReceivedToProcessedAspect = CustomMetricsAspect.endRecordingTime(
s"${id}_present_proof_flow_verifier_presentation_received_to_verification_success_or_failure_ms_gauge",
"present_proof_flow_verifier_presentation_received_to_verification_success_or_failure_ms_gauge"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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}
import sttp.tapir.{Schema, Validator}
import sttp.tapir.json.zio.schemaForZioJsonValue
import sttp.tapir.Schema.annotations.{description, encodedExample, validate}
import zio.json.*
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder}
import zio.json.EncoderOps

Expand Down Expand Up @@ -35,6 +37,9 @@ final case class PresentationStatus(
@description(annotations.requestData.description)
@encodedExample(annotations.requestData.example)
requestData: Seq[String],
@description(annotations.disclosedClaims.description)
@encodedExample(annotations.disclosedClaims.example)
disclosedClaims: Option[zio.json.ast.Json],
@description(annotations.connectionId.description)
@encodedExample(annotations.connectionId.example)
connectionId: Option[String] = None,
Expand Down Expand Up @@ -68,6 +73,7 @@ object PresentationStatus {
status = domain.protocolState.toString,
proofs = Seq.empty,
data = data,
disclosedClaims = domain.sdJwtDisclosedClaims,
requestData = requestData,
connectionId = domain.connectionId,
invitation = domain.invitation.map(invitation => OOBPresentationInvitation.fromDomain(invitation)),
Expand Down Expand Up @@ -159,6 +165,17 @@ object PresentationStatus {
description = "The list of proofs presented by the prover to the verifier.",
example = Seq.empty
)

object disclosedClaims
extends Annotation[zio.json.ast.Json](
description = """
|The set of claims disclosed from the issued credential, this field is applicable to credential type SDJWT only.
|""".stripMargin,
example = zio.json.ast.Json.Obj(
"firstname" -> zio.json.ast.Json.Str("Alice"),
"lastname" -> zio.json.ast.Json.Str("Wonderland"),
)
)
object requestData
extends Annotation[Seq[String]](
description = "The list of request presented by the verifier to 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,
disclosedClaims = None,
requestData = Seq.empty,
connectionId = Some("e0d81be9-47ca-4e0b-b8a7-325e8c3abc2f"),
invitation = None,
Expand All @@ -82,6 +83,7 @@ object PresentationStatusPage {
role = "Prover",
status = "RequestReceived",
proofs = Seq.empty,
disclosedClaims = None,
requestData = Seq.empty,
data = Seq.empty,
metaRetries = 5
Expand All @@ -92,6 +94,7 @@ object PresentationStatusPage {
role = "Prover",
status = "PresentationPending",
proofs = Seq.empty,
disclosedClaims = None,
requestData = Seq.empty,
data = Seq.empty,
metaRetries = 5
Expand All @@ -102,6 +105,7 @@ object PresentationStatusPage {
role = "Verifier",
status = "PresentationVerified",
proofs = Seq.empty,
disclosedClaims = None,
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 @@ -115,6 +119,7 @@ object PresentationStatusPage {
role = "Verifier",
status = "InvitationGenerated",
proofs = Seq.empty,
disclosedClaims = None,
data = Seq.empty,
requestData = Seq.empty,
connectionId = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.time.Instant

type AnoncredCredentialProofs = zio.json.ast.Json
type SdJwtCredentialToDisclose = zio.json.ast.Json
type SdJwtDisclosedClaims = zio.json.ast.Json

final case class PresentationRecord(
id: DidCommID,
Expand All @@ -30,6 +31,7 @@ final case class PresentationRecord(
anoncredCredentialsToUse: Option[AnoncredCredentialProofs],
sdJwtClaimsToUseJsonSchemaId: Option[String],
sdJwtClaimsToDisclose: Option[SdJwtCredentialToDisclose],
sdJwtDisclosedClaims: Option[SdJwtDisclosedClaims],
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[Failure],
Expand Down Expand Up @@ -64,6 +66,7 @@ object PresentationRecord {
anoncredCredentialsToUse: Option[AnoncredCredentialProofs],
sdJwtClaimsToUseJsonSchemaId: Option[String],
sdJwtClaimsToDisclose: Option[SdJwtCredentialToDisclose],
sdJwtDisclosedClaims: Option[SdJwtDisclosedClaims],
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[Failure]
Expand All @@ -88,6 +91,7 @@ object PresentationRecord {
anoncredCredentialsToUse,
sdJwtClaimsToUseJsonSchemaId,
sdJwtClaimsToDisclose,
sdJwtDisclosedClaims,
metaRetries,
metaNextRetry,
metaLastFailure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ trait PresentationRepository {
protocolState: ProtocolState
): URIO[WalletAccessContext, Unit]

def updateWithSDJWTDisclosedClaims(
recordId: DidCommID,
sdJwtDisclosedClaims: SdJwtDisclosedClaims,
): URIO[WalletAccessContext, Unit]

def updateWithPresentation(
recordId: DidCommID,
presentation: Presentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ trait PresentationService {
recordId: DidCommID
): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def updateWithSDJWTDisclosedClaims(
recordId: DidCommID,
claimsDisclosed: SdJwtDisclosedClaims
): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def verifyAnoncredPresentation(
presentation: Presentation,
requestPresentation: RequestPresentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ private class PresentationServiceImpl(
anoncredCredentialsToUse = None,
sdJwtClaimsToUseJsonSchemaId = None,
sdJwtClaimsToDisclose = None,
sdJwtDisclosedClaims = None,
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None
Expand Down Expand Up @@ -532,6 +533,7 @@ private class PresentationServiceImpl(
anoncredCredentialsToUse = None,
sdJwtClaimsToUseJsonSchemaId = None,
sdJwtClaimsToDisclose = None,
sdJwtDisclosedClaims = None,
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
Expand Down Expand Up @@ -865,6 +867,22 @@ private class PresentationServiceImpl(
} yield record
}

def updateWithSDJWTDisclosedClaims(
recordId: DidCommID,
claimsDisclosed: SdJwtDisclosedClaims
): ZIO[WalletAccessContext, PresentationError, PresentationRecord] = {
for {
record <- getRecordWithState(recordId, ProtocolState.PresentationReceived)
_ <-
presentationRepository
.updateWithSDJWTDisclosedClaims(
recordId,
claimsDisclosed
)
record <- getRecord(recordId)
} yield record
}

override def acceptAnoncredRequestPresentation(
recordId: DidCommID,
credentialsToUse: AnoncredCredentialProofsV1
Expand Down
Loading

0 comments on commit 5e00556

Please sign in to comment.