Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update the Holder to send the presentation only, No claims to disclose is needed separately #1158

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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()
yshyn-iohk marked this conversation as resolved.
Show resolved Hide resolved
)
case validAnyMatch: SDJWT.ValidAnyMatch.type => validAnyMatch
case invalid: SDJWT.Invalid => invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -59,7 +60,7 @@ trait PresentationService {
def createSDJwtPresentationPayloadFromRecord(
record: DidCommID,
issuer: Issuer,
): ZIO[WalletAccessContext, PresentationError, SdJwtPresentationPayload]
): ZIO[WalletAccessContext, PresentationError, PresentationJson]

def createSDJwtPresentation(
recordId: DidCommID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -144,7 +144,7 @@ private class PresentationServiceImpl(
)
)
)

// return presentationJson
presentationJson <- createSDJwtPresentationPayloadFromCredential(
issuedCredentials,
sdJwtClaimsToDisclose,
Expand All @@ -159,7 +159,7 @@ private class PresentationServiceImpl(
)
)

} yield presentationPayload
} yield presentationJson
}

override def createSDJwtPresentation(
Expand All @@ -178,7 +178,7 @@ private class PresentationServiceImpl(
attachments = Seq(
AttachmentDescriptor
.buildBase64Attachment(
payload = presentationPayload.toJson.getBytes,
payload = presentationPayload.value.getBytes,
mediaType = Some(PresentCredentialFormat.SDJWT.name)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ object SDJWT {
def getVerifiedClaims(
key: IssuerPublicKey,
presentation: PresentationJson,
claims: String
): ClaimsValidationResult = {
Try {
val verifier = SdjwtVerifierWrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
Loading