From 2660ec3ea29d66c1c78e4822164b414aabb82a52 Mon Sep 17 00:00:00 2001 From: Bassam Riman Date: Wed, 15 Nov 2023 11:50:46 -0500 Subject: [PATCH] feat: ATL-6019 Added Anoncred Presentation SerDeserialisation Signed-off-by: Bassam Riman --- ...redPresentationRequestSchemaSerDesV1.scala | 158 ------ .../serdes/AnoncredPresentationV1.scala | 511 ++++++++++++++++++ ... => AnoncredPresentationRequestSpec.scala} | 22 +- .../serdes/AnoncredPresentationSpec.scala | 213 ++++++++ 4 files changed, 735 insertions(+), 169 deletions(-) delete mode 100644 pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesV1.scala create mode 100644 pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationV1.scala rename pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/{AnoncredPresentationRequestSchemaSerDesSpec.scala => AnoncredPresentationRequestSpec.scala} (79%) create mode 100644 pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationSpec.scala diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesV1.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesV1.scala deleted file mode 100644 index e788e52b7d..0000000000 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesV1.scala +++ /dev/null @@ -1,158 +0,0 @@ -package io.iohk.atala.pollux.core.service.serdes - -import io.iohk.atala.pollux.core.model.schema.validator.SchemaSerDes -import zio.* -import zio.json.* - -case class AnoncredPresentationRequestSchemaSerDesV1( - requested_attributes: Map[String, AnoncredRequestedAttribute], - requested_predicates: Map[String, AnoncredRequestedPredicate], - name: String, - nonce: String, - version: String, - non_revoked: Option[AnoncredNonRevokedInterval] -) - -case class AnoncredRequestedAttribute(name: String, restrictions: List[AnoncredAttributeRestriction]) - -case class AnoncredRequestedPredicate( - name: String, - p_type: String, - p_value: Int, - restrictions: List[AnoncredPredicateRestriction] -) - -case class AnoncredAttributeRestriction( - schema_id: Option[String], - cred_def_id: Option[String], - non_revoked: Option[AnoncredNonRevokedInterval] -) - -case class AnoncredPredicateRestriction( - schema_id: Option[String], - cred_def_id: Option[String], - non_revoked: Option[AnoncredNonRevokedInterval] -) - -case class AnoncredNonRevokedInterval(from: Option[Int], to: Option[Int]) - -object AnoncredPresentationRequestSchemaSerDesV1 { - val version: String = "PresentationRequestV1" - - private val schema: String = - """ - |{ - | "$schema": "http://json-schema.org/draft-07/schema#", - | "type": "object", - | "properties": { - | "requested_attributes": { - | "type": "object", - | "additionalProperties": { - | "type": "object", - | "properties": { - | "name": { "type": "string" }, - | "restrictions": { - | "type": "array", - | "items": { - | "type": "object", - | "properties": { - | "schema_id": { "type": "string" }, - | "cred_def_id": { "type": "string" }, - | "non_revoked": { - | "type": "object", - | "properties": { - | "from": { "type": "integer" }, - | "to": { "type": "integer" } - | } - | } - | } - | } - | } - | }, - | "required": ["name", "restrictions"] - | } - | }, - | "requested_predicates": { - | "type": "object", - | "additionalProperties": { - | "type": "object", - | "properties": { - | "name": { "type": "string" }, - | "p_type": { "type": "string" }, - | "p_value": { "type": "integer" }, - | "restrictions": { - | "type": "array", - | "items": { - | "type": "object", - | "properties": { - | "schema_id": { "type": "string" }, - | "cred_def_id": { "type": "string" }, - | "non_revoked": { - | "type": "object", - | "properties": { - | "from": { "type": "integer" }, - | "to": { "type": "integer" } - | } - | } - | } - | } - | } - | }, - | "required": ["name", "p_type", "p_value", "restrictions"] - | } - | }, - | "name": { "type": "string" }, - | "nonce": { "type": "string" }, - | "version": { "type": "string" }, - | "non_revoked": { - | "type": "object", - | "properties": { - | "from": { "type": "integer" }, - | "to": { "type": "integer" } - | } - | } - | }, - | "required": ["requested_attributes", "requested_predicates", "name", "nonce", "version" ] - |} - | - |""".stripMargin - - val schemaSerDes: SchemaSerDes[AnoncredPresentationRequestSchemaSerDesV1] = SchemaSerDes(schema) - - given JsonDecoder[AnoncredRequestedAttribute] = - DeriveJsonDecoder.gen[AnoncredRequestedAttribute] - - given JsonEncoder[AnoncredRequestedAttribute] = - DeriveJsonEncoder.gen[AnoncredRequestedAttribute] - - given JsonDecoder[AnoncredRequestedPredicate] = - DeriveJsonDecoder.gen[AnoncredRequestedPredicate] - - given JsonEncoder[AnoncredRequestedPredicate] = - DeriveJsonEncoder.gen[AnoncredRequestedPredicate] - - given JsonDecoder[AnoncredAttributeRestriction] = - DeriveJsonDecoder.gen[AnoncredAttributeRestriction] - - given JsonEncoder[AnoncredNonRevokedInterval] = - DeriveJsonEncoder.gen[AnoncredNonRevokedInterval] - - given JsonDecoder[AnoncredNonRevokedInterval] = - DeriveJsonDecoder.gen[AnoncredNonRevokedInterval] - - given JsonEncoder[AnoncredAttributeRestriction] = - DeriveJsonEncoder.gen[AnoncredAttributeRestriction] - - given JsonDecoder[AnoncredPredicateRestriction] = - DeriveJsonDecoder.gen[AnoncredPredicateRestriction] - - given JsonEncoder[AnoncredPredicateRestriction] = - DeriveJsonEncoder.gen[AnoncredPredicateRestriction] - - given JsonDecoder[AnoncredPresentationRequestSchemaSerDesV1] = - DeriveJsonDecoder.gen[AnoncredPresentationRequestSchemaSerDesV1] - - given JsonEncoder[AnoncredPresentationRequestSchemaSerDesV1] = - DeriveJsonEncoder.gen[AnoncredPresentationRequestSchemaSerDesV1] - -} diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationV1.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationV1.scala new file mode 100644 index 0000000000..945a5c5d07 --- /dev/null +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationV1.scala @@ -0,0 +1,511 @@ +package io.iohk.atala.pollux.core.service.serdes + +import io.iohk.atala.pollux.core.model.schema.validator.SchemaSerDes +import zio.* +import zio.json.* + +case class AnoncredAdditionalPropertiesTypeStringV1(value: String) + +case class AnoncredRevealedAttrV1(sub_proof_index: Int, raw: String, encoded: String) + +case class AnoncredRequestedProofV1( + revealed_attrs: Map[String, AnoncredRevealedAttrV1], + self_attested_attrs: Map[String, String], + unrevealed_attrs: Map[String, String], + predicates: Map[String, AnoncredSubProofIndexV1] +) + +case class AnoncredSubProofIndexV1(sub_proof_index: Int) + +case class AnoncredIdentifierV1( + schema_id: String, + cred_def_id: String, + rev_reg_id: Option[String], + timestamp: Option[Int] +) + +case class AnoncredEqProofV1( + revealed_attrs: Map[String, String], + a_prime: String, + e: String, + v: String, + m: Map[String, String], + m2: String +) + +case class AnoncredPredicateV1(attr_name: String, p_type: String, value: Int) + +case class AnoncredGeProofV1( + u: Map[String, String], + r: Map[String, String], + mj: String, + alpha: String, + t: Map[String, String], + predicate: AnoncredPredicateV1 +) + +case class AnoncredPrimaryProofV1(eq_proof: AnoncredEqProofV1, ge_proofs: List[AnoncredGeProofV1]) + +case class AnoncredSubProofV1(primary_proof: AnoncredPrimaryProofV1, non_revoc_proof: Option[AnoncredNonRevocProofV1]) + +case class AnoncredProofV1(proofs: List[AnoncredSubProofV1], aggregated_proof: AnoncredAggregatedProofV1) + +case class AnoncredAggregatedProofV1(c_hash: String, c_list: List[List[Int]]) + +case class AnoncredNonRevocProofXListV1( + rho: String, + r: String, + r_prime: String, + r_prime_prime: String, + r_prime_prime_prime: String, + o: String, + o_prime: String, + m: String, + m_prime: String, + t: String, + t_prime: String, + m2: String, + s: String, + c: String +) + +case class AnoncredNonRevocProofCListV1(e: String, d: String, a: String, g: String, w: String, s: String, u: String) + +case class AnoncredNonRevocProofV1(x_list: AnoncredNonRevocProofXListV1, c_list: AnoncredNonRevocProofCListV1) + +case class AnoncredPresentationV1( + proof: AnoncredProofV1, + requested_proof: AnoncredRequestedProofV1, + identifiers: List[AnoncredIdentifierV1] +) + +object AnoncredPresentationV1 { + val version: String = "AnoncredPresentationV1" + + private val schema: String = + """ + |{ + | "$schema":"http://json-schema.org/draft-07/schema#", + | "type":"object", + | "properties":{ + | "proof":{ + | "type":"object", + | "properties":{ + | "proofs":{ + | "type":"array", + | "items":{ + | "type":"object", + | "properties":{ + | "primary_proof":{ + | "type":"object", + | "properties":{ + | "eq_proof":{ + | "type":"object", + | "properties":{ + | "revealed_attrs":{ + | "type":"object", + | "additionalProperties":{ + | "type":"string" + | } + | }, + | "a_prime":{ + | "type":"string" + | }, + | "e":{ + | "type":"string" + | }, + | "v":{ + | "type":"string" + | }, + | "m":{ + | "type":"object", + | "additionalProperties":{ + | "type":"string" + | } + | }, + | "m2":{ + | "type":"string" + | } + | }, + | "required":[ + | "revealed_attrs", + | "a_prime", + | "e", + | "v", + | "m", + | "m2" + | ] + | }, + | "ge_proofs":{ + | "type":"array", + | "items":{ + | "type":"object", + | "properties":{ + | "u":{ + | "type":"object", + | "additionalProperties":{ + | "type":"string" + | } + | }, + | "r":{ + | "type":"object", + | "additionalProperties":{ + | "type":"string" + | } + | }, + | "mj":{ + | "type":"string" + | }, + | "alpha":{ + | "type":"string" + | }, + | "t":{ + | "type":"object", + | "additionalProperties":{ + | "type":"string" + | } + | }, + | "predicate":{ + | "type":"object", + | "properties":{ + | "attr_name":{ + | "type":"string" + | }, + | "p_type":{ + | "type":"string" + | }, + | "value":{ + | "type":"integer" + | } + | }, + | "required":[ + | "attr_name", + | "p_type", + | "value" + | ] + | } + | }, + | "required":[ + | "u", + | "r", + | "mj", + | "alpha", + | "t", + | "predicate" + | ] + | } + | } + | }, + | "required":[ + | "eq_proof", + | "ge_proofs" + | ] + | }, + | "non_revoc_proof":{ + | "oneOf":[ + | { + | "type":"object", + | "properties":{ + | "x_list":{ + | "type":"object", + | "properties":{ + | "rho":{ + | "type":"string" + | }, + | "r":{ + | "type":"string" + | }, + | "r_prime":{ + | "type":"string" + | }, + | "r_prime_prime":{ + | "type":"string" + | }, + | "r_prime_prime_prime":{ + | "type":"string" + | }, + | "o":{ + | "type":"string" + | }, + | "o_prime":{ + | "type":"string" + | }, + | "m":{ + | "type":"string" + | }, + | "m_prime":{ + | "type":"string" + | }, + | "t":{ + | "type":"string" + | }, + | "t_prime":{ + | "type":"string" + | }, + | "m2":{ + | "type":"string" + | }, + | "s":{ + | "type":"string" + | }, + | "c":{ + | "type":"string" + | } + | }, + | "required":[ + | "rho", + | "r", + | "r_prime", + | "r_prime_prime", + | "r_prime_prime_prime", + | "o", + | "o_prime", + | "m", + | "m_prime", + | "t", + | "t_prime", + | "m2", + | "s", + | "c" + | ] + | }, + | "c_list":{ + | "type":"object", + | "properties":{ + | "e":{ + | "type":"string" + | }, + | "d":{ + | "type":"string" + | }, + | "a":{ + | "type":"string" + | }, + | "g":{ + | "type":"string" + | }, + | "w":{ + | "type":"string" + | }, + | "s":{ + | "type":"string" + | }, + | "u":{ + | "type":"string" + | } + | }, + | "required":[ + | "e", + | "d", + | "a", + | "g", + | "w", + | "s", + | "u" + | ] + | } + | }, + | "required":[ + | "x_list", + | "c_list" + | ] + | }, + | { + | "type":"null" + | } + | ] + | } + | }, + | "required":[ + | "primary_proof" + | ] + | } + | }, + | "aggregated_proof":{ + | "type":"object", + | "properties":{ + | "c_hash":{ + | "type":"string" + | }, + | "c_list":{ + | "type":"array", + | "items":{ + | "type":"array", + | "items":{ + | "type":"integer" + | } + | } + | } + | }, + | "required":[ + | "c_hash", + | "c_list" + | ] + | } + | }, + | "required":[ + | "proofs", + | "aggregated_proof" + | ] + | }, + | "requested_proof":{ + | "type":"object", + | "properties":{ + | "revealed_attrs":{ + | "type":"object", + | "additionalProperties":{ + | "type":"object", + | "properties":{ + | "sub_proof_index":{ + | "type":"integer" + | }, + | "raw":{ + | "type":"string" + | }, + | "encoded":{ + | "type":"string" + | } + | }, + | "required":[ + | "sub_proof_index", + | "raw", + | "encoded" + | ] + | } + | }, + | "self_attested_attrs":{ + | "type":"object" + | }, + | "unrevealed_attrs":{ + | "type":"object" + | }, + | "predicates":{ + | "type":"object", + | "additionalProperties":{ + | "type":"object", + | "properties":{ + | "sub_proof_index":{ + | "type":"integer" + | } + | }, + | "required":[ + | "sub_proof_index" + | ] + | } + | } + | }, + | "required":[ + | "revealed_attrs", + | "self_attested_attrs", + | "unrevealed_attrs", + | "predicates" + | ] + | }, + | "identifiers":{ + | "type":"array", + | "items":{ + | "type":"object", + | "properties":{ + | "schema_id":{ + | "type":"string" + | }, + | "cred_def_id":{ + | "type":"string" + | }, + | "rev_reg_id":{ + | "type":[ + | "string", + | "null" + | ] + | }, + | "timestamp":{ + | "type":[ + | "integer", + | "null" + | ] + | } + | }, + | "required":[ + | "schema_id", + | "cred_def_id" + | ] + | } + | } + | }, + | "required":[ + | "proof", + | "requested_proof", + | "identifiers" + | ] + |} + |""".stripMargin + + val schemaSerDes: SchemaSerDes[AnoncredPresentationV1] = SchemaSerDes(schema) + + given JsonDecoder[AnoncredAdditionalPropertiesTypeStringV1] = + DeriveJsonDecoder.gen[AnoncredAdditionalPropertiesTypeStringV1] + + given JsonEncoder[AnoncredAdditionalPropertiesTypeStringV1] = + DeriveJsonEncoder.gen[AnoncredAdditionalPropertiesTypeStringV1] + + given JsonDecoder[AnoncredEqProofV1] = DeriveJsonDecoder.gen[AnoncredEqProofV1] + + given JsonEncoder[AnoncredEqProofV1] = DeriveJsonEncoder.gen[AnoncredEqProofV1] + + given JsonDecoder[AnoncredPredicateV1] = DeriveJsonDecoder.gen[AnoncredPredicateV1] + + given JsonEncoder[AnoncredPredicateV1] = DeriveJsonEncoder.gen[AnoncredPredicateV1] + + given JsonDecoder[AnoncredGeProofV1] = DeriveJsonDecoder.gen[AnoncredGeProofV1] + + given JsonEncoder[AnoncredGeProofV1] = DeriveJsonEncoder.gen[AnoncredGeProofV1] + + given JsonDecoder[AnoncredNonRevocProofXListV1] = DeriveJsonDecoder.gen[AnoncredNonRevocProofXListV1] + + given JsonEncoder[AnoncredNonRevocProofXListV1] = DeriveJsonEncoder.gen[AnoncredNonRevocProofXListV1] + + given JsonDecoder[AnoncredNonRevocProofCListV1] = DeriveJsonDecoder.gen[AnoncredNonRevocProofCListV1] + + given JsonEncoder[AnoncredNonRevocProofCListV1] = DeriveJsonEncoder.gen[AnoncredNonRevocProofCListV1] + + given JsonDecoder[AnoncredNonRevocProofV1] = DeriveJsonDecoder.gen[AnoncredNonRevocProofV1] + + given JsonEncoder[AnoncredNonRevocProofV1] = DeriveJsonEncoder.gen[AnoncredNonRevocProofV1] + + given JsonDecoder[AnoncredPrimaryProofV1] = DeriveJsonDecoder.gen[AnoncredPrimaryProofV1] + + given JsonEncoder[AnoncredPrimaryProofV1] = DeriveJsonEncoder.gen[AnoncredPrimaryProofV1] + + given JsonDecoder[AnoncredAggregatedProofV1] = DeriveJsonDecoder.gen[AnoncredAggregatedProofV1] + + given JsonEncoder[AnoncredAggregatedProofV1] = DeriveJsonEncoder.gen[AnoncredAggregatedProofV1] + + given JsonDecoder[AnoncredSubProofV1] = DeriveJsonDecoder.gen[AnoncredSubProofV1] + + given JsonEncoder[AnoncredSubProofV1] = DeriveJsonEncoder.gen[AnoncredSubProofV1] + + given JsonDecoder[AnoncredProofV1] = DeriveJsonDecoder.gen[AnoncredProofV1] + + given JsonEncoder[AnoncredProofV1] = DeriveJsonEncoder.gen[AnoncredProofV1] + + given JsonDecoder[AnoncredRevealedAttrV1] = DeriveJsonDecoder.gen[AnoncredRevealedAttrV1] + + given JsonEncoder[AnoncredRevealedAttrV1] = DeriveJsonEncoder.gen[AnoncredRevealedAttrV1] + + given JsonDecoder[AnoncredSubProofIndexV1] = DeriveJsonDecoder.gen[AnoncredSubProofIndexV1] + + given JsonEncoder[AnoncredSubProofIndexV1] = DeriveJsonEncoder.gen[AnoncredSubProofIndexV1] + + given JsonDecoder[AnoncredRequestedProofV1] = DeriveJsonDecoder.gen[AnoncredRequestedProofV1] + + given JsonEncoder[AnoncredRequestedProofV1] = DeriveJsonEncoder.gen[AnoncredRequestedProofV1] + + given JsonDecoder[AnoncredIdentifierV1] = DeriveJsonDecoder.gen[AnoncredIdentifierV1] + + given JsonEncoder[AnoncredIdentifierV1] = DeriveJsonEncoder.gen[AnoncredIdentifierV1] + + given JsonDecoder[AnoncredPresentationV1] = DeriveJsonDecoder.gen[AnoncredPresentationV1] + + given JsonEncoder[AnoncredPresentationV1] = DeriveJsonEncoder.gen[AnoncredPresentationV1] + +} diff --git a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesSpec.scala b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSpec.scala similarity index 79% rename from pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesSpec.scala rename to pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSpec.scala index 5545985f22..35bd8416c7 100644 --- a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSchemaSerDesSpec.scala +++ b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationRequestSpec.scala @@ -4,8 +4,8 @@ import zio.* import zio.test.* import zio.test.Assertion.* -object AnoncredPresentationRequestSchemaSerDesSpec extends ZIOSpecDefault { - val json = +object AnoncredPresentationRequestSpec extends ZIOSpecDefault { + val json: String = """ |{ | "requested_attributes": { @@ -45,20 +45,20 @@ object AnoncredPresentationRequestSchemaSerDesSpec extends ZIOSpecDefault { override def spec: Spec[TestEnvironment with Scope, Any] = suite("AnoncredPresentationRequestSerDes")( test("should validate a correct schema") { - assertZIO(AnoncredPresentationRequestSchemaSerDesV1.schemaSerDes.validate(json))(isTrue) + assertZIO(AnoncredPresentationRequestV1.schemaSerDes.validate(json))(isTrue) }, test("should deserialize correctly") { val expectedPresentationRequest = - AnoncredPresentationRequestSchemaSerDesV1( + AnoncredPresentationRequestV1( requested_attributes = Map( - "attribute1" -> AnoncredRequestedAttribute( + "attribute1" -> AnoncredRequestedAttributeV1( "Attribute 1", List( - AnoncredAttributeRestriction( + AnoncredAttributeRestrictionV1( None, Some("credential_definition_id_of_attribute1"), Some( - AnoncredNonRevokedInterval( + AnoncredNonRevokedIntervalV1( Some(1635734400), Some(1735734400) ) @@ -69,16 +69,16 @@ object AnoncredPresentationRequestSchemaSerDesSpec extends ZIOSpecDefault { ), requested_predicates = Map( "predicate1" -> - AnoncredRequestedPredicate( + AnoncredRequestedPredicateV1( "Predicate 1", ">=", 18, List( - AnoncredPredicateRestriction( + AnoncredPredicateRestrictionV1( Some("schema_id_of_predicate1"), None, Some( - AnoncredNonRevokedInterval( + AnoncredNonRevokedIntervalV1( Some(1635734400), None ) @@ -93,7 +93,7 @@ object AnoncredPresentationRequestSchemaSerDesSpec extends ZIOSpecDefault { non_revoked = None ) - assertZIO(AnoncredPresentationRequestSchemaSerDesV1.schemaSerDes.deserialize(json))( + assertZIO(AnoncredPresentationRequestV1.schemaSerDes.deserialize(json))( Assertion.equalTo(expectedPresentationRequest) ) } diff --git a/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationSpec.scala b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationSpec.scala new file mode 100644 index 0000000000..f7e22a8f3e --- /dev/null +++ b/pollux/lib/core/src/test/scala/io/iohk/atala/pollux/core/service/serdes/AnoncredPresentationSpec.scala @@ -0,0 +1,213 @@ +package io.iohk.atala.pollux.core.service.serdes + +import io.iohk.atala.pollux.core.service.serdes.AnoncredPresentationV1.* +import zio.* +import zio.test.* +import zio.test.Assertion.* + +object AnoncredPresentationSpec extends ZIOSpecDefault { + val json: String = + """ + |{ + | "proof": { + | "proofs": [ + | { + | "primary_proof": { + | "eq_proof": { + | "revealed_attrs": { + | "sex": "4046863..." + | }, + | "a_prime": "2329247...", + | "e": "1666946...", + | "v": "2137556...", + | "m": { + | "age": "1025474...", + | "master_secret": "8005118...", + | "name": "1031839..." + | }, + | "m2": "5852217..." + | }, + | "ge_proofs": [ + | { + | "u": { + | "1": "1135835...", + | "0": "5209733...", + | "3": "6777506...", + | "2": "8790500..." + | }, + | "r": { + | "DELTA": "1094759...", + | "3": "3908998...", + | "1": "3551550...", + | "2": "4594656...", + | "0": "7769940..." + | }, + | "mj": "1025474...", + | "alpha": "4089177...", + | "t": { + | "0": "1208121...", + | "DELTA": "9078219...", + | "1": "5769003...", + | "3": "4089901...", + | "2": "2261914..." + | }, + | "predicate": { + | "attr_name": "age", + | "p_type": "GE", + | "value": 18 + | } + | } + | ] + | }, + | "non_revoc_proof": null + | } + | ], + | "aggregated_proof": { + | "c_hash": "3880251...", + | "c_list": [ + | [184, 131, 15], + | [95, 179], + | [1, 200, 254], + | [179, 45, 156], + | [1, 67, 251], + | [2, 207, 34, 43] + | ] + | } + | }, + | "requested_proof": { + | "revealed_attrs": { + | "sex": { + | "sub_proof_index": 0, + | "raw": "M", + | "encoded": "4046863..." + | } + | }, + | "self_attested_attrs":{}, + | "unrevealed_attrs":{}, + | "predicates": { + | "age": { + | "sub_proof_index": 0 + | } + | } + | }, + | "identifiers": [ + | { + | "schema_id": "resource:///anoncred-presentation-schema-example.json", + | "cred_def_id": "did:prism:issuer/b2c8ccb8-191a-4233-9b34-3e3111a4adaf?version=1.2", + | "rev_reg_id": null, + | "timestamp": null + | } + | ] + |} + | + |""".stripMargin + + override def spec: Spec[TestEnvironment with Scope, Any] = suite("AnoncredPresentationRequestSerDes")( + test("should validate a correct schema") { + assertZIO(AnoncredPresentationV1.schemaSerDes.validate(json))(isTrue) + }, + test("should deserialize correctly") { + val predicate = AnoncredPredicateV1( + attr_name = "age", + p_type = "GE", + value = 18 + ) + + val geProof = AnoncredGeProofV1( + u = Map( + "1" -> "1135835...", + "0" -> "5209733...", + "3" -> "6777506...", + "2" -> "8790500..." + ), + r = Map( + "DELTA" -> "1094759...", + "3" -> "3908998...", + "1" -> "3551550...", + "2" -> "4594656...", + "0" -> "7769940..." + ), + mj = "1025474...", + alpha = "4089177...", + t = Map( + "0" -> "1208121...", + "DELTA" -> "9078219...", + "1" -> "5769003...", + "3" -> "4089901...", + "2" -> "2261914..." + ), + predicate = predicate + ) + + val eqProof = AnoncredEqProofV1( + revealed_attrs = Map("sex" -> "4046863..."), + a_prime = "2329247...", + e = "1666946...", + v = "2137556...", + m = Map( + "age" -> "1025474...", + "master_secret" -> "8005118...", + "name" -> "1031839..." + ), + m2 = "5852217..." + ) + + val primaryProof = AnoncredPrimaryProofV1( + eq_proof = eqProof, + ge_proofs = List(geProof) + ) + + val subProof = AnoncredSubProofV1( + primary_proof = primaryProof, + non_revoc_proof = None + ) + + val aggregatedProof = AnoncredAggregatedProofV1( + c_hash = "3880251...", + c_list = List( + List(184, 131, 15), + List(95, 179), + List(1, 200, 254), + List(179, 45, 156), + List(1, 67, 251), + List(2, 207, 34, 43) + ) + ) + + val revealedAttr = AnoncredRevealedAttrV1( + sub_proof_index = 0, + raw = "M", + encoded = "4046863..." + ) + + val requestedProof = AnoncredRequestedProofV1( + revealed_attrs = Map("sex" -> revealedAttr), + self_attested_attrs = Map.empty, + unrevealed_attrs = Map.empty, + predicates = Map("age" -> AnoncredSubProofIndexV1(0)) + ) + + val identifier = AnoncredIdentifierV1( + schema_id = "resource:///anoncred-presentation-schema-example.json", + cred_def_id = "did:prism:issuer/b2c8ccb8-191a-4233-9b34-3e3111a4adaf?version=1.2", + rev_reg_id = None, + timestamp = None + ) + + val anoncredPresentationV1 = AnoncredPresentationV1( + proof = AnoncredProofV1( + proofs = List(subProof), + aggregated_proof = aggregatedProof + ), + requested_proof = requestedProof, + identifiers = List(identifier) + ) + + assert(AnoncredPresentationV1.schemaSerDes.serialize(anoncredPresentationV1))(Assertion.equalTo(json)) + + assertZIO(AnoncredPresentationV1.schemaSerDes.deserialize(json))( + Assertion.equalTo(anoncredPresentationV1) + ) + } + ) +}