Skip to content

Commit

Permalink
Fix lints from aries_vcx_core (#988)
Browse files Browse the repository at this point in the history
* Fix lints from aries_vcx_core (#988)

Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur authored Sep 21, 2023
1 parent 8c3fb06 commit 4b6c15b
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 127 deletions.
69 changes: 20 additions & 49 deletions aries_vcx_core/src/anoncreds/credx_anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ impl BaseAnonCreds for IndyCredxAnonCreds {
.get_wallet_record_value(CATEGORY_CRED_DEF_PRIV, cred_def_id)
.await?;

let mut revocation_config_parts = match (tails_dir, &rev_reg_id) {
(Some(tails_dir), Some(rev_reg_id)) => {
let mut revocation_config_parts = match &rev_reg_id {
Some(rev_reg_id) => {
let rev_reg_def = self
.get_wallet_record_value(CATEGORY_REV_REG_DEF, rev_reg_id)
.await?;
Expand All @@ -489,16 +489,9 @@ impl BaseAnonCreds for IndyCredxAnonCreds {
.get_wallet_record_value(CATEGORY_REV_REG_INFO, rev_reg_id)
.await?;

Some((
rev_reg_def,
rev_reg_def_priv,
rev_reg,
rev_reg_info,
tails_dir,
))
Some((rev_reg_def, rev_reg_def_priv, rev_reg, rev_reg_info))
}
(None, None) => None,
(tails_dir, rev_reg_id) => {
None => {
warn!(
"Missing revocation config params: tails_dir: {tails_dir:?} - {rev_reg_id:?}; \
Issuing non revokable credential"
Expand All @@ -508,37 +501,22 @@ impl BaseAnonCreds for IndyCredxAnonCreds {
};

let revocation_config = match &mut revocation_config_parts {
Some((rev_reg_def, rev_reg_def_priv, rev_reg, rev_reg_info, tails_dir)) => {
Some((rev_reg_def, rev_reg_def_priv, rev_reg, rev_reg_info)) => {
rev_reg_info.curr_id += 1;

let tails_file_hash = match rev_reg_def {
RevocationRegistryDefinition::RevocationRegistryDefinitionV1(rev_reg_def) => {
if rev_reg_info.curr_id > rev_reg_def.value.max_cred_num {
return Err(AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::ActionNotSupported,
"The revocation registry is full",
));
}

if rev_reg_def.value.issuance_type == IssuanceType::ISSUANCE_ON_DEMAND {
rev_reg_info.used_ids.insert(rev_reg_info.curr_id);
}

&rev_reg_def.value.tails_hash
}
};
let RevocationRegistryDefinition::RevocationRegistryDefinitionV1(rev_reg_def_v1) =
rev_reg_def;

let mut tails_file_path = std::path::PathBuf::new();
tails_file_path.push(&tails_dir);
tails_file_path.push(tails_file_hash);
if rev_reg_info.curr_id > rev_reg_def_v1.value.max_cred_num {
return Err(AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::ActionNotSupported,
"The revocation registry is full",
));
}

let tails_path = tails_file_path.to_str().ok_or_else(|| {
AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::InvalidOption,
"tails file is not an unicode string",
)
})?;
let tails_reader = TailsFileReader::new(tails_path);
if rev_reg_def_v1.value.issuance_type == IssuanceType::ISSUANCE_ON_DEMAND {
rev_reg_info.used_ids.insert(rev_reg_info.curr_id);
}

let revocation_config = CredentialRevocationConfig {
reg_def: rev_reg_def,
Expand Down Expand Up @@ -569,7 +547,7 @@ impl BaseAnonCreds for IndyCredxAnonCreds {
.transpose()?;

let cred_rev_id =
if let (Some(rev_reg_id), Some(str_rev_reg), Some((_, _, _, rev_reg_info, _))) =
if let (Some(rev_reg_id), Some(str_rev_reg), Some((_, _, _, rev_reg_info))) =
(rev_reg_id, &str_rev_reg, revocation_config_parts)
{
let cred_rev_id = rev_reg_info.curr_id.to_string();
Expand Down Expand Up @@ -911,7 +889,7 @@ impl BaseAnonCreds for IndyCredxAnonCreds {
};

let mut tails_file_path = std::path::PathBuf::new();
tails_file_path.push(&tails_dir);
tails_file_path.push(tails_dir);
tails_file_path.push(tails_file_hash);

let tails_path = tails_file_path.to_str().ok_or_else(|| {
Expand Down Expand Up @@ -1096,7 +1074,7 @@ impl BaseAnonCreds for IndyCredxAnonCreds {

async fn revoke_credential_local(
&self,
tails_dir: &str,
_tails_dir: &str,
rev_reg_id: &str,
cred_rev_id: &str,
) -> VcxCoreResult<()> {
Expand Down Expand Up @@ -1160,13 +1138,6 @@ impl BaseAnonCreds for IndyCredxAnonCreds {

let str_rev_reg_info = serde_json::to_string(&rev_reg_info)?;

let tails_file_hash = match &rev_reg_def {
RevocationRegistryDefinition::RevocationRegistryDefinitionV1(r) => &r.value.tails_hash,
};

let tails_file_path = format!("{tails_dir}/{tails_file_hash}");
let tails_reader = TailsFileReader::new(&tails_file_path);

let (rev_reg, new_rev_reg_delta) = credx::issuer::revoke_credential(
&cred_def,
&rev_reg_def,
Expand Down Expand Up @@ -1353,7 +1324,7 @@ fn _format_attribute_as_marker_tag_name(attribute_name: &str) -> String {
}

// common transformation requirement in credx
fn hashmap_as_ref<'a, T, U>(map: &'a HashMap<T, U>) -> HashMap<T, &'a U>
fn hashmap_as_ref<T, U>(map: &HashMap<T, U>) -> HashMap<T, &U>
where
T: std::hash::Hash,
T: std::cmp::Eq,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,42 @@ use serde_json::{Map, Value};
use vdrtools::{Locator, SearchHandle};

use crate::{
anoncreds::indy::general::close_search_handle,
errors::error::prelude::*,
anoncreds::indy::general::{blob_storage_open_reader, close_search_handle},
errors::error::{prelude::*, VcxCoreResult},
global::{mockdata::mock_settings::get_mock_creds_retrieved_for_proof_request, settings},
indy::utils::parse_and_validate,
utils,
utils::constants::{ATTRS, PROOF_REQUESTED_PREDICATES, REQUESTED_ATTRIBUTES},
utils::constants::{ATTRS, PROOF_REQUESTED_PREDICATES, REQUESTED_ATTRIBUTES, REV_STATE_JSON},
WalletHandle,
};

pub async fn libindy_prover_create_revocation_state(
tails_file_path: &str,
rev_reg_def_json: &str,
rev_reg_delta_json: &str,
timestamp: u64,
cred_rev_id: &str,
) -> VcxCoreResult<String> {
if settings::indy_mocks_enabled() {
return Ok(REV_STATE_JSON.to_string());
}

let blob_handle = blob_storage_open_reader(tails_file_path).await?;

let res = Locator::instance()
.prover_controller
.create_revocation_state(
blob_handle,
parse_and_validate(rev_reg_def_json)?,
parse_and_validate(rev_reg_delta_json)?,
timestamp,
cred_rev_id.into(),
)
.await?;

Ok(res)
}

pub async fn libindy_prover_create_proof(
wallet_handle: WalletHandle,
proof_req_json: &str,
Expand Down
35 changes: 0 additions & 35 deletions aries_vcx_core/src/anoncreds/indy/proofs/prover/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion aries_vcx_core/src/anoncreds/indy/proofs/verifier/mod.rs

This file was deleted.

9 changes: 4 additions & 5 deletions aries_vcx_core/src/anoncreds/indy_anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
anoncreds,
anoncreds::indy::primitives::credential_schema::libindy_issuer_create_schema,
errors::error::VcxCoreResult,
indy,
indy::utils::parse_and_validate,
wallet::indy::wallet_non_secrets::{clear_rev_reg_delta, get_rev_reg_delta},
WalletHandle,
Expand Down Expand Up @@ -34,7 +33,7 @@ impl BaseAnonCreds for IndySdkAnonCreds {
rev_reg_defs_json: &str,
rev_regs_json: &str,
) -> VcxCoreResult<bool> {
anoncreds::indy::proofs::verifier::verifier::libindy_verifier_verify_proof(
anoncreds::indy::proofs::verifier::libindy_verifier_verify_proof(
proof_req_json,
proof_json,
schemas_json,
Expand Down Expand Up @@ -123,7 +122,7 @@ impl BaseAnonCreds for IndySdkAnonCreds {
credential_defs_json: &str,
revoc_states_json: Option<&str>,
) -> VcxCoreResult<String> {
anoncreds::indy::proofs::prover::prover::libindy_prover_create_proof(
anoncreds::indy::proofs::prover::libindy_prover_create_proof(
self.indy_wallet_handle,
proof_req_json,
requested_credentials_json,
Expand All @@ -144,15 +143,15 @@ impl BaseAnonCreds for IndySdkAnonCreds {
}

async fn prover_get_credentials(&self, filter_json: Option<&str>) -> VcxCoreResult<String> {
anoncreds::indy::proofs::prover::prover::libindy_prover_get_credentials(
anoncreds::indy::proofs::prover::libindy_prover_get_credentials(
self.indy_wallet_handle,
filter_json,
)
.await
}

async fn prover_get_credentials_for_proof_req(&self, proof_req: &str) -> VcxCoreResult<String> {
anoncreds::indy::proofs::prover::prover::libindy_prover_get_credentials_for_proof_req(
anoncreds::indy::proofs::prover::libindy_prover_get_credentials_for_proof_req(
self.indy_wallet_handle,
proof_req,
)
Expand Down
5 changes: 1 addition & 4 deletions aries_vcx_core/src/errors/mapping_indy_api_types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pub use indy_api_types::{errors, ErrorCode};
use indy_api_types::{
errors::{err_msg, IndyErrorKind, IndyResult, IndyResultExt},
IndyError,
};
use indy_api_types::{errors::IndyErrorKind, IndyError};

use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind};

Expand Down
4 changes: 2 additions & 2 deletions aries_vcx_core/src/errors/mapping_ledger_response_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ impl From<LedgerResponseParserError> for AriesVcxCoreError {
LedgerResponseParserError::JsonError(err) => {
AriesVcxCoreError::from_msg(AriesVcxCoreErrorKind::InvalidJson, err.to_string())
}
LedgerResponseParserError::LedgerItemNotFound(item) => AriesVcxCoreError::from_msg(
LedgerResponseParserError::LedgerItemNotFound(_) => AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::LedgerItemNotFound,
err.to_string(),
),
LedgerResponseParserError::InvalidTransaction(message) => AriesVcxCoreError::from_msg(
LedgerResponseParserError::InvalidTransaction(_) => AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::InvalidLedgerResponse,
err.to_string(),
),
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod error;
mod mapping_agency_client;
#[cfg(any(feature = "modular_libs"))]
#[cfg(feature = "modular_libs")]
mod mapping_credx;
#[cfg(any(feature = "vdrtools_anoncreds", feature = "vdrtools_wallet"))]
mod mapping_indy_api_types;
Expand Down
1 change: 1 addition & 0 deletions aries_vcx_core/src/ledger/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResu
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Request {
#[allow(dead_code)]
pub req_id: u64,
pub identifier: String,
pub signature: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/ledger/indy/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub mod test_utils {
) {
let node_txns = get_txns();
let txn_file_data = node_txns.join("\n");
let mut f = fs::File::create(&genesis_file_path).unwrap();
let mut f = fs::File::create(genesis_file_path).unwrap();
f.write_all(txn_file_data.as_bytes()).unwrap();
f.flush().unwrap();
f.sync_all().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions aries_vcx_core/src/ledger/indy_vdr_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where
endorser_did: &str,
request_json: &str,
) -> VcxCoreResult<()> {
let mut request = PreparedRequest::from_request_json(&request_json)?;
let mut request = PreparedRequest::from_request_json(request_json)?;
verify_transaction_can_be_endorsed(request_json, endorser_did)?;
let signature_endorser = self.request_signer.sign(endorser_did, &request).await?;
request.set_multi_signature(&DidValue::from_str(endorser_did)?, &signature_endorser)?;
Expand Down Expand Up @@ -480,7 +480,7 @@ where
let revoc_reg_def_id = RevocationRegistryId::from_str(rev_reg_id)?;

let from = from.map(|x| x as i64);
let current_time = OffsetDateTime::now_utc().unix_timestamp() as i64;
let current_time = OffsetDateTime::now_utc().unix_timestamp();
let to = to.map_or(current_time, |x| x as i64);

let request = self.request_builder()?.build_get_revoc_reg_delta_request(
Expand Down Expand Up @@ -548,7 +548,7 @@ where
&self,
schema_json: &str,
submitter_did: &str,
endorser_did: Option<String>,
_endorser_did: Option<String>,
) -> VcxCoreResult<()> {
let identifier = DidValue::from_str(submitter_did)?;
let schema_data: SchemaV1 = serde_json::from_str(schema_json)?;
Expand Down
8 changes: 1 addition & 7 deletions aries_vcx_core/src/ledger/response_cacher/noop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ use serde::{Deserialize, Serialize};
use super::ResponseCacher;
use crate::errors::error::VcxCoreResult;

pub struct NoopResponseCacher {}

impl NoopResponseCacher {
pub fn new() -> Self {
Self {}
}
}
pub struct NoopResponseCacher;

#[async_trait]
impl ResponseCacher for NoopResponseCacher {
Expand Down
1 change: 0 additions & 1 deletion aries_vcx_core/src/wallet/indy/indy_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use async_trait::async_trait;

use crate::{
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult},
indy,
utils::async_fn_iterator::AsyncFnIterator,
wallet,
wallet::{
Expand Down
6 changes: 2 additions & 4 deletions aries_vcx_core/src/wallet/indy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::{collections::HashMap, thread};
use std::thread;

use async_trait::async_trait;
use futures::executor::block_on;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use super::base_wallet::BaseWallet;
use crate::{
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult},
indy,
errors::error::{AriesVcxCoreError, VcxCoreResult},
utils::{async_fn_iterator::AsyncFnIterator, json::TryGetIndex},
SearchHandle, WalletHandle,
};
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/wallet/indy/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub async fn unpack_message(wallet_handle: WalletHandle, msg: &[u8]) -> VcxCoreR
}

pub async fn create_key(wallet_handle: WalletHandle, seed: Option<&str>) -> VcxCoreResult<String> {
use vdrtools::{KeyInfo, Locator};
use vdrtools::KeyInfo;

let res = Locator::instance()
.crypto_controller
Expand Down
Loading

0 comments on commit 4b6c15b

Please sign in to comment.