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

Rename CredentialValidator to JwtCredentialValidator #1207

Merged
merged 8 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use identity_iota::core::Object;
use identity_iota::core::Url;
use identity_iota::credential::CredentialValidator as JwtCredentialValidator;
use identity_iota::credential::JwtCredentialValidator;
use identity_iota::credential::StatusCheck;
use identity_iota::did::CoreDID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::error::Result;
use crate::error::WasmResult;
use wasm_bindgen::prelude::*;

use identity_iota::credential::CredentialValidationOptions as JwtCredentialValidationOptions;
use identity_iota::credential::JwtCredentialValidationOptions;

/// Options to declare validation criteria when validating credentials.
#[wasm_bindgen(js_name = JwtCredentialValidationOptions)]
Expand Down
8 changes: 4 additions & 4 deletions examples/0_basic/5_create_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use examples::create_did;
use examples::MemStorage;
use identity_iota::core::Object;
use identity_iota::credential::CredentialValidationOptions;
use identity_iota::credential::CredentialValidator;
use identity_iota::credential::DecodedJwtCredential;
use identity_iota::credential::Jwt;
use identity_iota::credential::JwtCredentialValidationOptions;
use identity_iota::credential::JwtCredentialValidator;
use identity_iota::storage::JwkDocumentExt;
use identity_iota::storage::JwkMemStore;
use identity_iota::storage::JwsSignatureOptions;
Expand Down Expand Up @@ -93,11 +93,11 @@ async fn main() -> anyhow::Result<()> {

// Validate the credential's signature using the issuer's DID Document, the credential's semantic structure,
// that the issuance date is not in the future and that the expiration date is not in the past:
let decoded_credential: DecodedJwtCredential<Object> = CredentialValidator::new()
let decoded_credential: DecodedJwtCredential<Object> = JwtCredentialValidator::new()
.validate::<_, Object>(
&credential_jwt,
&issuer_document,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
FailFast::FirstError,
)
.unwrap();
Expand Down
14 changes: 7 additions & 7 deletions examples/0_basic/6_create_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ use identity_iota::core::Timestamp;
use identity_iota::core::Url;
use identity_iota::credential::Credential;
use identity_iota::credential::CredentialBuilder;
use identity_iota::credential::CredentialValidationOptions;
use identity_iota::credential::CredentialValidator;
use identity_iota::credential::FailFast;
use identity_iota::credential::JwtCredentialValidationOptions;
use identity_iota::credential::JwtCredentialValidator;
use identity_iota::credential::Subject;
use identity_iota::credential::SubjectHolderRelationship;
use identity_iota::did::DID;
Expand Down Expand Up @@ -119,11 +119,11 @@ async fn main() -> anyhow::Result<()> {

// Validate the credential's signature using the issuer's DID Document, the credential's semantic structure,
// that the issuance date is not in the future and that the expiration date is not in the past:
CredentialValidator::new()
JwtCredentialValidator::new()
.validate::<_, Object>(
&credential_jwt,
&issuer_document,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
FailFast::FirstError,
)
.unwrap();
Expand Down Expand Up @@ -203,13 +203,13 @@ async fn main() -> anyhow::Result<()> {
let jwt_credentials: &OneOrMany<Jwt> = &presentation.presentation.verifiable_credential;
let issuers: Vec<CoreDID> = jwt_credentials
.iter()
.map(CredentialValidator::extract_issuer_from_jwt)
.map(JwtCredentialValidator::extract_issuer_from_jwt)
.collect::<Result<Vec<CoreDID>, _>>()?;
let issuers_documents: HashMap<CoreDID, IotaDocument> = resolver.resolve_multiple(&issuers).await?;

// Validate the credentials in the presentation.
let credential_validator: CredentialValidator = CredentialValidator::new();
let validation_options: CredentialValidationOptions = CredentialValidationOptions::default()
let credential_validator: JwtCredentialValidator = JwtCredentialValidator::new();
let validation_options: JwtCredentialValidationOptions = JwtCredentialValidationOptions::default()
.subject_holder_relationship(holder_did.to_url().into(), SubjectHolderRelationship::AlwaysSubject);

for (index, jwt_vc) in jwt_credentials.iter().enumerate() {
Expand Down
18 changes: 9 additions & 9 deletions examples/0_basic/7_revoke_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use identity_iota::core::Url;
use identity_iota::credential::CompoundCredentialValidationError;
use identity_iota::credential::Credential;
use identity_iota::credential::CredentialBuilder;
use identity_iota::credential::CredentialValidationOptions;
use identity_iota::credential::CredentialValidator;
use identity_iota::credential::DecodedJwtCredential;
use identity_iota::credential::FailFast;
use identity_iota::credential::Jwt;
use identity_iota::credential::JwtCredentialValidationOptions;
use identity_iota::credential::JwtCredentialValidator;
use identity_iota::credential::RevocationBitmap;
use identity_iota::credential::RevocationBitmapStatus;
use identity_iota::credential::Status;
Expand Down Expand Up @@ -147,10 +147,10 @@ async fn main() -> anyhow::Result<()> {
.await?;

// Validate the credential's signature using the issuer's DID Document.
CredentialValidator::new().validate::<_, Object>(
JwtCredentialValidator::new().validate::<_, Object>(
&credential_jwt,
&issuer_document,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
FailFast::FirstError,
)?;

Expand All @@ -171,10 +171,10 @@ async fn main() -> anyhow::Result<()> {
issuer_document = client.publish_did_output(&secret_manager_issuer, alias_output).await?;

let validation_result: std::result::Result<DecodedJwtCredential, CompoundCredentialValidationError> =
CredentialValidator::new().validate(
JwtCredentialValidator::new().validate(
&credential_jwt,
&issuer_document,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
FailFast::FirstError,
);

Expand Down Expand Up @@ -207,13 +207,13 @@ async fn main() -> anyhow::Result<()> {
// We expect the verifiable credential to be revoked.
let mut resolver: Resolver<IotaDocument> = Resolver::new();
resolver.attach_iota_handler(client);
let resolved_issuer_did: IotaDID = CredentialValidator::extract_issuer_from_jwt(&credential_jwt)?;
let resolved_issuer_did: IotaDID = JwtCredentialValidator::extract_issuer_from_jwt(&credential_jwt)?;
let resolved_issuer_doc: IotaDocument = resolver.resolve(&resolved_issuer_did).await?;

let validation_result = CredentialValidator::new().validate::<_, Object>(
let validation_result = JwtCredentialValidator::new().validate::<_, Object>(
&credential_jwt,
&resolved_issuer_doc,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
FailFast::FirstError,
);

Expand Down
6 changes: 3 additions & 3 deletions examples/1_advanced/6_domain_linkage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use identity_iota::core::Timestamp;
use identity_iota::core::ToJson;
use identity_iota::core::Url;
use identity_iota::credential::Credential;
use identity_iota::credential::CredentialValidationOptions;
use identity_iota::credential::DomainLinkageConfiguration;
use identity_iota::credential::DomainLinkageCredentialBuilder;
use identity_iota::credential::DomainLinkageValidationError;
use identity_iota::credential::DomainLinkageValidator;
use identity_iota::credential::Jwt;
use identity_iota::credential::JwtCredentialValidationOptions;
use identity_iota::credential::LinkedDomainService;
use identity_iota::did::CoreDID;
use identity_iota::did::DIDUrl;
Expand Down Expand Up @@ -156,7 +156,7 @@ async fn main() -> anyhow::Result<()> {
&issuer_did_document,
&configuration_resource,
&domain_foo,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);
assert!(validation_result.is_ok());

Expand Down Expand Up @@ -200,7 +200,7 @@ async fn main() -> anyhow::Result<()> {
&did_document,
&configuration_resource,
&domain_foo,
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);
assert!(validation_result.is_ok());
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion identity_credential/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This crate contains types representing verifiable credentials and verifiable pre

Convenience methods for validating [Verifiable Credentials](https://wiki.iota.org/identity.rs/concepts/verifiable_credentials/overview) and [Verifiable Presentations](https://wiki.iota.org/identity.rs/concepts/verifiable_credentials/verifiable_presentations) are also provided:

- [`CredentialValidator`](crate::validator::CredentialValidator)
- [`JwtCredentialValidator`](crate::validator::JwtCredentialValidator)
- [`JwtPresentationValidator`](crate::validator::JwtPresentationValidator)

The [IOTA Identity Framework Wiki](https://wiki.iota.org/identity.rs/concepts/verifiable_credentials/overview) offers a comprehensive overview of verifiable credentials and presentations along with practical demonstrations and examples showcasing the capabilities of this crate in creating and validating them.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::credential::Jwt;
use crate::error::Result;
use crate::validator::CredentialValidator;
use crate::validator::JwtCredentialValidator;
use crate::validator::ValidationError;
use identity_core::common::Context;
use identity_core::common::Url;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl DomainLinkageConfiguration {
.0
.linked_dids
.iter()
.map(CredentialValidator::extract_issuer_from_jwt::<CoreDID>)
.map(JwtCredentialValidator::extract_issuer_from_jwt::<CoreDID>)
.collect()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::credential::Jwt;
use crate::domain_linkage::DomainLinkageConfiguration;
use crate::domain_linkage::DomainLinkageValidationError;
use crate::domain_linkage::DomainLinkageValidationErrorCause;
use crate::validator::CredentialValidationOptions;
use crate::validator::CredentialValidator;
use crate::validator::FailFast;
use crate::validator::JwtCredentialValidationOptions;
use crate::validator::JwtCredentialValidator;
use identity_core::common::OneOrMany;
use identity_core::common::Url;
use identity_did::CoreDID;
Expand All @@ -24,7 +24,7 @@ use super::DomainLinkageValidationResult;

#[derive(Debug, Clone)]
pub struct DomainLinkageValidator<V: JwsVerifier = EdDSAJwsVerifier> {
PhilippGackstatter marked this conversation as resolved.
Show resolved Hide resolved
validator: CredentialValidator<V>,
validator: JwtCredentialValidator<V>,
}

impl DomainLinkageValidator {
Expand All @@ -35,7 +35,7 @@ impl DomainLinkageValidator {
/// which enables you to supply a custom signature verifier if other JWS algorithms are of interest.
pub fn new() -> Self {
Self {
validator: CredentialValidator::new(),
validator: JwtCredentialValidator::new(),
}
}
}
Expand All @@ -49,7 +49,7 @@ where
/// constructor can be used. See [`DomainLinkageValidator::new`](DomainLinkageValidator::new).
pub fn with_signature_verifier(signature_verifier: V) -> Self {
Self {
validator: CredentialValidator::with_signature_verifier(signature_verifier),
validator: JwtCredentialValidator::with_signature_verifier(signature_verifier),
}
}

Expand All @@ -76,7 +76,7 @@ where
issuer: &DOC,
configuration: &DomainLinkageConfiguration,
domain: &Url,
validation_options: &CredentialValidationOptions,
validation_options: &JwtCredentialValidationOptions,
) -> DomainLinkageValidationResult {
let issuers: Vec<CoreDID> = configuration.issuers().map_err(|err| DomainLinkageValidationError {
cause: DomainLinkageValidationErrorCause::InvalidJwt,
Expand Down Expand Up @@ -123,7 +123,7 @@ where
issuer: &DOC,
credential: &Jwt,
domain: &Url,
validation_options: &CredentialValidationOptions,
validation_options: &JwtCredentialValidationOptions,
) -> DomainLinkageValidationResult {
let decoded_credential: DecodedJwtCredential = self
.validator
Expand Down Expand Up @@ -237,7 +237,7 @@ mod tests {
use crate::domain_linkage::DomainLinkageValidationResult;
use crate::domain_linkage::DomainLinkageValidator;
use crate::validator::test_utils::generate_jwk_document_with_keys;
use crate::validator::CredentialValidationOptions;
use crate::validator::JwtCredentialValidationOptions;

use crypto::signatures::ed25519::SecretKey;
use identity_core::common::Duration;
Expand Down Expand Up @@ -266,7 +266,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(validation_result.is_ok());
Expand All @@ -284,7 +284,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);
assert!(matches!(
validation_result.unwrap_err().cause,
Expand All @@ -303,7 +303,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -323,7 +323,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -347,7 +347,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(validation_result.is_ok());
Expand All @@ -369,7 +369,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -393,7 +393,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -418,7 +418,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(validation_result.is_ok());
Expand All @@ -438,7 +438,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -462,7 +462,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -485,7 +485,7 @@ mod tests {
&document,
&jwt,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(matches!(
Expand All @@ -506,7 +506,7 @@ mod tests {
&document,
&configuration,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);
assert!(matches!(
validation_result.unwrap_err().cause,
Expand All @@ -525,7 +525,7 @@ mod tests {
&document,
&configuration,
&url_foo(),
&CredentialValidationOptions::default(),
&JwtCredentialValidationOptions::default(),
);

assert!(validation_result.is_ok());
Expand Down
Loading
Loading