From 9f2e922667bee27a4261c05e511d2a014df8af82 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Thu, 25 May 2023 12:55:32 +0200 Subject: [PATCH] Split BaseLedger trait (#861) Signed-off-by: Miroslav Kovar --- .../aries-vcx-agent/src/services/schema.rs | 2 +- aries_vcx/src/common/anoncreds.rs | 2 +- aries_vcx/src/common/keys.rs | 18 +-- aries_vcx/src/common/ledger/transactions.rs | 16 +- .../primitives/credential_definition.rs | 35 +++-- .../common/primitives/credential_schema.rs | 8 +- aries_vcx/src/common/primitives/mod.rs | 10 +- .../common/primitives/revocation_registry.rs | 6 +- .../primitives/revocation_registry_delta.rs | 2 +- .../common/proofs/prover/prover_internal.rs | 6 +- .../proofs/verifier/verifier_internal.rs | 8 +- aries_vcx/src/common/test_utils.rs | 8 +- .../src/core/profile/modular_libs_profile.rs | 28 +++- aries_vcx/src/core/profile/profile.rs | 12 +- .../src/core/profile/vdr_proxy_profile.rs | 28 +++- .../src/core/profile/vdrtools_profile.rs | 33 +++- aries_vcx/src/global/author_agreement.rs | 2 +- .../issuance/holder/state_machine.rs | 4 +- aries_vcx/src/protocols/issuance/mod.rs | 2 +- aries_vcx/src/utils/mockdata/mock_settings.rs | 2 +- .../src/utils/mockdata/profile/mock_ledger.rs | 69 +++++---- .../utils/mockdata/profile/mock_profile.rs | 18 ++- aries_vcx/tests/test_agency.rs | 1 - aries_vcx/tests/test_creds_proofs.rs | 5 +- .../tests/test_creds_proofs_revocations.rs | 2 - aries_vcx/tests/test_pool.rs | 5 +- aries_vcx/tests/utils/devsetup_agent.rs | 1 + aries_vcx/tests/utils/scenarios.rs | 3 +- .../src/global/mockdata/mock_settings.rs | 2 +- .../src/indy/credentials/issuer/mod.rs | 2 +- .../indy/primitives/revocation_registry.rs | 8 +- aries_vcx_core/src/ledger/base_ledger.rs | 97 +++--------- aries_vcx_core/src/ledger/indy_ledger.rs | 80 +++++----- aries_vcx_core/src/ledger/indy_vdr_ledger.rs | 142 ++++++++++-------- aries_vcx_core/src/utils/mod.rs | 2 - did_resolver_sov/src/reader/mod.rs | 8 +- did_resolver_sov/tests/resolution.rs | 4 +- libvcx_core/src/api_vcx/api_global/ledger.rs | 6 +- libvcx_core/src/api_vcx/api_global/pool.rs | 2 +- libvcx_core/src/api_vcx/api_global/profile.rs | 2 +- libvcx_core/src/api_vcx/api_handle/schema.rs | 1 - 41 files changed, 361 insertions(+), 331 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/schema.rs b/agents/rust/aries-vcx-agent/src/services/schema.rs index e1b6589a7e..5ca5eaeb55 100644 --- a/agents/rust/aries-vcx-agent/src/services/schema.rs +++ b/agents/rust/aries-vcx-agent/src/services/schema.rs @@ -34,7 +34,7 @@ impl ServiceSchemas { } pub async fn schema_json(&self, thread_id: &str) -> AgentResult { - let ledger = Arc::clone(&self.profile).inject_ledger(); + let ledger = Arc::clone(&self.profile).inject_anoncreds_ledger_read(); Ok(ledger.get_schema(thread_id, None).await?) } diff --git a/aries_vcx/src/common/anoncreds.rs b/aries_vcx/src/common/anoncreds.rs index 7648a5af6c..a6e7a42ba6 100644 --- a/aries_vcx/src/common/anoncreds.rs +++ b/aries_vcx/src/common/anoncreds.rs @@ -71,7 +71,7 @@ pub mod integration_tests { ) .await; - let ledger = Arc::clone(&holder_setup.profile).inject_ledger(); + let ledger = Arc::clone(&holder_setup.profile).inject_anoncreds_ledger_read(); let (_, first_rev_reg_delta, first_timestamp) = ledger.get_rev_reg_delta_json(&rev_reg_id, None, None).await.unwrap(); diff --git a/aries_vcx/src/common/keys.rs b/aries_vcx/src/common/keys.rs index 22f4bed3d8..7d1b938de2 100644 --- a/aries_vcx/src/common/keys.rs +++ b/aries_vcx/src/common/keys.rs @@ -6,7 +6,7 @@ use crate::core::profile::profile::Profile; use crate::errors::error::prelude::*; pub async fn rotate_verkey_apply(profile: &Arc, did: &str, temp_vk: &str) -> VcxResult<()> { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_write(); let nym_result = ledger.publish_nym(did, did, Some(temp_vk), None, None).await?; @@ -41,7 +41,7 @@ pub async fn rotate_verkey(profile: &Arc, did: &str) -> VcxResult<( } pub async fn get_verkey_from_ledger(profile: &Arc, did: &str) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_read(); let nym_response: String = ledger.get_nym(did).await?; let nym_json: Value = serde_json::from_str(&nym_response).map_err(|err| { @@ -75,17 +75,17 @@ pub async fn get_verkey_from_ledger(profile: &Arc, did: &str) -> Vc #[cfg(test)] #[allow(clippy::unwrap_used)] mod test { - use aries_vcx_core::indy::utils::mocks::pool_mocks::{enable_pool_mocks, PoolMocks}; - - use crate::utils::devsetup::*; - use crate::utils::mockdata::mockdata_pool; - - use super::*; - #[tokio::test] #[ignore] #[cfg(not(feature = "vdr_proxy_ledger"))] async fn test_pool_rotate_verkey_fails() { + use super::*; + + use aries_vcx_core::indy::utils::mocks::pool_mocks::{enable_pool_mocks, PoolMocks}; + + use crate::utils::devsetup::*; + use crate::utils::mockdata::mockdata_pool; + SetupProfile::run_indy(|setup| async move { enable_pool_mocks(); diff --git a/aries_vcx/src/common/ledger/transactions.rs b/aries_vcx/src/common/ledger/transactions.rs index 864046692e..d7f187ce69 100644 --- a/aries_vcx/src/common/ledger/transactions.rs +++ b/aries_vcx/src/common/ledger/transactions.rs @@ -78,7 +78,7 @@ pub async fn add_new_did( ) -> VcxResult<(String, String)> { let (did, verkey) = profile.inject_wallet().create_and_store_my_did(None, None).await?; - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_write(); let res = ledger .publish_nym(submitter_did, &did, Some(&verkey), None, role) @@ -190,7 +190,7 @@ pub async fn get_service(profile: &Arc, did: &String) -> VcxResult< None => did_raw, Some((_, value)) => value.to_string(), }; - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_read(); let attr_resp = ledger.get_attr(&did_raw, "endpoint").await?; let data = get_data_from_response(&attr_resp)?; if data["endpoint"].is_object() { @@ -207,7 +207,7 @@ pub async fn get_service(profile: &Arc, did: &String) -> VcxResult< } pub async fn parse_legacy_endpoint_attrib(profile: &Arc, did_raw: &str) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_read(); let attr_resp = ledger.get_attr(did_raw, "service").await?; let data = get_data_from_response(&attr_resp)?; let ser_service = match data["service"].as_str() { @@ -227,7 +227,7 @@ pub async fn parse_legacy_endpoint_attrib(profile: &Arc, did_raw: & pub async fn write_endpoint_legacy(profile: &Arc, did: &str, service: &AriesService) -> VcxResult { let attrib_json = json!({ "service": service }).to_string(); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_write(); let res = ledger.add_attr(did, &attrib_json).await?; check_response(&res)?; Ok(res) @@ -235,20 +235,20 @@ pub async fn write_endpoint_legacy(profile: &Arc, did: &str, servic pub async fn write_endpoint(profile: &Arc, did: &str, service: &EndpointDidSov) -> VcxResult { let attrib_json = json!({ "endpoint": service }).to_string(); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_write(); let res = ledger.add_attr(did, &attrib_json).await?; check_response(&res)?; Ok(res) } pub async fn add_attr(profile: &Arc, did: &str, attr: &str) -> VcxResult<()> { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_write(); let res = ledger.add_attr(did, &attr).await?; check_response(&res) } pub async fn get_attr(profile: &Arc, did: &str, attr_name: &str) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_read(); let attr_resp = ledger.get_attr(did, attr_name).await?; let data = get_data_from_response(&attr_resp)?; match data.get(attr_name) { @@ -259,7 +259,7 @@ pub async fn get_attr(profile: &Arc, did: &str, attr_name: &str) -> } pub async fn clear_attr(profile: &Arc, did: &str, attr_name: &str) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_indy_ledger_write(); ledger .add_attr(did, &json!({ attr_name: Value::Null }).to_string()) diff --git a/aries_vcx/src/common/primitives/credential_definition.rs b/aries_vcx/src/common/primitives/credential_definition.rs index cfbd6481c7..a18f417196 100644 --- a/aries_vcx/src/common/primitives/credential_definition.rs +++ b/aries_vcx/src/common/primitives/credential_definition.rs @@ -1,5 +1,5 @@ use aries_vcx_core::errors::error::AriesVcxCoreErrorKind; -use aries_vcx_core::ledger::base_ledger::BaseLedger; +use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead; use crate::core::profile::profile::Profile; use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; @@ -104,7 +104,7 @@ impl Default for PublicEntityStateType { } async fn _try_get_cred_def_from_ledger( - ledger: &Arc, + ledger: &Arc, issuer_did: &str, cred_def_id: &str, ) -> VcxResult> { @@ -140,7 +140,7 @@ impl CredentialDef { schema_id, tag, } = config; - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let schema_json = ledger.get_schema(&schema_id, Some(&issuer_did)).await?; let (cred_def_id, cred_def_json) = generate_cred_def(profile, &issuer_did, &schema_json, &tag, None, Some(support_revocation)).await?; @@ -170,8 +170,10 @@ impl CredentialDef { self.issuer_did, self.id ); - let ledger = Arc::clone(profile).inject_ledger(); - if let Some(ledger_cred_def_json) = _try_get_cred_def_from_ledger(&ledger, &self.issuer_did, &self.id).await? { + let ledger_read = Arc::clone(profile).inject_anoncreds_ledger_read(); + if let Some(ledger_cred_def_json) = + _try_get_cred_def_from_ledger(&ledger_read, &self.issuer_did, &self.id).await? + { return Err(AriesVcxError::from_msg( AriesVcxErrorKind::CredDefAlreadyCreated, format!( @@ -180,6 +182,7 @@ impl CredentialDef { ), )); } + let ledger = Arc::clone(profile).inject_anoncreds_ledger_write(); ledger.publish_cred_def(&self.cred_def_json, &self.issuer_did).await?; Ok(Self { state: PublicEntityStateType::Published, @@ -230,7 +233,7 @@ impl CredentialDef { } pub async fn update_state(&mut self, profile: &Arc) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); if (ledger.get_cred_def(&self.id, None).await).is_ok() { self.state = PublicEntityStateType::Published } @@ -289,8 +292,9 @@ pub mod integration_tests { let (schema_id, _) = create_and_write_test_schema(&setup.profile, &setup.institution_did, DEFAULT_SCHEMA_ATTRS).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); - let schema_json = ledger.get_schema(&schema_id, None).await.unwrap(); + let ledger_read = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); + let ledger_write = Arc::clone(&setup.profile).inject_anoncreds_ledger_write(); + let schema_json = ledger_read.get_schema(&schema_id, None).await.unwrap(); let (cred_def_id, cred_def_json_local) = generate_cred_def( &setup.profile, @@ -303,14 +307,14 @@ pub mod integration_tests { .await .unwrap(); - ledger + ledger_write .publish_cred_def(&cred_def_json_local, &setup.institution_did) .await .unwrap(); std::thread::sleep(std::time::Duration::from_secs(2)); - let cred_def_json_ledger = ledger + let cred_def_json_ledger = ledger_read .get_cred_def(&cred_def_id, Some(&setup.institution_did)) .await .unwrap(); @@ -327,8 +331,9 @@ pub mod integration_tests { SetupProfile::run_indy(|setup| async move { let (schema_id, _) = create_and_write_test_schema(&setup.profile, &setup.institution_did, DEFAULT_SCHEMA_ATTRS).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); - let schema_json = ledger.get_schema(&schema_id, None).await.unwrap(); + let ledger_read = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); + let ledger_write = Arc::clone(&setup.profile).inject_anoncreds_ledger_write(); + let schema_json = ledger_read.get_schema(&schema_id, None).await.unwrap(); let (cred_def_id, cred_def_json) = generate_cred_def( &setup.profile, @@ -340,7 +345,7 @@ pub mod integration_tests { ) .await .unwrap(); - ledger + ledger_write .publish_cred_def(&cred_def_json, &setup.institution_did) .await .unwrap(); @@ -355,11 +360,11 @@ pub mod integration_tests { ) .await .unwrap(); - ledger + ledger_write .publish_rev_reg_def(&json!(rev_reg_def_json).to_string(), &setup.institution_did) .await .unwrap(); - ledger + ledger_write .publish_rev_reg_delta(&rev_reg_def_id, &rev_reg_entry_json, &setup.institution_did) .await .unwrap(); diff --git a/aries_vcx/src/common/primitives/credential_schema.rs b/aries_vcx/src/common/primitives/credential_schema.rs index 760a4c2fc9..aba57dd989 100644 --- a/aries_vcx/src/common/primitives/credential_schema.rs +++ b/aries_vcx/src/common/primitives/credential_schema.rs @@ -90,7 +90,7 @@ impl Schema { source_id: &str, schema_id: &str, ) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let schema_json = ledger.get_schema(schema_id, None).await?; let schema_data: SchemaData = serde_json::from_str(&schema_json).map_err(|err| { AriesVcxError::from_msg( @@ -121,7 +121,7 @@ impl Schema { }); } - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_write(); ledger .publish_schema(&self.schema_json, &self.submitter_did, endorser_did) .await?; @@ -153,7 +153,7 @@ impl Schema { } pub async fn update_state(&mut self, profile: &Arc) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); if ledger.get_schema(&self.schema_id, None).await.is_ok() { self.state = PublicEntityStateType::Published } @@ -164,7 +164,7 @@ impl Schema { if !self.schema_json.is_empty() { Ok(self.schema_json.clone()) } else { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); Ok(ledger.get_schema(&self.schema_id, None).await?) } } diff --git a/aries_vcx/src/common/primitives/mod.rs b/aries_vcx/src/common/primitives/mod.rs index 4220c19fbd..5ad11365cf 100644 --- a/aries_vcx/src/common/primitives/mod.rs +++ b/aries_vcx/src/common/primitives/mod.rs @@ -54,7 +54,7 @@ pub mod integration_tests { let (_, _, _, _, rev_reg_id, _, _) = create_and_store_credential_def(&setup.profile, &setup.institution_did, attrs).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let _json = ledger.get_rev_reg_def_json(&rev_reg_id).await.unwrap(); }) .await; @@ -68,7 +68,7 @@ pub mod integration_tests { let (_, _, _, _, rev_reg_id, _, _) = create_and_store_credential_def(&setup.profile, &setup.institution_did, attrs).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let (id, _delta, _timestamp) = ledger.get_rev_reg_delta_json(&rev_reg_id, None, None).await.unwrap(); assert_eq!(id, rev_reg_id); @@ -84,7 +84,7 @@ pub mod integration_tests { let (_, _, _, _, rev_reg_id, _, _) = create_and_store_credential_def(&setup.profile, &setup.institution_did, attrs).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let (id, _rev_reg, _timestamp) = ledger .get_rev_reg(&rev_reg_id, time::OffsetDateTime::now_utc().unix_timestamp() as u64) .await @@ -103,7 +103,7 @@ pub mod integration_tests { let (_, _, cred_def_id, cred_def_json, _) = create_and_store_nonrevocable_credential_def(&setup.profile, &setup.institution_did, attrs).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let cred_def = ledger.get_cred_def(&cred_def_id, None).await.unwrap(); assert_eq!( @@ -121,7 +121,7 @@ pub mod integration_tests { let (schema_id, _schema_json) = create_and_write_test_schema(&setup.profile, &setup.institution_did, DEFAULT_SCHEMA_ATTRS).await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let rc = ledger.get_schema(&schema_id, None).await; let retrieved_schema = rc.unwrap(); diff --git a/aries_vcx/src/common/primitives/revocation_registry.rs b/aries_vcx/src/common/primitives/revocation_registry.rs index 107d2769bd..b8c7e8b01b 100644 --- a/aries_vcx/src/common/primitives/revocation_registry.rs +++ b/aries_vcx/src/common/primitives/revocation_registry.rs @@ -101,7 +101,7 @@ impl RevocationRegistry { &self.rev_reg_def ); self.rev_reg_def.value.tails_location = String::from(tails_url); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_write(); ledger .publish_rev_reg_def(&json!(self.rev_reg_def).to_string(), issuer_did) .await @@ -121,7 +121,7 @@ impl RevocationRegistry { issuer_did, self.rev_reg_id ); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_write(); ledger .publish_rev_reg_delta(&self.rev_reg_id, &self.rev_reg_entry, issuer_did) .await @@ -196,7 +196,7 @@ impl RevocationRegistry { pub async fn publish_local_revocations(&self, profile: &Arc, submitter_did: &str) -> VcxResult<()> { let anoncreds = Arc::clone(profile).inject_anoncreds(); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_write(); if let Some(delta) = anoncreds.get_rev_reg_delta(&self.rev_reg_id).await? { ledger diff --git a/aries_vcx/src/common/primitives/revocation_registry_delta.rs b/aries_vcx/src/common/primitives/revocation_registry_delta.rs index f51f1fe964..75d15f648b 100644 --- a/aries_vcx/src/common/primitives/revocation_registry_delta.rs +++ b/aries_vcx/src/common/primitives/revocation_registry_delta.rs @@ -38,7 +38,7 @@ impl RevocationRegistryDelta { from: Option, to: Option, ) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let (_, rev_reg_delta_json, _) = ledger.get_rev_reg_delta_json(rev_reg_id, from, to).await?; serde_json::from_str(&rev_reg_delta_json).map_err(|err| { AriesVcxError::from_msg( diff --git a/aries_vcx/src/common/proofs/prover/prover_internal.rs b/aries_vcx/src/common/proofs/prover/prover_internal.rs index 182d62e144..df450d5ddd 100644 --- a/aries_vcx/src/common/proofs/prover/prover_internal.rs +++ b/aries_vcx/src/common/proofs/prover/prover_internal.rs @@ -31,7 +31,7 @@ pub async fn build_schemas_json_prover( "build_schemas_json_prover >>> credentials_identifiers: {:?}", credentials_identifiers ); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let mut rtn: Value = json!({}); for cred_info in credentials_identifiers { @@ -62,7 +62,7 @@ pub async fn build_cred_defs_json_prover( "build_cred_defs_json_prover >>> credentials_identifiers: {:?}", credentials_identifiers ); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let mut rtn: Value = json!({}); for cred_info in credentials_identifiers { @@ -167,7 +167,7 @@ pub async fn build_rev_states_json( "build_rev_states_json >> credentials_identifiers: {:?}", credentials_identifiers ); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let anoncreds = Arc::clone(profile).inject_anoncreds(); let mut rtn: Value = json!({}); let mut timestamps: HashMap = HashMap::new(); diff --git a/aries_vcx/src/common/proofs/verifier/verifier_internal.rs b/aries_vcx/src/common/proofs/verifier/verifier_internal.rs index 331005a4ac..737f510835 100644 --- a/aries_vcx/src/common/proofs/verifier/verifier_internal.rs +++ b/aries_vcx/src/common/proofs/verifier/verifier_internal.rs @@ -101,7 +101,7 @@ pub async fn build_cred_defs_json_verifier( credential_data: &[CredInfoVerifier], ) -> VcxResult { debug!("building credential_def_json for proof validation"); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let mut credential_json = json!({}); for cred_info in credential_data.iter() { @@ -129,7 +129,7 @@ pub async fn build_schemas_json_verifier( ) -> VcxResult { debug!("building schemas json for proof validation"); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let mut schemas_json = json!({}); for cred_info in credential_data.iter() { @@ -158,7 +158,7 @@ pub async fn build_rev_reg_defs_json( ) -> VcxResult { debug!("building rev_reg_def_json for proof validation"); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let mut rev_reg_defs_json = json!({}); for cred_info in credential_data.iter() { @@ -183,7 +183,7 @@ pub async fn build_rev_reg_defs_json( pub async fn build_rev_reg_json(profile: &Arc, credential_data: &[CredInfoVerifier]) -> VcxResult { debug!("building rev_reg_json for proof validation"); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let mut rev_regs_json = json!({}); for cred_info in credential_data.iter() { diff --git a/aries_vcx/src/common/test_utils.rs b/aries_vcx/src/common/test_utils.rs index ced9a42187..95fdd7d9a1 100644 --- a/aries_vcx/src/common/test_utils.rs +++ b/aries_vcx/src/common/test_utils.rs @@ -37,7 +37,7 @@ pub async fn create_and_write_test_schema( attr_list: &str, ) -> (String, String) { let (schema_id, schema_json) = create_schema(profile, attr_list, submitter_did).await; - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_write(); let _response = ledger.publish_schema(&schema_json, submitter_did, None).await.unwrap(); tokio::time::sleep(Duration::from_millis(1000)).await; (schema_id, schema_json) @@ -65,7 +65,7 @@ pub async fn create_and_store_nonrevocable_credential_def( let cred_def_id = cred_def.get_cred_def_id(); tokio::time::sleep(Duration::from_millis(1000)).await; - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let cred_def_json = ledger.get_cred_def(&cred_def_id, None).await.unwrap(); (schema_id, schema_json, cred_def_id, cred_def_json, cred_def) } @@ -115,7 +115,7 @@ pub async fn create_and_store_credential_def( tokio::time::sleep(Duration::from_millis(1000)).await; let cred_def_id = cred_def.get_cred_def_id(); tokio::time::sleep(Duration::from_millis(1000)).await; - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let cred_def_json = ledger.get_cred_def(&cred_def_id, None).await.unwrap(); ( schema_id, @@ -178,7 +178,7 @@ pub async fn create_and_store_credential( /* create cred */ let credential_data = r#"{"address1": ["123 Main St"], "address2": ["Suite 3"], "city": ["Draper"], "state": ["UT"], "zip": ["84000"]}"#; let encoded_attributes = encode_attributes(&credential_data).unwrap(); - let ledger = Arc::clone(issuer).inject_ledger(); + let ledger = Arc::clone(issuer).inject_anoncreds_ledger_read(); let rev_def_json = ledger.get_rev_reg_def_json(&rev_reg_id).await.unwrap(); let tails_file = get_temp_dir_path(TAILS_DIR).to_str().unwrap().to_string(); diff --git a/aries_vcx/src/core/profile/modular_libs_profile.rs b/aries_vcx/src/core/profile/modular_libs_profile.rs index cf8f820ea6..a96dcbe5fe 100644 --- a/aries_vcx/src/core/profile/modular_libs_profile.rs +++ b/aries_vcx/src/core/profile/modular_libs_profile.rs @@ -3,7 +3,7 @@ use std::time::Duration; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds; -use aries_vcx_core::ledger::base_ledger::BaseLedger; +use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}; use aries_vcx_core::ledger::indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig}; use aries_vcx_core::ledger::request_signer::base_wallet::BaseWalletRequestSigner; use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig}; @@ -19,8 +19,11 @@ use super::profile::Profile; #[derive(Debug)] pub struct ModularLibsProfile { wallet: Arc, - ledger: Arc, anoncreds: Arc, + anoncreds_ledger_read: Arc, + anoncreds_ledger_write: Arc, + indy_ledger_read: Arc, + indy_ledger_write: Arc, } impl ModularLibsProfile { @@ -44,21 +47,36 @@ impl ModularLibsProfile { let ledger = Arc::new(IndyVdrLedger::new(config)); Ok(ModularLibsProfile { wallet, - ledger, anoncreds, + anoncreds_ledger_read: ledger.clone(), + anoncreds_ledger_write: ledger.clone(), + indy_ledger_read: ledger.clone(), + indy_ledger_write: ledger, }) } } impl Profile for ModularLibsProfile { - fn inject_ledger(self: Arc) -> Arc { - Arc::clone(&self.ledger) + fn inject_indy_ledger_read(self: Arc) -> Arc { + Arc::clone(&self.indy_ledger_read) + } + + fn inject_indy_ledger_write(self: Arc) -> Arc { + Arc::clone(&self.indy_ledger_write) } fn inject_anoncreds(self: Arc) -> Arc { Arc::clone(&self.anoncreds) } + fn inject_anoncreds_ledger_read(self: Arc) -> Arc { + Arc::clone(&self.anoncreds_ledger_read) + } + + fn inject_anoncreds_ledger_write(self: Arc) -> Arc { + Arc::clone(&self.anoncreds_ledger_write) + } + fn inject_wallet(&self) -> Arc { Arc::clone(&self.wallet) } diff --git a/aries_vcx/src/core/profile/profile.rs b/aries_vcx/src/core/profile/profile.rs index 0609c748be..52017dea86 100644 --- a/aries_vcx/src/core/profile/profile.rs +++ b/aries_vcx/src/core/profile/profile.rs @@ -1,13 +1,21 @@ use std::sync::Arc; use aries_vcx_core::{ - anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::BaseLedger, wallet::base_wallet::BaseWallet, + anoncreds::base_anoncreds::BaseAnonCreds, + ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}, + wallet::base_wallet::BaseWallet, }; pub trait Profile: std::fmt::Debug + Send + Sync { - fn inject_ledger(self: Arc) -> Arc; + fn inject_indy_ledger_read(self: Arc) -> Arc; + + fn inject_indy_ledger_write(self: Arc) -> Arc; fn inject_anoncreds(self: Arc) -> Arc; + fn inject_anoncreds_ledger_read(self: Arc) -> Arc; + + fn inject_anoncreds_ledger_write(self: Arc) -> Arc; + fn inject_wallet(&self) -> Arc; } diff --git a/aries_vcx/src/core/profile/vdr_proxy_profile.rs b/aries_vcx/src/core/profile/vdr_proxy_profile.rs index 59d76d0590..f2e240bb58 100644 --- a/aries_vcx/src/core/profile/vdr_proxy_profile.rs +++ b/aries_vcx/src/core/profile/vdr_proxy_profile.rs @@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration}; use aries_vcx_core::{ anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds}, ledger::{ - base_ledger::BaseLedger, + base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}, indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig}, request_signer::base_wallet::BaseWalletRequestSigner, request_submitter::vdr_proxy::VdrProxySubmitter, @@ -20,8 +20,11 @@ use super::profile::Profile; #[derive(Debug)] pub struct VdrProxyProfile { wallet: Arc, - ledger: Arc, anoncreds: Arc, + anoncreds_ledger_read: Arc, + anoncreds_ledger_write: Arc, + indy_ledger_read: Arc, + indy_ledger_write: Arc, } impl VdrProxyProfile { @@ -45,21 +48,36 @@ impl VdrProxyProfile { let ledger = Arc::new(IndyVdrLedger::new(config)); Ok(VdrProxyProfile { wallet, - ledger, anoncreds, + anoncreds_ledger_read: ledger.clone(), + anoncreds_ledger_write: ledger.clone(), + indy_ledger_read: ledger.clone(), + indy_ledger_write: ledger, }) } } impl Profile for VdrProxyProfile { - fn inject_ledger(self: Arc) -> Arc { - Arc::clone(&self.ledger) + fn inject_indy_ledger_read(self: Arc) -> Arc { + Arc::clone(&self.indy_ledger_read) + } + + fn inject_indy_ledger_write(self: Arc) -> Arc { + Arc::clone(&self.indy_ledger_write) } fn inject_anoncreds(self: Arc) -> Arc { Arc::clone(&self.anoncreds) } + fn inject_anoncreds_ledger_read(self: Arc) -> Arc { + Arc::clone(&self.anoncreds_ledger_read) + } + + fn inject_anoncreds_ledger_write(self: Arc) -> Arc { + Arc::clone(&self.anoncreds_ledger_write) + } + fn inject_wallet(&self) -> Arc { Arc::clone(&self.wallet) } diff --git a/aries_vcx/src/core/profile/vdrtools_profile.rs b/aries_vcx/src/core/profile/vdrtools_profile.rs index 5c0bddc415..4a86ea87a0 100644 --- a/aries_vcx/src/core/profile/vdrtools_profile.rs +++ b/aries_vcx/src/core/profile/vdrtools_profile.rs @@ -2,7 +2,10 @@ use std::sync::Arc; use aries_vcx_core::{ anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds}, - ledger::{base_ledger::BaseLedger, indy_ledger::IndySdkLedger}, + ledger::{ + base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}, + indy_ledger::IndySdkLedger, + }, wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet}, PoolHandle, WalletHandle, }; @@ -12,32 +15,50 @@ use super::profile::Profile; #[derive(Debug)] pub struct VdrtoolsProfile { wallet: Arc, - ledger: Arc, anoncreds: Arc, + anoncreds_ledger_read: Arc, + anoncreds_ledger_write: Arc, + indy_ledger_read: Arc, + indy_ledger_write: Arc, } impl VdrtoolsProfile { pub fn new(indy_wallet_handle: WalletHandle, indy_pool_handle: PoolHandle) -> Self { let wallet = Arc::new(IndySdkWallet::new(indy_wallet_handle)); - let ledger = Arc::new(IndySdkLedger::new(indy_wallet_handle, indy_pool_handle)); let anoncreds = Arc::new(IndySdkAnonCreds::new(indy_wallet_handle)); + let ledger = Arc::new(IndySdkLedger::new(indy_wallet_handle, indy_pool_handle)); VdrtoolsProfile { wallet, - ledger, anoncreds, + anoncreds_ledger_read: ledger.clone(), + anoncreds_ledger_write: ledger.clone(), + indy_ledger_read: ledger.clone(), + indy_ledger_write: ledger, } } } impl Profile for VdrtoolsProfile { - fn inject_ledger(self: Arc) -> Arc { - Arc::clone(&self.ledger) + fn inject_indy_ledger_read(self: Arc) -> Arc { + Arc::clone(&self.indy_ledger_read) + } + + fn inject_indy_ledger_write(self: Arc) -> Arc { + Arc::clone(&self.indy_ledger_write) } fn inject_anoncreds(self: Arc) -> Arc { Arc::clone(&self.anoncreds) } + fn inject_anoncreds_ledger_read(self: Arc) -> Arc { + Arc::clone(&self.anoncreds_ledger_read) + } + + fn inject_anoncreds_ledger_write(self: Arc) -> Arc { + Arc::clone(&self.anoncreds_ledger_write) + } + fn inject_wallet(&self) -> Arc { Arc::clone(&self.wallet) } diff --git a/aries_vcx/src/global/author_agreement.rs b/aries_vcx/src/global/author_agreement.rs index fe030a589f..c904c63802 100644 --- a/aries_vcx/src/global/author_agreement.rs +++ b/aries_vcx/src/global/author_agreement.rs @@ -1,5 +1,5 @@ use crate::errors::error::VcxResult; -use aries_vcx_core::global::author_agreement::{set_txn_author_agreement, TxnAuthorAgreementAcceptanceData}; +use aries_vcx_core::global::author_agreement::set_txn_author_agreement; pub fn proxy_set_txn_author_agreement( text: Option, diff --git a/aries_vcx/src/protocols/issuance/holder/state_machine.rs b/aries_vcx/src/protocols/issuance/holder/state_machine.rs index afc8bce207..05efcaaf26 100644 --- a/aries_vcx/src/protocols/issuance/holder/state_machine.rs +++ b/aries_vcx/src/protocols/issuance/holder/state_machine.rs @@ -578,7 +578,7 @@ async fn _store_credential( cred_def_json ); - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let anoncreds = Arc::clone(profile).inject_anoncreds(); let credential_json = get_attach_as_string!(&credential.content.credentials_attach); @@ -619,7 +619,7 @@ pub async fn create_credential_request( prover_did: &str, cred_offer: &str, ) -> VcxResult<(String, String, String, String)> { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let anoncreds = Arc::clone(profile).inject_anoncreds(); let cred_def_json = ledger.get_cred_def(cred_def_id, None).await?; diff --git a/aries_vcx/src/protocols/issuance/mod.rs b/aries_vcx/src/protocols/issuance/mod.rs index d47654fc47..789b8afe75 100644 --- a/aries_vcx/src/protocols/issuance/mod.rs +++ b/aries_vcx/src/protocols/issuance/mod.rs @@ -23,7 +23,7 @@ pub fn verify_thread_id(thread_id: &str, message: &CredentialIssuanceAction) -> } pub async fn is_cred_def_revokable(profile: &Arc, cred_def_id: &str) -> VcxResult { - let ledger = Arc::clone(profile).inject_ledger(); + let ledger = Arc::clone(profile).inject_anoncreds_ledger_read(); let cred_def_json = ledger.get_cred_def(cred_def_id, None).await.map_err(|err| { AriesVcxError::from_msg( AriesVcxErrorKind::InvalidLedgerResponse, diff --git a/aries_vcx/src/utils/mockdata/mock_settings.rs b/aries_vcx/src/utils/mockdata/mock_settings.rs index c01e0f6e57..03467786db 100644 --- a/aries_vcx/src/utils/mockdata/mock_settings.rs +++ b/aries_vcx/src/utils/mockdata/mock_settings.rs @@ -1,5 +1,5 @@ +use std::collections::HashMap; use std::sync::RwLock; -use std::{collections::HashMap, sync::Mutex}; use crate::errors::error::{AriesVcxError, VcxResult}; diff --git a/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs b/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs index ebafa9891e..649bdc6749 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_ledger.rs @@ -1,32 +1,16 @@ use aries_vcx_core::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; -use aries_vcx_core::ledger::base_ledger::BaseLedger; +use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}; use async_trait::async_trait; -use crate::utils::{ - self, - constants::{rev_def_json, CRED_DEF_JSON, REV_REG_DELTA_JSON, REV_REG_ID, REV_REG_JSON, SCHEMA_JSON}, -}; +use crate::utils; +use crate::utils::constants::{rev_def_json, CRED_DEF_JSON, REV_REG_DELTA_JSON, REV_REG_ID, REV_REG_JSON, SCHEMA_JSON}; #[derive(Debug)] pub(crate) struct MockLedger; -// NOTE : currently matches the expected results if indy_mocks are enabled -/// Implementation of [BaseLedger] which responds with mock data #[allow(unused)] #[async_trait] -impl BaseLedger for MockLedger { - async fn submit_request(&self, request_json: &str) -> VcxCoreResult { - // not needed yet - Err(AriesVcxCoreError::from_msg( - AriesVcxCoreErrorKind::UnimplementedFeature, - "unimplemented mock method: submit_request", - )) - } - - async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> { - Ok(()) - } - +impl IndyLedgerRead for MockLedger { async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult { Ok(utils::constants::REQUEST_WITH_ENDORSER.to_string()) } @@ -43,6 +27,22 @@ impl BaseLedger for MockLedger { )) } + async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult { + Ok(r#"{"rc":"success"}"#.to_string()) + } + + async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult { + Ok(r#"{"rc":"success"}"#.to_string()) + } +} + +#[allow(unused)] +#[async_trait] +impl IndyLedgerWrite for MockLedger { + async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> { + Ok(()) + } + async fn publish_nym( &self, submitter_did: &str, @@ -54,6 +54,14 @@ impl BaseLedger for MockLedger { Ok(r#"{"rc":"success"}"#.to_string()) } + async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult { + Ok(r#"{"rc":"success"}"#.to_string()) + } +} + +#[allow(unused)] +#[async_trait] +impl AnoncredsLedgerRead for MockLedger { async fn get_schema(&self, schema_id: &str, submitter_did: Option<&str>) -> VcxCoreResult { Ok(SCHEMA_JSON.to_string()) } @@ -62,14 +70,6 @@ impl BaseLedger for MockLedger { Ok(CRED_DEF_JSON.to_string()) } - async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult { - Ok(r#"{"rc":"success"}"#.to_string()) - } - - async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult { - Ok(r#"{"rc":"success"}"#.to_string()) - } - async fn get_rev_reg_def_json(&self, rev_reg_id: &str) -> VcxCoreResult { Ok(rev_def_json()) } @@ -86,11 +86,11 @@ impl BaseLedger for MockLedger { async fn get_rev_reg(&self, rev_reg_id: &str, timestamp: u64) -> VcxCoreResult<(String, String, u64)> { Ok((REV_REG_ID.to_string(), REV_REG_JSON.to_string(), 1)) } +} - async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult { - Ok(r#"{"rc":"success"}"#.to_string()) - } - +#[allow(unused)] +#[async_trait] +impl AnoncredsLedgerWrite for MockLedger { async fn publish_schema( &self, schema_json: &str, @@ -124,7 +124,7 @@ mod unit_tests { use aries_vcx_core::{ errors::error::{AriesVcxCoreErrorKind, VcxCoreResult}, - ledger::base_ledger::BaseLedger, + ledger::base_ledger::IndyLedgerRead, }; use super::MockLedger; @@ -137,9 +137,8 @@ mod unit_tests { assert_eq!(result.unwrap_err().kind(), AriesVcxCoreErrorKind::UnimplementedFeature) } - let ledger: Box = Box::new(MockLedger); + let ledger: Box = Box::new(MockLedger); - assert_unimplemented(ledger.submit_request("").await); assert_unimplemented(ledger.get_nym("").await); } } diff --git a/aries_vcx/src/utils/mockdata/profile/mock_profile.rs b/aries_vcx/src/utils/mockdata/profile/mock_profile.rs index 2b7919430b..68a66957a6 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_profile.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_profile.rs @@ -1,7 +1,9 @@ use std::sync::Arc; use aries_vcx_core::{ - anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::BaseLedger, wallet::base_wallet::BaseWallet, + anoncreds::base_anoncreds::BaseAnonCreds, + ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}, + wallet::base_wallet::BaseWallet, }; use crate::core::profile::profile::Profile; @@ -14,7 +16,11 @@ use super::{mock_anoncreds::MockAnoncreds, mock_ledger::MockLedger, mock_wallet: pub struct MockProfile; impl Profile for MockProfile { - fn inject_ledger(self: Arc) -> Arc { + fn inject_indy_ledger_write(self: Arc) -> Arc { + Arc::new(MockLedger {}) + } + + fn inject_indy_ledger_read(self: Arc) -> Arc { Arc::new(MockLedger {}) } @@ -25,4 +31,12 @@ impl Profile for MockProfile { fn inject_wallet(&self) -> Arc { Arc::new(MockWallet {}) } + + fn inject_anoncreds_ledger_read(self: Arc) -> Arc { + Arc::new(MockLedger {}) + } + + fn inject_anoncreds_ledger_write(self: Arc) -> Arc { + Arc::new(MockLedger {}) + } } diff --git a/aries_vcx/tests/test_agency.rs b/aries_vcx/tests/test_agency.rs index 2cb23265fd..d73dbf69b6 100644 --- a/aries_vcx/tests/test_agency.rs +++ b/aries_vcx/tests/test_agency.rs @@ -9,7 +9,6 @@ pub mod utils; #[cfg(test)] mod integration_tests { use std::sync::Arc; - use std::thread; use std::time::Duration; use agency_client::agency_client::AgencyClient; diff --git a/aries_vcx/tests/test_creds_proofs.rs b/aries_vcx/tests/test_creds_proofs.rs index 44f8ac69c0..5ee0d392f4 100644 --- a/aries_vcx/tests/test_creds_proofs.rs +++ b/aries_vcx/tests/test_creds_proofs.rs @@ -13,7 +13,6 @@ mod integration_tests { create_and_store_credential, create_and_store_nonrevocable_credential, create_and_store_nonrevocable_credential_def, create_indy_proof, }; - use aries_vcx::errors::error::VcxResult; use aries_vcx::handlers::proof_presentation::prover::Prover; use aries_vcx::handlers::proof_presentation::verifier::Verifier; use aries_vcx::handlers::util::AttachmentId; @@ -75,7 +74,7 @@ mod integration_tests { ) .await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let r_cred_def_json = ledger.get_cred_def(&cred_def_id, None).await.unwrap(); let def1: serde_json::Value = serde_json::from_str(&cred_def_json).unwrap(); @@ -464,7 +463,6 @@ mod integration_tests { #[cfg(test)] mod tests { - use std::thread; use std::time::Duration; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; @@ -492,7 +490,6 @@ mod tests { send_cred_proposal, send_cred_proposal_1, send_cred_req, send_credential, send_proof_proposal, send_proof_proposal_1, send_proof_request, verifier_create_proof_and_send_request, verify_proof, }; - use crate::utils::test_macros::ProofStateType; use super::*; diff --git a/aries_vcx/tests/test_creds_proofs_revocations.rs b/aries_vcx/tests/test_creds_proofs_revocations.rs index 5bdd4719c6..8b49b8abe0 100644 --- a/aries_vcx/tests/test_creds_proofs_revocations.rs +++ b/aries_vcx/tests/test_creds_proofs_revocations.rs @@ -7,7 +7,6 @@ pub mod utils; #[cfg(test)] mod integration_tests { - use std::thread; use std::time::Duration; use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; @@ -23,7 +22,6 @@ mod integration_tests { revoke_credential_and_publish_accumulator, revoke_credential_local, rotate_rev_reg, send_proof_request, verifier_create_proof_and_send_request, }; - use crate::utils::test_macros::ProofStateType; use super::*; diff --git a/aries_vcx/tests/test_pool.rs b/aries_vcx/tests/test_pool.rs index 1cc3ef3aab..733b645cfc 100644 --- a/aries_vcx/tests/test_pool.rs +++ b/aries_vcx/tests/test_pool.rs @@ -12,9 +12,8 @@ mod integration_tests { use aries_vcx::common::ledger::transactions::{ add_attr, add_new_did, clear_attr, get_attr, get_service, write_endpoint, write_endpoint_legacy, }; - use aries_vcx::common::primitives::credential_schema::{Schema, SchemaData}; use aries_vcx::common::test_utils::create_and_store_nonrevocable_credential_def; - use aries_vcx::utils::constants::{DEFAULT_SCHEMA_ATTRS, SCHEMA_DATA}; + use aries_vcx::utils::constants::DEFAULT_SCHEMA_ATTRS; use aries_vcx::utils::devsetup::{SetupProfile, SetupWalletPool}; use diddoc_legacy::aries::service::AriesService; use std::sync::Arc; @@ -42,7 +41,7 @@ mod integration_tests { ) .await; - let ledger = Arc::clone(&setup.profile).inject_ledger(); + let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read(); let r_cred_def_json = ledger.get_cred_def(&cred_def_id, None).await.unwrap(); diff --git a/aries_vcx/tests/utils/devsetup_agent.rs b/aries_vcx/tests/utils/devsetup_agent.rs index 7a8f2b19bb..84a3358404 100644 --- a/aries_vcx/tests/utils/devsetup_agent.rs +++ b/aries_vcx/tests/utils/devsetup_agent.rs @@ -447,6 +447,7 @@ pub mod test_utils { } pub async fn create_test_alice_instance(setup: &SetupPool) -> Alice { + #[cfg(not(feature = "modular_libs"))] let (alice_profile, teardown) = { info!("create_test_alice_instance >> using indy profile"); Alice::setup_indy_profile(setup.pool_handle).await diff --git a/aries_vcx/tests/utils/scenarios.rs b/aries_vcx/tests/utils/scenarios.rs index 8ba3277554..db5279caa4 100644 --- a/aries_vcx/tests/utils/scenarios.rs +++ b/aries_vcx/tests/utils/scenarios.rs @@ -48,7 +48,6 @@ pub mod test_utils { use aries_vcx::utils::get_temp_dir_path; use crate::utils::devsetup_agent::test_utils::{Alice, Faber}; - use crate::utils::test_macros::ProofStateType; pub fn _send_message(sender: Sender) -> Option { Some(Box::new( @@ -769,7 +768,7 @@ pub mod test_utils { } pub async fn revoke_credential_local(faber: &mut Faber, issuer_credential: &Issuer, rev_reg_id: &str) { - let ledger = Arc::clone(&faber.profile).inject_ledger(); + let ledger = Arc::clone(&faber.profile).inject_anoncreds_ledger_read(); let (_, delta, timestamp) = ledger.get_rev_reg_delta_json(&rev_reg_id, None, None).await.unwrap(); info!("revoking credential locally"); issuer_credential.revoke_credential_local(&faber.profile).await.unwrap(); diff --git a/aries_vcx_core/src/global/mockdata/mock_settings.rs b/aries_vcx_core/src/global/mockdata/mock_settings.rs index 942a75f539..9050d454c5 100644 --- a/aries_vcx_core/src/global/mockdata/mock_settings.rs +++ b/aries_vcx_core/src/global/mockdata/mock_settings.rs @@ -1,5 +1,5 @@ +use std::collections::HashMap; use std::sync::RwLock; -use std::{collections::HashMap, sync::Mutex}; use crate::errors::error::VcxCoreResult; diff --git a/aries_vcx_core/src/indy/credentials/issuer/mod.rs b/aries_vcx_core/src/indy/credentials/issuer/mod.rs index b52d96a810..8ee22b8b53 100644 --- a/aries_vcx_core/src/indy/credentials/issuer/mod.rs +++ b/aries_vcx_core/src/indy/credentials/issuer/mod.rs @@ -1,6 +1,6 @@ use vdrtools::{CredentialOffer, CredentialRequest, CredentialValues, Locator, RevocationRegistryId}; -use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; +use crate::errors::error::VcxCoreResult; use crate::global::settings; use crate::indy::anoncreds; use crate::indy::utils::parse_and_validate; diff --git a/aries_vcx_core/src/indy/primitives/revocation_registry.rs b/aries_vcx_core/src/indy/primitives/revocation_registry.rs index 2dd6e47840..a6528cee23 100644 --- a/aries_vcx_core/src/indy/primitives/revocation_registry.rs +++ b/aries_vcx_core/src/indy/primitives/revocation_registry.rs @@ -1,17 +1,13 @@ -use std::sync::Arc; - use vdrtools::{DidValue, Locator}; -use crate::anoncreds::base_anoncreds::BaseAnonCreds; -use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; +use crate::errors::error::VcxCoreResult; use crate::global::settings; use crate::indy::anoncreds; use crate::indy::ledger::transactions::{ build_rev_reg_delta_request, build_rev_reg_request, check_response, sign_and_submit_to_ledger, }; use crate::indy::utils::parse_and_validate; -use crate::indy::wallet_non_secrets::{clear_rev_reg_delta, get_rev_reg_delta, set_rev_reg_delta}; -use crate::ledger::base_ledger::BaseLedger; +use crate::indy::wallet_non_secrets::{get_rev_reg_delta, set_rev_reg_delta}; use crate::{PoolHandle, WalletHandle}; pub const BLOB_STORAGE_TYPE: &str = "default"; diff --git a/aries_vcx_core/src/ledger/base_ledger.rs b/aries_vcx_core/src/ledger/base_ledger.rs index 17b2fe442a..49482d7648 100644 --- a/aries_vcx_core/src/ledger/base_ledger.rs +++ b/aries_vcx_core/src/ledger/base_ledger.rs @@ -1,25 +1,20 @@ +use std::fmt::Debug; + use async_trait::async_trait; use crate::errors::error::VcxCoreResult; -/// Trait defining standard 'ledger' related functionality. #[async_trait] -pub trait BaseLedger: std::fmt::Debug + Send + Sync { - // returns request result as JSON - async fn submit_request(&self, request_json: &str) -> VcxCoreResult; - - // endorsers/multi signs a request, submits to ledger, and verifies successful result - async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()>; - - // adds endorser to request and signs with submitter_did, returns the transaction ready for endorser to take - async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult; - - async fn get_txn_author_agreement(&self) -> VcxCoreResult; - - // returns request result as JSON +pub trait IndyLedgerRead: Debug + Send + Sync { + async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult; async fn get_nym(&self, did: &str) -> VcxCoreResult; + async fn get_txn_author_agreement(&self) -> VcxCoreResult; + async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult; + async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult; +} - // returns request result as JSON +#[async_trait] +pub trait IndyLedgerWrite: Debug + Send + Sync { async fn publish_nym( &self, submitter_did: &str, @@ -28,90 +23,34 @@ pub trait BaseLedger: std::fmt::Debug + Send + Sync { data: Option<&str>, role: Option<&str>, ) -> VcxCoreResult; + async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()>; + async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult; +} - // Schema json. - // { - // id: identifier of schema - // attrNames: array of attribute name strings - // name: Schema's name string - // version: Schema's version string - // ver: Version of the Schema json - // } - // if submitter_did provided - use cache - // TO CONSIDER - do we need to return the schema ID in a tuple? is it ever different to the input? +#[async_trait] +pub trait AnoncredsLedgerRead: Debug + Send + Sync { async fn get_schema(&self, schema_id: &str, submitter_did: Option<&str>) -> VcxCoreResult; - - // if submitter_did provided, try use cache - // TO CONSIDER - do we need to return the cred def ID in a tuple? is it ever different to the input? async fn get_cred_def(&self, cred_def_id: &str, submitter_did: Option<&str>) -> VcxCoreResult; - - // returns request result as JSON - async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult; - - // returns request result as JSON - async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult; - - // # Returns - // Revocation Registry Definition Id and Revocation Registry Definition json. - // { - // "id": string - ID of the Revocation Registry, - // "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now), - // "tag": string - Unique descriptive ID of the Registry, - // "credDefId": string - ID of the corresponding CredentialDefinition, - // "value": Registry-specific data { - // "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND), - // "maxCredNum": number - Maximum number of credentials the Registry can serve. - // "tailsHash": string - Hash of tails. - // "tailsLocation": string - Location of tails file. - // "publicKeys": - Registry's public key. - // }, - // "ver": string - version of revocation registry definition json. - // } - // TO CONSIDER - do we need to return the rev reg id in a tuple? is it ever different to the input? async fn get_rev_reg_def_json(&self, rev_reg_id: &str) -> VcxCoreResult; - - // # Returns - // Revocation Registry Definition Id, Revocation Registry Delta json and Timestamp. - // { - // "value": Registry-specific data { - // prevAccum: string - previous accumulator value. - // accum: string - current accumulator value. - // issued: array - an array of issued indices. - // revoked: array an array of revoked indices. - // }, - // "ver": string - version revocation registry delta json - // } async fn get_rev_reg_delta_json( &self, rev_reg_id: &str, from: Option, to: Option, ) -> VcxCoreResult<(String, String, u64)>; - - // # Returns - // Revocation Registry Definition Id, Revocation Registry json and Timestamp. - // { - // "value": Registry-specific data { - // "accum": string - current accumulator value. - // }, - // "ver": string - version revocation registry json - // } async fn get_rev_reg(&self, rev_reg_id: &str, timestamp: u64) -> VcxCoreResult<(String, String, u64)>; +} - // returns request result as JSON - async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult; - +#[async_trait] +pub trait AnoncredsLedgerWrite: Debug + Send + Sync { async fn publish_schema( &self, schema_json: &str, submitter_did: &str, endorser_did: Option, ) -> VcxCoreResult<()>; - async fn publish_cred_def(&self, cred_def_json: &str, submitter_did: &str) -> VcxCoreResult<()>; - async fn publish_rev_reg_def(&self, rev_reg_def: &str, submitter_did: &str) -> VcxCoreResult<()>; - async fn publish_rev_reg_delta( &self, rev_reg_id: &str, diff --git a/aries_vcx_core/src/ledger/indy_ledger.rs b/aries_vcx_core/src/ledger/indy_ledger.rs index ec57c96927..7efaa99c22 100644 --- a/aries_vcx_core/src/ledger/indy_ledger.rs +++ b/aries_vcx_core/src/ledger/indy_ledger.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::errors::error::VcxCoreResult; use crate::{indy, PoolHandle, WalletHandle}; -use super::base_ledger::BaseLedger; +use super::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}; #[derive(Debug)] pub struct IndySdkLedger { @@ -21,34 +21,36 @@ impl IndySdkLedger { } #[async_trait] -impl BaseLedger for IndySdkLedger { - async fn submit_request(&self, request_json: &str) -> VcxCoreResult { - indy::ledger::transactions::libindy_submit_request(self.indy_pool_handle, request_json).await - } - - async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> { - indy::ledger::transactions::endorse_transaction( - self.indy_wallet_handle, - self.indy_pool_handle, - endorser_did, - request_json, - ) - .await +impl IndyLedgerRead for IndySdkLedger { + async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult { + indy::ledger::transactions::get_attr(self.indy_pool_handle, target_did, attr_name).await } - async fn set_endorser(&self, submitter_did: &str, request_json: &str, endorser: &str) -> VcxCoreResult { - indy::ledger::transactions::set_endorser(self.indy_wallet_handle, submitter_did, request_json, endorser).await + async fn get_nym(&self, did: &str) -> VcxCoreResult { + indy::ledger::transactions::get_nym(self.indy_pool_handle, did).await } async fn get_txn_author_agreement(&self) -> VcxCoreResult { indy::ledger::transactions::libindy_get_txn_author_agreement(self.indy_pool_handle).await } - async fn get_nym(&self, did: &str) -> VcxCoreResult { - indy::ledger::transactions::get_nym(self.indy_pool_handle, did).await + async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult { + indy::ledger::transactions::set_endorser(self.indy_wallet_handle, submitter_did, request, endorser).await } - // returns request result as JSON + async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult { + indy::ledger::transactions::get_ledger_txn( + self.indy_wallet_handle, + self.indy_pool_handle, + seq_no, + submitter_did, + ) + .await + } +} + +#[async_trait] +impl IndyLedgerWrite for IndySdkLedger { async fn publish_nym( &self, submitter_did: &str, @@ -71,6 +73,24 @@ impl BaseLedger for IndySdkLedger { .await } + async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> { + indy::ledger::transactions::endorse_transaction( + self.indy_wallet_handle, + self.indy_pool_handle, + endorser_did, + request_json, + ) + .await + } + + async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult { + indy::ledger::transactions::add_attr(self.indy_wallet_handle, self.indy_pool_handle, target_did, attrib_json) + .await + } +} + +#[async_trait] +impl AnoncredsLedgerRead for IndySdkLedger { async fn get_schema(&self, schema_id: &str, submitter_did: Option<&str>) -> VcxCoreResult { if let Some(submitter_did) = submitter_did { // with cache if possible @@ -95,15 +115,6 @@ impl BaseLedger for IndySdkLedger { .map(|(_id, json)| json) } - async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult { - indy::ledger::transactions::get_attr(self.indy_pool_handle, target_did, attr_name).await - } - - async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult { - indy::ledger::transactions::add_attr(self.indy_wallet_handle, self.indy_pool_handle, target_did, attrib_json) - .await - } - async fn get_rev_reg_def_json(&self, rev_reg_id: &str) -> VcxCoreResult { indy::ledger::transactions::get_rev_reg_def_json(self.indy_pool_handle, rev_reg_id) .await @@ -122,17 +133,10 @@ impl BaseLedger for IndySdkLedger { async fn get_rev_reg(&self, rev_reg_id: &str, timestamp: u64) -> VcxCoreResult<(String, String, u64)> { indy::ledger::transactions::get_rev_reg(self.indy_pool_handle, rev_reg_id, timestamp).await } +} - async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult { - indy::ledger::transactions::get_ledger_txn( - self.indy_wallet_handle, - self.indy_pool_handle, - seq_no, - submitter_did, - ) - .await - } - +#[async_trait] +impl AnoncredsLedgerWrite for IndySdkLedger { async fn publish_schema( &self, schema_json: &str, diff --git a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs index 3f2210f2bc..6327337b10 100644 --- a/aries_vcx_core/src/ledger/indy_vdr_ledger.rs +++ b/aries_vcx_core/src/ledger/indy_vdr_ledger.rs @@ -22,7 +22,7 @@ use crate::errors::error::VcxCoreResult; use crate::global::author_agreement::get_txn_author_agreement; use crate::global::settings; -use super::base_ledger::BaseLedger; +use super::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}; use super::request_signer::RequestSigner; use super::request_submitter::RequestSubmitter; use super::response_cacher::ResponseCacher; @@ -223,31 +223,22 @@ where } #[async_trait] -impl BaseLedger for IndyVdrLedger +impl IndyLedgerRead for IndyVdrLedger where T: RequestSubmitter + Send + Sync, U: RequestSigner + Send + Sync, V: ResponseCacher + Send + Sync, { - async fn submit_request(&self, request_json: &str) -> VcxCoreResult { - let request = PreparedRequest::from_request_json(request_json)?; + async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult { + let request = self._build_get_attr_request(None, target_did, attr_name).await?; self._submit_request(request).await } - async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> { - let mut request = PreparedRequest::from_request_json(&request_json)?; - verify_transaction_can_be_endorsed(request_json, endorser_did)?; - let signature_endorser = self._get_request_signature(endorser_did, &request).await?; - request.set_multi_signature(&DidValue::from_str(endorser_did)?, &signature_endorser)?; - self._submit_request(request).await.map(|_| ()) - } + async fn get_nym(&self, did: &str) -> VcxCoreResult { + let dest = DidValue::from_str(did)?; + let request = self.request_builder()?.build_get_nym_request(None, &dest)?; - async fn set_endorser(&self, submitter_did: &str, request_json: &str, endorser: &str) -> VcxCoreResult { - let mut request = PreparedRequest::from_request_json(request_json)?; - request.set_endorser(&DidValue::from_str(endorser)?)?; - let signature_submitter = self._get_request_signature(submitter_did, &request).await?; - request.set_multi_signature(&DidValue::from_str(submitter_did)?, &signature_submitter)?; - Ok(request.req_json.to_string()) + self._submit_request_cached(did, request).await } async fn get_txn_author_agreement(&self) -> VcxCoreResult { @@ -257,19 +248,34 @@ where self._submit_request(request).await } - async fn get_nym(&self, did: &str) -> VcxCoreResult { - let dest = DidValue::from_str(did)?; - let request = self.request_builder()?.build_get_nym_request(None, &dest)?; + async fn set_endorser(&self, submitter_did: &str, request_json: &str, endorser: &str) -> VcxCoreResult { + let mut request = PreparedRequest::from_request_json(request_json)?; + request.set_endorser(&DidValue::from_str(endorser)?)?; + let signature_submitter = self._get_request_signature(submitter_did, &request).await?; + request.set_multi_signature(&DidValue::from_str(submitter_did)?, &signature_submitter)?; + Ok(request.req_json.to_string()) + } - self._submit_request_cached(did, request).await + async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult { + let request = self._build_get_txn_request(submitter_did, seq_no)?; + self._submit_request(request).await } +} +#[async_trait] +#[async_trait] +impl IndyLedgerWrite for IndyVdrLedger +where + T: RequestSubmitter + Send + Sync, + U: RequestSigner + Send + Sync, + V: ResponseCacher + Send + Sync, +{ async fn publish_nym( &self, submitter_did: &str, target_did: &str, verkey: Option<&str>, - alias: Option<&str>, + data: Option<&str>, role: Option<&str>, ) -> VcxCoreResult { let identifier = DidValue::from_str(submitter_did)?; @@ -278,13 +284,56 @@ where &identifier, &dest, verkey.map(String::from), - alias.map(String::from), + data.map(String::from), role.map(String::from), )?; self._sign_and_submit_request(submitter_did, request).await } + async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> { + let mut request = PreparedRequest::from_request_json(&request_json)?; + verify_transaction_can_be_endorsed(request_json, endorser_did)?; + let signature_endorser = self._get_request_signature(endorser_did, &request).await?; + request.set_multi_signature(&DidValue::from_str(endorser_did)?, &signature_endorser)?; + self._submit_request(request).await.map(|_| ()) + } + + async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult { + let request = self._build_attrib_request(target_did, target_did, Some(attrib_json))?; + let request = _append_txn_author_agreement_to_request(request).await?; + self._sign_and_submit_request(target_did, request).await + } +} + +fn current_epoch_time() -> i64 { + OffsetDateTime::now_utc().unix_timestamp() as i64 +} + +async fn _append_txn_author_agreement_to_request(request: PreparedRequest) -> VcxCoreResult { + if let Some(taa) = get_txn_author_agreement()? { + let mut request = request; + let acceptance = TxnAuthrAgrmtAcceptanceData { + mechanism: taa.acceptance_mechanism_type, + // TODO - investigate default digest + taa_digest: taa.taa_digest.map_or(String::from(""), |v| v), + time: taa.time_of_acceptance, + }; + request.set_txn_author_agreement_acceptance(&acceptance)?; + + Ok(request) + } else { + Ok(request) + } +} + +#[async_trait] +impl AnoncredsLedgerRead for IndyVdrLedger +where + T: RequestSubmitter + Send + Sync, + U: RequestSigner + Send + Sync, + V: ResponseCacher + Send + Sync, +{ async fn get_schema(&self, schema_id: &str, _submitter_did: Option<&str>) -> VcxCoreResult { let request = self .request_builder()? @@ -301,19 +350,6 @@ where Ok(serde_json::to_string(&cred_def)?) } - async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult { - let request = self._build_get_attr_request(None, target_did, attr_name).await?; - - self._submit_request(request).await - } - - async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult { - let request = self._build_attrib_request(target_did, target_did, Some(attrib_json))?; - let request = _append_txn_author_agreement_to_request(request).await?; - - self._sign_and_submit_request(target_did, request).await - } - async fn get_rev_reg_def_json(&self, rev_reg_id: &str) -> VcxCoreResult { let id = RevocationRegistryId::from_str(rev_reg_id)?; let request = self.request_builder()?.build_get_revoc_reg_def_request(None, &id)?; @@ -376,12 +412,15 @@ where timestamp, )) } +} - async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult { - let request = self._build_get_txn_request(submitter_did, seq_no)?; - self._submit_request(request).await - } - +#[async_trait] +impl AnoncredsLedgerWrite for IndyVdrLedger +where + T: RequestSubmitter + Send + Sync, + U: RequestSigner + Send + Sync, + V: ResponseCacher + Send + Sync, +{ async fn publish_schema( &self, schema_json: &str, @@ -422,24 +461,3 @@ where self._sign_and_submit_request(submitter_did, request).await.map(|_| ()) } } - -fn current_epoch_time() -> i64 { - OffsetDateTime::now_utc().unix_timestamp() as i64 -} - -async fn _append_txn_author_agreement_to_request(request: PreparedRequest) -> VcxCoreResult { - if let Some(taa) = get_txn_author_agreement()? { - let mut request = request; - let acceptance = TxnAuthrAgrmtAcceptanceData { - mechanism: taa.acceptance_mechanism_type, - // TODO - investigate default digest - taa_digest: taa.taa_digest.map_or(String::from(""), |v| v), - time: taa.time_of_acceptance, - }; - request.set_txn_author_agreement_acceptance(&acceptance)?; - - Ok(request) - } else { - Ok(request) - } -} diff --git a/aries_vcx_core/src/utils/mod.rs b/aries_vcx_core/src/utils/mod.rs index 876ff955e9..af887e822d 100644 --- a/aries_vcx_core/src/utils/mod.rs +++ b/aries_vcx_core/src/utils/mod.rs @@ -1,5 +1,3 @@ -use std::{env, path::PathBuf}; - pub mod async_fn_iterator; pub(crate) mod constants; pub(crate) mod json; diff --git a/did_resolver_sov/src/reader/mod.rs b/did_resolver_sov/src/reader/mod.rs index 605ff78646..7235a638af 100644 --- a/did_resolver_sov/src/reader/mod.rs +++ b/did_resolver_sov/src/reader/mod.rs @@ -5,7 +5,7 @@ pub mod vdr_reader; use std::sync::Arc; -use aries_vcx_core::ledger::base_ledger::BaseLedger; +use aries_vcx_core::ledger::base_ledger::IndyLedgerRead; use async_trait::async_trait; use crate::error::DidSovError; @@ -18,7 +18,7 @@ pub trait AttrReader: Send + Sync { } pub struct ConcreteAttrReader { - ledger: Arc, + ledger: Arc, } #[async_trait] @@ -35,8 +35,8 @@ impl AttrReader for ConcreteAttrReader { } } -impl From> for ConcreteAttrReader { - fn from(ledger: Arc) -> Self { +impl From> for ConcreteAttrReader { + fn from(ledger: Arc) -> Self { Self { ledger } } } diff --git a/did_resolver_sov/tests/resolution.rs b/did_resolver_sov/tests/resolution.rs index 8dfb10bfeb..4f02bef2c9 100644 --- a/did_resolver_sov/tests/resolution.rs +++ b/did_resolver_sov/tests/resolution.rs @@ -30,7 +30,7 @@ async fn write_service_on_ledger_and_resolve_did_doc() { let did = format!("did:sov:{}", init.institution_did); write_test_endpoint(&init.profile, &init.institution_did).await; let resolver = DidSovResolver::new(Arc::::new( - init.profile.inject_ledger().into(), + init.profile.inject_indy_ledger_read().into(), )); let did_doc = resolver .resolve( @@ -50,7 +50,7 @@ async fn test_error_handling_during_resolution() { let did = format!("did:unknownmethod:{}", init.institution_did); let resolver = DidSovResolver::new(Arc::::new( - init.profile.inject_ledger().into(), + init.profile.inject_indy_ledger_read().into(), )); let result = resolver diff --git a/libvcx_core/src/api_vcx/api_global/ledger.rs b/libvcx_core/src/api_vcx/api_global/ledger.rs index 5f69fdc274..823aa9da31 100644 --- a/libvcx_core/src/api_vcx/api_global/ledger.rs +++ b/libvcx_core/src/api_vcx/api_global/ledger.rs @@ -18,13 +18,13 @@ pub async fn endorse_transaction(transaction: &str) -> LibvcxResult<()> { let endorser_did = get_config_value(CONFIG_INSTITUTION_DID)?; let profile = get_main_profile()?; - let ledger = profile.inject_ledger(); + let ledger = profile.inject_indy_ledger_write(); map_ariesvcx_core_result(ledger.endorse_transaction(&endorser_did, transaction).await) } pub async fn get_ledger_txn(seq_no: i32, submitter_did: Option) -> LibvcxResult { let profile = get_main_profile()?; - let ledger = profile.inject_ledger(); + let ledger = profile.inject_indy_ledger_read(); map_ariesvcx_core_result(ledger.get_ledger_txn(seq_no, submitter_did.as_deref()).await) } @@ -94,7 +94,7 @@ pub async fn ledger_clear_attr(target_did: &str, attr: &str) -> LibvcxResult LibvcxResult { let profile = get_main_profile()?; - let ledger = profile.inject_ledger(); + let ledger = profile.inject_indy_ledger_read(); map_ariesvcx_core_result(ledger.get_txn_author_agreement().await) } diff --git a/libvcx_core/src/api_vcx/api_global/pool.rs b/libvcx_core/src/api_vcx/api_global/pool.rs index 3ada2bd53a..69c61be0fd 100644 --- a/libvcx_core/src/api_vcx/api_global/pool.rs +++ b/libvcx_core/src/api_vcx/api_global/pool.rs @@ -1,5 +1,5 @@ use aries_vcx::aries_vcx_core::indy::ledger::pool::{close, create_pool_ledger_config, open_pool_ledger, PoolConfig}; -use aries_vcx::aries_vcx_core::{PoolHandle, INVALID_POOL_HANDLE}; +use aries_vcx::aries_vcx_core::INVALID_POOL_HANDLE; use aries_vcx::global::settings::{indy_mocks_enabled, DEFAULT_POOL_NAME}; use std::sync::RwLock; diff --git a/libvcx_core/src/api_vcx/api_global/profile.rs b/libvcx_core/src/api_vcx/api_global/profile.rs index 444e9e0ac0..ec043078fc 100644 --- a/libvcx_core/src/api_vcx/api_global/profile.rs +++ b/libvcx_core/src/api_vcx/api_global/profile.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::errors::error::LibvcxResult; use aries_vcx::aries_vcx_core::{ wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet}, - PoolHandle, WalletHandle, + WalletHandle, }; use aries_vcx::core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile}; use aries_vcx::{global::settings::indy_mocks_enabled, utils::mockdata::profile::mock_profile::MockProfile}; diff --git a/libvcx_core/src/api_vcx/api_handle/schema.rs b/libvcx_core/src/api_vcx/api_handle/schema.rs index 940c7b3d39..05fd3561f7 100644 --- a/libvcx_core/src/api_vcx/api_handle/schema.rs +++ b/libvcx_core/src/api_vcx/api_handle/schema.rs @@ -1,5 +1,4 @@ use std::string::ToString; -use std::sync::Arc; use serde_json;