Skip to content

Commit

Permalink
address comments, use key from did_core
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 8, 2024
1 parent 91c0004 commit 8cccc79
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 78 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aries/aries_vcx/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub enum AriesVcxErrorKind {
ParsingError,

#[error("Unexpected wallet error")]
WalletUnexpected,
WalletError,

// A2A
#[error("Invalid HTTP response.")]
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/errors/mapping_others.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl From<AriesVcxCoreError> 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,
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion aries/aries_vcx_core/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub enum AriesVcxCoreErrorKind {
DuplicationDid,

#[error("Unexpected wallet error")]
WalletUnexpected,
WalletError,

// Logger
#[error("Logging Error")]
Expand Down
26 changes: 2 additions & 24 deletions aries/aries_vcx_core/src/wallet2/entry_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ pub struct EntryTags {
}

impl EntryTags {
pub fn from_vec(inner: Vec<EntryTag>) -> Self {
Self { inner }
}

pub fn add(&mut self, tag: EntryTag) {
self.inner.push(tag)
}
Expand All @@ -48,31 +44,13 @@ impl EntryTags {
}
}

pub struct EntryTagsIntoIterator {
entry_tags: Vec<EntryTag>,
}

impl Iterator for EntryTagsIntoIterator {
type Item = EntryTag;

fn next(&mut self) -> Option<Self::Item> {
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<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
Self::IntoIter {
entry_tags: self.into(),
}
self.inner.into_iter()
}
}

Expand Down
44 changes: 27 additions & 17 deletions aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use public_key::KeyType;
use vdrtools::{DidMethod, DidValue, KeyInfo, Locator, MyDidInfo};

use crate::{
Expand Down Expand Up @@ -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<String> {
Locator::instance()
async fn did_key(&self, did: &str) -> VcxCoreResult<Key> {
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<String> {
async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult<Key> {
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)
}

Expand All @@ -61,36 +69,38 @@ impl DidWallet for IndySdkWallet {
.await?)
}

async fn sign(&self, key: &str, msg: &[u8]) -> VcxCoreResult<Vec<u8>> {
async fn sign(&self, key: &Key, msg: &[u8]) -> VcxCoreResult<Vec<u8>> {
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<bool> {
async fn verify(&self, key: &Key, msg: &[u8], signature: &[u8]) -> VcxCoreResult<bool> {
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<String>,
sender_vk: Option<Key>,
receiver_keys: Vec<Key>,
msg: &[u8],
) -> VcxCoreResult<Vec<u8>> {
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?)
}

Expand Down
45 changes: 21 additions & 24 deletions aries/aries_vcx_core/src/wallet2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")]
Expand All @@ -41,7 +37,7 @@ impl From<IndyRecord> for Record {
#[derive(Debug, Deserialize, Serialize)]
pub struct DidData {
did: String,
verkey: String,
verkey: Key,
}

pub enum SearchFilter {
Expand All @@ -59,19 +55,19 @@ pub trait DidWallet {
method_name: Option<&str>,
) -> VcxCoreResult<DidData>;

async fn did_key(&self, name: &str) -> VcxCoreResult<String>;
async fn did_key(&self, name: &str) -> VcxCoreResult<Key>;

async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult<String>;
async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxCoreResult<Key>;

async fn replace_did_key_apply(&self, did: &str) -> VcxCoreResult<()>;

async fn sign(&self, key: &str, msg: &[u8]) -> VcxCoreResult<Vec<u8>>;
async fn sign(&self, key: &Key, msg: &[u8]) -> VcxCoreResult<Vec<u8>>;

async fn verify(&self, key: &str, msg: &[u8], signature: &[u8]) -> VcxCoreResult<bool>;
async fn verify(&self, key: &Key, msg: &[u8], signature: &[u8]) -> VcxCoreResult<bool>;

async fn pack_message(
&self,
sender_vk: Option<String>,
sender_vk: Option<Key>,
receiver_keys: Vec<Key>,
msg: &[u8],
) -> VcxCoreResult<Vec<u8>>;
Expand Down Expand Up @@ -117,7 +113,7 @@ mod tests {
wallet2::{
entry_tag::{EntryTag, EntryTags},
utils::random_seed,
DidWallet, Key, RecordBuilder, RecordWallet,
DidWallet, RecordBuilder, RecordWallet,
},
};

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion aries/misc/legacy/libvcx_core/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub enum LibvcxErrorKind {
DuplicationDid,

#[error("Unexpected wallet error")]
WalletUnexpected,
WalletError,

// Logger
#[error("Logging Error")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl From<AriesVcxErrorKind> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl From<AriesVcxCoreErrorKind> 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,
Expand Down
8 changes: 1 addition & 7 deletions aries/misc/test_utils/src/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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},
Expand Down

0 comments on commit 8cccc79

Please sign in to comment.