Skip to content

Commit

Permalink
(feat) Implement AnoncredsLedgerRead for cheqd #1306 (#1308)
Browse files Browse the repository at this point in the history
* try permissions in CI

Signed-off-by: George Mulhearn <[email protected]>

* new crate

Signed-off-by: George Mulhearn <[email protected]>

* resolution working

Signed-off-by: George Mulhearn <[email protected]>

* check in the proto types and have a standalone generator helper (rather than generate at build time)

Signed-off-by: George Mulhearn <[email protected]>

* regen lock

Signed-off-by: George Mulhearn <[email protected]>

* cheqd did parser

Signed-off-by: George Mulhearn <[email protected]>

* cheqd did url tests

Signed-off-by: George Mulhearn <[email protected]>

* re-gen lock

Signed-off-by: George Mulhearn <[email protected]>

* resolver system tests are working

Signed-off-by: George Mulhearn <[email protected]>

* run int tests in CI

Signed-off-by: George Mulhearn <[email protected]>

* clippy

Signed-off-by: George Mulhearn <[email protected]>

* resolution with contexts

Signed-off-by: George Mulhearn <[email protected]>

* finish some TODOs, and add doc metadata

Signed-off-by: George Mulhearn <[email protected]>

* update readme

Signed-off-by: George Mulhearn <[email protected]>

* try bumping rust ver on vdrproxy

Signed-off-by: George Mulhearn <[email protected]>

* lock auto update

Signed-off-by: George Mulhearn <[email protected]>

* readme updates

Signed-off-by: George Mulhearn <[email protected]>

* remove some debugs

Signed-off-by: George Mulhearn <[email protected]>

* more error info

Signed-off-by: George Mulhearn <[email protected]>

* updated hyper in did:web. fixes clients

Signed-off-by: George Mulhearn <[email protected]>

* fix up tls. works on android

Signed-off-by: George Mulhearn <[email protected]>

* some cleaning

Signed-off-by: George Mulhearn <[email protected]>

* begin. schema & cred def working in edge agent test

Signed-off-by: George Mulhearn <[email protected]>

* temporarily include new format vers

Signed-off-by: George Mulhearn <[email protected]>

* issuer id

Signed-off-by: George Mulhearn <[email protected]>

* move delta -> status list conversion as a ledger responsibility

Signed-off-by: George Mulhearn <[email protected]>

* cheqd get rev status list

Signed-off-by: George Mulhearn <[email protected]>

* return metadata

Signed-off-by: George Mulhearn <[email protected]>

* rev status list and resource query working

Signed-off-by: George Mulhearn <[email protected]>

* some bounds and comments

Signed-off-by: George Mulhearn <[email protected]>

* fmt typing

Signed-off-by: George Mulhearn <[email protected]>

* optimize with metadata

Signed-off-by: George Mulhearn <[email protected]>

* multi ledger aggregation

Signed-off-by: George Mulhearn <[email protected]>

* some more testing and todos

Signed-off-by: George Mulhearn <[email protected]>

* rm aliases

Signed-off-by: George Mulhearn <[email protected]>

* test and CI fixing

Signed-off-by: George Mulhearn <[email protected]>

* fmt

Signed-off-by: George Mulhearn <[email protected]>

* clippys and fmts

Signed-off-by: George Mulhearn <[email protected]>

* wrap sys tests in cheqd feature

Signed-off-by: George Mulhearn <[email protected]>

* refine did-url handling (percent encoding queries)

Signed-off-by: George Mulhearn <[email protected]>

* add deprecated flag for rev reg delta

Signed-off-by: George Mulhearn <[email protected]>

* dev note on multi ledger

Signed-off-by: George Mulhearn <[email protected]>

* fmt

Signed-off-by: George Mulhearn <[email protected]>

* try arc wrapper

Signed-off-by: George Mulhearn <[email protected]>

* more generic trait

Signed-off-by: George Mulhearn <[email protected]>

* whoops!

Signed-off-by: George Mulhearn <[email protected]>

* pipe thru schema to prover store credential

Signed-off-by: George Mulhearn <[email protected]>

* type the schema id to avoid parsing issues with legacy identifiers

Signed-off-by: George Mulhearn <[email protected]>

* move around schema id a bit

Signed-off-by: George Mulhearn <[email protected]>

* comment on weird typing

Signed-off-by: George Mulhearn <[email protected]>

---------

Signed-off-by: George Mulhearn <[email protected]>
Co-authored-by: George Mulhearn <[email protected]>
  • Loading branch information
gmulhearn and gmulhearn-anonyome authored Dec 17, 2024
1 parent cf43869 commit 0cf717c
Show file tree
Hide file tree
Showing 65 changed files with 2,727 additions and 322 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ jobs:
with:
name: "docker-services-${{ github.job }}"

test-integration-aries-vcx-ledger:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
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 }}
- name: "Install just"
run: sudo snap install --edge --classic just
- name: "Run aries-vcx-ledger integration tests"
run: just test-integration-aries-vcx-ledger

test-integration-did-crate:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
Expand Down
17 changes: 13 additions & 4 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/aries_vcx/src/common/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub async fn is_cred_revoked(
rev_id: u32,
) -> VcxResult<bool> {
let to = Some(OffsetDateTime::now_utc().unix_timestamp() as u64 + 100);
#[allow(deprecated)] // TODO - https://github.com/hyperledger/aries-vcx/issues/1309
let (rev_reg_delta, _) = ledger
.get_rev_reg_delta_json(&rev_reg_id.try_into()?, None, to)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ impl RevocationRegistry {
ledger: &impl AnoncredsLedgerRead,
cred_rev_id: u32,
) -> VcxResult<()> {
#[allow(deprecated)] // TODO - https://github.com/hyperledger/aries-vcx/issues/1309
let rev_reg_delta_json = ledger
.get_rev_reg_delta_json(&self.rev_reg_id.to_string().try_into()?, None, None)
.await?
Expand Down
16 changes: 8 additions & 8 deletions aries/aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use aries_vcx_anoncreds::anoncreds::base_anoncreds::{
BaseAnonCreds, CredentialDefinitionsMap, RevocationStatesMap, SchemasMap,
};
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerRead;
use chrono::Utc;

use crate::errors::error::prelude::*;

Expand Down Expand Up @@ -160,26 +161,25 @@ pub async fn build_rev_states_json(
if !rtn.contains_key(rev_reg_id) {
// Does this make sense in case cred_info's for same rev_reg_ids have different
// revocation intervals
let (from, to) = if let Some(ref interval) = cred_info.revocation_interval {
let (_from, to) = if let Some(ref interval) = cred_info.revocation_interval {
(interval.from, interval.to)
} else {
(None, None)
};

let rev_reg_def_json = ledger_read
.get_rev_reg_def_json(&rev_reg_id.to_owned().try_into()?)
.await?;
let parsed_id = &rev_reg_id.to_owned().try_into()?;
let (rev_reg_def_json, meta) = ledger_read.get_rev_reg_def_json(parsed_id).await?;

let (rev_reg_delta_json, timestamp) = ledger_read
.get_rev_reg_delta_json(&rev_reg_id.to_owned().try_into()?, from, to)
let on_or_before = to.unwrap_or(Utc::now().timestamp() as u64);
let (rev_status_list, timestamp) = ledger_read
.get_rev_status_list(parsed_id, on_or_before, Some(&meta))
.await?;

let rev_state_json = anoncreds
.create_revocation_state(
Path::new(tails_dir),
rev_reg_def_json,
rev_reg_delta_json,
timestamp,
rev_status_list,
*cred_rev_id,
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub async fn build_rev_reg_defs_json(
))?;

if rev_reg_defs_json.get(rev_reg_id).is_none() {
let json = ledger
let (json, _meta) = ledger
.get_rev_reg_def_json(&rev_reg_id.to_string().try_into()?)
.await?;
let rev_reg_def_json = serde_json::to_value(&json).or(Err(AriesVcxError::from_msg(
Expand Down
6 changes: 4 additions & 2 deletions aries/aries_vcx/src/errors/mapping_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl From<VcxLedgerError> for AriesVcxError {
VcxLedgerError::LedgerItemNotFound => {
Self::from_msg(AriesVcxErrorKind::LedgerItemNotFound, value)
}
VcxLedgerError::InvalidLedgerResponse => {
VcxLedgerError::InvalidLedgerResponse(_) => {
Self::from_msg(AriesVcxErrorKind::InvalidLedgerResponse, value)
}
VcxLedgerError::DuplicationSchema => {
Expand All @@ -33,7 +33,9 @@ impl From<VcxLedgerError> for AriesVcxError {
Self::from_msg(AriesVcxErrorKind::PoolLedgerConnect, value)
}
VcxLedgerError::IOError(_) => Self::from_msg(AriesVcxErrorKind::IOError, value),
VcxLedgerError::InvalidInput(_) | VcxLedgerError::IndyVdrValidation(_) => {
VcxLedgerError::InvalidInput(_)
| VcxLedgerError::IndyVdrValidation(_)
| VcxLedgerError::UnsupportedLedgerIdentifier(_) => {
Self::from_msg(AriesVcxErrorKind::InvalidInput, value)
}
VcxLedgerError::UnknownError(_) => {
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl Issuer {
revocation_info.rev_reg_id,
revocation_info.tails_file,
) {
#[allow(deprecated)] // TODO - https://github.com/hyperledger/aries-vcx/issues/1309
let rev_reg_delta_json = ledger
.get_rev_reg_delta_json(&rev_reg_id.to_owned().try_into()?, None, None)
.await?
Expand Down
48 changes: 28 additions & 20 deletions aries/aries_vcx/src/protocols/issuance/holder/state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fmt;

use anoncreds_types::data_types::{
identifiers::schema_id::SchemaId, messages::cred_offer::CredentialOffer,
};
use aries_vcx_anoncreds::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
Expand Down Expand Up @@ -224,11 +227,12 @@ impl HolderSM {
)
.await
{
Ok((msg_credential_request, req_meta, cred_def_json)) => {
Ok((msg_credential_request, req_meta, cred_def_json, schema_id)) => {
HolderFullState::RequestSet(RequestSetState {
msg_credential_request,
req_meta,
cred_def_json,
schema_id,
})
}
Err(err) => {
Expand Down Expand Up @@ -276,13 +280,16 @@ impl HolderSM {
trace!("HolderSM::receive_credential >>");
let state = match self.state {
HolderFullState::RequestSet(state_data) => {
let schema = ledger.get_schema(&state_data.schema_id, None).await?;
let schema_json = serde_json::to_string(&schema)?;
match _store_credential(
wallet,
ledger,
anoncreds,
&credential,
&state_data.req_meta,
&state_data.cred_def_json,
&schema_json,
)
.await
{
Expand Down Expand Up @@ -549,6 +556,7 @@ async fn _store_credential(
credential: &IssueCredentialV1,
req_meta: &str,
cred_def_json: &str,
schema_json: &str,
) -> VcxResult<(String, Option<String>)> {
trace!(
"Holder::_store_credential >>> credential: {:?}, req_meta: {}, cred_def_json: {}",
Expand All @@ -561,7 +569,7 @@ async fn _store_credential(

let rev_reg_id = _parse_rev_reg_id_from_credential(&credential_json)?;
let rev_reg_def_json = if let Some(rev_reg_id) = rev_reg_id {
let json = ledger.get_rev_reg_def_json(&rev_reg_id.try_into()?).await?;
let (json, _meta) = ledger.get_rev_reg_def_json(&rev_reg_id.try_into()?).await?;
Some(json)
} else {
None
Expand All @@ -572,6 +580,7 @@ async fn _store_credential(
wallet,
serde_json::from_str(req_meta)?,
serde_json::from_str(&credential_json)?,
serde_json::from_str(schema_json)?,
serde_json::from_str(cred_def_json)?,
rev_reg_def_json.clone(),
)
Expand All @@ -585,24 +594,27 @@ async fn _store_credential(
))
}

/// On success, returns: credential request, request metadata, cred_def_id, cred def, schema_id
pub async fn create_anoncreds_credential_request(
wallet: &impl BaseWallet,
ledger: &impl AnoncredsLedgerRead,
anoncreds: &impl BaseAnonCreds,
cred_def_id: &str,
prover_did: &Did,
cred_offer: &str,
) -> VcxResult<(String, String, String, String)> {
let cred_def_json = ledger
.get_cred_def(&cred_def_id.to_string().try_into()?, None)
.await?;
) -> VcxResult<(String, String, String, String, SchemaId)> {
let offer: CredentialOffer = serde_json::from_str(cred_offer)?;

let schema_id = offer.schema_id.clone();
let cred_def_id = offer.cred_def_id.clone();

let cred_def_json = ledger.get_cred_def(&cred_def_id, None).await?;

let master_secret_id = settings::DEFAULT_LINK_SECRET_ALIAS;
anoncreds
.prover_create_credential_req(
wallet,
prover_did,
serde_json::from_str(cred_offer)?,
offer,
cred_def_json.try_clone()?,
&master_secret_id.to_string(),
)
Expand All @@ -619,18 +631,21 @@ pub async fn create_anoncreds_credential_request(
serde_json::to_string(&s2).unwrap(),
cred_def_id.to_string(),
serde_json::to_string(&cred_def_json).unwrap(),
schema_id,
)
})
}

/// On success, returns: message with cred request, request metadata, cred def (for caching),
/// schema_id
async fn build_credential_request_msg(
wallet: &impl BaseWallet,
ledger: &impl AnoncredsLedgerRead,
anoncreds: &impl BaseAnonCreds,
thread_id: String,
my_pw_did: Did,
offer: &OfferCredentialV1,
) -> VcxResult<(RequestCredentialV1, String, String)> {
) -> VcxResult<(RequestCredentialV1, String, String, SchemaId)> {
trace!(
"Holder::_make_credential_request >>> my_pw_did: {:?}, offer: {:?}",
my_pw_did,
Expand All @@ -640,17 +655,10 @@ async fn build_credential_request_msg(
let cred_offer = get_attach_as_string!(&offer.content.offers_attach);

trace!("Parsed cred offer attachment: {}", cred_offer);
let cred_def_id = parse_cred_def_id_from_cred_offer(&cred_offer)?;
let (req, req_meta, _cred_def_id, cred_def_json) = create_anoncreds_credential_request(
wallet,
ledger,
anoncreds,
&cred_def_id,
&my_pw_did,
&cred_offer,
)
.await?;
let (req, req_meta, _cred_def_id, cred_def_json, schema_id) =
create_anoncreds_credential_request(wallet, ledger, anoncreds, &my_pw_did, &cred_offer)
.await?;
trace!("Created cred def json: {}", cred_def_json);
let credential_request_msg = _build_credential_request_msg(req, &thread_id);
Ok((credential_request_msg, req_meta, cred_def_json))
Ok((credential_request_msg, req_meta, cred_def_json, schema_id))
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anoncreds_types::data_types::identifiers::schema_id::SchemaId;
use messages::msg_fields::protocols::cred_issuance::v1::{
issue_credential::IssueCredentialV1, request_credential::RequestCredentialV1,
};
Expand All @@ -11,6 +12,7 @@ use crate::{
pub struct RequestSetState {
pub req_meta: String,
pub cred_def_json: String,
pub schema_id: SchemaId,
pub msg_credential_request: RequestCredentialV1,
}

Expand Down
2 changes: 2 additions & 0 deletions aries/aries_vcx/tests/test_anoncreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async fn test_pool_proof_req_attribute_names() -> Result<(), Box<dyn Error>> {
Ok(())
}

#[allow(deprecated)] // TODO - https://github.com/hyperledger/aries-vcx/issues/1309
#[tokio::test]
#[ignore]
async fn test_pool_revoke_credential() -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -109,6 +110,7 @@ async fn test_pool_revoke_credential() -> Result<(), Box<dyn Error>> {
&setup.anoncreds,
&setup.anoncreds,
&setup.institution_did,
&schema,
&cred_def,
Some(&rev_reg),
)
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx/tests/test_credential_retrieval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async fn test_agency_pool_case_for_proof_req_doesnt_matter_for_retrieve_creds(
&setup.anoncreds,
&setup.anoncreds,
&setup.institution_did,
&schema,
&cred_def,
None,
)
Expand Down
3 changes: 3 additions & 0 deletions aries/aries_vcx/tests/test_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async fn test_pool_prover_get_credential() -> Result<(), Box<dyn Error>> {
&setup.anoncreds,
&setup.anoncreds,
&setup.institution_did,
&schema,
&cred_def,
Some(&rev_reg),
)
Expand Down Expand Up @@ -102,6 +103,7 @@ async fn test_pool_is_cred_revoked() -> Result<(), Box<dyn Error>> {
&setup.anoncreds,
&setup.anoncreds,
&setup.institution_did,
&schema,
&cred_def,
Some(&rev_reg),
)
Expand All @@ -110,6 +112,7 @@ async fn test_pool_is_cred_revoked() -> Result<(), Box<dyn Error>> {

assert!(!is_cred_revoked(&setup.ledger_read, &rev_reg.rev_reg_id, cred_rev_id).await?);

#[allow(deprecated)] // TODO - https://github.com/hyperledger/aries-vcx/issues/1309
let rev_reg_delta_json = setup
.ledger_read
.get_rev_reg_delta_json(&rev_reg.rev_reg_id.to_owned().try_into()?, None, None)
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx/tests/test_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ async fn test_pool_get_rev_reg_delta_json() -> Result<(), Box<dyn Error>> {
.await?;

let ledger = &setup.ledger_read;
#[allow(deprecated)] // TODO - https://github.com/hyperledger/aries-vcx/issues/1309
let (_delta, _timestamp) = ledger
.get_rev_reg_delta_json(&rev_reg.rev_reg_id.to_owned().try_into()?, None, None)
.await?;
Expand Down
Loading

0 comments on commit 0cf717c

Please sign in to comment.