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

feat: add helper methods for PresentationRequest #15

Merged
merged 1 commit into from
Dec 20, 2023
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
39 changes: 39 additions & 0 deletions anoncred-kmm/anoncred-wrapper-rust/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,42 @@ val buildRust by tasks.register("buildRust") {
mustRunAfter(moveRustSrcFiles)
dependsOn(moveRustSrcFiles, requiredInstallation, verifyRust, copyBindings, copyAnoncredsBinariesToProcessedResources)
}

afterEvaluate {
tasks.named("buildAnonCredWrapperForAndroidX86_64") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForAndroidArmv7a") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForAndroidArch64") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForAndroidI686") {
dependsOn(moveRustSrcFiles)
}

tasks.named("buildAnonCredWrapperForLinuxArch64") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForLinuxX86_64") {
dependsOn(moveRustSrcFiles)
}

tasks.named("buildAnonCredWrapperForiOSArch64") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForiOSArch64Sim") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForiOSX86_64") {
dependsOn(moveRustSrcFiles)
}

tasks.named("buildAnonCredWrapperForMacOSArch64") {
dependsOn(moveRustSrcFiles)
}
tasks.named("buildAnonCredWrapperForMacOSX86_64") {
dependsOn(moveRustSrcFiles)
}
}
2 changes: 1 addition & 1 deletion anoncred-kmm/anoncreds-kmp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ publishing {
android {
ndkVersion = "26.0.10792818"
compileSdk = 33
namespace = "anoncredskmp"
namespace = "io.iohk.atala.prism.anoncredskmp"
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")

sourceSets["main"].jniLibs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="anoncredskmp" />
<manifest package="io.iohk.atala.prism.anoncredskmp" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package anoncred.wrapper

import anoncreds_wrapper.CredentialDefinitionConfig
import anoncreds_wrapper.Issuer
import anoncreds_wrapper.PresentationRequest
import anoncreds_wrapper.Prover
import anoncreds_wrapper.Schema
import anoncreds_wrapper.SignatureType
Expand Down Expand Up @@ -51,4 +52,32 @@ class ProverTests {
println(credentialRequest)
assertTrue(true)
}

@Test
fun test_presentation_request_parsing() {
val presentationRequestJson = """
{
"requested_attributes":{
"attribute_1":{
"name":"name",
"restrictions":[

]
}
},
"requested_predicates":{

},
"name":"presentation_request_1",
"nonce":"1177620373658433495312997",
"version":"0.1"
}
"""
val presentationRequest = PresentationRequest(presentationRequestJson)
presentationRequest.getRequestedAttributes().forEach {
println(it.key)
println(it.value.toString())
}
println(presentationRequest.getRequestedPredicates())
}
}
30 changes: 30 additions & 0 deletions uniffi/src/anoncreds.udl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ enum RegistryType {
"CL_ACCUM"
};

enum PredicateTypes {
"GE",
"LE",
"GT",
"LT"
};

interface LinkSecret {
constructor();
[Throws=AnoncredsError, Name=new_from_value]
Expand Down Expand Up @@ -348,6 +355,11 @@ interface PresentationRequest {
constructor(string json_string);
[Throws=AnoncredsError]
string get_json();
record<string, AttributeInfoValue> get_requested_attributes();
record<string, PredicateInfoValue> get_requested_predicates();
string get_name();
string get_version();
Nonce get_nonce();
};

interface Verifier {
Expand All @@ -363,4 +375,22 @@ interface Verifier {

};

interface AttributeInfoValue {
[Throws=AnoncredsError]
constructor(string json);
[Throws=AnoncredsError]
string get_json();
sequence<string> get_names();
string get_name();
};

interface PredicateInfoValue {
[Throws=AnoncredsError]
constructor(string json);
[Throws=AnoncredsError]
string get_json();
string get_name();
PredicateTypes get_p_type();
};

namespace anoncreds_wrapper {};
5 changes: 2 additions & 3 deletions uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod prover;
mod verifier;

pub use crate::cred_def::CredentialDefinitionPrivate;
pub use crate::custom_types::{AttributeValues, CredentialValues};
pub use crate::custom_types::{AttributeValues, CredentialValues, PredicateInfoValue, AttributeInfoValue};
pub use crate::types::cred_def::{
CredentialDefinition, CredentialDefinitionData, CredentialKeyCorrectnessProof,
};
Expand All @@ -30,13 +30,12 @@ pub use anoncreds_core::data_types::schema::{Schema, SchemaId};
pub use anoncreds_core::types::{
AttributeNames, CredentialDefinitionConfig, RegistryType, SignatureType,
};
pub use anoncreds_core::data_types::pres_request::PredicateTypes;

pub use issuer::CredentialRevocationConfig;
pub use issuer::*;
pub use prover::*;
pub use types::*;
pub use verifier::*;

// fn x() -> AttributeValues

uniffi::include_scaffolding!("anoncreds");
105 changes: 103 additions & 2 deletions uniffi/src/types/custom_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anoncreds_core::data_types::schema::SchemaId;
use anoncreds_core::data_types::issuer_id::IssuerId;
use anoncreds_core::data_types::pres_request::{AttributeInfo, PredicateInfo, PredicateTypes};
use anoncreds_core::data_types::rev_reg::RevocationRegistryId;
use anoncreds_core::data_types::rev_reg_def::RevocationRegistryDefinitionId;
use anoncreds_core::data_types::cred_def::CredentialDefinitionId;
Expand All @@ -8,7 +9,7 @@ use anoncreds_core::types::{
AttributeValues as AnoncredsAttributeValues
};
use anoncreds_core::data_types::credential::CredentialValues as AnoncredsCredentialValues;
use crate::UniffiCustomTypeConverter;
use crate::{AnoncredsError, UniffiCustomTypeConverter};
use std::collections::HashMap;

/// Make sure [AttributeNames] implements [UniffiCustomTypeConverter] so that UniFFI can use it as
Expand Down Expand Up @@ -132,4 +133,104 @@ impl From<AttributeValues> for AnoncredsAttributeValues {
fn from(def: AttributeValues) -> AnoncredsAttributeValues {
AnoncredsAttributeValues { raw: def.raw, encoded: def.encoded }
}
}
}

#[derive(Debug)]
pub struct AttributeInfoValue {
pub core: AttributeInfo
}

impl AttributeInfoValue {
pub fn new(json: String) -> Result<Self, AnoncredsError> {
let core = serde_json::from_str(&json)
.map_err(|err| AnoncredsError::ConversionError(err.to_string()))?;
return Ok(AttributeInfoValue {
core: core
});
}

pub fn get_json(&self) -> Result<String, AnoncredsError> {
return serde_json::to_string(&self.core)
.map_err(|err| AnoncredsError::ConversionError(err.to_string()))
}

pub fn get_name(&self) -> String {
return self.core.name.clone().unwrap()
}

pub fn get_names(&self) -> Vec<String> {
return self.core.names.clone().unwrap()
}
}

impl From<AttributeInfo> for AttributeInfoValue {
fn from(value: AttributeInfo) -> AttributeInfoValue {
return AttributeInfoValue {
core: value
};
}
}

impl From<&AttributeInfo> for AttributeInfoValue {
fn from(value: &AttributeInfo) -> AttributeInfoValue {
return AttributeInfoValue {
core: value.clone()
};
}
}

impl From<AttributeInfoValue> for AttributeInfo {
fn from(value: AttributeInfoValue) -> Self {
return value.core.clone();
}
}

#[derive(Debug)]
pub struct PredicateInfoValue {
pub core: PredicateInfo
}

impl PredicateInfoValue {
pub fn new(json: String) -> Result<Self, AnoncredsError> {
let core = serde_json::from_str(&json)
.map_err(|err| AnoncredsError::ConversionError(err.to_string()))?;
return Ok(PredicateInfoValue {
core: core
});
}

pub fn get_json(&self) -> Result<String, AnoncredsError> {
return serde_json::to_string(&self.core)
.map_err(|err| AnoncredsError::ConversionError(err.to_string()))
}

pub fn get_name(&self) -> String {
return self.core.name.clone()
}

pub fn get_p_type(&self) -> PredicateTypes {
return self.core.p_type.clone()
}
}

impl From<PredicateInfo> for PredicateInfoValue {
fn from(value: PredicateInfo) -> PredicateInfoValue {
return PredicateInfoValue {
core: value
};
}
}

impl From<&PredicateInfo> for PredicateInfoValue {
fn from(value: &PredicateInfo) -> PredicateInfoValue {
return PredicateInfoValue {
core: value.clone()
};
}
}

impl From<PredicateInfoValue> for PredicateInfo {
fn from(value: PredicateInfoValue) -> PredicateInfo {
return value.core.clone();
}
}
Loading