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

Simplify create_credential parameters and remove RevocationRegistryId #239

Merged
merged 5 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions src/data_types/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use crate::cl::{CredentialSignature, RevocationRegistry, SignatureCorrectnessPro
use crate::error::{ConversionError, ValidationError};
use crate::utils::validation::Validatable;

use super::{cred_def::CredentialDefinitionId, rev_reg::RevocationRegistryId, schema::SchemaId};
use super::rev_reg_def::RevocationRegistryDefinitionId;
use super::{cred_def::CredentialDefinitionId, schema::SchemaId};

#[derive(Debug, Deserialize, Serialize)]
pub struct Credential {
pub schema_id: SchemaId,
pub cred_def_id: CredentialDefinitionId,
pub rev_reg_id: Option<RevocationRegistryId>,
pub rev_reg_id: Option<RevocationRegistryDefinitionId>,
pub values: CredentialValues,
pub signature: CredentialSignature,
pub signature_correctness_proof: SignatureCorrectnessProof,
Expand Down Expand Up @@ -73,7 +74,7 @@ pub struct CredentialInfo {
pub attrs: ShortCredentialValues,
pub schema_id: SchemaId,
pub cred_def_id: CredentialDefinitionId,
pub rev_reg_id: Option<RevocationRegistryId>,
pub rev_reg_id: Option<RevocationRegistryDefinitionId>,
pub cred_rev_id: Option<String>,
}

Expand Down
3 changes: 1 addition & 2 deletions src/data_types/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ macro_rules! impl_anoncreds_object_identifier {
"IssuerId" => &LEGACY_DID_IDENTIFIER,
"CredentialDefinitionId" => &LEGACY_CRED_DEF_IDENTIFIER,
"SchemaId" => &LEGACY_SCHEMA_IDENTIFIER,
// TODO: we do not have correct validation for a revocation registry and definition id
"RevocationRegistryId" => &LEGACY_DID_IDENTIFIER,
// TODO: we do not have correct validation for a revocation registry definition id
"RevocationRegistryDefinitionId" => &LEGACY_DID_IDENTIFIER,
invalid_name => {
return Err($crate::invalid!(
Expand Down
3 changes: 0 additions & 3 deletions src/data_types/pres_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ impl Serialize for PresentationRequest {
}
}

#[allow(unused)]
pub type PresentationRequestExtraQuery = HashMap<String, Query>;

#[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct NonRevokedInterval {
pub from: Option<u64>,
Expand Down
6 changes: 4 additions & 2 deletions src/data_types/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::cl::Proof;
use crate::error::ValidationError;
use crate::utils::validation::Validatable;

use super::{cred_def::CredentialDefinitionId, rev_reg::RevocationRegistryId, schema::SchemaId};
use super::{
cred_def::CredentialDefinitionId, rev_reg_def::RevocationRegistryDefinitionId, schema::SchemaId,
};

#[derive(Debug, Deserialize, Serialize)]
pub struct Presentation {
Expand Down Expand Up @@ -55,7 +57,7 @@ pub struct AttributeValue {
pub struct Identifier {
pub schema_id: SchemaId,
pub cred_def_id: CredentialDefinitionId,
pub rev_reg_id: Option<RevocationRegistryId>,
pub rev_reg_id: Option<RevocationRegistryDefinitionId>,
pub timestamp: Option<u64>,
}

Expand Down
3 changes: 0 additions & 3 deletions src/data_types/rev_reg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::cl::RevocationRegistry as CryptoRevocationRegistry;
use crate::impl_anoncreds_object_identifier;

impl_anoncreds_object_identifier!(RevocationRegistryId);

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RevocationRegistry {
Expand Down
56 changes: 29 additions & 27 deletions src/ffi/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,56 @@ use super::error::{catch_error, ErrorCode};
use super::object::{AnoncredsObject, ObjectHandle};
use super::util::FfiStrList;
use crate::data_types::link_secret::LinkSecret;
use crate::data_types::rev_reg::RevocationRegistryId;
use crate::error::Result;
use crate::services::{
issuer::create_credential,
prover::process_credential,
types::{Credential, CredentialRevocationConfig, MakeCredentialValues},
utils::encode_credential_attribute,
};
use crate::Error;

#[derive(Debug)]
#[repr(C)]
pub struct FfiCredRevInfo {
reg_def: ObjectHandle,
reg_def_private: ObjectHandle,
status_list: ObjectHandle,
reg_idx: i64,
}

struct RevocationConfig {
reg_def: AnoncredsObject,
reg_def_private: AnoncredsObject,
status_list: AnoncredsObject,
reg_idx: u32,
}

impl RevocationConfig {
pub fn as_ref_config(&self) -> Result<CredentialRevocationConfig> {
impl TryFrom<&FfiCredRevInfo> for RevocationConfig {
type Error = Error;

fn try_from(value: &FfiCredRevInfo) -> Result<Self> {
Ok(Self {
reg_def: value.reg_def.load()?,
reg_def_private: value.reg_def_private.load()?,
reg_idx: value
.reg_idx
.try_into()
.map_err(|_| err_msg!("Invalid revocation index"))?,
status_list: value.status_list.load()?,
})
}
}

impl<'a> TryFrom<&'a RevocationConfig> for CredentialRevocationConfig<'a> {
type Error = Error;

fn try_from(value: &'a RevocationConfig) -> Result<Self> {
Ok(CredentialRevocationConfig {
reg_def: self.reg_def.cast_ref()?,
reg_def_private: self.reg_def_private.cast_ref()?,
registry_idx: self.reg_idx,
reg_def: value.reg_def.cast_ref()?,
reg_def_private: value.reg_def_private.cast_ref()?,
registry_idx: value.reg_idx,
status_list: value.status_list.cast_ref()?,
})
}
}
Expand All @@ -49,8 +70,6 @@ pub extern "C" fn anoncreds_create_credential(
attr_names: FfiStrList,
attr_raw_values: FfiStrList,
attr_enc_values: FfiStrList,
rev_reg_id: FfiStr,
rev_status_list: ObjectHandle,
revocation: *const FfiCredRevInfo,
cred_p: *mut ObjectHandle,
) -> ErrorCode {
Expand All @@ -64,10 +83,6 @@ pub extern "C" fn anoncreds_create_credential(
"Mismatch between length of attribute names and raw values"
));
}
let rev_reg_id = rev_reg_id
.as_opt_str()
.map(RevocationRegistryId::new)
.transpose()?;
let enc_values = attr_enc_values.as_slice();
let mut cred_values = MakeCredentialValues::default();
for (attr_idx, (name, raw)) in attr_names
Expand Down Expand Up @@ -99,14 +114,7 @@ pub extern "C" fn anoncreds_create_credential(
None
} else {
let revocation = unsafe { &*revocation };
Some(RevocationConfig {
reg_def: revocation.reg_def.load()?,
reg_def_private: revocation.reg_def_private.load()?,
reg_idx: revocation
.reg_idx
.try_into()
.map_err(|_| err_msg!("Invalid revocation index"))?,
})
Some(RevocationConfig::try_from(revocation)?)
};

let cred = create_credential(
Expand All @@ -115,15 +123,9 @@ pub extern "C" fn anoncreds_create_credential(
cred_offer.load()?.cast_ref()?,
cred_request.load()?.cast_ref()?,
cred_values.into(),
rev_reg_id,
rev_status_list
.opt_load()?
.as_ref()
.map(AnoncredsObject::cast_ref)
.transpose()?,
revocation_config
.as_ref()
.map(RevocationConfig::as_ref_config)
.map(TryInto::try_into)
.transpose()?,
)?;
let cred = ObjectHandle::create(cred)?;
Expand Down
1 change: 0 additions & 1 deletion src/ffi/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ impl AnoncredsObjectList {
Ok(Self(loaded))
}

#[allow(unused)]
pub fn refs<T>(&self) -> Result<Vec<&T>>
where
T: AnyAnoncredsObject + 'static,
Expand Down
29 changes: 12 additions & 17 deletions src/services/issuer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::cl::{Issuer, RevocationRegistry as CryptoRevocationRegistry};
use crate::data_types::cred_def::CredentialDefinitionId;
use crate::data_types::issuer_id::IssuerId;
use crate::data_types::rev_reg::RevocationRegistryId;
use crate::data_types::rev_reg_def::RevocationRegistryDefinitionId;
use crate::data_types::schema::SchemaId;
use crate::data_types::{
Expand Down Expand Up @@ -696,8 +695,6 @@ pub fn create_credential_offer(
/// &credential_offer,
/// &credential_request,
/// credential_values.into(),
/// None,
/// None,
/// None
/// ).expect("Unable to create credential");
/// ```
Expand All @@ -708,8 +705,6 @@ pub fn create_credential(
cred_offer: &CredentialOffer,
cred_request: &CredentialRequest,
cred_values: CredentialValues,
rev_reg_id: Option<RevocationRegistryId>,
rev_status_list: Option<&RevocationStatusList>,
revocation_config: Option<CredentialRevocationConfig>,
) -> Result<Credential> {
trace!("create_credential >>> cred_def: {:?}, cred_def_private: {:?}, cred_offer.nonce: {:?}, cred_request: {:?},\
Expand All @@ -724,25 +719,24 @@ pub fn create_credential(
))?;
let credential_values = build_credential_values(&cred_values.0, None)?;

let (credential_signature, signature_correctness_proof, rev_reg, witness) =
if let (Some(revocation_config), Some(rev_status_list)) =
(revocation_config, rev_status_list)
{
let rev_reg_def = &revocation_config.reg_def.value;
let rev_reg: Option<CryptoRevocationRegistry> = rev_status_list.into();
let (credential_signature, signature_correctness_proof, rev_reg_id, rev_reg, witness) =
if let Some(rev_config) = revocation_config {
let rev_reg_def: &RevocationRegistryDefinitionValue = &rev_config.reg_def.value;
let rev_reg: Option<CryptoRevocationRegistry> = rev_config.status_list.into();
let mut rev_reg = rev_reg.ok_or_else(|| {
err_msg!(
Unexpected,
"RevocationStatusList should have accumulator value"
)
})?;

let status = rev_status_list
.get(revocation_config.registry_idx as usize)
let status = rev_config
.status_list
.get(rev_config.registry_idx as usize)
.ok_or_else(|| {
err_msg!(
"Revocation status list does not have the index {}",
revocation_config.registry_idx
rev_config.registry_idx
)
})?;

Expand Down Expand Up @@ -770,15 +764,16 @@ pub fn create_credential(
&credential_values,
&cred_public_key,
&cred_def_private.value,
revocation_config.registry_idx,
rev_config.registry_idx,
rev_reg_def.max_cred_num,
issuance_by_default,
&mut rev_reg,
&revocation_config.reg_def_private.value,
&rev_config.reg_def_private.value,
)?;
(
credential_signature,
signature_correctness_proof,
rev_config.status_list.id(),
Some(rev_reg),
Some(witness),
)
Expand All @@ -793,7 +788,7 @@ pub fn create_credential(
&cred_public_key,
&cred_def_private.value,
)?;
(signature, correctness_proof, None, None)
(signature, correctness_proof, None, None, None)
};

let credential = Credential {
Expand Down
4 changes: 0 additions & 4 deletions src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ pub fn create_credential_request(
/// &credential_offer,
/// &credential_request,
/// credential_values.into(),
/// None,
/// None,
/// None
/// ).expect("Unable to create credential");
///
Expand Down Expand Up @@ -341,8 +339,6 @@ pub fn process_credential(
/// &credential_offer,
/// &credential_request,
/// credential_values.into(),
/// None,
/// None,
/// None
/// ).expect("Unable to create credential");
///
Expand Down
4 changes: 3 additions & 1 deletion src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,18 @@ impl Validatable for CredentialRevocationState {
pub struct CredentialRevocationConfig<'a> {
pub reg_def: &'a RevocationRegistryDefinition,
pub reg_def_private: &'a RevocationRegistryDefinitionPrivate,
pub status_list: &'a RevocationStatusList,
pub registry_idx: u32,
}

impl<'a> std::fmt::Debug for CredentialRevocationConfig<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"CredentialRevocationConfig {{ reg_def: {:?}, private: {:?}, idx: {} }}",
"CredentialRevocationConfig {{ reg_def: {:?}, private: {:?}, status_list: {:?}, idx: {} }}",
self.reg_def,
secret!(self.reg_def_private),
self.status_list,
secret!(self.registry_idx),
)
}
Expand Down
5 changes: 2 additions & 3 deletions src/services/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,6 @@ fn is_attr_operator(key: &str) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::data_types::rev_reg::RevocationRegistryId;

pub const SCHEMA_ID: &str = "123";
pub const SCHEMA_NAME: &str = "Schema Name";
Expand Down Expand Up @@ -1180,7 +1179,7 @@ mod tests {
timestamp: Some(1234),
schema_id: SchemaId::default(),
cred_def_id: CredentialDefinitionId::default(),
rev_reg_id: Some(RevocationRegistryId::default()),
rev_reg_id: Some(RevocationRegistryDefinitionId::default()),
},
);
res.insert(
Expand All @@ -1189,7 +1188,7 @@ mod tests {
timestamp: None,
schema_id: SchemaId::default(),
cred_def_id: CredentialDefinitionId::default(),
rev_reg_id: Some(RevocationRegistryId::default()),
rev_reg_id: Some(RevocationRegistryDefinitionId::default()),
},
);
res
Expand Down
Loading
Loading