diff --git a/Cargo.lock b/Cargo.lock index c87730dd1a..ce132ed414 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,6 +406,7 @@ dependencies = [ "libvdrtools", "log", "lru", + "public_key", "rand 0.8.5", "serde", "serde_json", diff --git a/aries/aries_vcx/src/errors/error.rs b/aries/aries_vcx/src/errors/error.rs index e0203f8171..d03927827c 100644 --- a/aries/aries_vcx/src/errors/error.rs +++ b/aries/aries_vcx/src/errors/error.rs @@ -151,7 +151,7 @@ pub enum AriesVcxErrorKind { ParsingError, #[error("Unexpected wallet error")] - WalletUnexpected, + WalletError, // A2A #[error("Invalid HTTP response.")] diff --git a/aries/aries_vcx/src/errors/mapping_others.rs b/aries/aries_vcx/src/errors/mapping_others.rs index 83c7a9bea8..65de411630 100644 --- a/aries/aries_vcx/src/errors/mapping_others.rs +++ b/aries/aries_vcx/src/errors/mapping_others.rs @@ -151,7 +151,7 @@ impl From for AriesVcxError { AriesVcxErrorKind::DuplicationMasterSecret } AriesVcxCoreErrorKind::DuplicationDid => AriesVcxErrorKind::DuplicationDid, - AriesVcxCoreErrorKind::WalletUnexpected => AriesVcxErrorKind::WalletUnexpected, + AriesVcxCoreErrorKind::WalletError => AriesVcxErrorKind::WalletError, AriesVcxCoreErrorKind::LoggingError => AriesVcxErrorKind::LoggingError, AriesVcxCoreErrorKind::EncodeError => AriesVcxErrorKind::EncodeError, AriesVcxCoreErrorKind::UnknownError => AriesVcxErrorKind::UnknownError, diff --git a/aries/aries_vcx_core/Cargo.toml b/aries/aries_vcx_core/Cargo.toml index 2130f3e441..102a983fc3 100644 --- a/aries/aries_vcx_core/Cargo.toml +++ b/aries/aries_vcx_core/Cargo.toml @@ -33,6 +33,7 @@ tokio = { version = "1.20" } indy-vdr-proxy-client = { git = "https://github.com/hyperledger/indy-vdr.git", rev = "c143268", optional = true } indy-ledger-response-parser = { path = "../misc/indy_ledger_response_parser" } lru = { version = "0.12.0" } +public_key = { path = "../../did_core/public_key"} [dev-dependencies] tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] } diff --git a/aries/aries_vcx_core/src/errors/error.rs b/aries/aries_vcx_core/src/errors/error.rs index 9a3e729c63..60e6c2969a 100644 --- a/aries/aries_vcx_core/src/errors/error.rs +++ b/aries/aries_vcx_core/src/errors/error.rs @@ -125,7 +125,7 @@ pub enum AriesVcxCoreErrorKind { DuplicationDid, #[error("Unexpected wallet error")] - WalletUnexpected, + WalletError, // Logger #[error("Logging Error")] diff --git a/aries/aries_vcx_core/src/wallet2/entry_tag.rs b/aries/aries_vcx_core/src/wallet2/entry_tag.rs index 93496f7089..9cc3974b52 100644 --- a/aries/aries_vcx_core/src/wallet2/entry_tag.rs +++ b/aries/aries_vcx_core/src/wallet2/entry_tag.rs @@ -35,10 +35,6 @@ pub struct EntryTags { } impl EntryTags { - pub fn from_vec(inner: Vec) -> Self { - Self { inner } - } - pub fn add(&mut self, tag: EntryTag) { self.inner.push(tag) } @@ -48,31 +44,13 @@ impl EntryTags { } } -pub struct EntryTagsIntoIterator { - entry_tags: Vec, -} - -impl Iterator for EntryTagsIntoIterator { - type Item = EntryTag; - - fn next(&mut self) -> Option { - if self.entry_tags.is_empty() { - return None; - } - let res = self.entry_tags.remove(0); - Some(res) - } -} - impl IntoIterator for EntryTags { type Item = EntryTag; - type IntoIter = EntryTagsIntoIterator; + type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { - Self::IntoIter { - entry_tags: self.into(), - } + self.inner.into_iter() } } diff --git a/aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs b/aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs index 0e0589386d..aa73168fdf 100644 --- a/aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs +++ b/aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +use public_key::KeyType; use vdrtools::{DidMethod, DidValue, KeyInfo, Locator, MyDidInfo}; use crate::{ @@ -28,29 +29,36 @@ impl DidWallet for IndySdkWallet { Ok(DidData { did: res.0, - verkey: res.1, + verkey: Key::from_base58(&res.1, KeyType::Ed25519).map_err(|err| { + AriesVcxCoreError::from_msg(AriesVcxCoreErrorKind::WalletError, err) + })?, }) } - async fn did_key(&self, did: &str) -> VcxCoreResult { - Locator::instance() + async fn did_key(&self, did: &str) -> VcxCoreResult { + let res = Locator::instance() .did_controller .key_for_local_did(self.wallet_handle, DidValue(did.into())) - .await - .map_err(From::from) + .await?; + + Key::from_base58(&res, KeyType::Ed25519) + .map_err(|err| AriesVcxCoreError::from_msg(AriesVcxCoreErrorKind::WalletError, err)) } - async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult { + async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult { let key_info = KeyInfo { seed: seed.map(Into::into), ..Default::default() }; - let key = Locator::instance() + let key_string = Locator::instance() .did_controller .replace_keys_start(self.wallet_handle, key_info, DidValue(did.into())) .await?; + let key = Key::from_base58(&key_string, KeyType::Ed25519) + .map_err(|err| AriesVcxCoreError::from_msg(AriesVcxCoreErrorKind::WalletError, err))?; + Ok(key) } @@ -61,36 +69,38 @@ impl DidWallet for IndySdkWallet { .await?) } - async fn sign(&self, key: &str, msg: &[u8]) -> VcxCoreResult> { + async fn sign(&self, key: &Key, msg: &[u8]) -> VcxCoreResult> { Locator::instance() .crypto_controller - .crypto_sign(self.wallet_handle, key, msg) + .crypto_sign(self.wallet_handle, &key.base58(), msg) .await .map_err(From::from) } - async fn verify(&self, key: &str, msg: &[u8], signature: &[u8]) -> VcxCoreResult { + async fn verify(&self, key: &Key, msg: &[u8], signature: &[u8]) -> VcxCoreResult { Locator::instance() .crypto_controller - .crypto_verify(key, msg, signature) + .crypto_verify(&key.base58(), msg, signature) .await .map_err(From::from) } async fn pack_message( &self, - sender_vk: Option, + sender_vk: Option, receiver_keys: Vec, msg: &[u8], ) -> VcxCoreResult> { - let receiver_keys_str = receiver_keys - .into_iter() - .map(|key| key.pubkey_bs58) - .collect(); + let receiver_keys_str = receiver_keys.into_iter().map(|key| key.base58()).collect(); Ok(Locator::instance() .crypto_controller - .pack_msg(msg.into(), receiver_keys_str, sender_vk, self.wallet_handle) + .pack_msg( + msg.into(), + receiver_keys_str, + sender_vk.map(|key| key.base58()), + self.wallet_handle, + ) .await?) } diff --git a/aries/aries_vcx_core/src/wallet2/mod.rs b/aries/aries_vcx_core/src/wallet2/mod.rs index c6e21b1575..11fe9c886d 100644 --- a/aries/aries_vcx_core/src/wallet2/mod.rs +++ b/aries/aries_vcx_core/src/wallet2/mod.rs @@ -2,6 +2,7 @@ use async_trait::async_trait; use derive_builder::Builder; #[cfg(feature = "vdrtools_wallet")] use indy_api_types::domain::wallet::Record as IndyRecord; +use public_key::Key; use serde::{Deserialize, Serialize}; use self::entry_tag::EntryTags; @@ -13,17 +14,12 @@ pub mod indy_wallet; pub mod entry_tag; pub mod utils; -pub struct Key { - pub pubkey_bs58: String, -} - #[derive(Debug, Default, Clone, Builder)] pub struct Record { - pub category: String, - pub name: String, - pub value: String, - #[builder(default = "EntryTags::default()")] - pub tags: EntryTags, + category: String, + name: String, + value: String, + tags: EntryTags, } #[cfg(feature = "vdrtools_wallet")] @@ -41,7 +37,7 @@ impl From for Record { #[derive(Debug, Deserialize, Serialize)] pub struct DidData { did: String, - verkey: String, + verkey: Key, } pub enum SearchFilter { @@ -59,19 +55,19 @@ pub trait DidWallet { method_name: Option<&str>, ) -> VcxCoreResult; - async fn did_key(&self, name: &str) -> VcxCoreResult; + async fn did_key(&self, name: &str) -> VcxCoreResult; - async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult; + async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult; async fn replace_did_key_apply(&self, did: &str) -> VcxCoreResult<()>; - async fn sign(&self, key: &str, msg: &[u8]) -> VcxCoreResult>; + async fn sign(&self, key: &Key, msg: &[u8]) -> VcxCoreResult>; - async fn verify(&self, key: &str, msg: &[u8], signature: &[u8]) -> VcxCoreResult; + async fn verify(&self, key: &Key, msg: &[u8], signature: &[u8]) -> VcxCoreResult; async fn pack_message( &self, - sender_vk: Option, + sender_vk: Option, receiver_keys: Vec, msg: &[u8], ) -> VcxCoreResult>; @@ -117,7 +113,7 @@ mod tests { wallet2::{ entry_tag::{EntryTag, EntryTags}, utils::random_seed, - DidWallet, Key, RecordBuilder, RecordWallet, + DidWallet, RecordBuilder, RecordWallet, }, }; @@ -193,13 +189,14 @@ mod tests { let receiver_data = wallet.create_and_store_my_did(None, None).await.unwrap(); - let receiver_key = Key { - pubkey_bs58: receiver_data.verkey, - }; let msg = "pack me"; let packed = wallet - .pack_message(Some(sender_data.verkey), vec![receiver_key], msg.as_bytes()) + .pack_message( + Some(sender_data.verkey), + vec![receiver_data.verkey], + msg.as_bytes(), + ) .await .unwrap(); @@ -307,7 +304,7 @@ mod tests { let category = "my"; let value1 = "xxx"; let value2 = "yyy"; - let tags1 = EntryTags::from_vec(vec![EntryTag::Plaintext("a".into(), "b".into())]); + let tags1: EntryTags = vec![EntryTag::Plaintext("a".into(), "b".into())].into(); let tags2 = EntryTags::default(); let record = RecordBuilder::default() @@ -341,7 +338,7 @@ mod tests { let category = "my"; let value1 = "xxx"; let value2 = "yyy"; - let tags = EntryTags::from_vec(vec![EntryTag::Plaintext("a".into(), "b".into())]); + let tags: EntryTags = vec![EntryTag::Plaintext("a".into(), "b".into())].into(); let record = RecordBuilder::default() .name(name.into()) @@ -369,8 +366,8 @@ mod tests { let name = "foo"; let category = "my"; let value = "xxx"; - let tags1 = EntryTags::from_vec(vec![EntryTag::Plaintext("a".into(), "b".into())]); - let tags2 = EntryTags::from_vec(vec![EntryTag::Plaintext("c".into(), "d".into())]); + let tags1: EntryTags = vec![EntryTag::Plaintext("a".into(), "b".into())].into(); + let tags2: EntryTags = vec![EntryTag::Plaintext("c".into(), "d".into())].into(); let record = RecordBuilder::default() .name(name.into()) diff --git a/aries/misc/legacy/libvcx_core/src/errors/error.rs b/aries/misc/legacy/libvcx_core/src/errors/error.rs index 8058d03187..63758e066b 100644 --- a/aries/misc/legacy/libvcx_core/src/errors/error.rs +++ b/aries/misc/legacy/libvcx_core/src/errors/error.rs @@ -161,7 +161,7 @@ pub enum LibvcxErrorKind { DuplicationDid, #[error("Unexpected wallet error")] - WalletUnexpected, + WalletError, // Logger #[error("Logging Error")] diff --git a/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcx.rs b/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcx.rs index 70e70fd41b..84a2fd7482 100644 --- a/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcx.rs +++ b/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcx.rs @@ -73,7 +73,7 @@ impl From for LibvcxErrorKind { AriesVcxErrorKind::WalletAlreadyOpen => LibvcxErrorKind::WalletAlreadyOpen, AriesVcxErrorKind::DuplicationMasterSecret => LibvcxErrorKind::DuplicationMasterSecret, AriesVcxErrorKind::DuplicationDid => LibvcxErrorKind::DuplicationDid, - AriesVcxErrorKind::WalletUnexpected => LibvcxErrorKind::WalletUnexpected, + AriesVcxErrorKind::WalletError => LibvcxErrorKind::WalletError, AriesVcxErrorKind::LoggingError => LibvcxErrorKind::LoggingError, AriesVcxErrorKind::EncodeError => LibvcxErrorKind::EncodeError, AriesVcxErrorKind::UnknownError => LibvcxErrorKind::UnknownError, diff --git a/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcxcore.rs b/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcxcore.rs index 71dfc66af3..41b696f9b8 100644 --- a/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcxcore.rs +++ b/aries/misc/legacy/libvcx_core/src/errors/mapping_from_ariesvcxcore.rs @@ -85,7 +85,7 @@ impl From for LibvcxErrorKind { LibvcxErrorKind::DuplicationMasterSecret } AriesVcxCoreErrorKind::DuplicationDid => LibvcxErrorKind::DuplicationDid, - AriesVcxCoreErrorKind::WalletUnexpected => LibvcxErrorKind::WalletUnexpected, + AriesVcxCoreErrorKind::WalletError => LibvcxErrorKind::WalletError, AriesVcxCoreErrorKind::LoggingError => LibvcxErrorKind::LoggingError, AriesVcxCoreErrorKind::EncodeError => LibvcxErrorKind::EncodeError, AriesVcxCoreErrorKind::UnknownError => LibvcxErrorKind::UnknownError, diff --git a/aries/misc/test_utils/src/devsetup.rs b/aries/misc/test_utils/src/devsetup.rs index 03a40b5278..27decd4efc 100644 --- a/aries/misc/test_utils/src/devsetup.rs +++ b/aries/misc/test_utils/src/devsetup.rs @@ -32,12 +32,7 @@ use aries_vcx_core::{ request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter}, response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig}, }, - wallet::{ - base_wallet::BaseWallet, - indy::{IndySdkWallet, WalletConfigBuilder}, - mock_wallet::MockWallet, - }, - wallet2::BaseWallet2, + wallet::{base_wallet::BaseWallet, mock_wallet::MockWallet}, PoolConfig, ResponseParser, }; #[cfg(feature = "vdr_proxy_ledger")] @@ -54,7 +49,6 @@ use chrono::{DateTime, Duration, Utc}; use lazy_static::lazy_static; use libvcx_logger::init_test_logging; use log::{debug, info, warn}; -use serde_json::json; use crate::{ constants::{INSTITUTION_DID, POOL1_TXN, TRUSTEE_SEED},