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 Dec 21, 2023
1 parent f4f7b5e commit c572e24
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 90 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.

3 changes: 2 additions & 1 deletion aries/aries_vcx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[features]
########################## DEP FLAGS ################################
vdrtools_wallet = ["dep:libvdrtools", "dep:indy-api-types"]
vdrtools_wallet = ["dep:libvdrtools", "dep:indy-api-types", "test_utils/vdrtools_wallet"]
# Feature flag to include the 'modular library' dependencies (vdrtools alternatives; indy-vdr, indy-credx)
credx = ["dep:indy-credx"]
vdr_proxy_ledger = ["credx", "dep:indy-vdr-proxy-client"]
Expand Down Expand Up @@ -36,4 +36,5 @@ indy-ledger-response-parser = { path = "../misc/indy_ledger_response_parser" }
lru = { version = "0.12.0" }

[dev-dependencies]
test_utils = { path = "../misc/test_utils" }
tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] }
26 changes: 10 additions & 16 deletions aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use vdrtools::{DidMethod, DidValue, KeyInfo, Locator, MyDidInfo};

use crate::{
errors::error::{AriesVcxCoreError, VcxCoreResult},
wallet::indy::IndySdkWallet,
wallet2::{DidData, DidWallet, SigType},
wallet2::{DidData, DidWallet},
};

#[async_trait]
impl DidWallet for IndySdkWallet {
impl DidWallet for crate::wallet::indy::IndySdkWallet {
async fn create_and_store_my_did(
&self,
seed: &str,
Expand Down Expand Up @@ -60,21 +59,15 @@ impl DidWallet for IndySdkWallet {
Ok(key)
}

async fn sign(&self, key: &str, msg: &[u8], _sig_type: SigType) -> VcxCoreResult<Vec<u8>> {
async fn sign(&self, key: &str, msg: &[u8]) -> VcxCoreResult<Vec<u8>> {
Locator::instance()
.crypto_controller
.crypto_sign(self.wallet_handle, key, msg)
.await
.map_err(From::from)
}

async fn verify(
&self,
key: &str,
msg: &[u8],
signature: &[u8],
_sig_type: SigType,
) -> VcxCoreResult<bool> {
async fn verify(&self, key: &str, msg: &[u8], signature: &[u8]) -> VcxCoreResult<bool> {
Locator::instance()
.crypto_controller
.crypto_verify(key, msg, signature)
Expand All @@ -86,13 +79,14 @@ impl DidWallet for IndySdkWallet {
#[cfg(test)]
mod tests {
use rand::{distributions::Alphanumeric, Rng};
use test_utils::devsetup::create_indy_test_wallet_handle;

use crate::wallet2::{indy_wallet::test_helper::create_test_wallet, DidWallet, SigType};
use crate::{wallet::indy::IndySdkWallet, wallet2::DidWallet};

#[tokio::test]
#[ignore]
async fn test_indy_should_sign_and_verify() {
let wallet = create_test_wallet().await;
let wallet = IndySdkWallet::new(create_indy_test_wallet_handle().await);

let seed: String = rand::thread_rng()
.sample_iter(Alphanumeric)
Expand All @@ -105,11 +99,11 @@ mod tests {
.unwrap();

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

let res = DidWallet::verify(&wallet, &did_data.verkey, msg, &sig, SigType::EdDSA)
let res = DidWallet::verify(&wallet, &did_data.verkey, msg, &sig)
.await
.unwrap();
assert!(res);
Expand All @@ -118,7 +112,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn test_indy_should_rotate_keys() {
let wallet = create_test_wallet().await;
let wallet = IndySdkWallet::new(create_indy_test_wallet_handle().await);

let seed: String = rand::thread_rng()
.sample_iter(Alphanumeric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,18 @@ impl RecordWallet for IndySdkWallet {

#[cfg(test)]
mod tests {
use super::*;
use test_utils::devsetup::create_indy_test_wallet_handle;

use crate::{
errors::error::AriesVcxCoreErrorKind,
wallet2::{indy_wallet::test_helper::create_test_wallet, RecordBuilder},
wallet::indy::IndySdkWallet,
wallet2::{EntryTag, RecordBuilder, RecordWallet},
};

#[tokio::test]
#[ignore]
async fn indy_wallet_should_create_record() {
let wallet = create_test_wallet().await;
let wallet = IndySdkWallet::new(create_indy_test_wallet_handle().await);

let name = "foo";
let category = "my";
Expand Down Expand Up @@ -179,7 +181,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn indy_wallet_should_delete_record() {
let wallet = create_test_wallet().await;
let wallet = IndySdkWallet::new(create_indy_test_wallet_handle().await);

let name = "foo";
let category = "my";
Expand Down Expand Up @@ -207,7 +209,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn indy_wallet_should_search_for_records() {
let wallet = create_test_wallet().await;
let wallet = IndySdkWallet::new(create_indy_test_wallet_handle().await);

let name1 = "foo";
let name2 = "foa";
Expand Down Expand Up @@ -243,7 +245,7 @@ mod tests {
#[tokio::test]
#[ignore]
async fn indy_wallet_should_update_record() {
let wallet = create_test_wallet().await;
let wallet = IndySdkWallet::new(create_indy_test_wallet_handle().await);

let name = "foo";
let category = "my";
Expand Down
40 changes: 0 additions & 40 deletions aries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,3 @@ const WALLET_OPTIONS: &str =
const SEARCH_OPTIONS: &str = r#"{"retrieveType": true, "retrieveValue": true, "retrieveTags": true, "retrieveRecords": true}"#;

impl BaseWallet2 for IndySdkWallet {}

#[allow(dead_code)]
pub(crate) mod test_helper {
use serde_json::json;

use crate::wallet::indy::{wallet::create_and_open_wallet, IndySdkWallet, WalletConfigBuilder};

pub async fn create_test_wallet() -> IndySdkWallet {
let default_wallet_key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY";
let wallet_kdf_raw = "RAW";

let db_name = format!("mysqltest_{}", uuid::Uuid::new_v4()).replace('-', "_");
let storage_config = json!({
"read_host": "localhost",
"write_host": "localhost",
"port": 3306,
"db_name": db_name,
"default_connection_limit": 50
})
.to_string();
let storage_credentials = json!({
"user": "root",
"pass": "mysecretpassword"
})
.to_string();
let config_wallet = WalletConfigBuilder::default()
.wallet_name(format!("faber_wallet_{}", uuid::Uuid::new_v4()))
.wallet_key(default_wallet_key)
.wallet_key_derivation(wallet_kdf_raw)
.wallet_type("mysql")
.storage_config(storage_config)
.storage_credentials(storage_credentials)
.build()
.unwrap();

let wallet_handle = create_and_open_wallet(&config_wallet).await.unwrap();

IndySdkWallet::new(wallet_handle)
}
}
28 changes: 2 additions & 26 deletions aries/aries_vcx_core/src/wallet2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ use crate::errors::error::VcxCoreResult;
#[cfg(feature = "vdrtools_wallet")]
pub mod indy_wallet;

pub enum SigType {
EdDSA,
ES256,
ES256K,
ES384,
}

impl From<SigType> for &str {
fn from(value: SigType) -> Self {
match value {
SigType::EdDSA => "eddsa",
SigType::ES256 => "es256",
SigType::ES256K => "es256k",
SigType::ES384 => "es384",
}
}
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum EntryTag {
Encrypted(String, String),
Expand Down Expand Up @@ -108,15 +90,9 @@ pub trait DidWallet {

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

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

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

#[async_trait]
Expand Down
42 changes: 41 additions & 1 deletion aries/misc/test_utils/src/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ use aries_vcx_core::{
request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter},
response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig},
},
wallet::{base_wallet::BaseWallet, mock_wallet::MockWallet},
wallet::{
base_wallet::BaseWallet,
indy::{IndySdkWallet, WalletConfigBuilder},
mock_wallet::MockWallet,
},
wallet2::BaseWallet2,
PoolConfig, ResponseParser,
};
#[cfg(feature = "vdr_proxy_ledger")]
Expand All @@ -49,6 +54,7 @@ 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 Expand Up @@ -270,6 +276,40 @@ pub async fn dev_build_indy_wallet(key_seed: &str) -> (String, impl BaseWallet)
(public_did, IndySdkWallet::new(wallet_handle))
}

#[cfg(feature = "vdrtools_wallet")]
pub async fn create_indy_test_wallet_handle() -> WalletHandle {
use aries_vcx_core::{
wallet::indy::{wallet::create_and_open_wallet, IndySdkWallet},
wallet2::{BaseWallet2, DidWallet, RecordWallet},
};

let db_name = format!("mysqltest_{}", uuid::Uuid::new_v4()).replace('-', "_");
let storage_config = json!({
"read_host": "localhost",
"write_host": "localhost",
"port": 3306,
"db_name": db_name,
"default_connection_limit": 50
})
.to_string();
let storage_credentials = json!({
"user": "root",
"pass": "mysecretpassword"
})
.to_string();
let config_wallet = WalletConfigBuilder::default()
.wallet_name(format!("faber_wallet_{}", uuid::Uuid::new_v4()))
.wallet_key(DEFAULT_WALLET_KEY)
.wallet_key_derivation(WALLET_KDF_RAW)
.wallet_type("mysql")
.storage_config(storage_config)
.storage_credentials(storage_credentials)
.build()
.unwrap();

create_and_open_wallet(&config_wallet).await.unwrap()
}

#[allow(unreachable_code)]
#[allow(unused_variables)]
pub async fn dev_build_featured_anoncreds() -> impl BaseAnonCreds {
Expand Down

0 comments on commit c572e24

Please sign in to comment.