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 all 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 @@ -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
Loading