Skip to content

Commit

Permalink
Rename CredentialValidator to JwtCredentialValidator (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmth authored Jul 19, 2023
1 parent 4aec3d0 commit 00b65cf
Show file tree
Hide file tree
Showing 22 changed files with 315 additions and 317 deletions.
146 changes: 73 additions & 73 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ See: <a href="https://identity.foundation/.well-known/resources/did-configuratio
<li>Only the <a href="https://identity.foundation/.well-known/resources/did-configuration/#json-web-token-proof-format">JSON Web Token Proof Format</a></li>
</ul>
</dd>
<dt><a href="#DomainLinkageValidator">DomainLinkageValidator</a></dt>
<dd><p>A validator for a Domain Linkage Configuration and Credentials.</p>
</dd>
<dt><a href="#Duration">Duration</a></dt>
<dd><p>A span of time.</p>
</dd>
Expand Down Expand Up @@ -76,6 +73,9 @@ and resolution of DID documents in Alias Outputs.</p>
<dt><a href="#JwtCredentialValidator">JwtCredentialValidator</a></dt>
<dd><p>A type for decoding and validating <code>Credentials</code>.</p>
</dd>
<dt><a href="#JwtDomainLinkageValidator">JwtDomainLinkageValidator</a></dt>
<dd><p>A validator for a Domain Linkage Configuration and Credentials.</p>
</dd>
<dt><a href="#JwtPresentationOptions">JwtPresentationOptions</a></dt>
<dd></dd>
<dt><a href="#JwtPresentationValidationOptions">JwtPresentationValidationOptions</a></dt>
Expand Down Expand Up @@ -822,7 +822,7 @@ See [RFC7515 section 3.1](https://www.rfc-editor.org/rfc/rfc7515#section-3.1).

### coreDocument.createCredentialJwt(storage, fragment, credential, options) ⇒ [<code>Promise.&lt;Jwt&gt;</code>](#Jwt)
Produces a JWT where the payload is produced from the given `credential`
in accordance with [VC-JWT version 1.1.](https://w3c.github.io/vc-jwt/#version-1.1).
in accordance with [VC-JWT version 1.1](https://w3c.github.io/vc-jwt/#version-1.1).

The `kid` in the protected header is the `id` of the method identified by `fragment` and the JWS signature will be
produced by the corresponding private key backed by the `storage` in accordance with the passed `options`.
Expand Down Expand Up @@ -1398,71 +1398,6 @@ Deserializes an instance from a JSON object.
| --- | --- |
| json | <code>any</code> |

<a name="DomainLinkageValidator"></a>

## DomainLinkageValidator
A validator for a Domain Linkage Configuration and Credentials.

**Kind**: global class

* [DomainLinkageValidator](#DomainLinkageValidator)
* [new DomainLinkageValidator(signatureVerifier)](#new_DomainLinkageValidator_new)
* [.validateLinkage(issuer, configuration, domain, options)](#DomainLinkageValidator+validateLinkage)
* [.validateCredential(issuer, credentialJwt, domain, options)](#DomainLinkageValidator+validateCredential)

<a name="new_DomainLinkageValidator_new"></a>

### new DomainLinkageValidator(signatureVerifier)
Creates a new `DomainLinkageValidator`. If a `signatureVerifier` is provided it will be used when
verifying decoded JWS signatures, otherwise the default which is only capable of handling the `EdDSA`
algorithm will be used.


| Param | Type |
| --- | --- |
| signatureVerifier | <code>IJwsVerifier</code> \| <code>undefined</code> |

<a name="DomainLinkageValidator+validateLinkage"></a>

### domainLinkageValidator.validateLinkage(issuer, configuration, domain, options)
Validates the linkage between a domain and a DID.
[`DomainLinkageConfiguration`] is validated according to [DID Configuration Resource Verification](https://identity.foundation/.well-known/resources/did-configuration/#did-configuration-resource-verification).

Linkage is valid if no error is thrown.

# Note:
- Only the [JSON Web Token Proof Format](https://identity.foundation/.well-known/resources/did-configuration/#json-web-token-proof-format)
- Only the Credential issued by `issuer` is verified.

# Errors
- Semantic structure of `configuration` is invalid.
- `configuration` includes multiple credentials issued by `issuer`.
- Validation of the matched Domain Linkage Credential fails.

**Kind**: instance method of [<code>DomainLinkageValidator</code>](#DomainLinkageValidator)

| Param | Type |
| --- | --- |
| issuer | [<code>CoreDocument</code>](#CoreDocument) \| <code>IToCoreDocument</code> |
| configuration | [<code>DomainLinkageConfiguration</code>](#DomainLinkageConfiguration) |
| domain | <code>string</code> |
| options | [<code>JwtCredentialValidationOptions</code>](#JwtCredentialValidationOptions) |

<a name="DomainLinkageValidator+validateCredential"></a>

### domainLinkageValidator.validateCredential(issuer, credentialJwt, domain, options)
Validates a [Domain Linkage Credential](https://identity.foundation/.well-known/resources/did-configuration/#domain-linkage-credential).
Error will be thrown in case the validation fails.

**Kind**: instance method of [<code>DomainLinkageValidator</code>](#DomainLinkageValidator)

| Param | Type |
| --- | --- |
| issuer | [<code>CoreDocument</code>](#CoreDocument) \| <code>IToCoreDocument</code> |
| credentialJwt | [<code>Jwt</code>](#Jwt) |
| domain | <code>string</code> |
| options | [<code>JwtCredentialValidationOptions</code>](#JwtCredentialValidationOptions) |

<a name="Duration"></a>

## Duration
Expand Down Expand Up @@ -1563,7 +1498,7 @@ A DID conforming to the IOTA DID method specification.
* [IotaDID](#IotaDID)
* [new IotaDID(bytes, network)](#new_IotaDID_new)
* _instance_
* [.networkStr()](#IotaDID+networkStr) ⇒ <code>string</code>
* [.network()](#IotaDID+network) ⇒ <code>string</code>
* [.tag()](#IotaDID+tag) ⇒ <code>string</code>
* [.toCoreDid()](#IotaDID+toCoreDid)[<code>CoreDID</code>](#CoreDID)
* [.scheme()](#IotaDID+scheme) ⇒ <code>string</code>
Expand Down Expand Up @@ -1599,9 +1534,9 @@ See also [placeholder](#IotaDID.placeholder).
| bytes | <code>Uint8Array</code> |
| network | <code>string</code> |

<a name="IotaDID+networkStr"></a>
<a name="IotaDID+network"></a>

### did.networkStr() ⇒ <code>string</code>
### did.network() ⇒ <code>string</code>
Returns the Tangle network name of the `IotaDID`.

**Kind**: instance method of [<code>IotaDID</code>](#IotaDID)
Expand Down Expand Up @@ -2246,7 +2181,7 @@ See [RFC7515 section 3.1](https://www.rfc-editor.org/rfc/rfc7515#section-3.1).

### iotaDocument.createCredentialJwt(storage, fragment, credential, options) ⇒ [<code>Promise.&lt;Jwt&gt;</code>](#Jwt)
Produces a JWS where the payload is produced from the given `credential`
in accordance with [VC-JWT version 1.1.](https://w3c.github.io/vc-jwt/#version-1.1).
in accordance with [VC-JWT version 1.1](https://w3c.github.io/vc-jwt/#version-1.1).

The `kid` in the protected header is the `id` of the method identified by `fragment` and the JWS signature will be
produced by the corresponding private key backed by the `storage` in accordance with the passed `options`.
Expand Down Expand Up @@ -3574,6 +3509,71 @@ If the JWT decoding fails or the issuer field is not a valid DID.
| --- | --- |
| credential | [<code>Jwt</code>](#Jwt) |

<a name="JwtDomainLinkageValidator"></a>

## JwtDomainLinkageValidator
A validator for a Domain Linkage Configuration and Credentials.

**Kind**: global class

* [JwtDomainLinkageValidator](#JwtDomainLinkageValidator)
* [new JwtDomainLinkageValidator(signatureVerifier)](#new_JwtDomainLinkageValidator_new)
* [.validateLinkage(issuer, configuration, domain, options)](#JwtDomainLinkageValidator+validateLinkage)
* [.validateCredential(issuer, credentialJwt, domain, options)](#JwtDomainLinkageValidator+validateCredential)

<a name="new_JwtDomainLinkageValidator_new"></a>

### new JwtDomainLinkageValidator(signatureVerifier)
Creates a new `JwtDomainLinkageValidator`. If a `signatureVerifier` is provided it will be used when
verifying decoded JWS signatures, otherwise the default which is only capable of handling the `EdDSA`
algorithm will be used.


| Param | Type |
| --- | --- |
| signatureVerifier | <code>IJwsVerifier</code> \| <code>undefined</code> |

<a name="JwtDomainLinkageValidator+validateLinkage"></a>

### jwtDomainLinkageValidator.validateLinkage(issuer, configuration, domain, options)
Validates the linkage between a domain and a DID.
[`DomainLinkageConfiguration`] is validated according to [DID Configuration Resource Verification](https://identity.foundation/.well-known/resources/did-configuration/#did-configuration-resource-verification).

Linkage is valid if no error is thrown.

# Note:
- Only the [JSON Web Token Proof Format](https://identity.foundation/.well-known/resources/did-configuration/#json-web-token-proof-format)
- Only the Credential issued by `issuer` is verified.

# Errors
- Semantic structure of `configuration` is invalid.
- `configuration` includes multiple credentials issued by `issuer`.
- Validation of the matched Domain Linkage Credential fails.

**Kind**: instance method of [<code>JwtDomainLinkageValidator</code>](#JwtDomainLinkageValidator)

| Param | Type |
| --- | --- |
| issuer | [<code>CoreDocument</code>](#CoreDocument) \| <code>IToCoreDocument</code> |
| configuration | [<code>DomainLinkageConfiguration</code>](#DomainLinkageConfiguration) |
| domain | <code>string</code> |
| options | [<code>JwtCredentialValidationOptions</code>](#JwtCredentialValidationOptions) |

<a name="JwtDomainLinkageValidator+validateCredential"></a>

### jwtDomainLinkageValidator.validateCredential(issuer, credentialJwt, domain, options)
Validates a [Domain Linkage Credential](https://identity.foundation/.well-known/resources/did-configuration/#domain-linkage-credential).
Error will be thrown in case the validation fails.

**Kind**: instance method of [<code>JwtDomainLinkageValidator</code>](#JwtDomainLinkageValidator)

| Param | Type |
| --- | --- |
| issuer | [<code>CoreDocument</code>](#CoreDocument) \| <code>IToCoreDocument</code> |
| credentialJwt | [<code>Jwt</code>](#Jwt) |
| domain | <code>string</code> |
| options | [<code>JwtCredentialValidationOptions</code>](#JwtCredentialValidationOptions) |

<a name="JwtPresentationOptions"></a>

## JwtPresentationOptions
Expand Down
6 changes: 3 additions & 3 deletions bindings/wasm/examples/src/1_advanced/5_domain_linkage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
Credential,
DIDUrl,
DomainLinkageConfiguration,
DomainLinkageValidator,
Duration,
IotaDID,
IotaDocument,
IotaIdentityClient,
JwkMemStore,
JwsSignatureOptions,
JwtCredentialValidationOptions,
JwtDomainLinkageValidator,
KeyIdMemStore,
LinkedDomainService,
Storage,
Expand Down Expand Up @@ -125,7 +125,7 @@ export async function domainLinkage() {

// Validate the linkage between the Domain Linkage Credential in the configuration and the provided issuer DID.
// Validation succeeds when no error is thrown.
new DomainLinkageValidator().validateLinkage(
new JwtDomainLinkageValidator().validateLinkage(
issuerDocument,
fetchedConfigurationResource,
domainFoo,
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function domainLinkage() {

// Validate the linkage between the Domain Linkage Credential in the configuration and the provided issuer DID.
// Validation succeeds when no error is thrown.
new DomainLinkageValidator().validateLinkage(
new JwtDomainLinkageValidator().validateLinkage(
didDocument,
fetchedConfigurationResource,
domains[0],
Expand Down
20 changes: 10 additions & 10 deletions bindings/wasm/src/credential/domain_linkage_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ use crate::error::WasmResult;
use crate::verification::IJwsVerifier;
use crate::verification::WasmJwsVerifier;
use identity_iota::core::Url;
use identity_iota::credential::DomainLinkageValidator;
use identity_iota::credential::JwtDomainLinkageValidator;
use wasm_bindgen::prelude::wasm_bindgen;

use super::WasmJwt;

/// A validator for a Domain Linkage Configuration and Credentials.
#[wasm_bindgen(js_name = DomainLinkageValidator)]
pub struct WasmDomainLinkageValidator {
validator: DomainLinkageValidator<WasmJwsVerifier>,
#[wasm_bindgen(js_name = JwtDomainLinkageValidator)]
pub struct WasmJwtDomainLinkageValidator {
validator: JwtDomainLinkageValidator<WasmJwsVerifier>,
}

#[wasm_bindgen(js_class = DomainLinkageValidator)]
impl WasmDomainLinkageValidator {
/// Creates a new `DomainLinkageValidator`. If a `signatureVerifier` is provided it will be used when
#[wasm_bindgen(js_class = JwtDomainLinkageValidator)]
impl WasmJwtDomainLinkageValidator {
/// Creates a new `JwtDomainLinkageValidator`. If a `signatureVerifier` is provided it will be used when
/// verifying decoded JWS signatures, otherwise the default which is only capable of handling the `EdDSA`
/// algorithm will be used.
#[wasm_bindgen(constructor)]
#[allow(non_snake_case)]
pub fn new(signatureVerifier: Option<IJwsVerifier>) -> WasmDomainLinkageValidator {
pub fn new(signatureVerifier: Option<IJwsVerifier>) -> WasmJwtDomainLinkageValidator {
let signature_verifier = WasmJwsVerifier::new(signatureVerifier);
WasmDomainLinkageValidator {
validator: DomainLinkageValidator::with_signature_verifier(signature_verifier),
WasmJwtDomainLinkageValidator {
validator: JwtDomainLinkageValidator::with_signature_verifier(signature_verifier),
}
}

Expand Down
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
2 changes: 1 addition & 1 deletion bindings/wasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl_wasm_error_from!(
identity_iota::did::Error,
identity_iota::document::Error,
identity_iota::iota::Error,
identity_iota::credential::ValidationError,
identity_iota::credential::JwtValidationError,
identity_iota::credential::RevocationError,
identity_iota::verification::Error,
identity_iota::credential::DomainLinkageValidationError
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
Loading

0 comments on commit 00b65cf

Please sign in to comment.