From 4b6c15b9ba23ac14eacc4ae13f0d97cf9d383361 Mon Sep 17 00:00:00 2001 From: Bogdan Mircea <98585737+bobozaur@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:17:51 +0300 Subject: [PATCH] Fix lints from aries_vcx_core (#988) * Fix lints from aries_vcx_core (#988) Signed-off-by: Bogdan Mircea --- .../src/anoncreds/credx_anoncreds.rs | 69 ++++++------------- .../indy/proofs/{prover => }/prover.rs | 33 ++++++++- .../src/anoncreds/indy/proofs/prover/mod.rs | 35 ---------- .../indy/proofs/{verifier => }/verifier.rs | 0 .../src/anoncreds/indy/proofs/verifier/mod.rs | 1 - .../src/anoncreds/indy_anoncreds.rs | 9 ++- .../src/errors/mapping_indy_api_types.rs | 5 +- .../errors/mapping_ledger_response_parser.rs | 4 +- aries_vcx_core/src/errors/mod.rs | 2 +- aries_vcx_core/src/ledger/common.rs | 1 + aries_vcx_core/src/ledger/indy/pool.rs | 2 +- aries_vcx_core/src/ledger/indy_vdr_ledger.rs | 6 +- .../src/ledger/response_cacher/noop/mod.rs | 8 +-- aries_vcx_core/src/wallet/indy/indy_wallet.rs | 1 - aries_vcx_core/src/wallet/indy/mod.rs | 6 +- aries_vcx_core/src/wallet/indy/signing.rs | 2 +- aries_vcx_core/src/wallet/indy/wallet.rs | 4 +- .../src/controllers/anoncreds/prover.rs | 7 -- 18 files changed, 68 insertions(+), 127 deletions(-) rename aries_vcx_core/src/anoncreds/indy/proofs/{prover => }/prover.rs (87%) delete mode 100644 aries_vcx_core/src/anoncreds/indy/proofs/prover/mod.rs rename aries_vcx_core/src/anoncreds/indy/proofs/{verifier => }/verifier.rs (100%) delete mode 100644 aries_vcx_core/src/anoncreds/indy/proofs/verifier/mod.rs diff --git a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs index e229effb55..e4c6a3a180 100644 --- a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs @@ -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?; @@ -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" @@ -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, @@ -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(); @@ -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(|| { @@ -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<()> { @@ -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, @@ -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) -> HashMap +fn hashmap_as_ref(map: &HashMap) -> HashMap where T: std::hash::Hash, T: std::cmp::Eq, diff --git a/aries_vcx_core/src/anoncreds/indy/proofs/prover/prover.rs b/aries_vcx_core/src/anoncreds/indy/proofs/prover.rs similarity index 87% rename from aries_vcx_core/src/anoncreds/indy/proofs/prover/prover.rs rename to aries_vcx_core/src/anoncreds/indy/proofs/prover.rs index de3ad205f1..2ff5e63c99 100644 --- a/aries_vcx_core/src/anoncreds/indy/proofs/prover/prover.rs +++ b/aries_vcx_core/src/anoncreds/indy/proofs/prover.rs @@ -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 { + 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, diff --git a/aries_vcx_core/src/anoncreds/indy/proofs/prover/mod.rs b/aries_vcx_core/src/anoncreds/indy/proofs/prover/mod.rs deleted file mode 100644 index 4179773fea..0000000000 --- a/aries_vcx_core/src/anoncreds/indy/proofs/prover/mod.rs +++ /dev/null @@ -1,35 +0,0 @@ -pub mod prover; - -use vdrtools::Locator; - -use crate::{ - anoncreds::indy::general::blob_storage_open_reader, errors::error::VcxCoreResult, - global::settings, indy, indy::utils::parse_and_validate, utils::constants::REV_STATE_JSON, -}; - -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 { - 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) -} diff --git a/aries_vcx_core/src/anoncreds/indy/proofs/verifier/verifier.rs b/aries_vcx_core/src/anoncreds/indy/proofs/verifier.rs similarity index 100% rename from aries_vcx_core/src/anoncreds/indy/proofs/verifier/verifier.rs rename to aries_vcx_core/src/anoncreds/indy/proofs/verifier.rs diff --git a/aries_vcx_core/src/anoncreds/indy/proofs/verifier/mod.rs b/aries_vcx_core/src/anoncreds/indy/proofs/verifier/mod.rs deleted file mode 100644 index 9a0722027d..0000000000 --- a/aries_vcx_core/src/anoncreds/indy/proofs/verifier/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod verifier; diff --git a/aries_vcx_core/src/anoncreds/indy_anoncreds.rs b/aries_vcx_core/src/anoncreds/indy_anoncreds.rs index fc0bf606e8..2aebefb665 100644 --- a/aries_vcx_core/src/anoncreds/indy_anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/indy_anoncreds.rs @@ -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, @@ -34,7 +33,7 @@ impl BaseAnonCreds for IndySdkAnonCreds { rev_reg_defs_json: &str, rev_regs_json: &str, ) -> VcxCoreResult { - anoncreds::indy::proofs::verifier::verifier::libindy_verifier_verify_proof( + anoncreds::indy::proofs::verifier::libindy_verifier_verify_proof( proof_req_json, proof_json, schemas_json, @@ -123,7 +122,7 @@ impl BaseAnonCreds for IndySdkAnonCreds { credential_defs_json: &str, revoc_states_json: Option<&str>, ) -> VcxCoreResult { - 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, @@ -144,7 +143,7 @@ impl BaseAnonCreds for IndySdkAnonCreds { } async fn prover_get_credentials(&self, filter_json: Option<&str>) -> VcxCoreResult { - anoncreds::indy::proofs::prover::prover::libindy_prover_get_credentials( + anoncreds::indy::proofs::prover::libindy_prover_get_credentials( self.indy_wallet_handle, filter_json, ) @@ -152,7 +151,7 @@ impl BaseAnonCreds for IndySdkAnonCreds { } async fn prover_get_credentials_for_proof_req(&self, proof_req: &str) -> VcxCoreResult { - 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, ) diff --git a/aries_vcx_core/src/errors/mapping_indy_api_types.rs b/aries_vcx_core/src/errors/mapping_indy_api_types.rs index f89f5aad1f..3659bdfdbc 100644 --- a/aries_vcx_core/src/errors/mapping_indy_api_types.rs +++ b/aries_vcx_core/src/errors/mapping_indy_api_types.rs @@ -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}; diff --git a/aries_vcx_core/src/errors/mapping_ledger_response_parser.rs b/aries_vcx_core/src/errors/mapping_ledger_response_parser.rs index 0c79dfa748..cd17952c8e 100644 --- a/aries_vcx_core/src/errors/mapping_ledger_response_parser.rs +++ b/aries_vcx_core/src/errors/mapping_ledger_response_parser.rs @@ -8,11 +8,11 @@ impl From 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(), ), diff --git a/aries_vcx_core/src/errors/mod.rs b/aries_vcx_core/src/errors/mod.rs index f56d8a0639..9ef99a5d30 100644 --- a/aries_vcx_core/src/errors/mod.rs +++ b/aries_vcx_core/src/errors/mod.rs @@ -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; diff --git a/aries_vcx_core/src/ledger/common.rs b/aries_vcx_core/src/ledger/common.rs index cbf40f5110..50bfae5b6d 100644 --- a/aries_vcx_core/src/ledger/common.rs +++ b/aries_vcx_core/src/ledger/common.rs @@ -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, diff --git a/aries_vcx_core/src/ledger/indy/pool.rs b/aries_vcx_core/src/ledger/indy/pool.rs index 8f397cc2e2..269ab7a391 100644 --- a/aries_vcx_core/src/ledger/indy/pool.rs +++ b/aries_vcx_core/src/ledger/indy/pool.rs @@ -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(); diff --git a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs index d03c369328..d9267d3cba 100644 --- a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs +++ b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs @@ -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)?; @@ -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( @@ -548,7 +548,7 @@ where &self, schema_json: &str, submitter_did: &str, - endorser_did: Option, + _endorser_did: Option, ) -> VcxCoreResult<()> { let identifier = DidValue::from_str(submitter_did)?; let schema_data: SchemaV1 = serde_json::from_str(schema_json)?; diff --git a/aries_vcx_core/src/ledger/response_cacher/noop/mod.rs b/aries_vcx_core/src/ledger/response_cacher/noop/mod.rs index e7c224590d..f0781406db 100644 --- a/aries_vcx_core/src/ledger/response_cacher/noop/mod.rs +++ b/aries_vcx_core/src/ledger/response_cacher/noop/mod.rs @@ -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 { diff --git a/aries_vcx_core/src/wallet/indy/indy_wallet.rs b/aries_vcx_core/src/wallet/indy/indy_wallet.rs index 23c8b48ae7..ce0ce178bd 100644 --- a/aries_vcx_core/src/wallet/indy/indy_wallet.rs +++ b/aries_vcx_core/src/wallet/indy/indy_wallet.rs @@ -4,7 +4,6 @@ use async_trait::async_trait; use crate::{ errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}, - indy, utils::async_fn_iterator::AsyncFnIterator, wallet, wallet::{ diff --git a/aries_vcx_core/src/wallet/indy/mod.rs b/aries_vcx_core/src/wallet/indy/mod.rs index f9ab552a57..4d46b2cb9d 100644 --- a/aries_vcx_core/src/wallet/indy/mod.rs +++ b/aries_vcx_core/src/wallet/indy/mod.rs @@ -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, }; diff --git a/aries_vcx_core/src/wallet/indy/signing.rs b/aries_vcx_core/src/wallet/indy/signing.rs index 955326d538..d19f1d07e6 100644 --- a/aries_vcx_core/src/wallet/indy/signing.rs +++ b/aries_vcx_core/src/wallet/indy/signing.rs @@ -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 { - use vdrtools::{KeyInfo, Locator}; + use vdrtools::KeyInfo; let res = Locator::instance() .crypto_controller diff --git a/aries_vcx_core/src/wallet/indy/wallet.rs b/aries_vcx_core/src/wallet/indy/wallet.rs index cfe50250e7..c5e0b61941 100644 --- a/aries_vcx_core/src/wallet/indy/wallet.rs +++ b/aries_vcx_core/src/wallet/indy/wallet.rs @@ -1,4 +1,3 @@ -use serde::{Deserialize, Serialize}; use vdrtools::{ types::{ domain::wallet::{default_key_derivation_method, KeyDerivationMethod}, @@ -10,12 +9,11 @@ use vdrtools::{ use crate::{ errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}, global::settings, - secret, utils, + utils, wallet::indy::{ did_mocks::{did_mocks_enabled, DidMocks}, IssuerConfig, RestoreWalletConfigs, WalletConfig, }, - SearchHandle, }; pub async fn open_wallet(wallet_config: &WalletConfig) -> VcxCoreResult { diff --git a/libvdrtools/src/controllers/anoncreds/prover.rs b/libvdrtools/src/controllers/anoncreds/prover.rs index de3ab83252..9c7537cc11 100644 --- a/libvdrtools/src/controllers/anoncreds/prover.rs +++ b/libvdrtools/src/controllers/anoncreds/prover.rs @@ -520,9 +520,6 @@ impl ProverController { /// If filter is NULL, then all credentials are returned. /// Credentials can be filtered by Issuer, credential_def and/or Schema. /// - /// NOTE: This method is deprecated because immediately returns all fetched credentials. - /// Use to fetch records by small batches. - /// /// #Params /// wallet_handle: wallet handle (created by open_wallet). /// filter_json: filter for credentials @@ -551,10 +548,6 @@ impl ProverController { /// Common* /// Wallet* #[no_mangle] - #[deprecated( - since = "1.6.1", - note = "Please use indy_prover_search_credentials instead!" - )] pub async fn get_credentials( &self, wallet_handle: WalletHandle,