Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Feature/anoncreds rs #902

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ jobs:
- 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-aries-vcx-anoncreds:
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 anoncreds -- --include-ignored;

test-integration-aries-vcx-migration:
needs: workflow-setup
runs-on: ubuntu-20.04
Expand Down
65 changes: 65 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ vdr_proxy_ledger = ["aries_vcx_core/vdr_proxy_ledger", "vdrtools"]
mixed_breed = ["vdrtools", "modular_libs"]
# Used for testing the migrator
migration = ["vdrtools", "modular_libs"]
# Feature flag to include the `anoncreds-rs` dependency library
anoncreds = ["modular_libs", "aries_vcx_core/anoncreds"]

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

let ledger = Arc::clone(&setup.profile).inject_anoncreds_ledger_read();

let (_, first_rev_reg_delta, first_timestamp) =
let (_, _, first_rev_reg_delta, first_timestamp) =
ledger.get_rev_reg_delta_json(&rev_reg_id, None, None).await.unwrap();

let (_, test_same_delta, test_same_timestamp) =
let (_, _, test_same_delta, test_same_timestamp) =
ledger.get_rev_reg_delta_json(&rev_reg_id, None, None).await.unwrap();

assert_eq!(first_rev_reg_delta, test_same_delta);
Expand All @@ -103,7 +103,7 @@ pub mod integration_tests {
.unwrap();

// Delta should change after revocation
let (_, second_rev_reg_delta, _) = ledger
let (_, _, second_rev_reg_delta, _) = ledger
.get_rev_reg_delta_json(&rev_reg_id, Some(first_timestamp + 1), None)
.await
.unwrap();
Expand Down
12 changes: 10 additions & 2 deletions aries_vcx/src/common/primitives/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl CredentialDef {
let (cred_def_id, cred_def_json) = generate_cred_def(
anoncreds,
&issuer_did,
&schema_id,
&schema_json,
&tag,
None,
Expand Down Expand Up @@ -258,6 +259,7 @@ impl CredentialDef {
pub async fn generate_cred_def(
anoncreds: &Arc<dyn BaseAnonCreds>,
issuer_did: &str,
schema_id: &str,
schema_json: &str,
tag: &str,
sig_type: Option<&str>,
Expand All @@ -278,7 +280,7 @@ pub async fn generate_cred_def(
let config_json = json!({"support_revocation": support_revocation.unwrap_or(false)}).to_string();

anoncreds
.issuer_create_and_store_credential_def(issuer_did, schema_json, tag, sig_type, &config_json)
.issuer_create_and_store_credential_def(issuer_did, schema_id, schema_json, tag, sig_type, &config_json)
.await
.map_err(|err| err.into())
}
Expand Down Expand Up @@ -314,6 +316,7 @@ pub mod integration_tests {
let (cred_def_id, cred_def_json_local) = generate_cred_def(
&setup.profile.inject_anoncreds(),
&setup.institution_did,
&schema_id,
&schema_json,
"tag_1",
None,
Expand Down Expand Up @@ -358,6 +361,7 @@ pub mod integration_tests {
let (cred_def_id, cred_def_json) = generate_cred_def(
&setup.profile.inject_anoncreds(),
&setup.institution_did,
&schema_id,
&schema_json,
"tag_1",
None,
Expand All @@ -384,7 +388,11 @@ pub mod integration_tests {
.await
.unwrap();
ledger_write
.publish_rev_reg_def(&json!(rev_reg_def_json).to_string(), &setup.institution_did)
.publish_rev_reg_def(
&rev_reg_def_id,
&json!(rev_reg_def_json).to_string(),
&setup.institution_did,
)
.await
.unwrap();
ledger_write
Expand Down
3 changes: 2 additions & 1 deletion aries_vcx/src/common/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ pub mod integration_tests {
.await;

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();
let (id, _issuer_did, _delta, _timestamp) =
ledger.get_rev_reg_delta_json(&rev_reg_id, None, None).await.unwrap();

assert_eq!(id, rev_reg_id);
})
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/common/primitives/revocation_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl RevocationRegistry {
);
self.rev_reg_def.value.tails_location = String::from(tails_url);
ledger
.publish_rev_reg_def(&json!(self.rev_reg_def).to_string(), issuer_did)
.publish_rev_reg_def(&self.rev_reg_id, &json!(self.rev_reg_def).to_string(), issuer_did)
.await
.map_err(|err| {
err.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl RevocationRegistryDelta {
from: Option<u64>,
to: Option<u64>,
) -> VcxResult<Self> {
let (_, rev_reg_delta_json, _) = ledger.get_rev_reg_delta_json(rev_reg_id, from, to).await?;
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(
AriesVcxErrorKind::SerializationError,
Expand Down
3 changes: 2 additions & 1 deletion aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ pub async fn build_rev_states_json(

let rev_reg_def_json = ledger_read.get_rev_reg_def_json(rev_reg_id).await?;

let (rev_reg_id, rev_reg_delta_json, timestamp) =
let (rev_reg_id, issuer_did, rev_reg_delta_json, timestamp) =
ledger_read.get_rev_reg_delta_json(rev_reg_id, from, to).await?;

let rev_state_json = anoncreds
.create_revocation_state(
&issuer_did,
tails_file,
&rev_reg_def_json,
&rev_reg_delta_json,
Expand Down
8 changes: 4 additions & 4 deletions aries_vcx/src/common/proofs/verifier/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use aries_vcx_core::ledger::base_ledger::AnoncredsLedgerRead;
use std::sync::Arc;

use crate::common::proofs::verifier::verifier_internal::{
build_cred_defs_json_verifier, build_rev_reg_defs_json, build_rev_reg_json, build_schemas_json_verifier,
build_cred_defs_json_verifier, build_rev_reg_defs_json, build_rev_reg_delta_json, build_schemas_json_verifier,
get_credential_info, validate_proof_revealed_attributes,
};
use crate::errors::error::prelude::*;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub async fn validate_indy_proof(
let rev_reg_defs_json = build_rev_reg_defs_json(ledger, &credential_data)
.await
.unwrap_or(json!({}).to_string());
let rev_regs_json = build_rev_reg_json(ledger, &credential_data)
let rev_regs_delta_json = build_rev_reg_delta_json(ledger, &credential_data)
.await
.unwrap_or(json!({}).to_string());

Expand All @@ -40,15 +40,15 @@ pub async fn validate_indy_proof(
debug!("*******\n{}\n********", proof_json);
debug!("*******\n{}\n********", proof_req_json);
debug!("*******\n{}\n********", rev_reg_defs_json);
debug!("*******\n{}\n********", rev_regs_json);
debug!("*******\n{}\n********", rev_regs_delta_json);
anoncreds
.verifier_verify_proof(
proof_req_json,
proof_json,
&schemas_json,
&credential_defs_json,
&rev_reg_defs_json,
&rev_regs_json,
&rev_regs_delta_json,
)
.await
.map_err(|err| err.into())
Expand Down
28 changes: 18 additions & 10 deletions aries_vcx/src/common/proofs/verifier/verifier_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub async fn build_rev_reg_defs_json(
Ok(rev_reg_defs_json.to_string())
}

pub async fn build_rev_reg_json(
pub async fn build_rev_reg_delta_json(
ledger: &Arc<dyn AnoncredsLedgerRead>,
credential_data: &[CredInfoVerifier],
) -> VcxResult<String> {
Expand All @@ -192,19 +192,26 @@ pub async fn build_rev_reg_json(
format!("Missing rev_reg_id in the record {:?}", cred_info),
))?;

let timestamp = cred_info.timestamp.as_ref().ok_or(AriesVcxError::from_msg(
let timestamp = cred_info.timestamp.ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidRevocationTimestamp,
format!("Revocation timestamp is missing on record {:?}", cred_info),
))?;

if rev_regs_json.get(rev_reg_id).is_none() {
let (id, rev_reg_json, timestamp) = ledger.get_rev_reg(rev_reg_id, timestamp.to_owned()).await?;
let rev_reg_json: Value = serde_json::from_str(&rev_reg_json).or(Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
format!("Failed to deserialize as json: {}", rev_reg_json),
)))?;
let rev_reg_json = json!({ timestamp.to_string(): rev_reg_json });
rev_regs_json[id] = rev_reg_json;
// The `from` arg is `None` because I think this is how
// we retrieve all the credentials issued/revoked up until timestamp `to`.
// Which is what anoncreds uses.
let (id, issuer_id, rev_reg_delta_json, timestamp) =
ledger.get_rev_reg_delta_json(rev_reg_id, None, Some(timestamp)).await?;
let mut rev_reg_delta_json: Value =
serde_json::from_str(&rev_reg_delta_json).or(Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
format!("Failed to deserialize as json: {}", rev_reg_delta_json),
)))?;

rev_reg_delta_json["issuer_id"] = json!(issuer_id);
let rev_reg_delta_json = json!({ timestamp.to_string(): rev_reg_delta_json });
rev_regs_json[id] = rev_reg_delta_json;
}
}

Expand Down Expand Up @@ -297,6 +304,7 @@ pub mod unit_tests {
}

#[tokio::test]
#[cfg(not(feature = "anoncreds"))]
async fn test_build_rev_reg_json() {
let _setup = SetupMocks::init();

Expand All @@ -314,7 +322,7 @@ pub mod unit_tests {
};
let ledger_read: Arc<dyn AnoncredsLedgerRead> = Arc::new(MockLedger {});
let credentials = vec![cred1, cred2];
let rev_reg_json = build_rev_reg_json(&ledger_read, &credentials).await.unwrap();
let rev_reg_json = build_rev_reg_delta_json(&ledger_read, &credentials).await.unwrap();

let json: Value = serde_json::from_str(REV_REG_JSON).unwrap();
let expected = json!({REV_REG_ID:{"1":json}}).to_string();
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/src/common/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub async fn create_and_store_credential(
let rev_def_json = ledger_read.get_rev_reg_def_json(&rev_reg_id).await.unwrap();
let tails_file = get_temp_dir_path(TAILS_DIR).to_str().unwrap().to_string();

let (cred, cred_rev_id, _) = anoncreds_issuer
let (cred, cred_rev_id) = anoncreds_issuer
.issuer_create_credential(
&offer,
&req,
Expand Down Expand Up @@ -262,7 +262,7 @@ pub async fn create_and_store_nonrevocable_credential(
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 (cred, _, _) = anoncreds_issuer
let (cred, _) = anoncreds_issuer
.issuer_create_credential(&offer, &req, &encoded_attributes, None, None)
.await
.unwrap();
Expand Down
Loading