Skip to content

Commit

Permalink
Replace trait objects in libvcx_core with generics/concrete types (#1011
Browse files Browse the repository at this point in the history
)

* Replaced trait objects in libvcx_core with generics/concrete types

* Remove obsolete feature flags due to vdrtools usage removal

---------

Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur authored Oct 5, 2023
1 parent 59938d7 commit 603a26c
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 1,043 deletions.
62 changes: 2 additions & 60 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,52 +160,6 @@ jobs:
env:
RUSTFLAGS: -D warnings

libvcx_core_clippy:
runs-on: ubuntu-20.04
strategy:
matrix:
backend: ["anoncreds_credx", "anoncreds_vdrtools"]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSON }}
components: clippy
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy -p libvcx_core --features ${{ matrix.backend }}
env:
RUSTFLAGS: -D warnings

node_wrapper_clippy:
runs-on: ubuntu-20.04
strategy:
matrix:
backend: ["anoncreds_credx", "anoncreds_vdrtools"]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSON }}
components: clippy
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy -p vcx-napi-rs --features ${{ matrix.backend }}
env:
RUSTFLAGS: -D warnings

##########################################################################################
############################## DOCKER BUILD ##########################################

Expand Down Expand Up @@ -306,12 +260,6 @@ jobs:
test-unit-workspace:
needs: workflow-setup
runs-on: ubuntu-20.04
strategy:
matrix:
features: [
"anoncreds_vdrtools",
"anoncreds_credx",
]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
Expand All @@ -321,7 +269,7 @@ jobs:
rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSON }}
skip-docker-setup: true
- name: "Run workspace unit tests"
run: RUST_TEST_THREADS=1 cargo test --workspace --lib --exclude aries-vcx-agent --exclude libvdrtools --exclude wallet_migrator --features ${{ matrix.features }}
run: RUST_TEST_THREADS=1 cargo test --workspace --lib --exclude aries-vcx-agent --exclude libvdrtools --exclude wallet_migrator

test-integration-aries-vcx:
needs: workflow-setup
Expand Down Expand Up @@ -406,12 +354,6 @@ jobs:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
runs-on: ubuntu-20.04
strategy:
matrix:
features: [
"anoncreds_vdrtools",
"anoncreds_credx"
]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
Expand All @@ -421,7 +363,7 @@ jobs:
rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSON }}
- name: "Run libvcx_core integration tests"
run: |
RUST_TEST_THREADS=1 cargo test --features ${{ matrix.features }} --manifest-path="libvcx_core/Cargo.toml" -- --include-ignored;
RUST_TEST_THREADS=1 cargo test --manifest-path="libvcx_core/Cargo.toml" -- --include-ignored;
test-integration-did-crate:
needs: workflow-setup
Expand Down
4 changes: 1 addition & 3 deletions aries_vcx/src/common/primitives/credential_definition.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds,
errors::error::AriesVcxCoreErrorKind,
Expand Down Expand Up @@ -219,7 +217,7 @@ impl CredentialDef {
self.source_id = source_id;
}

pub async fn update_state(&mut self, ledger: &Arc<dyn AnoncredsLedgerRead>) -> VcxResult<u32> {
pub async fn update_state(&mut self, ledger: &impl AnoncredsLedgerRead) -> VcxResult<u32> {
if (ledger.get_cred_def(&self.id, None).await).is_ok() {
self.state = PublicEntityStateType::Published
}
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/common/primitives/credential_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Schema {
.map_err(|err: AriesVcxError| err.extend("Cannot deserialize Schema"))
}

pub async fn update_state(&mut self, ledger: &Arc<dyn AnoncredsLedgerRead>) -> VcxResult<u32> {
pub async fn update_state(&mut self, ledger: &impl AnoncredsLedgerRead) -> VcxResult<u32> {
if ledger.get_schema(&self.schema_id, None).await.is_ok() {
self.state = PublicEntityStateType::Published
}
Expand Down
4 changes: 1 addition & 3 deletions aries_vcx/src/handlers/issuance/holder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::AnoncredsLedgerRead,
wallet::base_wallet::BaseWallet,
Expand Down Expand Up @@ -215,7 +213,7 @@ impl Holder {
self.holder_sm.is_revoked(ledger, anoncreds).await
}

pub async fn delete_credential(&self, anoncreds: &Arc<dyn BaseAnonCreds>) -> VcxResult<()> {
pub async fn delete_credential(&self, anoncreds: &impl BaseAnonCreds) -> VcxResult<()> {
self.holder_sm.delete_credential(anoncreds).await
}

Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/src/protocols/issuance/holder/state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt, sync::Arc};
use std::fmt;

use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::AnoncredsLedgerRead,
Expand Down Expand Up @@ -450,7 +450,7 @@ impl HolderSM {
}
}

pub async fn delete_credential(&self, anoncreds: &Arc<dyn BaseAnonCreds>) -> VcxResult<()> {
pub async fn delete_credential(&self, anoncreds: &impl BaseAnonCreds) -> VcxResult<()> {
trace!("Holder::delete_credential");

match self.state {
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/utils/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::errors::error::prelude::*;

pub async fn provision_cloud_agent(
client: &mut AgencyClient,
wallet: Arc<dyn BaseWallet>,
wallet: Arc<impl BaseWallet + 'static>,
provision_config: &AgentProvisionConfig,
) -> VcxResult<AgencyClientConfig> {
let seed = provision_config.agent_seed.as_deref();
Expand Down
224 changes: 0 additions & 224 deletions aries_vcx_core/src/anoncreds/base_anoncreds.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use async_trait::async_trait;

use crate::errors::error::VcxCoreResult;
Expand Down Expand Up @@ -120,225 +118,3 @@ pub trait BaseAnonCreds: std::fmt::Debug + Send + Sync {

async fn generate_nonce(&self) -> VcxCoreResult<String>;
}

/// TODO: Workaround to keep some bits and pieces (like libvcx) working with Arcs. Delete ASAP and
/// wash your hands after.
#[async_trait]
impl<T> BaseAnonCreds for Arc<T>
where
T: BaseAnonCreds + ?Sized,
{
async fn verifier_verify_proof(
&self,
proof_request_json: &str,
proof_json: &str,
schemas_json: &str,
credential_defs_json: &str,
rev_reg_defs_json: &str,
rev_regs_json: &str,
) -> VcxCoreResult<bool> {
(**self)
.verifier_verify_proof(
proof_request_json,
proof_json,
schemas_json,
credential_defs_json,
rev_reg_defs_json,
rev_regs_json,
)
.await
}

async fn issuer_create_and_store_revoc_reg(
&self,
issuer_did: &str,
cred_def_id: &str,
tails_dir: &str,
max_creds: u32,
tag: &str,
) -> VcxCoreResult<(String, String, String)> {
(**self)
.issuer_create_and_store_revoc_reg(issuer_did, cred_def_id, tails_dir, max_creds, tag)
.await
}

async fn issuer_create_and_store_credential_def(
&self,
issuer_did: &str,
schema_json: &str,
tag: &str,
signature_type: Option<&str>,
config_json: &str,
) -> VcxCoreResult<(String, String)> {
(**self)
.issuer_create_and_store_credential_def(
issuer_did,
schema_json,
tag,
signature_type,
config_json,
)
.await
}

async fn issuer_create_credential_offer(&self, cred_def_id: &str) -> VcxCoreResult<String> {
(**self).issuer_create_credential_offer(cred_def_id).await
}

async fn issuer_create_credential(
&self,
cred_offer_json: &str,
cred_req_json: &str,
cred_values_json: &str,
rev_reg_id: Option<String>,
tails_dir: Option<String>,
) -> VcxCoreResult<(String, Option<String>, Option<String>)> {
(**self)
.issuer_create_credential(
cred_offer_json,
cred_req_json,
cred_values_json,
rev_reg_id,
tails_dir,
)
.await
}

async fn prover_create_proof(
&self,
proof_req_json: &str,
requested_credentials_json: &str,
master_secret_id: &str,
schemas_json: &str,
credential_defs_json: &str,
revoc_states_json: Option<&str>,
) -> VcxCoreResult<String> {
(**self)
.prover_create_proof(
proof_req_json,
requested_credentials_json,
master_secret_id,
schemas_json,
credential_defs_json,
revoc_states_json,
)
.await
}

async fn prover_get_credential(&self, cred_id: &str) -> VcxCoreResult<String> {
(**self).prover_get_credential(cred_id).await
}

async fn prover_get_credentials(&self, filter_json: Option<&str>) -> VcxCoreResult<String> {
(**self).prover_get_credentials(filter_json).await
}

async fn prover_get_credentials_for_proof_req(
&self,
proof_request_json: &str,
) -> VcxCoreResult<String> {
(**self)
.prover_get_credentials_for_proof_req(proof_request_json)
.await
}

async fn prover_create_credential_req(
&self,
prover_did: &str,
cred_offer_json: &str,
cred_def_json: &str,
master_secret_id: &str,
) -> VcxCoreResult<(String, String)> {
(**self)
.prover_create_credential_req(
prover_did,
cred_offer_json,
cred_def_json,
master_secret_id,
)
.await
}

async fn create_revocation_state(
&self,
tails_dir: &str,
rev_reg_def_json: &str,
rev_reg_delta_json: &str,
timestamp: u64,
cred_rev_id: &str,
) -> VcxCoreResult<String> {
(**self)
.create_revocation_state(
tails_dir,
rev_reg_def_json,
rev_reg_delta_json,
timestamp,
cred_rev_id,
)
.await
}

async fn prover_store_credential(
&self,
cred_id: Option<&str>,
cred_req_metadata_json: &str,
cred_json: &str,
cred_def_json: &str,
rev_reg_def_json: Option<&str>,
) -> VcxCoreResult<String> {
(**self)
.prover_store_credential(
cred_id,
cred_req_metadata_json,
cred_json,
cred_def_json,
rev_reg_def_json,
)
.await
}

async fn prover_delete_credential(&self, cred_id: &str) -> VcxCoreResult<()> {
(**self).prover_delete_credential(cred_id).await
}

async fn prover_create_link_secret(&self, link_secret_id: &str) -> VcxCoreResult<String> {
(**self).prover_create_link_secret(link_secret_id).await
}

async fn issuer_create_schema(
&self,
issuer_did: &str,
name: &str,
version: &str,
attrs: &str,
) -> VcxCoreResult<(String, String)> {
(**self)
.issuer_create_schema(issuer_did, name, version, attrs)
.await
}

// TODO - FUTURE - think about moving this to somewhere else, as it aggregates other calls (not
// PURE Anoncreds)
async fn revoke_credential_local(
&self,
tails_dir: &str,
rev_reg_id: &str,
cred_rev_id: &str,
) -> VcxCoreResult<()> {
(**self)
.revoke_credential_local(tails_dir, rev_reg_id, cred_rev_id)
.await
}

async fn get_rev_reg_delta(&self, rev_reg_id: &str) -> VcxCoreResult<Option<String>> {
(**self).get_rev_reg_delta(rev_reg_id).await
}

async fn clear_rev_reg_delta(&self, rev_reg_id: &str) -> VcxCoreResult<()> {
(**self).clear_rev_reg_delta(rev_reg_id).await
}

async fn generate_nonce(&self) -> VcxCoreResult<String> {
(**self).generate_nonce().await
}
}
Loading

0 comments on commit 603a26c

Please sign in to comment.