Skip to content

Commit

Permalink
Merge branch 'main' into refactor/base_wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
tech-bash authored May 31, 2023
2 parents 339c045 + 1222ef7 commit ed38d6a
Show file tree
Hide file tree
Showing 66 changed files with 1,540 additions and 979 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup-codecov-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ inputs:
runs:
using: "composite"
steps:
- name: Install latest nightly
- name: Install nightly 1.71
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: nightly-2023-05-08
override: true
- uses: Swatinem/rust-cache@v2
- name: "Install dependencies"
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ jobs:
run: |
cd libvcx && cargo clippy
check-did-resolver-feature-variants:
runs-on: ubuntu-20.04
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.65.0
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify aries_vcx compiles with different dependency feature variants"
run: |
cd did_resolver_sov
cargo check
cargo check --features vdrtools --no-default-features
cargo check --features modular_libs --no-default-features
check-aries-vcx-feature-variants:
runs-on: ubuntu-20.04
steps:
Expand All @@ -176,6 +196,7 @@ jobs:
cargo check --features vdrtools --no-default-features
cargo check --features modular_libs --no-default-features
cargo check --features vdr_proxy_ledger --no-default-features
cargo check --features mixed_breed
##########################################################################################
############################## DOCKER BUILD ##########################################
Expand Down Expand Up @@ -480,6 +501,17 @@ jobs:
- name: "Run aries-vcx tests: vdrproxy_test"
run: cargo test --manifest-path="aries_vcx/Cargo.toml" -F vdr_proxy_ledger -- --ignored

test-integration-aries-vcx-mixed-breed:
needs: workflow-setup
runs-on: ubuntu-20.04
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- name: "Setup rust testing environment"
uses: ./.github/actions/setup-testing-rust
- name: "Run aries-vcx tests: pool_tests agency_pool_tests"
run: RUST_TEST_THREADS=1 cargo test --manifest-path="aries_vcx/Cargo.toml" -F mixed_breed -- --include-ignored;

test-integration-libvcx:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
Expand Down
25 changes: 13 additions & 12 deletions agents/rust/aries-vcx-agent/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::storage::object_cache::ObjectCache;
use crate::storage::Storage;
use aries_vcx::core::profile::profile::Profile;
use aries_vcx::handlers::proof_presentation::prover::Prover;
use aries_vcx::handlers::proof_presentation::types::SelectedCredentials;
use aries_vcx::handlers::util::PresentationProposalData;
use aries_vcx::messages::msg_fields::protocols::present_proof::ack::AckPresentation;
use aries_vcx::messages::msg_fields::protocols::present_proof::request::RequestPresentation;
Expand Down Expand Up @@ -57,23 +58,23 @@ impl ServiceProver {
Ok(connection_id)
}

async fn get_credentials_for_presentation(&self, prover: &Prover, tails_dir: Option<&str>) -> AgentResult<String> {
async fn get_credentials_for_presentation(
&self,
prover: &Prover,
tails_dir: Option<&str>,
) -> AgentResult<SelectedCredentials> {
let credentials = prover.retrieve_credentials(&self.profile).await?;
let credentials: HashMap<String, Value> = serde_json::from_str(&credentials).unwrap();

let mut res_credentials = json!({});
let mut res_credentials = SelectedCredentials::default();

for (key, val) in credentials["attrs"].as_object().unwrap().iter() {
let cred_array = val.as_array().unwrap();
for (referent, cred_array) in credentials.credentials_by_referent.into_iter() {
if !cred_array.is_empty() {
let first_cred = &cred_array[0];
res_credentials["attrs"][key]["credential"] = first_cred.clone();
if let Some(tails_dir) = tails_dir {
res_credentials["attrs"][key]["tails_file"] = Value::from(tails_dir);
}
let first_cred = cred_array[0].clone();
let tails_dir = tails_dir.map(|x| x.to_owned());
res_credentials.select_credential_for_referent_from_retrieved(referent, first_cred, tails_dir);
}
}
Ok(res_credentials.to_string())
Ok(res_credentials)
}

pub fn create_from_request(&self, connection_id: &str, request: RequestPresentation) -> AgentResult<String> {
Expand Down Expand Up @@ -117,7 +118,7 @@ impl ServiceProver {
let connection = self.service_connections.get_by_id(&connection_id)?;
let credentials = self.get_credentials_for_presentation(&prover, tails_dir).await?;
prover
.generate_presentation(&self.profile, credentials, "{}".to_string())
.generate_presentation(&self.profile, credentials, HashMap::new())
.await?;

let wallet = self.profile.inject_wallet();
Expand Down
2 changes: 1 addition & 1 deletion agents/rust/aries-vcx-agent/src/services/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ServiceSchemas {
}

pub async fn schema_json(&self, thread_id: &str) -> AgentResult<String> {
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?)
}

Expand Down
3 changes: 3 additions & 0 deletions aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ modular_libs = ["aries_vcx_core/modular_libs"]
# TODO: Remove using "vdrtools" feature flag for vdr_proxy_ledger once IndyCredxAnonCreds
# is fully implemented
vdr_proxy_ledger = ["aries_vcx_core/vdr_proxy_ledger", "vdrtools"]
# Temporary feature used for testing the full credx anoncreds impl
# using vdrtools ledger and wallet.
mixed_breed = ["vdrtools", "modular_libs"]

[dependencies]
agency_client = { path = "../agency_client" }
Expand Down
10 changes: 4 additions & 6 deletions aries_vcx/src/common/anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod integration_tests {

use crate::common::test_utils::create_and_store_credential;
use crate::utils::constants::TAILS_DIR;
use crate::utils::devsetup::{init_holder_setup_in_indy_context, SetupProfile};
use crate::utils::devsetup::SetupProfile;
use crate::utils::get_temp_dir_path;

#[tokio::test]
Expand Down Expand Up @@ -60,18 +60,16 @@ pub mod integration_tests {
#[tokio::test]
#[ignore]
async fn test_pool_revoke_credential() {
SetupProfile::run_indy(|setup| async move {
let holder_setup = init_holder_setup_in_indy_context(&setup).await;

SetupProfile::run(|setup| async move {
let (_, _, _, _, _, _, _, _, rev_reg_id, cred_rev_id, _, rev_reg) = create_and_store_credential(
&setup.profile,
&holder_setup.profile,
&setup.profile,
&setup.institution_did,
crate::utils::constants::DEFAULT_SCHEMA_ATTRS,
)
.await;

let ledger = Arc::clone(&holder_setup.profile).inject_ledger();
let ledger = Arc::clone(&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();
Expand Down
28 changes: 11 additions & 17 deletions aries_vcx/src/common/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ mod integration_tests {

use crate::common::test_utils::create_and_store_credential;
use crate::utils::constants::DEFAULT_SCHEMA_ATTRS;
use crate::utils::devsetup::{init_holder_setup_in_indy_context, SetupProfile};
use crate::utils::devsetup::SetupProfile;

#[tokio::test]
#[ignore]
async fn test_pool_prover_get_credential() {
SetupProfile::run_indy(|setup| async move {
let holder_setup = init_holder_setup_in_indy_context(&setup).await;

SetupProfile::run(|setup| async move {
let res = create_and_store_credential(
&setup.profile,
&holder_setup.profile,
&setup.profile,
&setup.institution_did,
DEFAULT_SCHEMA_ATTRS,
)
Expand All @@ -69,7 +67,7 @@ mod integration_tests {
let rev_reg_id = res.8;
let cred_rev_id = res.9;

let anoncreds = Arc::clone(&holder_setup.profile).inject_anoncreds();
let anoncreds = Arc::clone(&setup.profile).inject_anoncreds();

let cred_json = anoncreds.prover_get_credential(&cred_id).await.unwrap();
let prover_cred = serde_json::from_str::<ProverCredential>(&cred_json).unwrap();
Expand All @@ -85,20 +83,18 @@ mod integration_tests {
#[tokio::test]
#[ignore]
async fn test_pool_get_cred_rev_id() {
SetupProfile::run_indy(|setup| async move {
let holder_setup = init_holder_setup_in_indy_context(&setup).await;

SetupProfile::run(|setup| async move {
let res = create_and_store_credential(
&setup.profile,
&holder_setup.profile,
&setup.profile,
&setup.institution_did,
DEFAULT_SCHEMA_ATTRS,
)
.await;
let cred_id = res.7;
let cred_rev_id = res.9;

let cred_rev_id_ = get_cred_rev_id(&holder_setup.profile, &cred_id).await.unwrap();
let cred_rev_id_ = get_cred_rev_id(&setup.profile, &cred_id).await.unwrap();

assert_eq!(cred_rev_id, cred_rev_id_.to_string());
})
Expand All @@ -108,12 +104,10 @@ mod integration_tests {
#[tokio::test]
#[ignore]
async fn test_pool_is_cred_revoked() {
SetupProfile::run_indy(|setup| async move {
let holder_setup = init_holder_setup_in_indy_context(&setup).await;

SetupProfile::run(|setup| async move {
let res = create_and_store_credential(
&setup.profile,
&holder_setup.profile,
&setup.profile,
&setup.institution_did,
DEFAULT_SCHEMA_ATTRS,
)
Expand All @@ -123,7 +117,7 @@ mod integration_tests {
let tails_file = res.10;
let rev_reg = res.11;

assert!(!is_cred_revoked(&holder_setup.profile, &rev_reg_id, &cred_rev_id)
assert!(!is_cred_revoked(&setup.profile, &rev_reg_id, &cred_rev_id)
.await
.unwrap());

Expand All @@ -140,7 +134,7 @@ mod integration_tests {

std::thread::sleep(std::time::Duration::from_millis(500));

assert!(is_cred_revoked(&holder_setup.profile, &rev_reg_id, &cred_rev_id)
assert!(is_cred_revoked(&setup.profile, &rev_reg_id, &cred_rev_id)
.await
.unwrap());
})
Expand Down
26 changes: 15 additions & 11 deletions aries_vcx/src/common/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::core::profile::profile::Profile;
use crate::errors::error::prelude::*;

pub async fn rotate_verkey_apply(profile: &Arc<dyn Profile>, 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?;

Expand Down Expand Up @@ -41,7 +41,7 @@ pub async fn rotate_verkey(profile: &Arc<dyn Profile>, did: &str) -> VcxResult<(
}

pub async fn get_verkey_from_ledger(profile: &Arc<dyn Profile>, did: &str) -> VcxResult<String> {
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| {
Expand Down Expand Up @@ -75,18 +75,22 @@ pub async fn get_verkey_from_ledger(profile: &Arc<dyn Profile>, 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"))]
#[cfg(all(
not(feature = "vdr_proxy_ledger"),
not(feature = "modular_libs"),
not(feature = "mixed_breed")
))]
async fn test_pool_rotate_verkey_fails() {
SetupProfile::run_indy(|setup| async move {
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(|setup| async move {
enable_pool_mocks();

PoolMocks::set_next_pool_response(mockdata_pool::RESPONSE_REQNACK);
Expand Down
16 changes: 8 additions & 8 deletions aries_vcx/src/common/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -190,7 +190,7 @@ pub async fn get_service(profile: &Arc<dyn Profile>, 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() {
Expand All @@ -207,7 +207,7 @@ pub async fn get_service(profile: &Arc<dyn Profile>, did: &String) -> VcxResult<
}

pub async fn parse_legacy_endpoint_attrib(profile: &Arc<dyn Profile>, did_raw: &str) -> VcxResult<AriesService> {
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() {
Expand All @@ -227,28 +227,28 @@ pub async fn parse_legacy_endpoint_attrib(profile: &Arc<dyn Profile>, did_raw: &

pub async fn write_endpoint_legacy(profile: &Arc<dyn Profile>, did: &str, service: &AriesService) -> VcxResult<String> {
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)
}

pub async fn write_endpoint(profile: &Arc<dyn Profile>, did: &str, service: &EndpointDidSov) -> VcxResult<String> {
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<dyn Profile>, 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<dyn Profile>, did: &str, attr_name: &str) -> VcxResult<String> {
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) {
Expand All @@ -259,7 +259,7 @@ pub async fn get_attr(profile: &Arc<dyn Profile>, did: &str, attr_name: &str) ->
}

pub async fn clear_attr(profile: &Arc<dyn Profile>, did: &str, attr_name: &str) -> VcxResult<String> {
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())
Expand Down
Loading

0 comments on commit ed38d6a

Please sign in to comment.