Skip to content

Commit

Permalink
split update method
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
  • Loading branch information
Ondrej Prazak committed Jan 4, 2024
1 parent 748ab8a commit bc3a5c6
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 411 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions 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", "test_utils/vdrtools_wallet"]
vdrtools_wallet = ["dep:libvdrtools", "dep:indy-api-types"]
# 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 All @@ -14,7 +14,6 @@ legacy_proof = []

[dependencies]
agency_client = { path = "../misc/legacy/agency_client" }
bs58 = { version = "0.5" }
indy-vdr = { git = "https://github.com/hyperledger/indy-vdr.git", rev = "c143268", default-features = false, features = ["log"] }
indy-credx = { git = "https://github.com/hyperledger/indy-shared-rs", tag = "v1.1.0", optional = true }
libvdrtools = { path = "../misc/legacy/libvdrtools", optional = true }
Expand All @@ -36,5 +35,4 @@ 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"] }
4 changes: 4 additions & 0 deletions aries/aries_vcx_core/src/wallet2/entry_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum EntryTag {
Plaintext(String, String),
}

#[cfg(feature = "vdrtools_wallet")]
impl From<EntryTag> for (String, String) {
fn from(value: EntryTag) -> Self {
match value {
Expand All @@ -17,6 +18,7 @@ impl From<EntryTag> for (String, String) {
}
}

#[cfg(feature = "vdrtools_wallet")]
impl From<(String, String)> for EntryTag {
fn from(value: (String, String)) -> Self {
if value.0.starts_with('~') {
Expand Down Expand Up @@ -100,6 +102,7 @@ impl From<EntryTags> for Vec<EntryTag> {
}
}

#[cfg(feature = "vdrtools_wallet")]
impl From<EntryTags> for HashMap<String, String> {
fn from(value: EntryTags) -> Self {
let tags: Vec<EntryTag> = value.into();
Expand All @@ -112,6 +115,7 @@ impl From<EntryTags> for HashMap<String, String> {
}
}

#[cfg(feature = "vdrtools_wallet")]
impl From<HashMap<String, String>> for EntryTags {
fn from(value: HashMap<String, String>) -> Self {
Self {
Expand Down
107 changes: 3 additions & 104 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 @@ -4,7 +4,7 @@ use vdrtools::{DidMethod, DidValue, KeyInfo, Locator, MyDidInfo};
use crate::{
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult},
wallet::{indy::IndySdkWallet, structs_io::UnpackMessageOutput},
wallet2::{DidData, DidWallet, Key, UnpackedMessage},
wallet2::{DidData, DidWallet, Key},
};

#[async_trait]
Expand Down Expand Up @@ -94,7 +94,7 @@ impl DidWallet for IndySdkWallet {
.await?)
}

async fn unpack_message(&self, msg: &[u8]) -> VcxCoreResult<UnpackedMessage> {
async fn unpack_message(&self, msg: &[u8]) -> VcxCoreResult<UnpackMessageOutput> {
let unpacked_bytes = Locator::instance()
.crypto_controller
.unpack_msg(serde_json::from_slice(msg)?, self.wallet_handle)
Expand All @@ -105,107 +105,6 @@ impl DidWallet for IndySdkWallet {
AriesVcxCoreError::from_msg(AriesVcxCoreErrorKind::ParsingError, err.to_string())
})?;

Ok(res.into())
}
}

#[cfg(test)]
mod tests {
use rand::{distributions::Alphanumeric, Rng};
use test_utils::devsetup::create_indy_test_wallet_handle;

use crate::{
wallet::indy::IndySdkWallet,
wallet2::{DidWallet, Key},
};

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

let seed: String = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(32)
.map(char::from)
.collect();

let did_data = DidWallet::create_and_store_my_did(&wallet, Some(&seed), None)
.await
.unwrap();

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

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

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

let seed: String = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(32)
.map(char::from)
.collect();

let did_data = DidWallet::create_and_store_my_did(&wallet, Some(&seed), None)
.await
.unwrap();

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

assert_eq!(did_data.verkey, key);

let new_seed: String = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(32)
.map(char::from)
.collect();

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

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

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

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

let sender_data = DidWallet::create_and_store_my_did(&wallet, None, None)
.await
.unwrap();

let receiver_data = DidWallet::create_and_store_my_did(&wallet, 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())
.await
.unwrap();

let unpacked = wallet.unpack_message(&packed).await.unwrap();

assert_eq!(msg, unpacked.message);
Ok(res)
}
}
Loading

0 comments on commit bc3a5c6

Please sign in to comment.