Skip to content

Commit

Permalink
updated rev_reg_id to rev_reg_def_id
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <[email protected]>
  • Loading branch information
berendsliedrecht committed Jan 12, 2023
1 parent 783e51c commit 424e474
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 75 deletions.
12 changes: 6 additions & 6 deletions anoncreds/src/data_types/anoncreds/rev_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Validatable for RevocationRegistryDelta {}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RevocationStatusList {
rev_reg_id: RevocationRegistryId,
rev_reg_def_id: RevocationRegistryId,
#[serde(with = "serde_revocation_list")]
revocation_list: bitvec::vec::BitVec,
#[serde(flatten)]
Expand All @@ -45,8 +45,8 @@ pub struct RevocationStatusList {
}

impl From<&RevocationStatusList> for ursa::cl::RevocationRegistry {
fn from(rev_reg_list: &RevocationStatusList) -> ursa::cl::RevocationRegistry {
rev_reg_list.registry.clone()
fn from(rev_status_list: &RevocationStatusList) -> ursa::cl::RevocationRegistry {
rev_status_list.registry.clone()
}
}

Expand All @@ -68,13 +68,13 @@ impl RevocationStatusList {
}

pub fn new(
rev_reg_id: &str,
rev_reg_def_id: &str,
revocation_list: bitvec::vec::BitVec,
registry: ursa::cl::RevocationRegistry,
timestamp: u64,
) -> Result<Self, error::Error> {
Ok(RevocationStatusList {
rev_reg_id: RevocationRegistryId::new(rev_reg_id)?,
rev_reg_def_id: RevocationRegistryId::new(rev_reg_def_id)?,
revocation_list,
registry,
timestamp,
Expand Down Expand Up @@ -141,7 +141,7 @@ mod tests {

const REVOCATION_LIST: &str = r#"
{
"revRegId": "reg",
"revRegDefId": "reg",
"revocationList": [1, 1, 1, 1],
"accum": "1 1379509F4D411630D308A5ABB4F422FCE6737B330B1C5FD286AA5C26F2061E60 1 235535CC45D4816C7686C5A402A230B35A62DDE82B4A652E384FD31912C4E4BB 1 0C94B61595FCAEFC892BB98A27D524C97ED0B7ED1CC49AD6F178A59D4199C9A4 1 172482285606DEE8500FC8A13E6A35EC071F8B84F0EB4CD3DD091C0B4CD30E5E 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": 1234
Expand Down
4 changes: 2 additions & 2 deletions anoncreds/src/ffi/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub extern "C" fn anoncreds_create_credential(
attr_raw_values: FfiStrList,
attr_enc_values: FfiStrList,
rev_reg_id: FfiStr,
rev_reg_list: ObjectHandle,
rev_status_list: ObjectHandle,
revocation: *const FfiCredRevInfo,
cred_p: *mut ObjectHandle,
rev_reg_p: *mut ObjectHandle,
Expand Down Expand Up @@ -144,7 +144,7 @@ pub extern "C" fn anoncreds_create_credential(
cred_request.load()?.cast_ref()?,
cred_values.into(),
rev_reg_id,
rev_reg_list.load()?.cast_ref().ok(),
rev_status_list.load()?.cast_ref().ok(),
revocation_config
.as_ref()
.map(RevocationConfig::as_ref_config)
Expand Down
10 changes: 5 additions & 5 deletions anoncreds/src/ffi/revocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ impl_anoncreds_object_from_json!(RevocationStatusList, anoncreds_revocation_list
#[no_mangle]
pub extern "C" fn anoncreds_create_or_update_revocation_state(
rev_reg_def: ObjectHandle,
rev_reg_list: ObjectHandle,
rev_status_list: ObjectHandle,
rev_reg_index: i64,
tails_path: FfiStr,
rev_state: ObjectHandle,
old_rev_reg_list: ObjectHandle,
old_rev_status_list: ObjectHandle,
rev_state_p: *mut ObjectHandle,
) -> ErrorCode {
catch_error(|| {
check_useful_c_ptr!(rev_state_p);
let prev_rev_state = rev_state.opt_load()?;
let prev_rev_reg_list = old_rev_reg_list.opt_load()?;
let prev_rev_status_list = old_rev_status_list.opt_load()?;
let tails_reader = TailsFileReader::new_tails_reader(
tails_path
.as_opt_str()
Expand All @@ -251,15 +251,15 @@ pub extern "C" fn anoncreds_create_or_update_revocation_state(
let rev_state = create_or_update_revocation_state(
tails_reader,
rev_reg_def.load()?.cast_ref()?,
rev_reg_list.load()?.cast_ref()?,
rev_status_list.load()?.cast_ref()?,
rev_reg_index
.try_into()
.map_err(|_| err_msg!("Invalid credential revocation index"))?,
prev_rev_state
.as_ref()
.map(AnonCredsObject::cast_ref)
.transpose()?,
prev_rev_reg_list
prev_rev_status_list
.as_ref()
.map(AnonCredsObject::cast_ref)
.transpose()?,
Expand Down
18 changes: 12 additions & 6 deletions anoncreds/src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,19 @@ pub fn create_credential(
let credential_values = build_credential_values(&cred_values.0, None)?;

let (credential_signature, signature_correctness_proof, rev_reg, rev_reg_delta, witness) =
match (revocation_config, rev_status_list ) {
match (revocation_config, rev_status_list) {
(Some(revocation_config), Some(rev_status_list)) => {
let rev_reg_def = &revocation_config.reg_def.value;
let mut rev_reg = revocation_config.registry.value.clone();

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

// This will be a temporary solution for the `issuance_on_demand` vs
// `issuance_by_default` state. Right now, we pass in the revcation status list and
Expand All @@ -288,7 +293,7 @@ pub fn create_credential(
//
// If the index is inside the revocation status list we check whether it is set to
// `true` or `false` within the bitvec.
// When it is set to `true`, or 1, we invert the value. This means that we use
// When it is set to `true`, or 1, we invert the value. This means that we use
// `issuance_on_demand`.
// When it is set to `false`, or 0, we invert the value. This means that we use
// `issuance_by_default`.
Expand All @@ -314,7 +319,8 @@ pub fn create_credential(

let witness = {
let empty = HashSet::new();
let (by_default, issued, revoked) = (true, &empty, revocation_config.registry_used);
let (by_default, issued, revoked) =
(true, &empty, revocation_config.registry_used);

let rev_reg_delta =
CryptoRevocationRegistryDelta::from_parts(None, &rev_reg, issued, revoked);
Expand Down
107 changes: 55 additions & 52 deletions anoncreds/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,75 +249,78 @@ pub fn create_presentation(
pub fn create_or_update_revocation_state(
tails_reader: TailsReader,
revoc_reg_def: &RevocationRegistryDefinition,
rev_reg_list: &RevocationStatusList,
rev_status_list: &RevocationStatusList,
rev_reg_idx: u32,
rev_state: Option<&CredentialRevocationState>, // for witness update
old_rev_reg_list: Option<&RevocationStatusList>, // for witness update
old_rev_status_list: Option<&RevocationStatusList>, // for witness update
) -> Result<CredentialRevocationState> {
trace!(
"create_or_update_revocation_state >>> , tails_reader: {:?}, revoc_reg_def: {:?}, \
rev_reg_list: {:?}, rev_reg_idx: {}, rev_state: {:?}, old_rev_reg_list {:?}",
rev_status_list: {:?}, rev_reg_idx: {}, rev_state: {:?}, old_rev_status_list {:?}",
tails_reader,
revoc_reg_def,
rev_reg_list,
rev_status_list,
rev_reg_idx,
rev_state,
old_rev_reg_list,
old_rev_status_list,
);

let mut issued = HashSet::<u32>::new();
let mut revoked = HashSet::<u32>::new();
let witness =
if let (Some(source_rev_state), Some(source_rev_list)) = (rev_state, old_rev_reg_list) {
_create_index_deltas(
rev_reg_list.state_owned().bitxor(source_rev_list.state()),
rev_reg_list.state(),
&mut issued,
&mut revoked,
);
let witness = if let (Some(source_rev_state), Some(source_rev_list)) =
(rev_state, old_rev_status_list)
{
_create_index_deltas(
rev_status_list
.state_owned()
.bitxor(source_rev_list.state()),
rev_status_list.state(),
&mut issued,
&mut revoked,
);

let rev_reg_delta = RevocationRegistryDelta::from_parts(
Some(&source_rev_list.into()),
&rev_reg_list.into(),
&issued,
&revoked,
);
let mut witness = source_rev_state.witness.clone();
witness.update(
rev_reg_idx,
revoc_reg_def.value.max_cred_num,
&rev_reg_delta,
&tails_reader,
)?;
witness
} 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()))?;
// Issuance by default
let bit: usize = 0;
let list = bitvec![bit; list_size];
_create_index_deltas(
rev_reg_list.state_owned().bitxor(list),
rev_reg_list.state(),
&mut issued,
&mut revoked,
);
let rev_reg_delta =
RevocationRegistryDelta::from_parts(None, &rev_reg_list.into(), &issued, &revoked);
Witness::new(
rev_reg_idx,
revoc_reg_def.value.max_cred_num,
// issuance by default
true,
&rev_reg_delta,
&tails_reader,
)?
};
let rev_reg_delta = RevocationRegistryDelta::from_parts(
Some(&source_rev_list.into()),
&rev_status_list.into(),
&issued,
&revoked,
);
let mut witness = source_rev_state.witness.clone();
witness.update(
rev_reg_idx,
revoc_reg_def.value.max_cred_num,
&rev_reg_delta,
&tails_reader,
)?;
witness
} 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()))?;
// Issuance by default
let bit: usize = 0;
let list = bitvec![bit; list_size];
_create_index_deltas(
rev_status_list.state_owned().bitxor(list),
rev_status_list.state(),
&mut issued,
&mut revoked,
);
let rev_reg_delta =
RevocationRegistryDelta::from_parts(None, &rev_status_list.into(), &issued, &revoked);
Witness::new(
rev_reg_idx,
revoc_reg_def.value.max_cred_num,
// issuance by default
true,
&rev_reg_delta,
&tails_reader,
)?
};

Ok(CredentialRevocationState {
witness,
rev_reg: rev_reg_list.into(),
timestamp: rev_reg_list.timestamp(),
rev_reg: rev_status_list.into(),
timestamp: rev_status_list.timestamp(),
})
}

Expand Down
13 changes: 9 additions & 4 deletions anoncreds/tests/anoncreds_demos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub static CRED_DEF_ID: &str = "mock:uri";
pub static ISSUER_ID: &str = "mock:issuer_id/path&q=bar";
pub const GVT_SCHEMA_NAME: &str = "gvt";
pub const GVT_SCHEMA_ATTRIBUTES: &[&str; 4] = &["name", "age", "sex", "height"];
pub static REV_REG_DEF_ID: &str = "mock:uri:revregdefid";
pub static REV_REG_ID: &str = "mock:uri:revregid";
pub static REV_IDX: u32 = 89;
pub static MAX_CRED_NUM: u32 = 150;
Expand Down Expand Up @@ -337,7 +338,7 @@ fn anoncreds_with_revocation_works_for_single_issuer_single_prover() {
.add_raw("age", "28")
.expect("Error encoding attribute");

let rev_reg_id = RevocationRegistryId::new_unchecked(REV_REG_ID);
let rev_reg_def_id = RevocationRegistryId::new_unchecked(REV_REG_DEF_ID);

// Get the location of the tails_file so it can be read
let location = rev_reg_def_pub.clone().value.tails_location;
Expand All @@ -354,7 +355,9 @@ fn anoncreds_with_revocation_works_for_single_issuer_single_prover() {
&cred_offer,
&cred_request,
cred_values.into(),
Some(rev_reg_id.clone()),
Some(rev_reg_def_id.clone()),
// TODO: this should be a rev_status_list
None,
Some(CredentialRevocationConfig {
reg_def: &rev_reg_def_pub,
reg_def_private: &rev_reg_def_priv,
Expand Down Expand Up @@ -444,11 +447,13 @@ fn anoncreds_with_revocation_works_for_single_issuer_single_prover() {

// Verifier verifies presentation of not Revoked rev_state
// TODO: rev reg def id is the same as the rev reg id?
let rev_reg_def_id = RevocationRegistryDefinitionId::new_unchecked(REV_REG_ID);
let rev_reg_def_id = RevocationRegistryDefinitionId::new_unchecked(REV_REG_DEF_ID);
let rev_reg_def_map = HashMap::from([(&rev_reg_def_id, &rev_reg_def_pub)]);

// Create the map that contines the registries
let rev_timestamp_map = HashMap::from([(prover_timestamp, &cred_rev_reg)]);

let rev_reg_id = RevocationRegistryId::new_unchecked(REV_REG_ID);
let mut rev_reg_map = HashMap::from([(rev_reg_id.clone(), rev_timestamp_map.clone())]);

let valid = verifier::verify_presentation(
Expand Down Expand Up @@ -477,7 +482,7 @@ fn anoncreds_with_revocation_works_for_single_issuer_single_prover() {
let ursa_rev_reg = revoked_rev_reg.value.clone();

let revocation_list =
RevocationStatusList::new(REV_REG_ID, list, ursa_rev_reg, prover_timestamp).unwrap();
RevocationStatusList::new(REV_REG_DEF_ID, list, ursa_rev_reg, prover_timestamp).unwrap();
let new_rev_state = prover::create_or_update_revocation_state(
tr,
&rev_reg_def_pub,
Expand Down

0 comments on commit 424e474

Please sign in to comment.