Skip to content

Commit

Permalink
cred_rev_id is u32
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee committed Feb 9, 2024
1 parent 55c5cd8 commit d314493
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 82 deletions.
2 changes: 1 addition & 1 deletion aries/agents/rust/aries-vcx-agent/src/services/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl ServiceCredentialsIssuer {
issuer.get_rev_reg_id().map_err(|err| err.into())
}

pub fn get_rev_id(&self, thread_id: &str) -> AgentResult<String> {
pub fn get_rev_id(&self, thread_id: &str) -> AgentResult<u32> {
let issuer = self.get_issuer(thread_id)?;
issuer.get_rev_id().map_err(|err| err.into())
}
Expand Down
11 changes: 4 additions & 7 deletions aries/aries_vcx/src/common/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub struct ProverCredential {
pub schema_id: String,
pub cred_def_id: String,
pub rev_reg_id: Option<String>,
pub cred_rev_id: Option<String>,
pub cred_rev_id: Option<u32>,
}

pub async fn get_cred_rev_id(
wallet: &impl BaseWallet,
anoncreds: &impl BaseAnonCreds,
cred_id: &str,
) -> VcxResult<String> {
) -> VcxResult<u32> {
let cred_json = anoncreds.prover_get_credential(wallet, cred_id).await?;
let prover_cred = serde_json::from_str::<ProverCredential>(&cred_json).map_err(|err| {
AriesVcxError::from_msg(
Expand All @@ -42,7 +42,7 @@ pub async fn get_cred_rev_id(
pub async fn is_cred_revoked(
ledger: &impl AnoncredsLedgerRead,
rev_reg_id: &str,
rev_id: &str,
rev_id: u32,
) -> VcxResult<bool> {
let to = Some(OffsetDateTime::now_utc().unix_timestamp() as u64 + 100);
let (rev_reg_delta_json, _) = ledger
Expand All @@ -51,8 +51,5 @@ pub async fn is_cred_revoked(
let rev_reg_delta =
RevocationRegistryDelta::create_from_ledger(&serde_json::to_string(&rev_reg_delta_json)?)
.await?;
Ok(rev_reg_delta
.revoked()
.iter()
.any(|s| s.to_string().eq(rev_id)))
Ok(rev_reg_delta.revoked().iter().any(|s| s.eq(&rev_id)))
}
34 changes: 17 additions & 17 deletions aries/aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct CredInfoProver {
pub schema_id: SchemaId,
pub cred_def_id: String,
pub rev_reg_id: Option<String>,
pub cred_rev_id: Option<String>,
pub cred_rev_id: Option<u32>,
pub revocation_interval: Option<NonRevokedInterval>,
pub tails_dir: Option<String>,
pub timestamp: Option<u64>,
Expand Down Expand Up @@ -193,7 +193,7 @@ pub async fn build_rev_states_json(
rev_reg_def_json,
rev_reg_delta_json,
timestamp,
cred_rev_id.parse()?,
*cred_rev_id,
)
.await?;

Expand Down Expand Up @@ -315,7 +315,7 @@ pub mod pool_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: None,
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
tails_dir: Some(get_temp_dir_path().to_str().unwrap().to_string()),
revocation_interval: None,
timestamp: None,
Expand All @@ -335,9 +335,9 @@ pub mod unit_tests {
use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path;
use test_utils::{
constants::{
address_schema_id, schema_id, ADDRESS_CRED_DEF_ID, ADDRESS_CRED_ID,
ADDRESS_CRED_REV_ID, ADDRESS_REV_REG_ID, ADDRESS_SCHEMA_ID, CRED_DEF_ID, CRED_REV_ID,
LICENCE_CRED_ID, REV_REG_ID, REV_STATE_JSON, SCHEMA_ID,
address_schema_id, schema_id, ADDRESS_CRED_DEF_ID, ADDRESS_CRED_ID, ADDRESS_REV_REG_ID,
ADDRESS_SCHEMA_ID, CRED_DEF_ID, CRED_REV_ID, LICENCE_CRED_ID, REV_REG_ID,
REV_STATE_JSON, SCHEMA_ID,
},
devsetup::*,
mockdata::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger},
Expand Down Expand Up @@ -372,7 +372,7 @@ pub mod unit_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: Some(REV_REG_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: None,
timestamp: None,
Expand All @@ -384,7 +384,7 @@ pub mod unit_tests {
schema_id: address_schema_id(),
cred_def_id: ADDRESS_CRED_DEF_ID.to_string(),
rev_reg_id: Some(ADDRESS_REV_REG_ID.to_string()),
cred_rev_id: Some(ADDRESS_CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: None,
timestamp: None,
Expand Down Expand Up @@ -419,7 +419,7 @@ pub mod unit_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: Some(REV_REG_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: None,
timestamp: None,
Expand All @@ -431,7 +431,7 @@ pub mod unit_tests {
schema_id: address_schema_id(),
cred_def_id: ADDRESS_CRED_DEF_ID.to_string(),
rev_reg_id: Some(ADDRESS_REV_REG_ID.to_string()),
cred_rev_id: Some(ADDRESS_CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: None,
timestamp: None,
Expand All @@ -458,7 +458,7 @@ pub mod unit_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: Some(REV_REG_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: Some(NonRevokedInterval {
from: Some(123),
to: Some(456),
Expand All @@ -473,7 +473,7 @@ pub mod unit_tests {
schema_id: address_schema_id(),
cred_def_id: ADDRESS_CRED_DEF_ID.to_string(),
rev_reg_id: Some(ADDRESS_REV_REG_ID.to_string()),
cred_rev_id: Some(ADDRESS_CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: Some(NonRevokedInterval {
from: None,
to: Some(987),
Expand Down Expand Up @@ -517,7 +517,7 @@ pub mod unit_tests {
"schema_id":ADDRESS_SCHEMA_ID,
"cred_def_id":ADDRESS_CRED_DEF_ID,
"rev_reg_id":ADDRESS_REV_REG_ID,
"cred_rev_id":ADDRESS_CRED_REV_ID
"cred_rev_id":CRED_REV_ID
},
"interval":null
},
Expand Down Expand Up @@ -598,7 +598,7 @@ pub mod unit_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: None,
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: Some(get_temp_dir_path().to_str().unwrap().to_string()),
timestamp: None,
Expand Down Expand Up @@ -636,7 +636,7 @@ pub mod unit_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: Some(REV_REG_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: None,
timestamp: Some(800),
Expand All @@ -648,7 +648,7 @@ pub mod unit_tests {
schema_id: address_schema_id(),
cred_def_id: ADDRESS_CRED_DEF_ID.to_string(),
rev_reg_id: Some(ADDRESS_REV_REG_ID.to_string()),
cred_rev_id: Some(ADDRESS_CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
revocation_interval: None,
tails_dir: None,
timestamp: Some(800),
Expand Down Expand Up @@ -707,7 +707,7 @@ pub mod unit_tests {
schema_id: schema_id(),
cred_def_id: CRED_DEF_ID.to_string(),
rev_reg_id: Some(REV_REG_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID.to_string()),
cred_rev_id: Some(CRED_REV_ID),
tails_dir: Some(get_temp_dir_path().to_str().unwrap().to_string()),
revocation_interval: None,
timestamp: None,
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/handlers/issuance/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl Holder {
&self,
wallet: &impl BaseWallet,
anoncreds: &impl BaseAnonCreds,
) -> VcxResult<String> {
) -> VcxResult<u32> {
get_cred_rev_id(wallet, anoncreds, &self.get_cred_id()?).await
}

Expand Down
6 changes: 3 additions & 3 deletions aries/aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Issuer {
self.issuer_sm.is_terminal_state()
}

pub fn get_revocation_id(&self) -> VcxResult<String> {
pub fn get_revocation_id(&self) -> VcxResult<u32> {
self.issuer_sm
.get_revocation_info()
.ok_or(AriesVcxError::from_msg(
Expand Down Expand Up @@ -250,7 +250,7 @@ impl Issuer {
.revoke_credential_local(
wallet,
&rev_reg_id.try_into()?,
cred_rev_id.parse()?,
cred_rev_id,
rev_reg_delta_json,
)
.await?;
Expand All @@ -267,7 +267,7 @@ impl Issuer {
self.issuer_sm.get_rev_reg_id()
}

pub fn get_rev_id(&self) -> VcxResult<String> {
pub fn get_rev_id(&self) -> VcxResult<u32> {
self.issuer_sm.get_rev_id()
}

Expand Down
4 changes: 2 additions & 2 deletions aries/aries_vcx/src/handlers/proof_presentation/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct RetrievedCredentialInfo {
pub schema_id: SchemaId,
pub cred_def_id: String,
pub rev_reg_id: Option<String>,
pub cred_rev_id: Option<String>,
pub cred_rev_id: Option<u32>,
}

// NOTE: in the future this could probably be moved to a more common location.
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct SelectedCredentialInfo {
pub schema_id: SchemaId,
pub cred_def_id: String,
pub rev_reg_id: Option<String>,
pub cred_rev_id: Option<String>,
pub cred_rev_id: Option<u32>,
/// Whether the raw attribute value/s should be proven and sent to the verifier.
/// Selecting false will still produce a proof for this credential, but no details
/// about the attributes values will be revealed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct RevocationNotificationReceiver {
}

impl RevocationNotificationReceiver {
pub fn build(rev_reg_id: String, cred_rev_id: String) -> Self {
pub fn build(rev_reg_id: String, cred_rev_id: u32) -> Self {
Self {
receiver_sm: RevocationNotificationReceiverSM::create(rev_reg_id, cred_rev_id),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl HolderSM {
let rev_reg_id = self.get_rev_reg_id()?;
let cred_id = self.get_cred_id()?;
let rev_id = get_cred_rev_id(wallet, anoncreds, &cred_id).await?;
is_cred_revoked(ledger, &rev_reg_id, &rev_id).await
is_cred_revoked(ledger, &rev_reg_id, rev_id).await
} else {
Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
Expand Down
26 changes: 10 additions & 16 deletions aries/aries_vcx/src/protocols/issuance/issuer/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Display for IssuerFullState {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RevocationInfoV1 {
pub cred_rev_id: Option<String>,
pub cred_rev_id: Option<u32>,
pub rev_reg_id: Option<String>,
pub tails_file: Option<String>,
}
Expand Down Expand Up @@ -199,24 +199,18 @@ impl IssuerSM {
}
}

pub fn get_rev_id(&self) -> VcxResult<String> {
pub fn get_rev_id(&self) -> VcxResult<u32> {
let err = AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
"No revocation info found - is this credential revokable?",
);
let rev_id = match &self.state {
IssuerFullState::CredentialSet(state) => state
.revocation_info_v1
.as_ref()
.ok_or(err)?
.cred_rev_id
.clone(),
IssuerFullState::Finished(state) => state
.revocation_info_v1
.as_ref()
.ok_or(err)?
.cred_rev_id
.clone(),
IssuerFullState::CredentialSet(state) => {
state.revocation_info_v1.as_ref().ok_or(err)?.cred_rev_id
}
IssuerFullState::Finished(state) => {
state.revocation_info_v1.as_ref().ok_or(err)?.cred_rev_id
}
_ => None,
};
rev_id.ok_or(AriesVcxError::from_msg(
Expand Down Expand Up @@ -284,7 +278,7 @@ impl IssuerSM {
if self.is_revokable() {
let rev_reg_id = self.get_rev_reg_id()?;
let rev_id = self.get_rev_id()?;
is_cred_revoked(ledger, &rev_reg_id, &rev_id).await
is_cred_revoked(ledger, &rev_reg_id, rev_id).await
} else {
Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidState,
Expand Down Expand Up @@ -579,7 +573,7 @@ async fn create_credential(
offer: &OfferCredentialV1,
cred_data: &str,
thread_id: String,
) -> VcxResult<(IssueCredentialV1, Option<String>)> {
) -> VcxResult<(IssueCredentialV1, Option<u32>)> {
let offer = get_attach_as_string!(&offer.content.offers_attach);

trace!(
Expand Down
4 changes: 2 additions & 2 deletions aries/aries_vcx/src/protocols/revocation_notification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub mod test_utils {
String::from(REV_REG_ID)
}

pub fn _cred_rev_id() -> String {
String::from("12")
pub fn _cred_rev_id() -> u32 {
12
}

pub fn _comment() -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
pub struct RevocationNotificationReceiverSM {
state: ReceiverFullState,
rev_reg_id: String,
cred_rev_id: String,
cred_rev_id: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand All @@ -37,7 +37,7 @@ pub enum ReceiverFullState {
}

impl RevocationNotificationReceiverSM {
pub fn create(rev_reg_id: String, cred_rev_id: String) -> Self {
pub fn create(rev_reg_id: String, cred_rev_id: u32) -> Self {
Self {
state: ReceiverFullState::Initial(InitialState),
rev_reg_id,
Expand Down Expand Up @@ -217,7 +217,7 @@ impl RevocationNotificationReceiverSM {
};
let check_cred_rev_id = |()| -> VcxResult<()> {
if let Some(cred_rev_id) = parts.get(1) {
if *cred_rev_id != self.cred_rev_id {
if cred_rev_id.parse::<u32>()? != self.cred_rev_id {
Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidRevocationDetails,
"Credential revocation ID in received notification does not match \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum SenderFullState {
#[derive(Default, Builder)]
pub struct SenderConfig {
rev_reg_id: String,
cred_rev_id: String,
cred_rev_id: u32,
comment: Option<String>,
ack_on: Vec<AckOn>,
}
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/tests/test_anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async fn test_pool_revoke_credential() -> Result<(), Box<dyn Error>> {
.revoke_credential_local(
&setup.wallet,
&rev_reg.rev_reg_id.to_owned().try_into()?,
cred_rev_id.parse()?,
cred_rev_id,
rev_reg_delta_json,
)
.await?;
Expand Down
6 changes: 3 additions & 3 deletions aries/aries_vcx/tests/test_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async fn test_pool_is_cred_revoked() -> Result<(), Box<dyn Error>> {
.await;
let cred_rev_id = get_cred_rev_id(&setup.wallet, &setup.anoncreds, &cred_id).await?;

assert!(!is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, &cred_rev_id).await?);
assert!(!is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, cred_rev_id).await?);

let rev_reg_delta_json = setup
.ledger_read
Expand All @@ -125,7 +125,7 @@ async fn test_pool_is_cred_revoked() -> Result<(), Box<dyn Error>> {
.revoke_credential_local(
&setup.wallet,
&rev_reg.rev_reg_id.to_owned().try_into()?,
cred_rev_id.parse()?,
cred_rev_id,
rev_reg_delta_json,
)
.await?;
Expand All @@ -140,6 +140,6 @@ async fn test_pool_is_cred_revoked() -> Result<(), Box<dyn Error>> {

std::thread::sleep(std::time::Duration::from_millis(500));

assert!(is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, &cred_rev_id).await?);
assert!(is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, cred_rev_id).await?);
Ok(())
}
Loading

0 comments on commit d314493

Please sign in to comment.