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

(feat) Implement AnoncredsLedgerRead for cheqd #1306 #1308

Merged
merged 57 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e070717
try permissions in CI
gmulhearn-anonyome Aug 15, 2024
1693dd5
new crate
gmulhearn-anonyome Nov 24, 2024
d40d9c7
resolution working
gmulhearn-anonyome Nov 25, 2024
b39bc4c
check in the proto types and have a standalone generator helper (rath…
gmulhearn-anonyome Nov 25, 2024
65b1e9b
Merge branch 'main' into gm/1300-did-cheqd-resolver
gmulhearn-anonyome Nov 25, 2024
8d0fd4f
regen lock
gmulhearn-anonyome Nov 25, 2024
d0bf0af
cheqd did parser
gmulhearn-anonyome Nov 26, 2024
881410e
cheqd did url tests
gmulhearn-anonyome Nov 26, 2024
96d74e9
re-gen lock
gmulhearn-anonyome Nov 26, 2024
a98803a
resolver system tests are working
gmulhearn-anonyome Nov 26, 2024
accc65d
run int tests in CI
gmulhearn-anonyome Nov 26, 2024
dcbb8a5
clippy
gmulhearn-anonyome Nov 26, 2024
8ae721c
resolution with contexts
gmulhearn-anonyome Nov 26, 2024
c9464cb
finish some TODOs, and add doc metadata
gmulhearn-anonyome Nov 26, 2024
0353b02
update readme
gmulhearn-anonyome Nov 26, 2024
d1692e1
try bumping rust ver on vdrproxy
gmulhearn-anonyome Nov 26, 2024
d4550d5
Merge branch 'main' into gm/1300-did-cheqd-resolver
gmulhearn-anonyome Nov 26, 2024
8d46987
lock auto update
gmulhearn-anonyome Nov 26, 2024
f0908aa
readme updates
gmulhearn-anonyome Nov 27, 2024
cb57bc9
remove some debugs
gmulhearn-anonyome Nov 27, 2024
e722982
more error info
gmulhearn-anonyome Nov 27, 2024
fd2c009
updated hyper in did:web. fixes clients
gmulhearn-anonyome Nov 27, 2024
25c10ee
fix up tls. works on android
gmulhearn-anonyome Dec 1, 2024
b3e183e
some cleaning
gmulhearn-anonyome Dec 2, 2024
ecb736c
begin. schema & cred def working in edge agent test
gmulhearn-anonyome Dec 3, 2024
25e766c
temporarily include new format vers
gmulhearn-anonyome Dec 3, 2024
a68446f
Merge branch 'main' into gm/1300-did-cheqd-resolver
gmulhearn-anonyome Dec 3, 2024
d3d1a97
Merge branch 'gm/1300-did-cheqd-resolver' into gm/1306-cheqd-anoncred…
gmulhearn-anonyome Dec 3, 2024
ab7becb
issuer id
gmulhearn-anonyome Dec 4, 2024
6c82328
move delta -> status list conversion as a ledger responsibility
gmulhearn-anonyome Dec 4, 2024
c08b2c1
cheqd get rev status list
gmulhearn-anonyome Dec 4, 2024
19d4e21
return metadata
gmulhearn-anonyome Dec 4, 2024
e786571
rev status list and resource query working
gmulhearn-anonyome Dec 5, 2024
3461fc0
some bounds and comments
gmulhearn-anonyome Dec 5, 2024
10695cd
fmt typing
gmulhearn-anonyome Dec 5, 2024
b9111aa
optimize with metadata
gmulhearn-anonyome Dec 9, 2024
fbe3054
multi ledger aggregation
gmulhearn-anonyome Dec 9, 2024
c48f329
some more testing and todos
gmulhearn-anonyome Dec 9, 2024
7c31d58
rm aliases
gmulhearn-anonyome Dec 9, 2024
56c282f
test and CI fixing
gmulhearn-anonyome Dec 9, 2024
9b13ff7
fmt
gmulhearn-anonyome Dec 9, 2024
269df99
clippys and fmts
gmulhearn-anonyome Dec 9, 2024
0a50ddc
Merge branch 'main' into gm/1306-cheqd-anoncreds-read
gmulhearn-anonyome Dec 9, 2024
a123936
wrap sys tests in cheqd feature
gmulhearn-anonyome Dec 9, 2024
3e4f1a2
refine did-url handling (percent encoding queries)
gmulhearn-anonyome Dec 10, 2024
e48f23b
add deprecated flag for rev reg delta
gmulhearn-anonyome Dec 11, 2024
3cd9e86
dev note on multi ledger
gmulhearn-anonyome Dec 11, 2024
47cccec
fmt
gmulhearn-anonyome Dec 11, 2024
4af894c
try arc wrapper
gmulhearn-anonyome Dec 11, 2024
f0d93dd
more generic trait
gmulhearn-anonyome Dec 11, 2024
ecc7c81
whoops!
gmulhearn-anonyome Dec 11, 2024
06f9afd
pipe thru schema to prover store credential
gmulhearn-anonyome Dec 12, 2024
e5bee98
Merge branch 'hyperledger-main' into gm/1306-cheqd-anoncreds-read
gmulhearn-anonyome Dec 12, 2024
a4eb40b
type the schema id to avoid parsing issues with legacy identifiers
gmulhearn-anonyome Dec 12, 2024
7f69365
move around schema id a bit
gmulhearn-anonyome Dec 12, 2024
08c557b
Merge branch 'hyperledger-main' into gm/1306-cheqd-anoncreds-read
gmulhearn-anonyome Dec 15, 2024
19d0430
comment on weird typing
gmulhearn-anonyome Dec 17, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,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.

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
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,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 Down
140 changes: 51 additions & 89 deletions aries/aries_vcx_anoncreds/src/anoncreds/anoncreds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,41 @@ use anoncreds::{
RevocationRegistryDefinition as AnoncredsRevocationRegistryDefinition,
},
};
use anoncreds_types::data_types::{
identifiers::{
cred_def_id::CredentialDefinitionId, rev_reg_def_id::RevocationRegistryDefinitionId,
schema_id::SchemaId,
},
ledger::{
cred_def::{CredentialDefinition, SignatureType},
rev_reg::RevocationRegistry,
rev_reg_def::RevocationRegistryDefinition,
rev_reg_delta::{RevocationRegistryDelta, RevocationRegistryDeltaValue},
rev_status_list::RevocationStatusList,
schema::{AttributeNames, Schema},
},
messages::{
cred_definition_config::CredentialDefinitionConfig,
cred_offer::CredentialOffer,
cred_request::{CredentialRequest, CredentialRequestMetadata},
cred_selection::{
RetrievedCredentialForReferent, RetrievedCredentialInfo, RetrievedCredentials,
use anoncreds_types::{
data_types::{
identifiers::{
cred_def_id::CredentialDefinitionId, rev_reg_def_id::RevocationRegistryDefinitionId,
schema_id::SchemaId,
},
ledger::{
cred_def::{CredentialDefinition, SignatureType},
rev_reg::RevocationRegistry,
rev_reg_def::RevocationRegistryDefinition,
rev_reg_delta::{RevocationRegistryDelta, RevocationRegistryDeltaValue},
rev_status_list::RevocationStatusList,
schema::{AttributeNames, Schema},
},
messages::{
cred_definition_config::CredentialDefinitionConfig,
cred_offer::CredentialOffer,
cred_request::{CredentialRequest, CredentialRequestMetadata},
cred_selection::{
RetrievedCredentialForReferent, RetrievedCredentialInfo, RetrievedCredentials,
},
credential::{Credential, CredentialValues},
nonce::Nonce,
pres_request::PresentationRequest,
presentation::{Presentation, RequestedCredentials},
revocation_state::CredentialRevocationState,
},
credential::{Credential, CredentialValues},
nonce::Nonce,
pres_request::PresentationRequest,
presentation::{Presentation, RequestedCredentials},
revocation_state::CredentialRevocationState,
},
utils::conversions::from_revocation_registry_delta_to_revocation_status_list,
};
use aries_vcx_wallet::wallet::{
base_wallet::{record::Record, record_category::RecordCategory, BaseWallet},
record_tags::{RecordTag, RecordTags},
};
use async_trait::async_trait;
use bitvec::bitvec;
use did_parser_nom::Did;
use log::warn;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand All @@ -82,36 +84,6 @@ use crate::{
errors::error::{VcxAnoncredsError, VcxAnoncredsResult},
};

fn from_revocation_registry_delta_to_revocation_status_list(
delta: &RevocationRegistryDeltaValue,
rev_reg_def: &AnoncredsRevocationRegistryDefinition,
rev_reg_def_id: &RevocationRegistryDefinitionId,
timestamp: Option<u64>,
issuance_by_default: bool,
) -> VcxAnoncredsResult<RevocationStatusList> {
let default_state = if issuance_by_default { 0 } else { 1 };
let mut revocation_list = bitvec![default_state; rev_reg_def.value.max_cred_num as usize];

for issued in &delta.issued {
revocation_list.insert(*issued as usize, false);
}

for revoked in &delta.revoked {
revocation_list.insert(*revoked as usize, true);
}

let accum = delta.accum.into();

RevocationStatusList::new(
Some(&rev_reg_def_id.to_string()),
rev_reg_def.issuer_id.clone().convert(())?,
revocation_list,
Some(accum),
timestamp,
)
.map_err(Into::into)
}

fn from_revocation_status_list_to_revocation_registry_delta(
rev_status_list: &RevocationStatusList,
prev_accum: Option<Accumulator>,
Expand Down Expand Up @@ -288,17 +260,35 @@ impl BaseAnonCreds for Anoncreds {
let cred_defs: HashMap<AnoncredsCredentialDefinitionId, AnoncredsCredentialDefinition> =
credential_defs_json.convert(())?;

// tack on issuerId for ease of processing status lists
let rev_regs_map_with_issuer_ids: Option<HashMap<_, _>> =
match (rev_regs_json, &rev_reg_defs_json) {
(Some(regs), Some(defs)) => Some(
regs.into_iter()
.filter_map(|(k, v)| {
let def = defs.get(&k)?;
Some((k, (v, def.issuer_id.clone())))
})
.collect(),
),
_ => None,
};

let rev_reg_defs: Option<
HashMap<AnoncredsRevocationRegistryDefinitionId, AnoncredsRevocationRegistryDefinition>,
> = rev_reg_defs_json.map(|v| v.convert(())).transpose()?;

let rev_status_lists = rev_regs_map_with_issuer_ids
.map(|r| r.convert(()))
.transpose()?;

Ok(anoncreds::verifier::verify_presentation(
&presentation,
&pres_req,
&schemas,
&cred_defs,
rev_reg_defs.as_ref(),
rev_regs_json.map(|r| r.convert(())).transpose()?,
rev_status_lists,
None, // no idea what this is
)?)
}
Expand Down Expand Up @@ -947,18 +937,9 @@ impl BaseAnonCreds for Anoncreds {
&self,
tails_dir: &Path,
rev_reg_def_json: RevocationRegistryDefinition,
rev_reg_delta_json: RevocationRegistryDelta,
timestamp: u64,
rev_status_list: RevocationStatusList,
cred_rev_id: u32,
) -> VcxAnoncredsResult<CredentialRevocationState> {
let cred_def_id = rev_reg_def_json.cred_def_id.to_string();
let max_cred_num = rev_reg_def_json.value.max_cred_num;
let rev_reg_def_id = rev_reg_def_json.id.to_string();
let (_cred_def_method, issuer_did, _signature_type, _schema_num, _tag) =
cred_def_parts(&cred_def_id).ok_or(VcxAnoncredsError::InvalidSchema(format!(
"Could not process cred_def_id {cred_def_id} as parts."
)))?;

let revoc_reg_def: AnoncredsRevocationRegistryDefinition = rev_reg_def_json.convert(())?;
let tails_file_hash = revoc_reg_def.value.tails_hash.as_str();

Expand All @@ -970,25 +951,6 @@ impl BaseAnonCreds for Anoncreds {
VcxAnoncredsError::InvalidOption("tails file is not an unicode string".into())
})?;

let RevocationRegistryDeltaValue { accum, revoked, .. } = rev_reg_delta_json.value;

let issuer_id = IssuerId::new(issuer_did.did()).unwrap();
let mut revocation_list = bitvec!(0; max_cred_num as usize);
revoked.into_iter().for_each(|id| {
revocation_list
.get_mut(id as usize)
.map(|mut b| *b = true)
.unwrap_or_default()
});
let registry = CryptoRevocationRegistry { accum };

let rev_status_list = RevocationStatusList::new(
Some(&rev_reg_def_id),
issuer_id.convert(())?,
revocation_list,
Some(registry),
Some(timestamp),
)?;
let rev_state = anoncreds::prover::create_or_update_revocation_state(
tails_path,
&revoc_reg_def,
Expand Down Expand Up @@ -1164,10 +1126,10 @@ impl BaseAnonCreds for Anoncreds {
let current_time = OffsetDateTime::now_utc().unix_timestamp() as u64;
let rev_status_list = from_revocation_registry_delta_to_revocation_status_list(
&last_rev_reg_delta.value,
&rev_reg_def.clone().convert(())?,
rev_reg_id,
Some(current_time),
true,
current_time,
&rev_reg_def.id,
rev_reg_def.value.max_cred_num as usize,
rev_reg_def.issuer_id.clone(),
)?;

let cred_def = self
Expand Down
Loading
Loading