Skip to content

Commit

Permalink
Added revocation status list to create_credential function
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <[email protected]>
  • Loading branch information
blu3beri committed Jan 12, 2023
1 parent de74355 commit 783e51c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions anoncreds/src/data_types/anoncreds/rev_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl RevocationStatusList {
self.revocation_list.clone()
}

pub(crate) fn get(&self, idx: usize) -> Option<bool> {
self.revocation_list.get(idx).as_deref().copied()
}

pub fn new(
rev_reg_id: &str,
revocation_list: bitvec::vec::BitVec,
Expand Down
3 changes: 3 additions & 0 deletions anoncreds/src/ffi/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +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,
revocation: *const FfiCredRevInfo,
cred_p: *mut ObjectHandle,
rev_reg_p: *mut ObjectHandle,
Expand Down Expand Up @@ -135,13 +136,15 @@ pub extern "C" fn anoncreds_create_credential(
} else {
None
};

let (cred, rev_reg, rev_delta) = create_credential(
cred_def.load()?.cast_ref()?,
cred_def_private.load()?.cast_ref()?,
cred_offer.load()?.cast_ref()?,
cred_request.load()?.cast_ref()?,
cred_values.into(),
rev_reg_id,
rev_reg_list.load()?.cast_ref().ok(),
revocation_config
.as_ref()
.map(RevocationConfig::as_ref_config)
Expand Down
44 changes: 31 additions & 13 deletions anoncreds/src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ pub fn create_credential(
cred_request: &CredentialRequest,
cred_values: CredentialValues,
rev_reg_id: Option<RevocationRegistryId>,
rev_status_list: Option<&RevocationStatusList>,
revocation_config: Option<CredentialRevocationConfig>,
) -> Result<(
Credential,
Expand All @@ -270,10 +271,28 @@ 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 {
Some(revocation) => {
let rev_reg_def = &revocation.reg_def.value;
let mut rev_reg = revocation.registry.value.clone();
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)
)?;

// 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
// we check in this list whether the provided idx (revocation_config.registry_idx)
// is inside the revocation status list. If it is not in there we hit an edge case,
// which should not be possible within the happy flow.
//
// 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
// `issuance_on_demand`.
// When it is set to `false`, or 0, we invert the value. This means that we use
// `issuance_by_default`.
let issuance_type = !status;

let (credential_signature, signature_correctness_proof, delta) =
CryptoIssuer::sign_credential_with_revoc(
Expand All @@ -285,27 +304,26 @@ pub fn create_credential(
&credential_values,
&cred_public_key,
&cred_def_private.value,
revocation.registry_idx,
revocation_config.registry_idx,
rev_reg_def.max_cred_num,
// issuance by default
true,
issuance_type,
&mut rev_reg,
&revocation.reg_def_private.value,
&revocation.tails_reader,
&revocation_config.reg_def_private.value,
&revocation_config.tails_reader,
)?;

let witness = {
let empty = HashSet::new();
let (by_default, issued, revoked) = (true, &empty, revocation.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);
Witness::new(
revocation.registry_idx,
revocation_config.registry_idx,
rev_reg_def.max_cred_num,
by_default,
&rev_reg_delta,
&revocation.tails_reader,
&revocation_config.tails_reader,
)?
};
(
Expand All @@ -316,7 +334,7 @@ pub fn create_credential(
Some(witness),
)
}
None => {
_ => {
let (signature, correctness_proof) = CryptoIssuer::sign_credential(
&cred_request.prover_did.0,
&cred_request.blinded_ms,
Expand Down
1 change: 1 addition & 0 deletions anoncreds/tests/anoncreds_demos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fn anoncreds_works_for_single_issuer_single_prover() {
cred_values.into(),
None,
None,
None,
)
.expect("Error creating credential");

Expand Down

0 comments on commit 783e51c

Please sign in to comment.