forked from hyperledger/anoncreds-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a621b5a
commit 102a64c
Showing
4 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use anoncreds_core::types::Presentation as AnoncredsPresentation; | ||
use anoncreds_core::types::PresentationRequest as AnoncredsPresentationRequest; | ||
|
||
use crate::AnoncredsError; | ||
|
||
pub struct Presentation { | ||
pub core: AnoncredsPresentation, | ||
} | ||
|
||
impl Presentation { | ||
pub fn new(json_string: String) -> Result<Self, AnoncredsError> { | ||
let core_def: AnoncredsPresentation = | ||
serde_json::from_str(&json_string).map_err(|_| AnoncredsError::ConversionError)?; | ||
return Ok(Presentation { core: core_def }); | ||
} | ||
|
||
pub fn get_json(&self) -> Result<String, AnoncredsError> { | ||
serde_json::to_string(&self.core).map_err(|_| AnoncredsError::ConversionError) | ||
} | ||
} | ||
|
||
pub struct PresentationRequest { | ||
pub core: AnoncredsPresentationRequest, | ||
} | ||
|
||
impl PresentationRequest { | ||
pub fn new(json_string: String) -> Result<Self, AnoncredsError> { | ||
let core_def: AnoncredsPresentationRequest = | ||
serde_json::from_str(&json_string).map_err(|_| AnoncredsError::ConversionError)?; | ||
return Ok(PresentationRequest { core: core_def }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::error::AnoncredsError; | ||
use crate::presentation::{Presentation, PresentationRequest}; | ||
use crate::CredentialDefinition; | ||
use anoncreds_core::data_types::cred_def::CredentialDefinitionId; | ||
use anoncreds_core::data_types::schema::{Schema, SchemaId}; | ||
use anoncreds_core::verifier; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
//https://mozilla.github.io/uniffi-rs/udl/builtin_types.html | ||
|
||
pub struct Verifier {} | ||
|
||
impl Verifier { | ||
/// Create a new instance of [Verifier] | ||
pub fn new() -> Self { | ||
Verifier {} | ||
} | ||
|
||
/// Verify an incoming proof presentation | ||
pub fn verify_presentation( | ||
&self, | ||
presentation: Arc<Presentation>, | ||
presentation_request: Arc<PresentationRequest>, | ||
schemas: HashMap<SchemaId, Schema>, | ||
credential_definitions: HashMap<CredentialDefinitionId, Arc<CredentialDefinition>>, | ||
// rev_reg_defs: Option< | ||
// &HashMap<&RevocationRegistryDefinitionId, &RevocationRegistryDefinition>, | ||
// >, | ||
// rev_status_lists: Option<Vec<&RevocationStatusList>>, | ||
// nonrevoke_interval_override: Option< | ||
// &HashMap<&RevocationRegistryDefinitionId, HashMap<u64, u64>>, | ||
// >, | ||
) -> Result<bool, AnoncredsError> { | ||
let schemas_anoncreds = schemas.iter().map(|(k, v)| (k, v)).collect(); | ||
let cred_defs = credential_definitions | ||
.iter() | ||
.map(|(k, v)| { | ||
let tmp = &v.core; | ||
(k, tmp) | ||
}) | ||
.collect(); | ||
|
||
let ret = verifier::verify_presentation( | ||
&presentation.core, //&(*presentation_core).core | ||
&presentation_request.core, | ||
&schemas_anoncreds, | ||
&cred_defs, | ||
None, //TODO | ||
None, //TODO | ||
None, //TODO | ||
) | ||
.map_err(|err| AnoncredsError::ProcessCredentialError(format!("Error: {}", err)))?; | ||
|
||
return Ok(ret); | ||
// return Ok(true); | ||
} | ||
} |