Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Prazak <[email protected]>
  • Loading branch information
Ondrej Prazak committed Jan 26, 2024
1 parent 8774af6 commit 6c138c9
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 192 deletions.
6 changes: 3 additions & 3 deletions aries/aries_vcx_core/src/anoncreds/credx_anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use crate::{
json::{AsTypeOrDeserializationError, TryGetIndex},
},
wallet::{
base_wallet::{BaseWallet, Record, RecordWallet, SearchFilter},
base_wallet::{record::Record, search_filter::SearchFilter, BaseWallet, RecordWallet},
entry_tag::EntryTags,
indy::IndyTags,
indy::indy_tag::IndyTags,
},
};

Expand Down Expand Up @@ -1035,7 +1035,7 @@ impl BaseAnonCreds for IndyCredxAnonCreds {
.name(credential_id.clone())
.category(CATEGORY_CREDENTIAL.into())
.value(record_value)
.tags(IndyTags::new(tags_map).to_entry_tags())
.tags(IndyTags::new(tags_map).into_entry_tags())
.build();

wallet.add_record(record).await?;
Expand Down
9 changes: 6 additions & 3 deletions aries/aries_vcx_core/src/wallet/agency_client_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use async_trait::async_trait;
use public_key::{Key, KeyType};

use super::{
base_wallet::{BaseWallet, DidData, DidWallet, Record, RecordWallet, SearchFilter},
base_wallet::{
did_data::DidData, record::Record, search_filter::SearchFilter, BaseWallet, DidWallet,
RecordWallet,
},
structs_io::UnpackMessageOutput,
};
use crate::{
Expand Down Expand Up @@ -78,12 +81,12 @@ impl DidWallet for AgencyClientWallet {
method_name: Option<&str>,
) -> VcxCoreResult<DidData> {
Err(unimplemented_agency_client_wallet_method(
"create_nad_store_my_did",
"create_and_store_my_did",
))
}

async fn key_for_did(&self, name: &str) -> VcxCoreResult<Key> {
Err(unimplemented_agency_client_wallet_method("did_key"))
Err(unimplemented_agency_client_wallet_method("key_for_did"))
}

async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult<Key> {
Expand Down
25 changes: 25 additions & 0 deletions aries/aries_vcx_core/src/wallet/base_wallet/did_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use public_key::Key;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
pub struct DidData {
did: String,
verkey: Key,
}

impl DidData {
pub fn new(did: &str, verkey: Key) -> Self {
Self {
did: did.into(),
verkey,
}
}

pub fn did(&self) -> &str {
&self.did
}

pub fn verkey(&self) -> &Key {
&self.verkey
}
}
Original file line number Diff line number Diff line change
@@ -1,90 +1,18 @@
use async_trait::async_trait;
#[cfg(feature = "vdrtools_wallet")]
use indy_api_types::domain::wallet::IndyRecord;
use public_key::Key;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use super::{entry_tag::EntryTags, indy::IndyTags};
use crate::{errors::error::VcxCoreResult, wallet::structs_io::UnpackMessageOutput};

#[derive(Debug, Default, Clone, TypedBuilder)]
pub struct Record {
category: String,
name: String,
value: String,
#[builder(default)]
tags: EntryTags,
}

impl Record {
pub fn value(&self) -> &str {
&self.value
}

pub fn name(&self) -> &str {
&self.name
}
use super::entry_tag::EntryTags;
use crate::{
errors::error::VcxCoreResult,
wallet::{
base_wallet::{did_data::DidData, record::Record, search_filter::SearchFilter},
structs_io::UnpackMessageOutput,
},
};

pub fn category(&self) -> &str {
&self.category
}

pub fn tags(&self) -> &EntryTags {
&self.tags
}
}

#[cfg(feature = "vdrtools_wallet")]
impl From<IndyRecord> for Record {
fn from(ir: IndyRecord) -> Self {
Self {
name: ir.id,
category: ir.type_,
value: ir.value,
tags: IndyTags::new(ir.tags).to_entry_tags(),
}
}
}

#[cfg(feature = "vdrtools_wallet")]
impl From<Record> for IndyRecord {
fn from(record: Record) -> Self {
Self {
id: record.name,
type_: record.category,
value: record.value,
tags: IndyTags::from_entry_tags(record.tags).to_inner(),
}
}
}

#[derive(Debug, Deserialize, Serialize)]
pub struct DidData {
did: String,
verkey: Key,
}

impl DidData {
pub fn new(did: &str, verkey: Key) -> Self {
Self {
did: did.into(),
verkey,
}
}

pub fn did(&self) -> &str {
&self.did
}

pub fn verkey(&self) -> &Key {
&self.verkey
}
}

pub enum SearchFilter {
JsonFilter(String),
}
pub mod did_data;
pub mod record;
pub mod search_filter;

pub trait BaseWallet: RecordWallet + DidWallet + Send + Sync + std::fmt::Debug {}

Expand Down Expand Up @@ -201,9 +129,9 @@ mod tests {
.unwrap();

let msg = "sign this".as_bytes();
let sig = wallet.sign(&did_data.verkey, msg).await.unwrap();
let sig = wallet.sign(did_data.verkey(), msg).await.unwrap();

let res = wallet.verify(&did_data.verkey, msg, &sig).await.unwrap();
let res = wallet.verify(did_data.verkey(), msg, &sig).await.unwrap();
assert!(res);
}

Expand All @@ -216,18 +144,18 @@ mod tests {
.await
.unwrap();

let key = wallet.key_for_did(&did_data.did).await.unwrap();
let key = wallet.key_for_did(did_data.did()).await.unwrap();

assert_eq!(did_data.verkey, key);
assert_eq!(did_data.verkey(), &key);

let res = wallet
.replace_did_key_start(&did_data.did, Some(&random_seed()))
.replace_did_key_start(did_data.did(), Some(&random_seed()))
.await
.unwrap();

wallet.replace_did_key_apply(&did_data.did).await.unwrap();
wallet.replace_did_key_apply(did_data.did()).await.unwrap();

let new_key = wallet.key_for_did(&did_data.did).await.unwrap();
let new_key = wallet.key_for_did(did_data.did()).await.unwrap();
assert_eq!(res, new_key);
}

Expand All @@ -243,8 +171,8 @@ mod tests {

let packed = wallet
.pack_message(
Some(sender_data.verkey),
vec![receiver_data.verkey],
Some(sender_data.verkey().clone()),
vec![receiver_data.verkey().clone()],
msg.as_bytes(),
)
.await
Expand Down Expand Up @@ -279,7 +207,7 @@ mod tests {

let res = wallet.get_record(category, name).await.unwrap();

assert_eq!(value, res.value);
assert_eq!(value, res.value());
}

#[tokio::test]
Expand All @@ -300,7 +228,7 @@ mod tests {

let res = wallet.get_record(category, name).await.unwrap();

assert_eq!(value, res.value);
assert_eq!(value, res.value());

wallet.delete_record(category, name).await.unwrap();

Expand Down Expand Up @@ -374,8 +302,8 @@ mod tests {
.unwrap();

let res = wallet.get_record(category, name).await.unwrap();
assert_eq!(value2, res.value);
assert_eq!(tags2, res.tags);
assert_eq!(value2, res.value());
assert_eq!(&tags2, res.tags());
}

#[tokio::test]
Expand All @@ -402,8 +330,8 @@ mod tests {
.unwrap();

let res = wallet.get_record(category, name).await.unwrap();
assert_eq!(value2, res.value);
assert_eq!(tags, res.tags);
assert_eq!(value2, res.value());
assert_eq!(&tags, res.tags());
}

#[tokio::test]
Expand All @@ -430,7 +358,7 @@ mod tests {
.unwrap();

let res = wallet.get_record(category, name).await.unwrap();
assert_eq!(value, res.value);
assert_eq!(tags2, res.tags);
assert_eq!(value, res.value());
assert_eq!(&tags2, res.tags());
}
}
30 changes: 30 additions & 0 deletions aries/aries_vcx_core/src/wallet/base_wallet/record.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use typed_builder::TypedBuilder;

use crate::wallet::entry_tag::EntryTags;

#[derive(Debug, Default, Clone, TypedBuilder)]
pub struct Record {
category: String,
name: String,
value: String,
#[builder(default)]
tags: EntryTags,
}

impl Record {
pub fn value(&self) -> &str {
&self.value
}

pub fn name(&self) -> &str {
&self.name
}

pub fn category(&self) -> &str {
&self.category
}

pub fn tags(&self) -> &EntryTags {
&self.tags
}
}
3 changes: 3 additions & 0 deletions aries/aries_vcx_core/src/wallet/base_wallet/search_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub enum SearchFilter {
JsonFilter(String),
}
2 changes: 1 addition & 1 deletion aries/aries_vcx_core/src/wallet/indy/indy_did_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use vdrtools::{DidMethod, DidValue, KeyInfo, Locator, MyDidInfo};
use crate::{
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult},
wallet::{
base_wallet::{DidData, DidWallet},
base_wallet::{did_data::DidData, DidWallet},
indy::IndySdkWallet,
structs_io::UnpackMessageOutput,
},
Expand Down
8 changes: 4 additions & 4 deletions aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use serde::Deserialize;
use serde_json::Value;
use vdrtools::Locator;

use super::{IndyTags, SEARCH_OPTIONS, WALLET_OPTIONS};
use super::{indy_tag::IndyTags, SEARCH_OPTIONS, WALLET_OPTIONS};
use crate::{
errors::error::{AriesVcxCoreError, VcxCoreResult},
wallet::{
base_wallet::{Record, RecordWallet, SearchFilter},
base_wallet::{record::Record, search_filter::SearchFilter, RecordWallet},
entry_tag::EntryTags,
indy::IndySdkWallet,
},
Expand All @@ -20,7 +20,7 @@ impl RecordWallet for IndySdkWallet {
let tags_map = if record.tags().is_empty() {
None
} else {
Some(IndyTags::from_entry_tags(record.tags().clone()).to_inner())
Some(IndyTags::from_entry_tags(record.tags().clone()).into_inner())
};

Ok(Locator::instance()
Expand Down Expand Up @@ -63,7 +63,7 @@ impl RecordWallet for IndySdkWallet {
self.wallet_handle,
category.into(),
name.into(),
IndyTags::from_entry_tags(new_tags).to_inner(),
IndyTags::from_entry_tags(new_tags).into_inner(),
)
.await?)
}
Expand Down
Loading

0 comments on commit 6c138c9

Please sign in to comment.