From 4767b94f24ad19db7878d0cd6e7b7ec90d4d80ec Mon Sep 17 00:00:00 2001 From: FabioPinheiro Date: Tue, 19 Dec 2023 15:44:56 +0000 Subject: [PATCH] handle exceptions --- .../atala/pollux/anoncreds/AnoncredLib.scala | 38 +++++++++++-------- .../atala/pollux/anoncreds/PoCNewLib.scala | 4 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala b/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala index aa6e49ebda..9bd681714c 100644 --- a/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala +++ b/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala @@ -146,23 +146,29 @@ object AnoncredLib { linkSecret: LinkSecret, schemas: Map[SchemaId, SchemaDef], credentialDefinitions: Map[CredentialDefinitionId, CredentialDefinition], - ): Presentation = { - uniffi.anoncreds_wrapper - .Prover() - .createPresentation( - presentationRequest, // uniffi.anoncreds - credentialRequests - .map(i => i: uniffi.anoncreds_wrapper.CredentialRequests) - .asJava, // sequence credentials, - selfAttested.asJava, // record? self_attested, - linkSecret, // LinkSecret link_secret, - schemas.view - .mapValues(i => i: uniffi.anoncreds_wrapper.Schema) - .toMap - .asJava, // record schemas, - credentialDefinitions.view.mapValues(i => i: uniffi.anoncreds_wrapper.CredentialDefinition).toMap.asJava - // record credential_definitions + ): Either[uniffi.anoncreds_wrapper.AnoncredsException.CreatePresentationException, Presentation] = { + try { + Right( + uniffi.anoncreds_wrapper + .Prover() + .createPresentation( + presentationRequest, // uniffi.anoncreds + credentialRequests + .map(i => i: uniffi.anoncreds_wrapper.CredentialRequests) + .asJava, // sequence credentials, + selfAttested.asJava, // record? self_attested, + linkSecret, // LinkSecret link_secret, + schemas.view + .mapValues(i => i: uniffi.anoncreds_wrapper.Schema) + .toMap + .asJava, // record schemas, + credentialDefinitions.view.mapValues(i => i: uniffi.anoncreds_wrapper.CredentialDefinition).toMap.asJava + // record credential_definitions + ) ) + } catch { + case ex: uniffi.anoncreds_wrapper.AnoncredsException.CreatePresentationException => Left(ex) + } } // TODO FIX diff --git a/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala b/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala index ed5401aed4..7172e28ea7 100644 --- a/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala +++ b/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala @@ -98,7 +98,7 @@ class PoCNewLib extends AnyFlatSpec { "sex":{"name":"sex", "restrictions":{"attr::sex::value":"M","cred_def_id":"$CRED_DEF_ID"}} }, "requested_predicates":{ - "age":{"name":"age", "p_type":">=", "p_value":32} + "age":{"name":"age", "p_type":">=", "p_value":18} } }""".stripMargin @@ -122,7 +122,7 @@ class PoCNewLib extends AnyFlatSpec { println("*** PROVER " + ("*" * 100) + " verifyPresentation") val verifyPresentation = AnoncredLib.verifyPresentation( - presentation, // : Presentation, + presentation.getOrElse(???), // : Presentation, presentationRequest, // : PresentationRequest, Map(credentialOffer.schemaId -> schema), // schemas: Map[SchemaId, SchemaDef], Map(