Skip to content

Commit

Permalink
Process review comments
Browse files Browse the repository at this point in the history
Signed-off-by: artem.ivanov <[email protected]>
  • Loading branch information
Artemkaaas committed Dec 7, 2023
1 parent 8267bc9 commit 77df074
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 31 deletions.
9 changes: 5 additions & 4 deletions src/data_types/w3c/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use chrono::{DateTime, Utc};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;
use std::collections::{HashMap, HashSet};
use std::fmt::{Display, Formatter};
use std::string::ToString;
use zeroize::Zeroize;

Expand Down Expand Up @@ -201,13 +202,13 @@ pub enum CredentialStatusType {
Other(String),
}

impl ToString for CredentialStatusType {
fn to_string(&self) -> String {
impl Display for CredentialStatusType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
CredentialStatusType::AnonCredsCredentialStatusList2023 => {
"AnonCredsCredentialStatusList2023".to_string()
f.write_str("AnonCredsCredentialStatusList2023")
}
CredentialStatusType::Other(other) => other.to_string(),
CredentialStatusType::Other(other) => f.write_str(other),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/data_types/w3c/presentation_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::collections::HashSet;
pub struct CredentialPresentationProof {
#[serde(rename = "type")]
pub type_: PresentationProofType,
/// Uniform Resource Identifier - https://www.w3.org/TR/vc-data-model/#dfn-uri
// FIXME: Consider either removing or moving under proof_value
// In fact, it's only needed to make attributes validation on the verifier side
// Revealed attributes and predicates can be restored from credential subject, but not unrevealed attributes
Expand Down
4 changes: 2 additions & 2 deletions src/services/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub fn get_non_revoked_interval(

impl RequestedProof {
// get list of revealed attributes per credential
pub(crate) fn attribute_referents(&self, index: u32) -> HashSet<String> {
pub(crate) fn get_attribute_referents(&self, index: u32) -> HashSet<String> {
let mut referents = HashSet::new();
for (referent, into) in self.revealed_attrs.iter() {
if into.sub_proof_index == index {
Expand All @@ -267,7 +267,7 @@ impl RequestedProof {
}

// get list of revealed predicates per credential
pub(crate) fn predicate_referents(&self, index: u32) -> HashSet<String> {
pub(crate) fn get_predicate_referents(&self, index: u32) -> HashSet<String> {
let mut referents = HashSet::new();
for (referent, info) in self.predicates.iter() {
if info.sub_proof_index == index {
Expand Down
10 changes: 5 additions & 5 deletions src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ pub fn create_credential(
);

let (credential_signature, signature_correctness_proof, rev_reg_id, rev_reg, witness) =
CLCredentialIssuer::init(cred_def, cred_def_private)?.create_credential(
CLCredentialIssuer::new(cred_def, cred_def_private).create_credential(
cred_offer,
cred_request,
&cred_values,
Expand Down Expand Up @@ -746,14 +746,14 @@ pub(crate) struct CLCredentialIssuer<'a> {
}

impl<'a> CLCredentialIssuer<'a> {
pub(crate) fn init(
pub(crate) fn new(
cred_def: &'a CredentialDefinition,
cred_def_private: &'a CredentialDefinitionPrivate,
) -> Result<CLCredentialIssuer<'a>> {
Ok(CLCredentialIssuer {
) -> CLCredentialIssuer<'a> {
CLCredentialIssuer {
cred_def,
cred_def_private,
})
}
}

#[allow(clippy::type_complexity)]
Expand Down
14 changes: 6 additions & 8 deletions src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub fn process_credential(
trace!("process_credential >>> credential: {:?}, cred_request_metadata: {:?}, link_secret: {:?}, cred_def: {:?}, rev_reg_def: {:?}",
credential, cred_request_metadata, secret!(&link_secret), cred_def, rev_reg_def);

CLCredentialProver::init(link_secret)?.process_credential(
CLCredentialProver::new(link_secret).process_credential(
&mut credential.signature,
&credential.signature_correctness_proof,
&credential.values,
Expand Down Expand Up @@ -417,7 +417,7 @@ pub fn create_presentation(
let mut sub_proof_index = 0;
let mut identifiers: Vec<Identifier> = Vec::with_capacity(credentials.len());

let mut proof_builder = CLProofBuilder::init(pres_req_val, schemas, cred_defs)?;
let mut proof_builder = CLProofBuilder::new(pres_req_val, schemas, cred_defs)?;

for present in credentials.0 {
if present.is_empty() {
Expand Down Expand Up @@ -770,8 +770,8 @@ pub(crate) struct CLCredentialProver<'a> {
}

impl<'a> CLCredentialProver<'a> {
pub(crate) fn init(link_secret: &'a LinkSecret) -> Result<CLCredentialProver<'a>> {
Ok(CLCredentialProver { link_secret })
pub(crate) fn new(link_secret: &'a LinkSecret) -> CLCredentialProver<'a> {
CLCredentialProver { link_secret }
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -821,7 +821,7 @@ pub(crate) struct CLProofBuilder<'a> {
}

impl<'a> CLProofBuilder<'a> {
pub(crate) fn init(
pub(crate) fn new(
presentation_request: &'a PresentationRequestPayload,
schemas: &'a HashMap<SchemaId, Schema>,
cred_defs: &'a HashMap<CredentialDefinitionId, CredentialDefinition>,
Expand Down Expand Up @@ -862,7 +862,7 @@ impl<'a> CLProofBuilder<'a> {

let (attrs_for_credential, attrs_nonrevoked_interval) = self
.presentation_request
.get_requested_attributes(&present.requested_attributes())?;
.get_requested_attributes(&present.revealed_attributes())?;
let (predicates_for_credential, pred_nonrevoked_interval) = self
.presentation_request
.get_requested_predicates(&present.requested_predicates)?;
Expand Down Expand Up @@ -936,8 +936,6 @@ impl<'a> CLProofBuilder<'a> {
mod tests {
use super::*;

// use crate::data_types::pres_request::PredicateTypes;

macro_rules! hashmap {
($( $key: expr => $val: expr ),*) => {
{
Expand Down
2 changes: 1 addition & 1 deletion src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<T> PresentCredential<'_, T> {
self.requested_attributes.is_empty() && self.requested_predicates.is_empty()
}

pub(crate) fn requested_attributes(&self) -> HashSet<String> {
pub(crate) fn revealed_attributes(&self) -> HashSet<String> {
let mut referents = HashSet::new();
for (referent, revealed) in self.requested_attributes.iter() {
if *revealed {
Expand Down
8 changes: 4 additions & 4 deletions src/services/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn verify_presentation(
&received_self_attested_attrs,
)?;

let mut proof_verifier = CLProofVerifier::init(
let mut proof_verifier = CLProofVerifier::new(
pres_req,
schemas,
cred_defs,
Expand All @@ -102,10 +102,10 @@ pub fn verify_presentation(

let attributes = presentation
.requested_proof
.attribute_referents(sub_proof_index as u32);
.get_attribute_referents(sub_proof_index as u32);
let predicates = presentation
.requested_proof
.predicate_referents(sub_proof_index as u32);
.get_predicate_referents(sub_proof_index as u32);

proof_verifier.add_sub_proof(
&attributes,
Expand Down Expand Up @@ -760,7 +760,7 @@ pub(crate) struct CLProofVerifier<'a> {
}

impl<'a> CLProofVerifier<'a> {
pub(crate) fn init(
pub(crate) fn new(
presentation_request: &'a PresentationRequestPayload,
schemas: &'a HashMap<SchemaId, Schema>,
cred_defs: &'a HashMap<CredentialDefinitionId, CredentialDefinition>,
Expand Down
2 changes: 1 addition & 1 deletion src/services/w3c/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl W3CCredential {
.ok_or_else(|| err_msg!("Credential attribute {} not found", requested_attribute))
}

pub(crate) fn attributes(&self) -> HashMap<String, String> {
pub(crate) fn get_attributes(&self) -> HashMap<String, String> {
let mut attributes: HashMap<String, String> = HashMap::new();
for (name, attribute) in self.credential_subject.attributes.0.iter() {
if let CredentialAttributeValue::Attribute(attribute) = attribute {
Expand Down
2 changes: 1 addition & 1 deletion src/services/w3c/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn create_credential(
let credential_values = raw_credential_values.encode(&encoding)?;

let (credential_signature, signature_correctness_proof, rev_reg_id, rev_reg, witness) =
CLCredentialIssuer::init(cred_def, cred_def_private)?.create_credential(
CLCredentialIssuer::new(cred_def, cred_def_private).create_credential(
cred_offer,
cred_request,
&credential_values,
Expand Down
4 changes: 2 additions & 2 deletions src/services/w3c/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn process_credential(
let proof = w3c_credential.get_mut_credential_signature_proof()?;
let mut signature = proof.get_credential_signature()?;

CLCredentialProver::init(link_secret)?.process_credential(
CLCredentialProver::new(link_secret).process_credential(
&mut signature.signature,
&signature.signature_correctness_proof,
&cred_values,
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn create_presentation(

let pres_req = pres_req.value();

let mut proof_builder = CLProofBuilder::init(pres_req, schemas, cred_defs)?;
let mut proof_builder = CLProofBuilder::new(pres_req, schemas, cred_defs)?;

for present in credentials.0.iter() {
if present.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions src/services/w3c/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn verify_presentation(
aggregated_proof: proof_data.aggregated,
};

let mut proof_verifier = CLProofVerifier::init(
let mut proof_verifier = CLProofVerifier::new(
pres_req,
schemas,
cred_defs,
Expand Down Expand Up @@ -233,7 +233,7 @@ fn _check_encoded_attributes(
credential_proof: &CredentialPresentationProofValue,
) -> Result<()> {
credential
.attributes()
.get_attributes()
.iter()
.map(|(name, value)| {
encode_credential_attribute(value).and_then(|encoded| {
Expand Down

0 comments on commit 77df074

Please sign in to comment.