Skip to content

Commit

Permalink
handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed Dec 19, 2023
1 parent ca76952 commit 4767b94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Credential> credentials,
selfAttested.asJava, // record<string, string>? self_attested,
linkSecret, // LinkSecret link_secret,
schemas.view
.mapValues(i => i: uniffi.anoncreds_wrapper.Schema)
.toMap
.asJava, // record<SchemaId, Schema> schemas,
credentialDefinitions.view.mapValues(i => i: uniffi.anoncreds_wrapper.CredentialDefinition).toMap.asJava
// record<CredentialDefinitionId, CredentialDefinition> 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<Credential> credentials,
selfAttested.asJava, // record<string, string>? self_attested,
linkSecret, // LinkSecret link_secret,
schemas.view
.mapValues(i => i: uniffi.anoncreds_wrapper.Schema)
.toMap
.asJava, // record<SchemaId, Schema> schemas,
credentialDefinitions.view.mapValues(i => i: uniffi.anoncreds_wrapper.CredentialDefinition).toMap.asJava
// record<CredentialDefinitionId, CredentialDefinition> credential_definitions
)
)
} catch {
case ex: uniffi.anoncreds_wrapper.AnoncredsException.CreatePresentationException => Left(ex)
}
}

// TODO FIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down

0 comments on commit 4767b94

Please sign in to comment.