From 9eaa5d444665dbda00038a9032b890afcfa4bc15 Mon Sep 17 00:00:00 2001 From: Shailesh Patil <53746241+mineme0110@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:30:11 +0100 Subject: [PATCH] fix: Update the Holder to send the presentation only, No claims to disclose is needed separately (#1158) Signed-off-by: mineme0110 --- .../agent/server/jobs/PresentBackgroundJobs.scala | 12 +++++------- .../core/service/MockPresentationService.scala | 3 ++- .../pollux/core/service/PresentationService.scala | 3 ++- .../core/service/PresentationServiceImpl.scala | 8 ++++---- .../core/service/PresentationServiceNotifier.scala | 3 ++- .../org/hyperledger/identus/pollux/sdjwt/SDJWT.scala | 1 - .../hyperledger/identus/pollux/sdjwt/SDJWTSpec.scala | 7 +++++-- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala index fa66430eca..b93aebf567 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala @@ -24,7 +24,7 @@ import org.hyperledger.identus.pollux.core.model.error.PresentationError.* import org.hyperledger.identus.pollux.core.model.presentation.SdJwtPresentationPayload import org.hyperledger.identus.pollux.core.service.{CredentialService, PresentationService} import org.hyperledger.identus.pollux.core.service.serdes.AnoncredCredentialProofsV1 -import org.hyperledger.identus.pollux.sdjwt.{IssuerPublicKey, SDJWT} +import org.hyperledger.identus.pollux.sdjwt.{IssuerPublicKey, PresentationJson, SDJWT} import org.hyperledger.identus.pollux.vc.jwt.{DidResolver as JwtDidResolver, JWT, JwtPresentation} import org.hyperledger.identus.resolvers.DIDResolver import org.hyperledger.identus.shared.http.* @@ -839,21 +839,19 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { case Base64(data) => val base64Decoded = new String(java.util.Base64.getDecoder.decode(data)) val verifiedClaims = for { - sdJwtPresentationPayload <- ZIO.fromEither(base64Decoded.fromJson[SdJwtPresentationPayload]) - iss <- ZIO.fromEither(sdJwtPresentationPayload.presentation.iss) + presentation <- ZIO.succeed(PresentationJson(base64Decoded)) + iss <- ZIO.fromEither(presentation.iss) ed25519PublicKey <- resolveToEd25519PublicKey(iss) verifiedClaims = SDJWT.getVerifiedClaims( IssuerPublicKey(ed25519PublicKey), - sdJwtPresentationPayload.presentation, - sdJwtPresentationPayload.claimsToDisclose.toJson + presentation ) _ <- ZIO.logInfo(s"ClaimsValidationResult: $verifiedClaims") - _ <- ZIO.logInfo(s"ClaimsValidationResult: ${sdJwtPresentationPayload.claimsToDisclose}") result: SDJWT.ClaimsValidationResult = verifiedClaims match { case validClaims: SDJWT.ValidClaims => validClaims.verifyDiscoseClaims( - sdJwtPresentationPayload.claimsToDisclose.asObject.getOrElse(Json.Obj()) + Json.Obj() ) case validAnyMatch: SDJWT.ValidAnyMatch.type => validAnyMatch case invalid: SDJWT.Invalid => invalid diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala index 1866cf7dd5..32110f7be4 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/MockPresentationService.scala @@ -12,6 +12,7 @@ import org.hyperledger.identus.pollux.core.model.{DidCommID, PresentationRecord} import org.hyperledger.identus.pollux.core.model.error.PresentationError import org.hyperledger.identus.pollux.core.model.presentation.{Options, SdJwtPresentationPayload} import org.hyperledger.identus.pollux.core.service.serdes.{AnoncredCredentialProofsV1, AnoncredPresentationRequestV1} +import org.hyperledger.identus.pollux.sdjwt.PresentationJson import org.hyperledger.identus.pollux.vc.jwt.{Issuer, PresentationPayload, W3cCredentialPayload} import org.hyperledger.identus.shared.models.WalletAccessContext import zio.{mock, IO, URLayer, ZIO, ZLayer} @@ -210,7 +211,7 @@ object MockPresentationService extends Mock[PresentationService] { override def createSDJwtPresentationPayloadFromRecord( record: DidCommID, issuer: Issuer, - ): IO[PresentationError, SdJwtPresentationPayload] = ??? + ): IO[PresentationError, PresentationJson] = ??? def createSDJwtPresentation( recordId: DidCommID, diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala index 8231795fe5..1f13eafca6 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationService.scala @@ -7,6 +7,7 @@ import org.hyperledger.identus.pollux.core.model.* import org.hyperledger.identus.pollux.core.model.error.PresentationError import org.hyperledger.identus.pollux.core.model.presentation.* import org.hyperledger.identus.pollux.core.service.serdes.{AnoncredCredentialProofsV1, AnoncredPresentationRequestV1} +import org.hyperledger.identus.pollux.sdjwt.PresentationJson import org.hyperledger.identus.pollux.vc.jwt.* import org.hyperledger.identus.shared.models.WalletAccessContext import zio.* @@ -59,7 +60,7 @@ trait PresentationService { def createSDJwtPresentationPayloadFromRecord( record: DidCommID, issuer: Issuer, - ): ZIO[WalletAccessContext, PresentationError, SdJwtPresentationPayload] + ): ZIO[WalletAccessContext, PresentationError, PresentationJson] def createSDJwtPresentation( recordId: DidCommID, diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala index 7ffb6a1326..6ce918eeee 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala @@ -112,7 +112,7 @@ private class PresentationServiceImpl( override def createSDJwtPresentationPayloadFromRecord( recordId: DidCommID, prover: Issuer - ): ZIO[WalletAccessContext, PresentationError, SdJwtPresentationPayload] = { + ): ZIO[WalletAccessContext, PresentationError, PresentationJson] = { for { maybeRecord <- presentationRepository @@ -144,7 +144,7 @@ private class PresentationServiceImpl( ) ) ) - + // return presentationJson presentationJson <- createSDJwtPresentationPayloadFromCredential( issuedCredentials, sdJwtClaimsToDisclose, @@ -159,7 +159,7 @@ private class PresentationServiceImpl( ) ) - } yield presentationPayload + } yield presentationJson } override def createSDJwtPresentation( @@ -178,7 +178,7 @@ private class PresentationServiceImpl( attachments = Seq( AttachmentDescriptor .buildBase64Attachment( - payload = presentationPayload.toJson.getBytes, + payload = presentationPayload.value.getBytes, mediaType = Some(PresentCredentialFormat.SDJWT.name) ) ), diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala index d6cb828be4..4b07694a1b 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifier.scala @@ -13,6 +13,7 @@ import org.hyperledger.identus.pollux.core.model.{DidCommID, PresentationRecord} import org.hyperledger.identus.pollux.core.model.error.PresentationError import org.hyperledger.identus.pollux.core.model.presentation.{Options, SdJwtPresentationPayload} import org.hyperledger.identus.pollux.core.service.serdes.{AnoncredCredentialProofsV1, AnoncredPresentationRequestV1} +import org.hyperledger.identus.pollux.sdjwt.PresentationJson import org.hyperledger.identus.pollux.vc.jwt.{Issuer, PresentationPayload, W3cCredentialPayload} import org.hyperledger.identus.shared.models.WalletAccessContext import zio.{IO, URLayer, ZIO, ZLayer} @@ -204,7 +205,7 @@ class PresentationServiceNotifier( override def createSDJwtPresentationPayloadFromRecord( record: DidCommID, issuer: Issuer - ): ZIO[WalletAccessContext, PresentationError, SdJwtPresentationPayload] = + ): ZIO[WalletAccessContext, PresentationError, PresentationJson] = svc.createSDJwtPresentationPayloadFromRecord(record, issuer) override def createSDJwtPresentation( diff --git a/pollux/sd-jwt/src/main/scala/org/hyperledger/identus/pollux/sdjwt/SDJWT.scala b/pollux/sd-jwt/src/main/scala/org/hyperledger/identus/pollux/sdjwt/SDJWT.scala index ca0124a8a5..1fd0b7b3e2 100644 --- a/pollux/sd-jwt/src/main/scala/org/hyperledger/identus/pollux/sdjwt/SDJWT.scala +++ b/pollux/sd-jwt/src/main/scala/org/hyperledger/identus/pollux/sdjwt/SDJWT.scala @@ -129,7 +129,6 @@ object SDJWT { def getVerifiedClaims( key: IssuerPublicKey, presentation: PresentationJson, - claims: String ): ClaimsValidationResult = { Try { val verifier = SdjwtVerifierWrapper( diff --git a/pollux/sd-jwt/src/test/scala/org/hyperledger/identus/pollux/sdjwt/SDJWTSpec.scala b/pollux/sd-jwt/src/test/scala/org/hyperledger/identus/pollux/sdjwt/SDJWTSpec.scala index b94dc96403..ff0da53231 100644 --- a/pollux/sd-jwt/src/test/scala/org/hyperledger/identus/pollux/sdjwt/SDJWTSpec.scala +++ b/pollux/sd-jwt/src/test/scala/org/hyperledger/identus/pollux/sdjwt/SDJWTSpec.scala @@ -119,7 +119,8 @@ object SDJWTSpec extends ZIOSpecDefault { test("getVerifiedClaims presentation") { val credential = SDJWT.issueCredential(ISSUER_KEY, CLAIMS) val presentation = SDJWT.createPresentation(credential, CLAIMS_QUERY) - val ret = SDJWT.getVerifiedClaims(ISSUER_KEY_PUBLIC, presentation, CLAIMS_PRESENTED) + println(presentation) + val ret = SDJWT.getVerifiedClaims(ISSUER_KEY_PUBLIC, presentation) assertTrue( """{"iss":"did:example:issuer","iat":1683000000,"exp":1883000000,"address":{"country":"DE"}}""" .fromJson[ast.Json.Obj] @@ -129,8 +130,9 @@ object SDJWTSpec extends ZIOSpecDefault { }, test("issue credential without sub & iat and getVerifiedClaims") { val credential = SDJWT.issueCredential(ISSUER_KEY, CLAIMS_WITHOUT_SUB_IAT) + // verfier asking to disclose val presentation = SDJWT.createPresentation(credential, CLAIMS_QUERY) - val ret = SDJWT.getVerifiedClaims(ISSUER_KEY_PUBLIC, presentation, CLAIMS_PRESENTED) + val ret = SDJWT.getVerifiedClaims(ISSUER_KEY_PUBLIC, presentation) assertTrue( """{"iss":"did:example:issuer","exp":1883000000,"address":{"country":"DE"}}""" .fromJson[ast.Json.Obj] @@ -215,6 +217,7 @@ object SDJWTSpec extends ZIOSpecDefault { val issuerPublicKey = IssuerPublicKey(ed25519KeyPair.publicKey) val credential = SDJWT.issueCredential(issuerKey, CLAIMS) + // verifer addres val presentation = SDJWT.createPresentation(credential, CLAIMS_PRESENTED) val ret = SDJWT.verifyAndComparePresentation(issuerPublicKey, presentation, CLAIMS_PRESENTED) assertTrue(ret == SDJWT.ValidAnyMatch)