Skip to content

Commit

Permalink
anoncreds-rs integration (#1119)
Browse files Browse the repository at this point in the history
* anoncreds-rs integration (#1119)

Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee authored Feb 2, 2024
1 parent e177471 commit 8b77c06
Show file tree
Hide file tree
Showing 27 changed files with 2,041 additions and 35 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ jobs:
- name: "Run aries-vcx integration tests"
run: cargo test --manifest-path="aries/aries_vcx/Cargo.toml" -F vdrtools_wallet,credx -- --ignored;

test-integration-aries-vcx-anoncreds-rs:
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
with:
rust-toolchain-version: ${{ env.RUST_TOOLCHAIN_VERSION }}
default: true
- name: "Run anoncreds-rs integration tests"
run: cargo test --manifest-path="aries/aries_vcx/Cargo.toml" -F anoncreds --test test_revocations --test test_proof_presentation --test test_anoncreds -- --ignored

test-integration-aries-vcx-mysql:
needs: workflow-setup
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -392,8 +406,6 @@ jobs:
- name: "Run integration tests"
run: (cd aries/agents/node/vcxagent-core && AGENCY_URL=http://localhost:8080 npm run test:integration)



##########################################################################################
############################ NPMJS PUBLISHING #######################################

Expand Down
96 changes: 91 additions & 5 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions aries/agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl Agent {
));
let rev_regs = Arc::new(ServiceRevocationRegistries::new(
ledger_write.clone(),
ledger_read.clone(),
anoncreds,
wallet.clone(),
config_issuer.institution_did.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::{
use aries_vcx::common::primitives::revocation_registry::RevocationRegistry;
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::indy_vdr_ledger::DefaultIndyLedgerWrite, wallet::indy::IndySdkWallet,
ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
wallet::indy::IndySdkWallet,
};

use crate::{
Expand All @@ -16,6 +17,7 @@ use crate::{

pub struct ServiceRevocationRegistries {
ledger_write: Arc<DefaultIndyLedgerWrite>,
ledger_read: Arc<DefaultIndyLedgerRead>,
anoncreds: IndyCredxAnonCreds,
wallet: Arc<IndySdkWallet>,
issuer_did: String,
Expand All @@ -25,6 +27,7 @@ pub struct ServiceRevocationRegistries {
impl ServiceRevocationRegistries {
pub fn new(
ledger_write: Arc<DefaultIndyLedgerWrite>,
ledger_read: Arc<DefaultIndyLedgerRead>,
anoncreds: IndyCredxAnonCreds,
wallet: Arc<IndySdkWallet>,
issuer_did: String,
Expand All @@ -33,6 +36,7 @@ impl ServiceRevocationRegistries {
issuer_did,
rev_regs: ObjectCache::new("rev-regs"),
ledger_write,
ledger_read,
anoncreds,
wallet,
}
Expand Down Expand Up @@ -91,7 +95,12 @@ impl ServiceRevocationRegistries {
pub async fn revoke_credential_locally(&self, id: &str, cred_rev_id: &str) -> AgentResult<()> {
let rev_reg = self.rev_regs.get(id)?;
rev_reg
.revoke_credential_local(self.wallet.as_ref(), &self.anoncreds, cred_rev_id)
.revoke_credential_local(
self.wallet.as_ref(),
&self.anoncreds,
self.ledger_read.as_ref(),
cred_rev_id,
)
.await?;
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ credx = [
"test_utils/vdrtools_wallet",
"test_utils/credx"
]
anoncreds = ["aries_vcx_core/anoncreds", "test_utils/anoncreds", "test_utils/vdrtools_wallet"]
vdr_proxy_ledger = [
"aries_vcx_core/vdr_proxy_ledger",
"aries_vcx_core/vdrtools_wallet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl CredentialDef {
wallet,
anoncreds,
&issuer_did,
&schema_id,
&schema_json,
&tag,
None,
Expand Down Expand Up @@ -234,10 +235,12 @@ impl CredentialDef {
}
}

#[allow(clippy::too_many_arguments)]
pub async fn generate_cred_def(
wallet: &impl BaseWallet,
anoncreds: &impl BaseAnonCreds,
issuer_did: &str,
schema_id: &str,
schema_json: &str,
tag: &str,
sig_type: Option<&str>,
Expand All @@ -260,6 +263,7 @@ pub async fn generate_cred_def(
.issuer_create_and_store_credential_def(
wallet,
issuer_did,
schema_id,
schema_json,
tag,
sig_type,
Expand Down
33 changes: 23 additions & 10 deletions aries/aries_vcx/src/common/primitives/revocation_registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds, errors::error::AriesVcxCoreErrorKind,
ledger::base_ledger::AnoncredsLedgerWrite, wallet::base_wallet::BaseWallet,
anoncreds::base_anoncreds::BaseAnonCreds,
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind},
ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite},
wallet::base_wallet::BaseWallet,
};

use super::credential_definition::PublicEntityStateType;
Expand Down Expand Up @@ -115,9 +117,9 @@ impl RevocationRegistry {
.publish_rev_reg_def(wallet, &json!(self.rev_reg_def).to_string(), issuer_did)
.await
.map_err(|err| {
err.map(
AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::InvalidState,
"Cannot publish revocation registry definition",
format!("Cannot publish revocation registry definition; {err}"),
)
})?;
self.rev_reg_def_state = PublicEntityStateType::Published;
Expand All @@ -139,9 +141,9 @@ impl RevocationRegistry {
.publish_rev_reg_delta(wallet, &self.rev_reg_id, &self.rev_reg_entry, issuer_did)
.await
.map_err(|err| {
err.map(
AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::InvalidRevocationEntry,
"Cannot post RevocationEntry",
format!("Cannot publish revocation entry; {err}"),
)
})?;
self.rev_reg_delta_state = PublicEntityStateType::Published;
Expand Down Expand Up @@ -216,10 +218,21 @@ impl RevocationRegistry {
&self,
wallet: &impl BaseWallet,
anoncreds: &impl BaseAnonCreds,
ledger: &impl AnoncredsLedgerRead,
cred_rev_id: &str,
) -> VcxResult<()> {
let rev_reg_delta_json = ledger
.get_rev_reg_delta_json(&self.rev_reg_id, None, None)
.await?
.1;
anoncreds
.revoke_credential_local(wallet, &self.tails_dir, &self.rev_reg_id, cred_rev_id)
.revoke_credential_local(
wallet,
&self.tails_dir,
&self.rev_reg_id,
&rev_reg_delta_json,
cred_rev_id,
)
.await
.map_err(|err| err.into())
}
Expand Down Expand Up @@ -280,7 +293,7 @@ impl RevocationRegistry {
#[derive(Clone, Deserialize, Debug, Serialize, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct RevocationRegistryDefinitionValue {
pub issuance_type: String,
pub issuance_type: String, // FILL IN
pub max_cred_num: u32,
pub public_keys: serde_json::Value,
pub tails_hash: String,
Expand All @@ -290,12 +303,12 @@ pub struct RevocationRegistryDefinitionValue {
#[derive(Clone, Deserialize, Debug, Serialize, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct RevocationRegistryDefinition {
pub id: String,
pub id: String, // FILL IN
pub revoc_def_type: String,
pub tag: String,
pub cred_def_id: String,
pub value: RevocationRegistryDefinitionValue,
pub ver: String,
pub ver: String, // FILL IN
}
pub async fn generate_rev_reg(
wallet: &impl BaseWallet,
Expand Down
5 changes: 4 additions & 1 deletion aries/aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub async fn build_schemas_json_prover(
.get_schema(&cred_info.schema_id, None)
.await
.map_err(|err| {
err.map(AriesVcxCoreErrorKind::InvalidSchema, "Cannot get schema")
AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidSchema,
format!("Cannot get schema id {}; {}", cred_info.schema_id, err),
)
})?;

let schema_json = serde_json::from_str(&schema_json).map_err(|err| {
Expand Down
Loading

0 comments on commit 8b77c06

Please sign in to comment.