Skip to content

Commit

Permalink
multi ledger aggregation
Browse files Browse the repository at this point in the history
Signed-off-by: George Mulhearn <[email protected]>
  • Loading branch information
gmulhearn-anonyome committed Dec 9, 2024
1 parent b9111aa commit fbe3054
Show file tree
Hide file tree
Showing 11 changed files with 1,007 additions and 10 deletions.
10 changes: 6 additions & 4 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion aries/aries_vcx/src/errors/mapping_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions aries/aries_vcx_ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ tokio = { version = "1.38.0", default-features = false, features = [
"rt",
] }
chrono = { version = "0.4", default-features = true }
mockall = "0.13.1"
uuid = { version = "1.4.1", default-features = false, features = ["v4"] }

2 changes: 2 additions & 0 deletions aries/aries_vcx_ledger/src/errors/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum VcxLedgerError {
InvalidOption(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Unsupported ledger identifier: {0}")]
UnsupportedLedgerIdentifier(String),
#[error("Unknown error: {0}")]
UnknownError(String),
#[error("Indy Vdr Validation error: {0}")]
Expand Down
8 changes: 8 additions & 0 deletions aries/aries_vcx_ledger/src/ledger/base_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ pub trait AnoncredsLedgerWrite: Debug + Send + Sync {
) -> VcxLedgerResult<()>;
}

/// Simple utility trait to determine whether the implementor can support reading/writing
/// the specific identifier types.
pub trait AnoncredsLedgerSupport {
fn supports_schema(&self, id: &SchemaId) -> bool;
fn supports_credential_definition(&self, id: &CredentialDefinitionId) -> bool;
fn supports_revocation_registry(&self, id: &RevocationRegistryDefinitionId) -> bool;
}

pub trait TaaConfigurator: Debug + Send + Sync {
fn set_txn_author_agreement_options(
&self,
Expand Down
123 changes: 122 additions & 1 deletion aries/aries_vcx_ledger/src/ledger/cheqd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ use models::{
CheqdAnoncredsCredentialDefinition, CheqdAnoncredsRevocationRegistryDefinition,
CheqdAnoncredsRevocationStatusList, CheqdAnoncredsSchema,
};
use serde::{Deserialize, Serialize};

use super::base_ledger::AnoncredsLedgerRead;
use super::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerSupport};
use crate::errors::error::{VcxLedgerError, VcxLedgerResult};

mod models;
Expand All @@ -34,6 +35,10 @@ const CRED_DEF_RESOURCE_TYPE: &str = "anonCredsCredDef";
const REV_REG_DEF_RESOURCE_TYPE: &str = "anonCredsRevocRegDef";
const STATUS_LIST_RESOURCE_TYPE: &str = "anonCredsStatusList";

/// Struct for resolving anoncreds objects from cheqd ledgers using the cheqd
/// anoncreds object method: https://docs.cheqd.io/product/advanced/anoncreds.
///
/// Relies on a cheqd DID resolver ([DidCheqdResolver]) to fetch DID resources.
pub struct CheqdAnoncredsLedgerRead {
resolver: Arc<DidCheqdResolver>,
}
Expand Down Expand Up @@ -77,6 +82,7 @@ impl CheqdAnoncredsLedgerRead {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RevocationRegistryDefinitionAdditionalMetadata {
pub resource_name: String,
}
Expand Down Expand Up @@ -234,8 +240,123 @@ fn extract_issuer_id(url: &DidUrl) -> VcxLedgerResult<IssuerId> {
.map_err(|e| VcxLedgerError::InvalidInput(format!("DID is not an IssuerId {e}")))
}

impl AnoncredsLedgerSupport for CheqdAnoncredsLedgerRead {
fn supports_schema(&self, id: &SchemaId) -> bool {
let Ok(url) = DidUrl::parse(id.to_string()) else {
return false;
};
url.method() == Some("cheqd")
}

fn supports_credential_definition(&self, id: &CredentialDefinitionId) -> bool {
let Ok(url) = DidUrl::parse(id.to_string()) else {
return false;
};
url.method() == Some("cheqd")
}

fn supports_revocation_registry(&self, id: &RevocationRegistryDefinitionId) -> bool {
let Ok(url) = DidUrl::parse(id.to_string()) else {
return false;
};
url.method() == Some("cheqd")
}
}

impl Debug for CheqdAnoncredsLedgerRead {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CheqdAnoncredsLedgerRead instance")
}
}

#[cfg(test)]
mod unit_tests {
use super::*;

fn default_cheqd_reader() -> CheqdAnoncredsLedgerRead {
CheqdAnoncredsLedgerRead::new(Arc::new(DidCheqdResolver::new(Default::default())))
}

#[test]
fn test_anoncreds_schema_support() {
let reader = default_cheqd_reader();

// qualified cheqd
assert!(reader.supports_schema(
&SchemaId::new(
"did:cheqd:mainnet:7BPMqYgYLQni258J8JPS8K/resources/\
6259d357-eeb1-4b98-8bee-12a8390d3497"
)
.unwrap()
));

// unqualified
assert!(!reader.supports_schema(
&SchemaId::new("7BPMqYgYLQni258J8JPS8K:2:degree schema:46.58.87").unwrap()
));
// qualified sov
assert!(!reader.supports_schema(
&SchemaId::new("did:sov:7BPMqYgYLQni258J8JPS8K:2:degree schema:46.58.87").unwrap()
));
}

#[test]
fn test_anoncreds_cred_def_support() {
let reader = default_cheqd_reader();

// qualified cheqd
assert!(reader.supports_credential_definition(
&CredentialDefinitionId::new(
"did:cheqd:mainnet:7BPMqYgYLQni258J8JPS8K/resources/\
6259d357-eeb1-4b98-8bee-12a8390d3497"
)
.unwrap()
));

// unqualified
assert!(!reader.supports_credential_definition(
&CredentialDefinitionId::new(
"7BPMqYgYLQni258J8JPS8K:3:CL:70:faber.agent.degree_schema"
)
.unwrap()
));
// qualified sov
assert!(!reader.supports_credential_definition(
&CredentialDefinitionId::new(
"did:sov:7BPMqYgYLQni258J8JPS8K:3:CL:70:faber.agent.degree_schema"
)
.unwrap()
));
}

#[test]
fn test_anoncreds_rev_reg_support() {
let reader = default_cheqd_reader();

// qualified cheqd
assert!(reader.supports_revocation_registry(
&RevocationRegistryDefinitionId::new(
"did:cheqd:mainnet:7BPMqYgYLQni258J8JPS8K/resources/\
6259d357-eeb1-4b98-8bee-12a8390d3497"
)
.unwrap()
));

// unqualified
assert!(!reader.supports_revocation_registry(
&RevocationRegistryDefinitionId::new(
"7BPMqYgYLQni258J8JPS8K:4:7BPMqYgYLQni258J8JPS8K:3:CL:70:faber.agent.\
degree_schema:CL_ACCUM:61d5a381-30be-4120-9307-b150b49c203c"
)
.unwrap()
));
// qualified sov
assert!(!reader.supports_revocation_registry(
&RevocationRegistryDefinitionId::new(
"did:sov:7BPMqYgYLQni258J8JPS8K:4:7BPMqYgYLQni258J8JPS8K:3:CL:70:faber.agent.\
degree_schema:CL_ACCUM:61d5a381-30be-4120-9307-b150b49c203c"
)
.unwrap()
));
}
}
Loading

0 comments on commit fbe3054

Please sign in to comment.