From 72ad9262c2884cc503d6a056d1dc8d4023e7e68e Mon Sep 17 00:00:00 2001 From: Ondrej Prazak Date: Tue, 13 Feb 2024 10:21:12 +0100 Subject: [PATCH] address review comments Signed-off-by: Ondrej Prazak --- .../src/anoncreds/credx_anoncreds/mod.rs | 9 ++- .../src/wallet/agency_client_wallet.rs | 8 +-- .../src/wallet/base_wallet/migrate.rs | 2 +- .../src/wallet/base_wallet/mod.rs | 11 +--- .../src/wallet/base_wallet/record.rs | 20 ------- .../src/wallet/base_wallet/record_wallet.rs | 12 +++- .../src/wallet/indy/indy_record_wallet.rs | 40 ++++++++++++- aries/aries_vcx_core/src/wallet/indy/mod.rs | 56 +++++++------------ .../src/wallet/indy/restore_wallet_configs.rs | 4 +- .../src/wallet/indy/wallet_credentials.rs | 13 ----- .../aries_vcx_core/src/wallet/mock_wallet.rs | 8 +-- .../src/api_vcx/api_global/wallet.rs | 12 ++-- aries/wrappers/vcx-napi-rs/src/api/wallet.rs | 4 +- 13 files changed, 97 insertions(+), 102 deletions(-) delete mode 100644 aries/aries_vcx_core/src/wallet/indy/wallet_credentials.rs diff --git a/aries/aries_vcx_core/src/anoncreds/credx_anoncreds/mod.rs b/aries/aries_vcx_core/src/anoncreds/credx_anoncreds/mod.rs index af65c24bf1..d92e207d31 100644 --- a/aries/aries_vcx_core/src/anoncreds/credx_anoncreds/mod.rs +++ b/aries/aries_vcx_core/src/anoncreds/credx_anoncreds/mod.rs @@ -52,7 +52,10 @@ use crate::{ }, wallet::{ base_wallet::{ - record::Record, record_wallet::RecordWallet, search_filter::SearchFilter, BaseWallet, + record::{AllRecords, Record}, + record_wallet::RecordWallet, + search_filter::SearchFilter, + BaseWallet, }, record_tags::{RecordTag, RecordTags}, }, @@ -89,6 +92,10 @@ struct WalletAdapter(Arc); #[async_trait] impl RecordWallet for WalletAdapter { + async fn all_records(&self) -> VcxCoreResult> { + self.0.all_records().await + } + async fn add_record(&self, record: Record) -> VcxCoreResult<()> { self.0.add_record(record).await } diff --git a/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs b/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs index b86cbf44de..ecdd221d82 100644 --- a/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/agency_client_wallet.rs @@ -43,15 +43,15 @@ impl BaseWallet for AgencyClientWallet { "configure_issuer", )) } - - async fn all(&self) -> VcxCoreResult> { - Err(unimplemented_agency_client_wallet_method("get_all")) - } } #[allow(unused_variables)] #[async_trait] impl RecordWallet for AgencyClientWallet { + async fn all_records(&self) -> VcxCoreResult> { + Err(unimplemented_agency_client_wallet_method("get_all")) + } + async fn add_record(&self, record: Record) -> VcxCoreResult<()> { Err(unimplemented_agency_client_wallet_method("add_record")) } diff --git a/aries/aries_vcx_core/src/wallet/base_wallet/migrate.rs b/aries/aries_vcx_core/src/wallet/base_wallet/migrate.rs index 9036069a69..51a028f87c 100644 --- a/aries/aries_vcx_core/src/wallet/base_wallet/migrate.rs +++ b/aries/aries_vcx_core/src/wallet/base_wallet/migrate.rs @@ -20,7 +20,7 @@ pub async fn migrate_records( where E: std::fmt::Display, { - let mut records = src_wallet.all().await?; + let mut records = src_wallet.all_records().await?; let total = records.total_count(); info!("Migrating {total:?} records"); let mut num_record = 0; diff --git a/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs b/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs index 485dc60426..486bf9088b 100644 --- a/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs +++ b/aries/aries_vcx_core/src/wallet/base_wallet/mod.rs @@ -2,10 +2,7 @@ use std::sync::Arc; use async_trait::async_trait; -use self::{ - did_wallet::DidWallet, issuer_config::IssuerConfig, record::AllRecords, - record_wallet::RecordWallet, -}; +use self::{did_wallet::DidWallet, issuer_config::IssuerConfig, record_wallet::RecordWallet}; use crate::errors::error::VcxCoreResult; pub mod did_data; @@ -37,8 +34,6 @@ pub trait BaseWallet: RecordWallet + DidWallet + Send + Sync + std::fmt::Debug { async fn close_wallet(&self) -> VcxCoreResult<()>; async fn configure_issuer(&self, key_seed: &str) -> VcxCoreResult; - - async fn all(&self) -> VcxCoreResult>; } #[async_trait] @@ -54,10 +49,6 @@ impl BaseWallet for Arc { async fn configure_issuer(&self, key_seed: &str) -> VcxCoreResult { self.as_ref().configure_issuer(key_seed).await } - - async fn all(&self) -> VcxCoreResult> { - self.as_ref().all().await - } } #[cfg(test)] diff --git a/aries/aries_vcx_core/src/wallet/base_wallet/record.rs b/aries/aries_vcx_core/src/wallet/base_wallet/record.rs index 6fbaba0edf..2e465662c3 100644 --- a/aries/aries_vcx_core/src/wallet/base_wallet/record.rs +++ b/aries/aries_vcx_core/src/wallet/base_wallet/record.rs @@ -1,7 +1,5 @@ use async_trait::async_trait; use typed_builder::TypedBuilder; -#[cfg(feature = "vdrtools_wallet")] -use vdrtools::WalletRecord; use crate::{errors::error::VcxCoreResult, wallet::record_tags::RecordTags}; @@ -57,24 +55,6 @@ impl PartialRecord { pub fn tags(&self) -> &Option { &self.tags } - - #[cfg(feature = "vdrtools_wallet")] - pub fn from_wallet_record(wallet_record: WalletRecord) -> Self { - use crate::wallet::indy::indy_tags::IndyTags; - - let name = wallet_record.get_id().into(); - let category = wallet_record.get_type(); - let value = wallet_record.get_value(); - - let found_tags = wallet_record.get_tags(); - - Self::builder() - .name(name) - .category(category.map(Into::into)) - .value(value.map(Into::into)) - .tags(found_tags.map(|tags| IndyTags::new(tags.clone()).into_entry_tags())) - .build() - } } #[async_trait] diff --git a/aries/aries_vcx_core/src/wallet/base_wallet/record_wallet.rs b/aries/aries_vcx_core/src/wallet/base_wallet/record_wallet.rs index d1988e7c22..ccb7354242 100644 --- a/aries/aries_vcx_core/src/wallet/base_wallet/record_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/base_wallet/record_wallet.rs @@ -2,11 +2,17 @@ use std::sync::Arc; use async_trait::async_trait; -use super::{record::Record, search_filter::SearchFilter, BaseWallet}; +use super::{ + record::{AllRecords, Record}, + search_filter::SearchFilter, + BaseWallet, +}; use crate::{errors::error::VcxCoreResult, wallet::record_tags::RecordTags}; #[async_trait] pub trait RecordWallet { + async fn all_records(&self) -> VcxCoreResult>; + async fn add_record(&self, record: Record) -> VcxCoreResult<()>; async fn get_record(&self, category: &str, name: &str) -> VcxCoreResult; @@ -36,6 +42,10 @@ pub trait RecordWallet { #[async_trait] impl RecordWallet for Arc { + async fn all_records(&self) -> VcxCoreResult> { + self.as_ref().all_records().await + } + async fn add_record(&self, record: Record) -> VcxCoreResult<()> { self.as_ref().add_record(record).await } diff --git a/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs b/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs index ffc0153de0..48b5058346 100644 --- a/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs @@ -2,20 +2,56 @@ use async_trait::async_trait; use indy_api_types::domain::wallet::IndyRecord; use serde::Deserialize; use serde_json::Value; -use vdrtools::Locator; +use vdrtools::{indy_wallet::iterator::WalletIterator, Locator}; use super::{indy_tags::IndyTags, SEARCH_OPTIONS, WALLET_OPTIONS}; use crate::{ errors::error::{AriesVcxCoreError, VcxCoreResult}, wallet::{ - base_wallet::{record::Record, record_wallet::RecordWallet, search_filter::SearchFilter}, + base_wallet::{ + record::{AllRecords, PartialRecord, Record}, + record_wallet::RecordWallet, + search_filter::SearchFilter, + }, indy::IndySdkWallet, record_tags::RecordTags, }, }; +pub struct AllIndyRecords { + iterator: WalletIterator, +} + +impl AllIndyRecords { + pub fn new(iterator: WalletIterator) -> Self { + Self { iterator } + } +} + +#[async_trait] +impl AllRecords for AllIndyRecords { + fn total_count(&self) -> VcxCoreResult> { + Ok(self.iterator.get_total_count()?) + } + + async fn next(&mut self) -> VcxCoreResult> { + let item = self.iterator.next().await?; + + Ok(item.map(PartialRecord::from_wallet_record)) + } +} + #[async_trait] impl RecordWallet for IndySdkWallet { + async fn all_records(&self) -> VcxCoreResult> { + let all = Locator::instance() + .wallet_controller + .get_all(self.get_wallet_handle()) + .await?; + + Ok(Box::new(AllIndyRecords::new(all))) + } + async fn add_record(&self, record: Record) -> VcxCoreResult<()> { let tags_map = if record.tags().is_empty() { None diff --git a/aries/aries_vcx_core/src/wallet/indy/mod.rs b/aries/aries_vcx_core/src/wallet/indy/mod.rs index cb3dcd830f..579b3bd553 100644 --- a/aries/aries_vcx_core/src/wallet/indy/mod.rs +++ b/aries/aries_vcx_core/src/wallet/indy/mod.rs @@ -1,24 +1,40 @@ use async_trait::async_trait; use indy_api_types::domain::wallet::{default_key_derivation_method, IndyRecord}; -use vdrtools::{indy_wallet::iterator::WalletIterator, Locator}; +use vdrtools::{Locator, WalletRecord}; use self::indy_tags::IndyTags; use super::base_wallet::{ did_wallet::DidWallet, issuer_config::IssuerConfig, - record::{AllRecords, PartialRecord, Record}, + record::{PartialRecord, Record}, BaseWallet, }; use crate::{errors::error::VcxCoreResult, WalletHandle}; mod indy_did_wallet; mod indy_record_wallet; -pub(crate) mod indy_tags; +mod indy_tags; mod indy_utils; pub mod indy_wallet_record; pub mod restore_wallet_configs; pub mod wallet_config; -pub mod wallet_credentials; + +impl PartialRecord { + pub fn from_wallet_record(wallet_record: WalletRecord) -> Self { + let name = wallet_record.get_id().into(); + let category = wallet_record.get_type(); + let value = wallet_record.get_value(); + + let found_tags = wallet_record.get_tags(); + + Self::builder() + .name(name) + .category(category.map(Into::into)) + .value(value.map(Into::into)) + .tags(found_tags.map(|tags| IndyTags::new(tags.clone()).into_entry_tags())) + .build() + } +} impl From for Record { fn from(ir: IndyRecord) -> Self { @@ -97,38 +113,6 @@ impl BaseWallet for IndySdkWallet { institution_did: did_data.did().to_string(), }) } - - async fn all(&self) -> VcxCoreResult> { - let all = Locator::instance() - .wallet_controller - .get_all(self.get_wallet_handle()) - .await?; - - Ok(Box::new(AllIndyRecords::new(all))) - } -} - -pub struct AllIndyRecords { - iterator: WalletIterator, -} - -impl AllIndyRecords { - pub fn new(iterator: WalletIterator) -> Self { - Self { iterator } - } -} - -#[async_trait] -impl AllRecords for AllIndyRecords { - fn total_count(&self) -> VcxCoreResult> { - Ok(self.iterator.get_total_count()?) - } - - async fn next(&mut self) -> VcxCoreResult> { - let item = self.iterator.next().await?; - - Ok(item.map(PartialRecord::from_wallet_record)) - } } #[cfg(test)] diff --git a/aries/aries_vcx_core/src/wallet/indy/restore_wallet_configs.rs b/aries/aries_vcx_core/src/wallet/indy/restore_wallet_configs.rs index 01e5d2808b..f417300837 100644 --- a/aries/aries_vcx_core/src/wallet/indy/restore_wallet_configs.rs +++ b/aries/aries_vcx_core/src/wallet/indy/restore_wallet_configs.rs @@ -6,7 +6,7 @@ use super::indy_utils::parse_key_derivation_method; use crate::{errors::error::VcxCoreResult, wallet::base_wallet::ImportWallet}; #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RestoreWalletConfigs { +pub struct ImportWalletConfigs { pub wallet_name: String, pub wallet_key: String, pub exported_wallet_path: String, @@ -16,7 +16,7 @@ pub struct RestoreWalletConfigs { } #[async_trait] -impl ImportWallet for RestoreWalletConfigs { +impl ImportWallet for ImportWalletConfigs { async fn import_wallet(&self) -> VcxCoreResult<()> { Locator::instance() .wallet_controller diff --git a/aries/aries_vcx_core/src/wallet/indy/wallet_credentials.rs b/aries/aries_vcx_core/src/wallet/indy/wallet_credentials.rs deleted file mode 100644 index a634ac6eda..0000000000 --- a/aries/aries_vcx_core/src/wallet/indy/wallet_credentials.rs +++ /dev/null @@ -1,13 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Serialize, Deserialize)] -struct WalletCredentials { - key: String, - #[serde(skip_serializing_if = "Option::is_none")] - rekey: Option, - #[serde(skip_serializing_if = "Option::is_none")] - storage_credentials: Option, - key_derivation_method: String, - #[serde(skip_serializing_if = "Option::is_none")] - rekey_derivation_method: Option, -} diff --git a/aries/aries_vcx_core/src/wallet/mock_wallet.rs b/aries/aries_vcx_core/src/wallet/mock_wallet.rs index fba61dbb5a..69d1275c3a 100644 --- a/aries/aries_vcx_core/src/wallet/mock_wallet.rs +++ b/aries/aries_vcx_core/src/wallet/mock_wallet.rs @@ -49,15 +49,15 @@ impl BaseWallet for MockWallet { async fn configure_issuer(&self, key_seed: &str) -> VcxCoreResult { Ok(IssuerConfig::builder().build()) } - - async fn all(&self) -> VcxCoreResult> { - Ok(Box::new(MockAllRecords {})) - } } #[async_trait] #[allow(unused_variables)] impl RecordWallet for MockWallet { + async fn all_records(&self) -> VcxCoreResult> { + Ok(Box::new(MockAllRecords {})) + } + async fn add_record(&self, record: Record) -> VcxCoreResult<()> { Ok(()) } diff --git a/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs b/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs index 0cb5426801..15246f5bfa 100644 --- a/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs +++ b/aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs @@ -17,7 +17,7 @@ use aries_vcx_core::{ ManageWallet, }, indy::{ - indy_wallet_record::IndyWalletRecord, restore_wallet_configs::RestoreWalletConfigs, + indy_wallet_record::IndyWalletRecord, restore_wallet_configs::ImportWalletConfigs, wallet_config::WalletConfig, }, record_tags::RecordTags, @@ -288,7 +288,7 @@ pub async fn wallet_search_records(xtype: &str, query_json: &str) -> LibvcxResul map_ariesvcx_core_result(res) } -pub async fn wallet_import(config: &RestoreWalletConfigs) -> LibvcxResult<()> { +pub async fn wallet_import(config: &ImportWalletConfigs) -> LibvcxResult<()> { map_ariesvcx_core_result(config.import_wallet().await) } @@ -395,7 +395,7 @@ pub mod test_utils { #[cfg(test)] mod tests { use aries_vcx::{ - aries_vcx_core::wallet::indy::restore_wallet_configs::RestoreWalletConfigs, + aries_vcx_core::wallet::indy::restore_wallet_configs::ImportWalletConfigs, global::settings::{DEFAULT_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW}, }; use aries_vcx_core::wallet::{ @@ -584,7 +584,7 @@ mod tests { .unwrap(); close_main_wallet().await.unwrap(); wallet_config.delete_wallet().await.unwrap(); - let import_config: RestoreWalletConfigs = serde_json::from_value(json!({ + let import_config: ImportWalletConfigs = serde_json::from_value(json!({ "wallet_name": wallet_config.wallet_name.clone(), "wallet_key": wallet_config.wallet_key.clone(), "exported_wallet_path": export_file.path, @@ -649,7 +649,7 @@ mod tests { wallet_config.delete_wallet().await.unwrap(); - let import_config = RestoreWalletConfigs { + let import_config = ImportWalletConfigs { wallet_name: wallet_name.clone(), wallet_key: DEFAULT_WALLET_KEY.into(), exported_wallet_path: export_wallet_path.path.clone(), @@ -677,7 +677,7 @@ mod tests { open_as_main_wallet(&wallet_config).await.unwrap(); - let import_config = RestoreWalletConfigs { + let import_config = ImportWalletConfigs { wallet_name, wallet_key: DEFAULT_WALLET_KEY.into(), exported_wallet_path: export_wallet_path.path.clone(), diff --git a/aries/wrappers/vcx-napi-rs/src/api/wallet.rs b/aries/wrappers/vcx-napi-rs/src/api/wallet.rs index 858a937cda..9665ae5f34 100644 --- a/aries/wrappers/vcx-napi-rs/src/api/wallet.rs +++ b/aries/wrappers/vcx-napi-rs/src/api/wallet.rs @@ -4,7 +4,7 @@ use libvcx_core::{ api_vcx::api_global::{ledger, wallet}, aries_vcx::aries_vcx_core::wallet::{ base_wallet::{BaseWallet, ManageWallet}, - indy::{restore_wallet_configs::RestoreWalletConfigs, wallet_config::WalletConfig}, + indy::{restore_wallet_configs::ImportWalletConfigs, wallet_config::WalletConfig}, }, errors::error::{LibvcxError, LibvcxErrorKind}, serde_json::{self, json}, @@ -88,7 +88,7 @@ pub async fn create_and_store_did(seed: Option) -> napi::Result #[napi] pub async fn wallet_import(config: String) -> napi::Result<()> { - let config = serde_json::from_str::(&config) + let config = serde_json::from_str::(&config) .map_err(|err| { LibvcxError::from_msg( LibvcxErrorKind::InvalidConfiguration,