Skip to content

Commit

Permalink
removed issuance by default reference
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <[email protected]>
  • Loading branch information
berendsliedrecht committed Jan 11, 2023
1 parent 294bdfb commit a26e197
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 69 deletions.
40 changes: 0 additions & 40 deletions anoncreds/src/data_types/anoncreds/rev_reg_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,8 @@ use super::cred_def::CredentialDefinitionId;

pub const CL_ACCUM: &str = "CL_ACCUM";

pub const ISSUANCE_BY_DEFAULT: &str = "ISSUANCE_BY_DEFAULT";
pub const ISSUANCE_ON_DEMAND: &str = "ISSUANCE_ON_DEMAND";

impl_anoncreds_object_identifier!(RevocationRegistryDefinitionId);

#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
pub enum IssuanceType {
#[default]
ISSUANCE_BY_DEFAULT,
ISSUANCE_ON_DEMAND,
}

impl FromStr for IssuanceType {
type Err = ConversionError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
ISSUANCE_BY_DEFAULT => Ok(Self::ISSUANCE_BY_DEFAULT),
ISSUANCE_ON_DEMAND => Ok(Self::ISSUANCE_ON_DEMAND),
_ => Err(ConversionError::from_msg("Invalid issuance type")),
}
}
}

impl From<IssuanceType> for usize {
fn from(value: IssuanceType) -> usize {
match value {
// Credentials are by default revoked
IssuanceType::ISSUANCE_ON_DEMAND => 1,
// Credentials are by default not revoked
IssuanceType::ISSUANCE_BY_DEFAULT => 0,
}
}
}

impl IssuanceType {
pub fn to_bool(&self) -> bool {
*self == IssuanceType::ISSUANCE_BY_DEFAULT
}
}
#[allow(non_camel_case_types)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum RegistryType {
Expand All @@ -70,7 +31,6 @@ impl FromStr for RegistryType {
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RevocationRegistryDefinitionValue {
pub issuance_type: IssuanceType,
pub max_cred_num: u32,
pub public_keys: RevocationRegistryDefinitionValuePublicKeys,
pub tails_hash: String,
Expand Down
8 changes: 1 addition & 7 deletions anoncreds/src/ffi/revocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::services::{
prover::create_or_update_revocation_state,
tails::{TailsFileReader, TailsFileWriter},
types::{
CredentialRevocationState, IssuanceType, RegistryType, RevocationRegistry,
CredentialRevocationState, RegistryType, RevocationRegistry,
RevocationRegistryDefinition, RevocationRegistryDefinitionPrivate, RevocationRegistryDelta,
RevocationStatusList,
},
Expand All @@ -28,7 +28,6 @@ pub extern "C" fn anoncreds_create_revocation_registry(
cred_def_id: FfiStr,
tag: FfiStr,
rev_reg_type: FfiStr,
issuance_type: FfiStr,
max_cred_num: i64,
tails_dir_path: FfiStr,
reg_def_p: *mut ObjectHandle,
Expand All @@ -51,17 +50,12 @@ pub extern "C" fn anoncreds_create_revocation_registry(
.ok_or_else(|| err_msg!("Missing registry type"))?;
RegistryType::from_str(rtype).map_err(err_map!(Input))?
};
let issuance_type = match issuance_type.as_opt_str() {
Some(s) => IssuanceType::from_str(s).map_err(err_map!(Input))?,
None => IssuanceType::default(),
};
let mut tails_writer = TailsFileWriter::new(tails_dir_path.into_opt_string());
let (reg_def, reg_def_private, reg_entry, reg_init_delta) = create_revocation_registry(
cred_def.load()?.cast_ref()?,
cred_def_id,
tag,
rev_reg_type,
issuance_type,
max_cred_num
.try_into()
.map_err(|_| err_msg!("Invalid maximum credential count"))?,
Expand Down
23 changes: 6 additions & 17 deletions anoncreds/src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pub fn create_revocation_registry<TW>(
cred_def_id: impl TryInto<CredentialDefinitionId, Error = ValidationError>,
tag: &str,
rev_reg_type: RegistryType,
issuance_type: IssuanceType,
max_cred_num: u32,
tails_writer: &mut TW,
) -> Result<(
Expand All @@ -129,8 +128,8 @@ pub fn create_revocation_registry<TW>(
where
TW: TailsWriter,
{
trace!("create_revocation_registry >>> cred_def: {:?}, tag: {:?}, max_cred_num: {:?}, rev_reg_type: {:?}, issuance_type: {:?}",
cred_def, tag, max_cred_num, rev_reg_type, issuance_type);
trace!("create_revocation_registry >>> cred_def: {:?}, tag: {:?}, max_cred_num: {:?}, rev_reg_type: {:?}",
cred_def, tag, max_cred_num, rev_reg_type);
let cred_def_id = cred_def_id.try_into()?;

let credential_pub_key = cred_def.get_public_key().map_err(err_map!(
Expand All @@ -151,7 +150,6 @@ where

let revoc_reg_def_value = RevocationRegistryDefinitionValue {
max_cred_num,
issuance_type,
public_keys: rev_keys_pub,
tails_location: tails_location.clone(),
tails_hash,
Expand All @@ -169,7 +167,7 @@ where
};

// now update registry to reflect issuance-by-default
let (revoc_reg, revoc_init_delta) = if issuance_type == IssuanceType::ISSUANCE_BY_DEFAULT {
let (revoc_reg, revoc_init_delta) = {
let tails_reader = TailsFileReader::new_tails_reader(&tails_location);
let issued = BTreeSet::from_iter(1..=max_cred_num);
update_revocation_registry(
Expand All @@ -179,9 +177,6 @@ where
BTreeSet::new(),
&tails_reader,
)?
} else {
let delta = revoc_reg.initial_delta();
(revoc_reg, delta)
};

let revoc_def_priv = RevocationRegistryDefinitionPrivate {
Expand Down Expand Up @@ -289,22 +284,16 @@ pub fn create_credential(
&cred_def_private.value,
revocation.registry_idx,
rev_reg_def.max_cred_num,
rev_reg_def.issuance_type.to_bool(),
// issuance by default
true,
&mut rev_reg,
&revocation.reg_def_private.value,
&revocation.tails_reader,
)?;

let witness = {
let empty = HashSet::new();
let (by_default, issued, revoked) = match rev_reg_def.issuance_type {
IssuanceType::ISSUANCE_ON_DEMAND => {
(false, revocation.registry_used, &empty)
}
IssuanceType::ISSUANCE_BY_DEFAULT => {
(true, &empty, revocation.registry_used)
}
};
let (by_default, issued, revoked) = (true, &empty, revocation.registry_used);

let rev_reg_delta =
CryptoRevocationRegistryDelta::from_parts(None, &rev_reg, issued, revoked);
Expand Down
6 changes: 4 additions & 2 deletions anoncreds/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ pub fn create_or_update_revocation_state(
} else {
let list_size = usize::try_from(revoc_reg_def.value.max_cred_num)
.map_err(|e| Error::from_msg(crate::ErrorKind::InvalidState, e.to_string()))?;
let bit: usize = revoc_reg_def.value.issuance_type.into();
// Issuance by default
let bit: usize = 0;
let list = bitvec![bit; list_size];
_create_index_deltas(
rev_reg_list.state_owned().bitxor(list),
Expand All @@ -306,7 +307,8 @@ pub fn create_or_update_revocation_state(
Witness::new(
rev_reg_idx,
revoc_reg_def.value.max_cred_num,
revoc_reg_def.value.issuance_type.to_bool(),
// issuance by default
true,
&rev_reg_delta,
&tails_reader,
)?
Expand Down
2 changes: 1 addition & 1 deletion anoncreds/src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use crate::data_types::anoncreds::{
presentation::Presentation,
rev_reg::{RevocationRegistry, RevocationRegistryDelta, RevocationStatusList},
rev_reg_def::{
IssuanceType, RegistryType, RevocationRegistryDefinition,
RegistryType, RevocationRegistryDefinition,
RevocationRegistryDefinitionPrivate,
},
schema::AttributeNames,
Expand Down
3 changes: 1 addition & 2 deletions anoncreds/tests/anoncreds_demos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use anoncreds::{
tails::{TailsFileReader, TailsFileWriter},
types::{
CredentialDefinitionConfig, CredentialRevocationConfig, CredentialRevocationState,
IssuanceType, MakeCredentialValues, PresentCredentials, PresentationRequest, RegistryType,
MakeCredentialValues, PresentCredentials, PresentationRequest, RegistryType,
RevocationStatusList, SignatureType,
},
verifier,
Expand Down Expand Up @@ -286,7 +286,6 @@ fn anoncreds_with_revocation_works_for_single_issuer_single_prover() {
CRED_DEF_ID,
"some_tag",
RegistryType::CL_ACCUM,
IssuanceType::ISSUANCE_BY_DEFAULT,
MAX_CRED_NUM,
&mut tf,
)
Expand Down

0 comments on commit a26e197

Please sign in to comment.