diff --git a/bindings/wasm/docs/api-reference.md b/bindings/wasm/docs/api-reference.md index 81983cc9f0..40686ddf64 100644 --- a/bindings/wasm/docs/api-reference.md +++ b/bindings/wasm/docs/api-reference.md @@ -76,8 +76,6 @@ and resolution of DID documents in Alias Outputs.

JwtCredentialValidator

A type for decoding and validating Credentials.

-
JwtPresentation
-
JwtPresentationOptions
JwtPresentationValidationOptions
@@ -102,6 +100,8 @@ use the methods pack and unpack instead.

MethodType

Supported verification method types.

+
Presentation
+
Resolver

Convenience type for resolving DID documents from different DID methods.

Also provides methods for resolving DID Documents associated with @@ -121,6 +121,8 @@ working with storage backed DID documents.

Timestamp
+
UnknownCredential
+
VerificationMethod

A DID Document Verification Method.

@@ -183,6 +185,12 @@ This variant is the default used if no other variant is specified when construct
start()

Initializes the console error panic hook for better error messages

+
encodeB64(data)string
+

Encode the given bytes in url-safe base64.

+
+
decodeB64(data)Uint8Array
+

Decode the given url-safe base64-encoded slice into its raw bytes.

+
verifyEdDSA(alg, signingInput, decodedSignature, publicKey)

Verify a JWS signature secured with the JwsAlgorithm::EdDSA algorithm. Only the EdCurve::Ed25519 variant is supported for now.

@@ -192,12 +200,6 @@ the IOTA Identity Framework.

This function does not check whether alg = EdDSA in the protected header. Callers are expected to assert this prior to calling the function.

-
encodeB64(data)string
-

Encode the given bytes in url-safe base64.

-
-
decodeB64(data)Uint8Array
-

Decode the given url-safe base64-encoded slice into its raw bytes.

-
@@ -849,7 +851,7 @@ produced by the corresponding private key backed by the `storage` in accordance | --- | --- | | storage | [Storage](#Storage) | | fragment | string | -| presentation | [JwtPresentation](#JwtPresentation) | +| presentation | [Presentation](#Presentation) | | signature_options | [JwsSignatureOptions](#JwsSignatureOptions) | | presentation_options | [JwtPresentationOptions](#JwtPresentationOptions) | @@ -1285,16 +1287,16 @@ It does not imply anything about a potentially present proof property on the pre **Kind**: global class * [DecodedJwtPresentation](#DecodedJwtPresentation) - * [.presentation()](#DecodedJwtPresentation+presentation) ⇒ [JwtPresentation](#JwtPresentation) + * [.presentation()](#DecodedJwtPresentation+presentation) ⇒ [Presentation](#Presentation) * [.protectedHeader()](#DecodedJwtPresentation+protectedHeader) ⇒ [JwsHeader](#JwsHeader) - * [.intoPresentation()](#DecodedJwtPresentation+intoPresentation) ⇒ [JwtPresentation](#JwtPresentation) + * [.intoPresentation()](#DecodedJwtPresentation+intoPresentation) ⇒ [Presentation](#Presentation) * [.expirationDate()](#DecodedJwtPresentation+expirationDate) ⇒ [Timestamp](#Timestamp) \| undefined * [.issuanceDate()](#DecodedJwtPresentation+issuanceDate) ⇒ [Timestamp](#Timestamp) \| undefined * [.audience()](#DecodedJwtPresentation+audience) ⇒ string \| undefined -### decodedJwtPresentation.presentation() ⇒ [JwtPresentation](#JwtPresentation) +### decodedJwtPresentation.presentation() ⇒ [Presentation](#Presentation) **Kind**: instance method of [DecodedJwtPresentation](#DecodedJwtPresentation) @@ -1304,7 +1306,7 @@ Returns a copy of the protected header parsed from the decoded JWS. **Kind**: instance method of [DecodedJwtPresentation](#DecodedJwtPresentation) -### decodedJwtPresentation.intoPresentation() ⇒ [JwtPresentation](#JwtPresentation) +### decodedJwtPresentation.intoPresentation() ⇒ [Presentation](#Presentation) Consumes the object and returns the decoded presentation. ### Warning @@ -2273,7 +2275,7 @@ produced by the corresponding private key backed by the `storage` in accordance | --- | --- | | storage | [Storage](#Storage) | | fragment | string | -| presentation | [JwtPresentation](#JwtPresentation) | +| presentation | [Presentation](#Presentation) | | signature_options | [JwsSignatureOptions](#JwsSignatureOptions) | | presentation_options | [JwtPresentationOptions](#JwtPresentationOptions) | @@ -3362,7 +3364,7 @@ Options to declare validation criteria when validating credentials. | Param | Type | | --- | --- | -| options | IJwtCredentialValidationOptions | +| options | IJwtCredentialValidationOptions \| undefined | @@ -3572,129 +3574,6 @@ If the JWT decoding fails or the issuer field is not a valid DID. | --- | --- | | credential | [Jwt](#Jwt) | - - -## JwtPresentation -**Kind**: global class - -* [JwtPresentation](#JwtPresentation) - * [new JwtPresentation(values)](#new_JwtPresentation_new) - * _instance_ - * [.context()](#JwtPresentation+context) ⇒ Array.<(string\|Record.<string, any>)> - * [.id()](#JwtPresentation+id) ⇒ string \| undefined - * [.type()](#JwtPresentation+type) ⇒ Array.<string> - * [.verifiableCredential()](#JwtPresentation+verifiableCredential) ⇒ [Array.<Jwt>](#Jwt) - * [.holder()](#JwtPresentation+holder) ⇒ string - * [.refreshService()](#JwtPresentation+refreshService) ⇒ Array.<RefreshService> - * [.termsOfUse()](#JwtPresentation+termsOfUse) ⇒ Array.<Policy> - * [.proof()](#JwtPresentation+proof) ⇒ Map.<string, any> \| undefined - * [.properties()](#JwtPresentation+properties) ⇒ Map.<string, any> - * [.toJSON()](#JwtPresentation+toJSON) ⇒ any - * [.clone()](#JwtPresentation+clone) ⇒ [JwtPresentation](#JwtPresentation) - * _static_ - * [.BaseContext()](#JwtPresentation.BaseContext) ⇒ string - * [.BaseType()](#JwtPresentation.BaseType) ⇒ string - * [.fromJSON(json)](#JwtPresentation.fromJSON) ⇒ [JwtPresentation](#JwtPresentation) - - - -### new JwtPresentation(values) -Constructs a new presentation. - - -| Param | Type | -| --- | --- | -| values | IJwtPresentation | - - - -### jwtPresentation.context() ⇒ Array.<(string\|Record.<string, any>)> -Returns a copy of the JSON-LD context(s) applicable to the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.id() ⇒ string \| undefined -Returns a copy of the unique `URI` identifying the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.type() ⇒ Array.<string> -Returns a copy of the URIs defining the type of the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.verifiableCredential() ⇒ [Array.<Jwt>](#Jwt) -Returns the JWT credentials expressing the claims of the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.holder() ⇒ string -Returns a copy of the URI of the entity that generated the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.refreshService() ⇒ Array.<RefreshService> -Returns a copy of the service(s) used to refresh an expired [Credential](#Credential) in the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.termsOfUse() ⇒ Array.<Policy> -Returns a copy of the terms-of-use specified by the presentation holder - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.proof() ⇒ Map.<string, any> \| undefined -Optional proof that can be verified by users in addition to JWS. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.properties() ⇒ Map.<string, any> -Returns a copy of the miscellaneous properties on the presentation. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.toJSON() ⇒ any -Serializes this to a JSON object. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### jwtPresentation.clone() ⇒ [JwtPresentation](#JwtPresentation) -Deep clones the object. - -**Kind**: instance method of [JwtPresentation](#JwtPresentation) - - -### JwtPresentation.BaseContext() ⇒ string -Returns the base JSON-LD context. - -**Kind**: static method of [JwtPresentation](#JwtPresentation) - - -### JwtPresentation.BaseType() ⇒ string -Returns the base type. - -**Kind**: static method of [JwtPresentation](#JwtPresentation) - - -### JwtPresentation.fromJSON(json) ⇒ [JwtPresentation](#JwtPresentation) -Deserializes an instance from a JSON object. - -**Kind**: static method of [JwtPresentation](#JwtPresentation) - -| Param | Type | -| --- | --- | -| json | any | - ## JwtPresentationOptions @@ -3776,7 +3655,7 @@ Throws an error if any of the options are invalid. | Param | Type | | --- | --- | -| options | IJwtPresentationValidationOptions | +| options | IJwtPresentationValidationOptions \| undefined | @@ -3838,28 +3717,26 @@ algorithm will be used. Validates a [`JwtPresentation`]. The following properties are validated according to `options`: -- the JWT can be decoded into semantically valid presentation. +- the JWT can be decoded into a semantically valid presentation. - the expiration and issuance date contained in the JWT claims. - the holder's signature. Validation is done with respect to the properties set in `options`. # Warning -* This method does NOT validate the constituent credentials, nor the relationship between the -credentials' issuers and the presentation holder. + +* This method does NOT validate the constituent credentials and therefore also not the relationship between the +credentials' subjects and the presentation holder. This can be done with `JwtCredentialValidationOptions`. * The lack of an error returned from this method is in of itself not enough to conclude that the presentation can be trusted. This section contains more information on additional checks that should be carried out before and after calling this method. ## The state of the supplied DID Documents. -The caller must ensure that the DID Documents in `holder` and `issuers` are up-to-date. -## Properties that are not validated - There are many properties defined in [The Verifiable Credentials Data Model](https://www.w3.org/TR/vc-data-model/) that are **not** validated, such as: -`verifiableCredential`, credentialStatus`, `type`, `credentialSchema`, `refreshService`, **and more**. -These should be manually checked after validation, according to your requirements. +The caller must ensure that the DID Documents in `holder` are up-to-date. # Errors + An error is returned whenever a validated condition is not satisfied or when decoding fails. **Kind**: instance method of [JwtPresentationValidator](#JwtPresentationValidator) @@ -3879,7 +3756,7 @@ Validates the semantic structure of the `JwtPresentation`. | Param | Type | | --- | --- | -| presentation | [JwtPresentation](#JwtPresentation) | +| presentation | [Presentation](#Presentation) | @@ -4246,6 +4123,129 @@ Deserializes an instance from a JSON object. | --- | --- | | json | any | + + +## Presentation +**Kind**: global class + +* [Presentation](#Presentation) + * [new Presentation(values)](#new_Presentation_new) + * _instance_ + * [.context()](#Presentation+context) ⇒ Array.<(string\|Record.<string, any>)> + * [.id()](#Presentation+id) ⇒ string \| undefined + * [.type()](#Presentation+type) ⇒ Array.<string> + * [.verifiableCredential()](#Presentation+verifiableCredential) ⇒ [Array.<UnknownCredential>](#UnknownCredential) + * [.holder()](#Presentation+holder) ⇒ string + * [.refreshService()](#Presentation+refreshService) ⇒ Array.<RefreshService> + * [.termsOfUse()](#Presentation+termsOfUse) ⇒ Array.<Policy> + * [.proof()](#Presentation+proof) ⇒ Map.<string, any> \| undefined + * [.properties()](#Presentation+properties) ⇒ Map.<string, any> + * [.toJSON()](#Presentation+toJSON) ⇒ any + * [.clone()](#Presentation+clone) ⇒ [Presentation](#Presentation) + * _static_ + * [.BaseContext()](#Presentation.BaseContext) ⇒ string + * [.BaseType()](#Presentation.BaseType) ⇒ string + * [.fromJSON(json)](#Presentation.fromJSON) ⇒ [Presentation](#Presentation) + + + +### new Presentation(values) +Constructs a new presentation. + + +| Param | Type | +| --- | --- | +| values | IPresentation | + + + +### presentation.context() ⇒ Array.<(string\|Record.<string, any>)> +Returns a copy of the JSON-LD context(s) applicable to the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.id() ⇒ string \| undefined +Returns a copy of the unique `URI` identifying the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.type() ⇒ Array.<string> +Returns a copy of the URIs defining the type of the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.verifiableCredential() ⇒ [Array.<UnknownCredential>](#UnknownCredential) +Returns the JWT credentials expressing the claims of the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.holder() ⇒ string +Returns a copy of the URI of the entity that generated the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.refreshService() ⇒ Array.<RefreshService> +Returns a copy of the service(s) used to refresh an expired [Credential](#Credential) in the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.termsOfUse() ⇒ Array.<Policy> +Returns a copy of the terms-of-use specified by the presentation holder + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.proof() ⇒ Map.<string, any> \| undefined +Optional proof that can be verified by users in addition to JWS. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.properties() ⇒ Map.<string, any> +Returns a copy of the miscellaneous properties on the presentation. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.toJSON() ⇒ any +Serializes this to a JSON object. + +**Kind**: instance method of [Presentation](#Presentation) + + +### presentation.clone() ⇒ [Presentation](#Presentation) +Deep clones the object. + +**Kind**: instance method of [Presentation](#Presentation) + + +### Presentation.BaseContext() ⇒ string +Returns the base JSON-LD context. + +**Kind**: static method of [Presentation](#Presentation) + + +### Presentation.BaseType() ⇒ string +Returns the base type. + +**Kind**: static method of [Presentation](#Presentation) + + +### Presentation.fromJSON(json) ⇒ [Presentation](#Presentation) +Deserializes an instance from a JSON object. + +**Kind**: static method of [Presentation](#Presentation) + +| Param | Type | +| --- | --- | +| json | any | + ## Resolver @@ -4596,6 +4596,62 @@ Deserializes an instance from a JSON object. | --- | --- | | json | any | + + +## UnknownCredential +**Kind**: global class + +* [UnknownCredential](#UnknownCredential) + * _instance_ + * [.tryIntoJwt()](#UnknownCredential+tryIntoJwt) ⇒ [Jwt](#Jwt) \| undefined + * [.tryIntoCredential()](#UnknownCredential+tryIntoCredential) ⇒ [Credential](#Credential) \| undefined + * [.tryIntoRaw()](#UnknownCredential+tryIntoRaw) ⇒ Record.<string, any> \| undefined + * [.toJSON()](#UnknownCredential+toJSON) ⇒ any + * [.clone()](#UnknownCredential+clone) ⇒ [UnknownCredential](#UnknownCredential) + * _static_ + * [.fromJSON(json)](#UnknownCredential.fromJSON) ⇒ [UnknownCredential](#UnknownCredential) + + + +### unknownCredential.tryIntoJwt() ⇒ [Jwt](#Jwt) \| undefined +Returns a `Jwt` if the credential is of type string, `undefined` otherwise. + +**Kind**: instance method of [UnknownCredential](#UnknownCredential) + + +### unknownCredential.tryIntoCredential() ⇒ [Credential](#Credential) \| undefined +Returns a `Credential` if the credential is of said type, `undefined` otherwise. + +**Kind**: instance method of [UnknownCredential](#UnknownCredential) + + +### unknownCredential.tryIntoRaw() ⇒ Record.<string, any> \| undefined +Returns the contained value as JSON, if it can be converted, `undefined` otherwise. + +**Kind**: instance method of [UnknownCredential](#UnknownCredential) + + +### unknownCredential.toJSON() ⇒ any +Serializes this to a JSON object. + +**Kind**: instance method of [UnknownCredential](#UnknownCredential) + + +### unknownCredential.clone() ⇒ [UnknownCredential](#UnknownCredential) +Deep clones the object. + +**Kind**: instance method of [UnknownCredential](#UnknownCredential) + + +### UnknownCredential.fromJSON(json) ⇒ [UnknownCredential](#UnknownCredential) +Deserializes an instance from a JSON object. + +**Kind**: static method of [UnknownCredential](#UnknownCredential) + +| Param | Type | +| --- | --- | +| json | any | + ## VerificationMethod @@ -4848,28 +4904,6 @@ Return after the first error occurs. Initializes the console error panic hook for better error messages **Kind**: global function - - -## verifyEdDSA(alg, signingInput, decodedSignature, publicKey) -Verify a JWS signature secured with the `JwsAlgorithm::EdDSA` algorithm. -Only the `EdCurve::Ed25519` variant is supported for now. - -This function is useful when one is building an `IJwsVerifier` that extends the default provided by -the IOTA Identity Framework. - -# Warning -This function does not check whether `alg = EdDSA` in the protected header. Callers are expected to assert this -prior to calling the function. - -**Kind**: global function - -| Param | Type | -| --- | --- | -| alg | JwsAlgorithm | -| signingInput | Uint8Array | -| decodedSignature | Uint8Array | -| publicKey | [Jwk](#Jwk) | - ## encodeB64(data) ⇒ string @@ -4892,3 +4926,25 @@ Decode the given url-safe base64-encoded slice into its raw bytes. | --- | --- | | data | Uint8Array | + + +## verifyEdDSA(alg, signingInput, decodedSignature, publicKey) +Verify a JWS signature secured with the `JwsAlgorithm::EdDSA` algorithm. +Only the `EdCurve::Ed25519` variant is supported for now. + +This function is useful when one is building an `IJwsVerifier` that extends the default provided by +the IOTA Identity Framework. + +# Warning +This function does not check whether `alg = EdDSA` in the protected header. Callers are expected to assert this +prior to calling the function. + +**Kind**: global function + +| Param | Type | +| --- | --- | +| alg | JwsAlgorithm | +| signingInput | Uint8Array | +| decodedSignature | Uint8Array | +| publicKey | [Jwk](#Jwk) | + diff --git a/bindings/wasm/examples/src/0_basic/6_create_vp.ts b/bindings/wasm/examples/src/0_basic/6_create_vp.ts index e321f040e6..deb43a8476 100644 --- a/bindings/wasm/examples/src/0_basic/6_create_vp.ts +++ b/bindings/wasm/examples/src/0_basic/6_create_vp.ts @@ -15,11 +15,11 @@ import { Jwt, JwtCredentialValidationOptions, JwtCredentialValidator, - JwtPresentation, JwtPresentationOptions, JwtPresentationValidationOptions, JwtPresentationValidator, KeyIdMemStore, + Presentation, Resolver, Storage, SubjectHolderRelationship, @@ -130,7 +130,7 @@ export async function createVP() { // =========================================================================== // Create a Verifiable Presentation from the Credential - const unsignedVp = new JwtPresentation({ + const unsignedVp = new Presentation({ holder: aliceDocument.id(), verifiableCredential: [credentialJwt], }); @@ -188,13 +188,16 @@ export async function createVP() { // Validate the credentials in the presentation. let credentialValidator = new JwtCredentialValidator(); let validationOptions = new JwtCredentialValidationOptions({ - subjectHolderRelationship: [presentationHolderDID.toString(), SubjectHolderRelationship.AlwaysSubject], + subjectHolderRelationship: [ + presentationHolderDID.toString(), + SubjectHolderRelationship.AlwaysSubject, + ], }); let jwtCredentials: Jwt[] = decodedPresentation .presentation() .verifiableCredential() - .map(credential => { + .map((credential) => { const jwt = credential.tryIntoJwt(); if (!jwt) { throw new Error("expected a JWT credential"); diff --git a/bindings/wasm/examples/src/0_basic/7_revoke_vc.ts b/bindings/wasm/examples/src/0_basic/7_revoke_vc.ts index cacb2963fb..06fdcc7701 100644 --- a/bindings/wasm/examples/src/0_basic/7_revoke_vc.ts +++ b/bindings/wasm/examples/src/0_basic/7_revoke_vc.ts @@ -47,7 +47,10 @@ export async function revokeVC() { }; // Create an identity for the issuer with one verification method `key-1`. - const issuerStorage: Storage = new Storage(new JwkMemStore(), new KeyIdMemStore()); + const issuerStorage: Storage = new Storage( + new JwkMemStore(), + new KeyIdMemStore(), + ); let { document: issuerDocument, fragment: issuerFragment } = await createDid( client, issuerSecretManager, @@ -55,8 +58,11 @@ export async function revokeVC() { ); // Create an identity for the holder, in this case also the subject. - const aliceStorage: Storage = new Storage(new JwkMemStore(), new KeyIdMemStore()); - let { document: aliceDocument, fragment: aliceFragment } = await createDid( + const aliceStorage: Storage = new Storage( + new JwkMemStore(), + new KeyIdMemStore(), + ); + let { document: aliceDocument } = await createDid( client, issuerSecretManager, aliceStorage, @@ -74,15 +80,23 @@ export async function revokeVC() { issuerDocument.insertService(service); // Resolve the latest output and update it with the given document. - let aliasOutput: IAliasOutput = await didClient.updateDidOutput(issuerDocument); + let aliasOutput: IAliasOutput = await didClient.updateDidOutput( + issuerDocument, + ); // Because the size of the DID document increased, we have to increase the allocated storage deposit. // This increases the deposit amount to the new minimum. let rentStructure: IRent = await didClient.getRentStructure(); - aliasOutput.amount = TransactionHelper.getStorageDeposit(aliasOutput, rentStructure).toString(); + aliasOutput.amount = TransactionHelper.getStorageDeposit( + aliasOutput, + rentStructure, + ).toString(); // Publish the document. - issuerDocument = await didClient.publishDidOutput(issuerSecretManager, aliasOutput); + issuerDocument = await didClient.publishDidOutput( + issuerSecretManager, + aliasOutput, + ); // Create a credential subject indicating the degree earned by Alice, linked to their DID. const subject = { @@ -137,8 +151,14 @@ export async function revokeVC() { // Publish the changes. aliasOutput = await didClient.updateDidOutput(issuerDocument); rentStructure = await didClient.getRentStructure(); - aliasOutput.amount = TransactionHelper.getStorageDeposit(aliasOutput, rentStructure).toString(); - const update2: IotaDocument = await didClient.publishDidOutput(issuerSecretManager, aliasOutput); + aliasOutput.amount = TransactionHelper.getStorageDeposit( + aliasOutput, + rentStructure, + ).toString(); + const update2: IotaDocument = await didClient.publishDidOutput( + issuerSecretManager, + aliasOutput, + ); // Credential verification now fails. try { @@ -159,20 +179,30 @@ export async function revokeVC() { // By removing the verification method, that signed the credential, from the issuer's DID document, // we effectively revoke the credential, as it will no longer be possible to validate the signature. - let originalMethod = issuerDocument.resolveMethod(`#${issuerFragment}`) as VerificationMethod; + let originalMethod = issuerDocument.resolveMethod( + `#${issuerFragment}`, + ) as VerificationMethod; await issuerDocument.purgeMethod(issuerStorage, originalMethod.id()); // Publish the changes. aliasOutput = await didClient.updateDidOutput(issuerDocument); rentStructure = await didClient.getRentStructure(); - aliasOutput.amount = TransactionHelper.getStorageDeposit(aliasOutput, rentStructure).toString(); - issuerDocument = await didClient.publishDidOutput(issuerSecretManager, aliasOutput); + aliasOutput.amount = TransactionHelper.getStorageDeposit( + aliasOutput, + rentStructure, + ).toString(); + issuerDocument = await didClient.publishDidOutput( + issuerSecretManager, + aliasOutput, + ); // We expect the verifiable credential to be revoked. const resolver = new Resolver({ client: didClient }); try { // Resolve the issuer's updated DID Document to ensure the key was revoked successfully. - const resolvedIssuerDoc = await resolver.resolve(issuerDocument.id().toString()); + const resolvedIssuerDoc = await resolver.resolve( + issuerDocument.id().toString(), + ); jwtCredentialValidator.validate( credentialJwt, resolvedIssuerDoc, diff --git a/bindings/wasm/src/credential/jwt_presentation/mod.rs b/bindings/wasm/src/credential/jwt_presentation/mod.rs index 3f4bb3b90c..aa4af436ab 100644 --- a/bindings/wasm/src/credential/jwt_presentation/mod.rs +++ b/bindings/wasm/src/credential/jwt_presentation/mod.rs @@ -1,7 +1,8 @@ // Copyright 2020-2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod jwt_presentation; -mod jwt_presentation_builder; +mod presentation; +mod presentation_builder; -pub use self::jwt_presentation::*; +pub use self::presentation::*; +pub use self::presentation_builder::*; diff --git a/bindings/wasm/src/credential/jwt_presentation/jwt_presentation.rs b/bindings/wasm/src/credential/jwt_presentation/presentation.rs similarity index 77% rename from bindings/wasm/src/credential/jwt_presentation/jwt_presentation.rs rename to bindings/wasm/src/credential/jwt_presentation/presentation.rs index 73a1b54ed2..eabda25465 100644 --- a/bindings/wasm/src/credential/jwt_presentation/jwt_presentation.rs +++ b/bindings/wasm/src/credential/jwt_presentation/presentation.rs @@ -3,48 +3,48 @@ use identity_iota::core::Context; use identity_iota::core::Object; -use identity_iota::credential::JwtPresentation; -use identity_iota::credential::JwtPresentationBuilder; +use identity_iota::credential::Presentation; +use identity_iota::credential::PresentationBuilder; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; use crate::common::ArrayString; use crate::common::MapStringAny; -use crate::credential::jwt_presentation::jwt_presentation_builder::IJwtPresentation; use crate::credential::ArrayContext; use crate::credential::ArrayPolicy; use crate::credential::ArrayRefreshService; use crate::credential::ArrayUnknownCredential; +use crate::credential::IPresentation; use crate::credential::UnknownCredential; use crate::credential::WasmUnknownCredentialContainer; use crate::error::Result; use crate::error::WasmResult; -#[wasm_bindgen(js_name = JwtPresentation, inspectable)] -pub struct WasmJwtPresentation(pub(crate) JwtPresentation); +#[wasm_bindgen(js_name = Presentation, inspectable)] +pub struct WasmPresentation(pub(crate) Presentation); -#[wasm_bindgen(js_class = JwtPresentation)] -impl WasmJwtPresentation { +#[wasm_bindgen(js_class = Presentation)] +impl WasmPresentation { /// Returns the base JSON-LD context. #[wasm_bindgen(js_name = "BaseContext")] pub fn base_context() -> Result { - match JwtPresentation::::base_context() { + match Presentation::::base_context() { Context::Url(url) => Ok(url.to_string()), - Context::Obj(_) => Err(JsError::new("JwtPresentation.BaseContext should be a single URL").into()), + Context::Obj(_) => Err(JsError::new("Presentation.BaseContext should be a single URL").into()), } } /// Returns the base type. #[wasm_bindgen(js_name = "BaseType")] pub fn base_type() -> String { - JwtPresentation::::base_type().to_owned() + Presentation::::base_type().to_owned() } /// Constructs a new presentation. #[wasm_bindgen(constructor)] - pub fn new(values: IJwtPresentation) -> Result { - let builder: JwtPresentationBuilder = - JwtPresentationBuilder::::try_from(values)?; + pub fn new(values: IPresentation) -> Result { + let builder: PresentationBuilder = + PresentationBuilder::::try_from(values)?; builder.build().map(Self).wasm_result() } @@ -139,11 +139,11 @@ impl WasmJwtPresentation { } } -impl_wasm_json!(WasmJwtPresentation, JwtPresentation); -impl_wasm_clone!(WasmJwtPresentation, JwtPresentation); +impl_wasm_json!(WasmPresentation, Presentation); +impl_wasm_clone!(WasmPresentation, Presentation); -impl From> for WasmJwtPresentation { - fn from(presentation: JwtPresentation) -> WasmJwtPresentation { +impl From> for WasmPresentation { + fn from(presentation: Presentation) -> WasmPresentation { Self(presentation) } } diff --git a/bindings/wasm/src/credential/jwt_presentation/jwt_presentation_builder.rs b/bindings/wasm/src/credential/jwt_presentation/presentation_builder.rs similarity index 81% rename from bindings/wasm/src/credential/jwt_presentation/jwt_presentation_builder.rs rename to bindings/wasm/src/credential/jwt_presentation/presentation_builder.rs index d800b1bf4a..c5ea298710 100644 --- a/bindings/wasm/src/credential/jwt_presentation/jwt_presentation_builder.rs +++ b/bindings/wasm/src/credential/jwt_presentation/presentation_builder.rs @@ -5,8 +5,8 @@ use identity_iota::core::Context; use identity_iota::core::Object; use identity_iota::core::OneOrMany; use identity_iota::core::Url; -use identity_iota::credential::JwtPresentationBuilder; use identity_iota::credential::Policy; +use identity_iota::credential::PresentationBuilder; use identity_iota::credential::RefreshService; use proc_typescript::typescript; use wasm_bindgen::prelude::*; @@ -14,11 +14,11 @@ use wasm_bindgen::prelude::*; use crate::credential::UnknownCredential; use crate::error::WasmResult; -impl TryFrom for JwtPresentationBuilder { +impl TryFrom for PresentationBuilder { type Error = JsValue; - fn try_from(values: IJwtPresentation) -> std::result::Result { - let IJwtPresentationHelper { + fn try_from(values: IPresentation) -> std::result::Result { + let IPresentationHelper { context, id, r#type, @@ -27,10 +27,10 @@ impl TryFrom for JwtPresentationBuilder { refresh_service, terms_of_use, properties, - } = values.into_serde::().wasm_result()?; + } = values.into_serde::().wasm_result()?; - let mut builder: JwtPresentationBuilder = - JwtPresentationBuilder::new(Url::parse(holder).wasm_result()?, properties); + let mut builder: PresentationBuilder = + PresentationBuilder::new(Url::parse(holder).wasm_result()?, properties); if let Some(context) = context { for value in context.into_vec() { @@ -65,15 +65,15 @@ impl TryFrom for JwtPresentationBuilder { #[wasm_bindgen] extern "C" { - #[wasm_bindgen(typescript_type = "IJwtPresentation")] - pub type IJwtPresentation; + #[wasm_bindgen(typescript_type = "IPresentation")] + pub type IPresentation; } -/// Fields for constructing a new {@link JwtPresentation}. +/// Fields for constructing a new {@link Presentation}. #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -#[typescript(name = "IJwtPresentation", readonly, optional)] -struct IJwtPresentationHelper { +#[typescript(name = "IPresentation", readonly, optional)] +struct IPresentationHelper { /// The JSON-LD context(s) applicable to the presentation. #[typescript(type = "string | Record | Array>")] context: Option>, diff --git a/bindings/wasm/src/credential/jwt_presentation_validation/decoded_jwt_presentation.rs b/bindings/wasm/src/credential/jwt_presentation_validation/decoded_jwt_presentation.rs index 9019e61ea0..aa2447f22e 100644 --- a/bindings/wasm/src/credential/jwt_presentation_validation/decoded_jwt_presentation.rs +++ b/bindings/wasm/src/credential/jwt_presentation_validation/decoded_jwt_presentation.rs @@ -5,7 +5,7 @@ use identity_iota::credential::DecodedJwtPresentation; use wasm_bindgen::prelude::*; use crate::common::WasmTimestamp; -use crate::credential::jwt_presentation::WasmJwtPresentation; +use crate::credential::jwt_presentation::WasmPresentation; use crate::credential::UnknownCredential; use crate::jose::WasmJwsHeader; @@ -19,8 +19,8 @@ pub struct WasmDecodedJwtPresentation(pub(crate) DecodedJwtPresentation WasmJwtPresentation { - WasmJwtPresentation(self.0.presentation.clone()) + pub fn presentation(&self) -> WasmPresentation { + WasmPresentation(self.0.presentation.clone()) } /// Returns a copy of the protected header parsed from the decoded JWS. @@ -34,8 +34,8 @@ impl WasmDecodedJwtPresentation { /// ### Warning /// This destroys the `DecodedJwtPresentation` object. #[wasm_bindgen(js_name = intoPresentation)] - pub fn into_presentation(self) -> WasmJwtPresentation { - WasmJwtPresentation(self.0.presentation) + pub fn into_presentation(self) -> WasmPresentation { + WasmPresentation(self.0.presentation) } /// The expiration date parsed from the JWT claims. diff --git a/bindings/wasm/src/credential/jwt_presentation_validation/jwt_presentation_validator.rs b/bindings/wasm/src/credential/jwt_presentation_validation/jwt_presentation_validator.rs index 045b06d689..b1db11c3cb 100644 --- a/bindings/wasm/src/credential/jwt_presentation_validation/jwt_presentation_validator.rs +++ b/bindings/wasm/src/credential/jwt_presentation_validation/jwt_presentation_validator.rs @@ -4,7 +4,7 @@ use super::decoded_jwt_presentation::WasmDecodedJwtPresentation; use super::options::WasmJwtPresentationValidationOptions; use crate::common::ImportedDocumentLock; -use crate::credential::jwt_presentation::WasmJwtPresentation; +use crate::credential::jwt_presentation::WasmPresentation; use crate::credential::WasmJwt; use crate::did::IToCoreDocument; use crate::did::WasmCoreDID; @@ -73,7 +73,7 @@ impl WasmJwtPresentationValidator { /// Validates the semantic structure of the `JwtPresentation`. #[wasm_bindgen(js_name = checkStructure)] - pub fn check_structure(presentation: &WasmJwtPresentation) -> Result<()> { + pub fn check_structure(presentation: &WasmPresentation) -> Result<()> { JwtPresentationValidator::check_structure(&presentation.0).wasm_result()?; Ok(()) } diff --git a/bindings/wasm/src/did/wasm_core_document.rs b/bindings/wasm/src/did/wasm_core_document.rs index a4ed615a75..43cefa603d 100644 --- a/bindings/wasm/src/did/wasm_core_document.rs +++ b/bindings/wasm/src/did/wasm_core_document.rs @@ -20,7 +20,7 @@ use crate::credential::UnknownCredential; use crate::credential::WasmCredential; use crate::credential::WasmJws; use crate::credential::WasmJwt; -use crate::credential::WasmJwtPresentation; +use crate::credential::WasmPresentation; use crate::did::service::WasmService; use crate::did::wasm_did_url::WasmDIDUrl; use crate::error::Result; @@ -43,8 +43,8 @@ use identity_iota::core::OneOrSet; use identity_iota::core::OrderedSet; use identity_iota::core::Url; use identity_iota::credential::Credential; -use identity_iota::credential::JwtPresentation; use identity_iota::credential::JwtPresentationOptions; +use identity_iota::credential::Presentation; use identity_iota::credential::RevocationDocumentExt; use identity_iota::did::CoreDID; use identity_iota::did::DIDUrl; @@ -706,14 +706,14 @@ impl WasmCoreDocument { &self, storage: &WasmStorage, fragment: String, - presentation: &WasmJwtPresentation, + presentation: &WasmPresentation, signature_options: &WasmJwsSignatureOptions, presentation_options: &WasmJwtPresentationOptions, ) -> Result { let storage_clone: Rc = storage.0.clone(); let options_clone: JwsSignatureOptions = signature_options.0.clone(); let document_lock_clone: Rc = self.0.clone(); - let presentation_clone: JwtPresentation = presentation.0.clone(); + let presentation_clone: Presentation = presentation.0.clone(); let presentation_options_clone: JwtPresentationOptions = presentation_options.0.clone(); let promise: Promise = future_to_promise(async move { document_lock_clone diff --git a/bindings/wasm/src/iota/iota_document.rs b/bindings/wasm/src/iota/iota_document.rs index 029be6b905..ec62e707e6 100644 --- a/bindings/wasm/src/iota/iota_document.rs +++ b/bindings/wasm/src/iota/iota_document.rs @@ -8,8 +8,8 @@ use identity_iota::core::OrderedSet; use identity_iota::core::Timestamp; use identity_iota::core::Url; use identity_iota::credential::Credential; -use identity_iota::credential::JwtPresentation; use identity_iota::credential::JwtPresentationOptions; +use identity_iota::credential::Presentation; use identity_iota::did::DIDUrl; use identity_iota::iota::block::output::dto::AliasOutputDto; use identity_iota::iota::block::output::AliasOutput; @@ -45,7 +45,7 @@ use crate::credential::UnknownCredential; use crate::credential::WasmCredential; use crate::credential::WasmJws; use crate::credential::WasmJwt; -use crate::credential::WasmJwtPresentation; +use crate::credential::WasmPresentation; use crate::did::CoreDocumentLock; use crate::did::PromiseJws; use crate::did::PromiseJwt; @@ -774,14 +774,14 @@ impl WasmIotaDocument { &self, storage: &WasmStorage, fragment: String, - presentation: &WasmJwtPresentation, + presentation: &WasmPresentation, signature_options: &WasmJwsSignatureOptions, presentation_options: &WasmJwtPresentationOptions, ) -> Result { let storage_clone: Rc = storage.0.clone(); let options_clone: JwsSignatureOptions = signature_options.0.clone(); let document_lock_clone: Rc = self.0.clone(); - let presentation_clone: JwtPresentation = presentation.0.clone(); + let presentation_clone: Presentation = presentation.0.clone(); let presentation_options_clone: JwtPresentationOptions = presentation_options.0.clone(); let promise: Promise = future_to_promise(async move { document_lock_clone diff --git a/bindings/wasm/tests/credentials.ts b/bindings/wasm/tests/credentials.ts index bd54a603d0..eae0562da8 100644 --- a/bindings/wasm/tests/credentials.ts +++ b/bindings/wasm/tests/credentials.ts @@ -5,12 +5,12 @@ import { JwkMemStore, JwsAlgorithm, JwsSignatureOptions, - JwtPresentation, JwtPresentationOptions, JwtPresentationValidationOptions, JwtPresentationValidator, KeyIdMemStore, MethodScope, + Presentation, Storage, Timestamp, UnknownCredential, @@ -157,14 +157,14 @@ const presentationFields = { describe("Presentation", function() { describe("#new and field getters", function() { it("should work", async () => { - const presentation = new JwtPresentation(presentationFields); + const presentation = new Presentation(presentationFields); assert.deepStrictEqual(presentation.context(), [ - JwtPresentation.BaseContext(), + Presentation.BaseContext(), presentationFields.context, ]); assert.deepStrictEqual(presentation.id(), presentationFields.id); assert.deepStrictEqual(presentation.type(), [ - JwtPresentation.BaseType(), + Presentation.BaseType(), presentationFields.type, ]); assert.deepStrictEqual( @@ -230,12 +230,12 @@ describe("Presentation", function() { ); const otherCredential = { - "custom": "property", - "other": 5, - "isCredential": true, + custom: "property", + other: 5, + isCredential: true, }; - const unsignedVp = new JwtPresentation({ + const unsignedVp = new Presentation({ holder: doc.id(), verifiableCredential: [credentialJwt, unsignedVc, otherCredential], }); @@ -257,10 +257,18 @@ describe("Presentation", function() { new JwtPresentationValidationOptions(), ); - const credentials: UnknownCredential[] = decodedPresentation.presentation().verifiableCredential(); + const credentials: UnknownCredential[] = decodedPresentation + .presentation() + .verifiableCredential(); - assert.deepStrictEqual(credentials[0].tryIntoJwt()?.toString(), credentialJwt.toString()); - assert.deepStrictEqual(credentials[1].tryIntoCredential()?.toJSON(), unsignedVc.toJSON()); + assert.deepStrictEqual( + credentials[0].tryIntoJwt()?.toString(), + credentialJwt.toString(), + ); + assert.deepStrictEqual( + credentials[1].tryIntoCredential()?.toJSON(), + unsignedVc.toJSON(), + ); assert.deepStrictEqual(credentials[2].tryIntoRaw()!, otherCredential); }); }); diff --git a/bindings/wasm/tests/storage.ts b/bindings/wasm/tests/storage.ts index 7800be592d..6efa266d78 100644 --- a/bindings/wasm/tests/storage.ts +++ b/bindings/wasm/tests/storage.ts @@ -15,13 +15,13 @@ import { Jwt, JwtCredentialValidationOptions, JwtCredentialValidator, - JwtPresentation, JwtPresentationOptions, JwtPresentationValidationOptions, JwtPresentationValidator, KeyIdMemStore, MethodDigest, MethodScope, + Presentation, Storage, Timestamp, VerificationMethod, @@ -335,7 +335,7 @@ describe("#JwkStorageDocument", function() { new JwsSignatureOptions(), ); - const presentation = new JwtPresentation({ + const presentation = new Presentation({ holder: holderDoc.id(), verifiableCredential: [ credentialJwt.toString(), diff --git a/examples/0_basic/6_create_vp.rs b/examples/0_basic/6_create_vp.rs index fd01c6617b..e934726220 100644 --- a/examples/0_basic/6_create_vp.rs +++ b/examples/0_basic/6_create_vp.rs @@ -16,11 +16,11 @@ use identity_iota::core::OneOrMany; use identity_iota::credential::DecodedJwtCredential; use identity_iota::credential::DecodedJwtPresentation; use identity_iota::credential::Jwt; -use identity_iota::credential::JwtPresentation; -use identity_iota::credential::JwtPresentationBuilder; use identity_iota::credential::JwtPresentationOptions; use identity_iota::credential::JwtPresentationValidationOptions; use identity_iota::credential::JwtPresentationValidator; +use identity_iota::credential::Presentation; +use identity_iota::credential::PresentationBuilder; use identity_iota::did::CoreDID; use identity_iota::document::verifiable::JwsVerificationOptions; use identity_iota::storage::JwkDocumentExt; @@ -151,8 +151,8 @@ async fn main() -> anyhow::Result<()> { // =========================================================================== // Create an unsigned Presentation from the previously issued Verifiable Credential. - let presentation: JwtPresentation = - JwtPresentationBuilder::new(alice_document.id().to_url().into(), Default::default()) + let presentation: Presentation = + PresentationBuilder::new(alice_document.id().to_url().into(), Default::default()) .credential(credential_jwt) .build()?; diff --git a/identity_credential/src/credential/credential.rs b/identity_credential/src/credential/credential.rs index 89b3b89ac2..a6134065c7 100644 --- a/identity_credential/src/credential/credential.rs +++ b/identity_credential/src/credential/credential.rs @@ -70,7 +70,7 @@ pub struct Credential { #[serde(default, skip_serializing_if = "OneOrMany::is_empty")] pub evidence: OneOrMany, /// Indicates that the `Credential` must only be contained within a - /// [`Presentation`][crate::presentation::JwtPresentation] with a proof issued from the `Credential` subject. + /// [`Presentation`][crate::presentation::Presentation] with a proof issued from the `Credential` subject. #[serde(rename = "nonTransferable", skip_serializing_if = "Option::is_none")] pub non_transferable: Option, /// Miscellaneous properties. diff --git a/identity_credential/src/credential/policy.rs b/identity_credential/src/credential/policy.rs index 3d0c82f176..cd954ae81a 100644 --- a/identity_credential/src/credential/policy.rs +++ b/identity_credential/src/credential/policy.rs @@ -6,7 +6,7 @@ use identity_core::common::OneOrMany; use identity_core::common::Url; /// Information used to express obligations, prohibitions, and permissions about -/// a [`Credential`][crate::credential::Credential] or [`Presentation`][crate::presentation::JwtPresentation]. +/// a [`Credential`][crate::credential::Credential] or [`Presentation`][crate::presentation::Presentation]. /// /// [More Info](https://www.w3.org/TR/vc-data-model/#terms-of-use) #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] diff --git a/identity_credential/src/error.rs b/identity_credential/src/error.rs index cb5fb656b1..eb01449ff5 100644 --- a/identity_credential/src/error.rs +++ b/identity_credential/src/error.rs @@ -44,7 +44,7 @@ pub enum Error { #[error("could not convert JWT to the VC data model: {0}")] InconsistentCredentialJwtClaims(&'static str), - /// Caused when attempting to convert a JWT to a `JwtPresentation` that has conflicting values + /// Caused when attempting to convert a JWT to a `Presentation` that has conflicting values /// between the registered claims and those in the `vp` object. #[error("could not convert JWT to the VP data model: {0}")] InconsistentPresentationJwtClaims(&'static str), diff --git a/identity_credential/src/presentation/jwt_serialization.rs b/identity_credential/src/presentation/jwt_serialization.rs index 894998e60d..53ac27b567 100644 --- a/identity_credential/src/presentation/jwt_serialization.rs +++ b/identity_credential/src/presentation/jwt_serialization.rs @@ -16,7 +16,7 @@ use crate::credential::IssuanceDateClaims; use crate::credential::Jwt; use crate::credential::Policy; use crate::credential::RefreshService; -use crate::presentation::JwtPresentation; +use crate::presentation::Presentation; #[cfg(feature = "validator")] use crate::Error; use crate::Result; @@ -58,10 +58,10 @@ where CRED: ToOwned + Serialize + DeserializeOwned + Clone, { pub(super) fn new( - presentation: &'presentation JwtPresentation, + presentation: &'presentation Presentation, options: &JwtPresentationOptions, ) -> Result { - let JwtPresentation { + let Presentation { context, id, types, @@ -100,28 +100,28 @@ where T: ToOwned + Serialize, ::Owned: DeserializeOwned, { - /// The JSON-LD context(s) applicable to the `JwtPresentation`. + /// The JSON-LD context(s) applicable to the `Presentation`. #[serde(rename = "@context")] context: Cow<'presentation, OneOrMany>, - /// A unique `URI` that may be used to identify the `JwtPresentation`. + /// A unique `URI` that may be used to identify the `Presentation`. #[serde(skip_serializing_if = "Option::is_none")] id: Option, - /// One or more URIs defining the type of the `JwtPresentation`. + /// One or more URIs defining the type of the `Presentation`. #[serde(rename = "type")] types: Cow<'presentation, OneOrMany>, - /// Credential(s) expressing the claims of the `JwtPresentation`. + /// Credential(s) expressing the claims of the `Presentation`. #[serde(default = "Default::default", rename = "verifiableCredential")] pub(crate) verifiable_credential: Cow<'presentation, OneOrMany>, - /// Service(s) used to refresh an expired [`Credential`] in the `JwtPresentation`. + /// Service(s) used to refresh an expired [`Credential`] in the `Presentation`. #[serde(default, rename = "refreshService", skip_serializing_if = "OneOrMany::is_empty")] refresh_service: Cow<'presentation, OneOrMany>, - /// Terms-of-use specified by the `JwtPresentation` holder. + /// Terms-of-use specified by the `Presentation` holder. #[serde(default, rename = "termsOfUse", skip_serializing_if = "OneOrMany::is_empty")] terms_of_use: Cow<'presentation, OneOrMany>, /// Miscellaneous properties. #[serde(flatten)] properties: Cow<'presentation, T>, - /// Proof(s) used to verify a `JwtPresentation` + /// Proof(s) used to verify a `Presentation` #[serde(skip_serializing_if = "Option::is_none")] proof: Option>, } @@ -132,7 +132,7 @@ where CRED: ToOwned + Serialize + DeserializeOwned + Clone, T: ToOwned + Serialize + DeserializeOwned, { - pub(crate) fn try_into_presentation(self) -> Result> { + pub(crate) fn try_into_presentation(self) -> Result> { self.check_consistency()?; let Self { exp: _, @@ -153,7 +153,7 @@ where proof, } = vp; - let presentation = JwtPresentation { + let presentation = Presentation { context: context.into_owned(), id: jti.map(Cow::into_owned), types: types.into_owned(), diff --git a/identity_credential/src/presentation/mod.rs b/identity_credential/src/presentation/mod.rs index 528c7c73b1..c070ecaa6f 100644 --- a/identity_credential/src/presentation/mod.rs +++ b/identity_credential/src/presentation/mod.rs @@ -5,14 +5,14 @@ #![allow(clippy::module_inception)] -mod jwt_presentation; -mod jwt_presentation_builder; mod jwt_presentation_options; mod jwt_serialization; +mod presentation; +mod presentation_builder; -pub use self::jwt_presentation::JwtPresentation; -pub use self::jwt_presentation_builder::JwtPresentationBuilder; pub use self::jwt_presentation_options::JwtPresentationOptions; +pub use self::presentation::Presentation; +pub use self::presentation_builder::PresentationBuilder; #[cfg(feature = "validator")] pub(crate) use self::jwt_serialization::PresentationJwtClaims; diff --git a/identity_credential/src/presentation/jwt_presentation.rs b/identity_credential/src/presentation/presentation.rs similarity index 83% rename from identity_credential/src/presentation/jwt_presentation.rs rename to identity_credential/src/presentation/presentation.rs index be73baccf4..7519d5a246 100644 --- a/identity_credential/src/presentation/jwt_presentation.rs +++ b/identity_credential/src/presentation/presentation.rs @@ -20,12 +20,12 @@ use crate::error::Error; use crate::error::Result; use super::jwt_serialization::PresentationJwtClaims; -use super::JwtPresentationBuilder; use super::JwtPresentationOptions; +use super::PresentationBuilder; /// Represents a bundle of one or more [`Credential`]s. #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub struct JwtPresentation { +pub struct Presentation { /// The JSON-LD context(s) applicable to the `Presentation`. #[serde(rename = "@context")] pub context: OneOrMany, @@ -54,26 +54,26 @@ pub struct JwtPresentation { pub proof: Option, } -impl JwtPresentation { - /// Returns the base JSON-LD context for `JwtPresentation`s. +impl Presentation { + /// Returns the base JSON-LD context for `Presentation`s. pub fn base_context() -> &'static Context { Credential::::base_context() } - /// Returns the base type for `JwtPresentation`s. + /// Returns the base type for `Presentation`s. pub const fn base_type() -> &'static str { "VerifiablePresentation" } - /// Creates a `JwtPresentationBuilder` to configure a new Presentation. + /// Creates a `PresentationBuilder` to configure a new Presentation. /// - /// This is the same as [JwtPresentationBuilder::new]. - pub fn builder(holder: Url, properties: T) -> JwtPresentationBuilder { - JwtPresentationBuilder::new(holder, properties) + /// This is the same as [PresentationBuilder::new]. + pub fn builder(holder: Url, properties: T) -> PresentationBuilder { + PresentationBuilder::new(holder, properties) } - /// Returns a new `JwtPresentation` based on the `JwtPresentationBuilder` configuration. - pub fn from_builder(builder: JwtPresentationBuilder) -> Result { + /// Returns a new `Presentation` based on the `PresentationBuilder` configuration. + pub fn from_builder(builder: PresentationBuilder) -> Result { let this: Self = Self { context: builder.context.into(), id: builder.id, @@ -90,7 +90,7 @@ impl JwtPresentation { Ok(this) } - /// Validates the semantic structure of the `JwtPresentation`. + /// Validates the semantic structure of the `Presentation`. /// /// # Warning /// @@ -110,7 +110,7 @@ impl JwtPresentation { Ok(()) } - /// Serializes the [`JwtPresentation`] as a JWT claims set + /// Serializes the [`Presentation`] as a JWT claims set /// in accordance with [VC-JWT version 1.1.](https://w3c.github.io/vc-jwt/#version-1.1). /// /// The resulting string can be used as the payload of a JWS when issuing the credential. @@ -125,7 +125,7 @@ impl JwtPresentation { .map_err(|err| Error::JwtClaimsSetSerializationError(err.into())) } - /// Returns a reference to the `JwtPresentation` proof, if it exists. + /// Returns a reference to the `Presentation` proof, if it exists. /// /// Note that this is not the JWS or JWT of the presentation but a separate field that can be used to /// prove additional claims or include proofs not based on digital signatures like Proof-of-Work. @@ -139,7 +139,7 @@ impl JwtPresentation { } } -impl Display for JwtPresentation +impl Display for Presentation where T: Serialize, { diff --git a/identity_credential/src/presentation/jwt_presentation_builder.rs b/identity_credential/src/presentation/presentation_builder.rs similarity index 78% rename from identity_credential/src/presentation/jwt_presentation_builder.rs rename to identity_credential/src/presentation/presentation_builder.rs index 620988dd72..e6c750b42d 100644 --- a/identity_credential/src/presentation/jwt_presentation_builder.rs +++ b/identity_credential/src/presentation/presentation_builder.rs @@ -10,11 +10,11 @@ use crate::credential::Policy; use crate::credential::RefreshService; use crate::error::Result; -use super::JwtPresentation; +use super::Presentation; -/// A `JwtPresentationBuilder` is used to create a customized [JwtPresentation]. +/// A `PresentationBuilder` is used to create a customized [Presentation]. #[derive(Clone, Debug)] -pub struct JwtPresentationBuilder { +pub struct PresentationBuilder { pub(crate) context: Vec, pub(crate) id: Option, pub(crate) types: Vec, @@ -25,13 +25,13 @@ pub struct JwtPresentationBuilder { pub(crate) properties: T, } -impl JwtPresentationBuilder { - /// Creates a new `JwtPresentationBuilder`. +impl PresentationBuilder { + /// Creates a new `PresentationBuilder`. pub fn new(holder: Url, properties: T) -> Self { Self { - context: vec![JwtPresentation::::base_context().clone()], + context: vec![Presentation::::base_context().clone()], id: None, - types: vec![JwtPresentation::::base_type().into()], + types: vec![Presentation::::base_type().into()], credentials: Vec::new(), holder, refresh_service: Vec::new(), @@ -83,12 +83,12 @@ impl JwtPresentationBuilder { } /// Returns a new `Presentation` based on the `PresentationBuilder` configuration. - pub fn build(self) -> Result> { - JwtPresentation::from_builder(self) + pub fn build(self) -> Result> { + Presentation::from_builder(self) } } -impl JwtPresentationBuilder { +impl PresentationBuilder { /// Adds a new custom property. #[must_use] pub fn property(mut self, key: K, value: V) -> Self @@ -128,8 +128,8 @@ mod tests { use crate::credential::CredentialBuilder; use crate::credential::Jwt; use crate::credential::Subject; - use crate::presentation::JwtPresentation; - use crate::presentation::JwtPresentationBuilder; + use crate::presentation::Presentation; + use crate::presentation::PresentationBuilder; fn subject() -> Subject { let json: Value = json!({ @@ -158,23 +158,19 @@ mod tests { let credential_jwt = Jwt::new(credential.serialize_jwt().unwrap()); - let presentation: JwtPresentation = - JwtPresentationBuilder::new(Url::parse("did:test:abc1").unwrap(), Object::new()) - .type_("ExamplePresentation") - .credential(credential_jwt) - .build() - .unwrap(); + let presentation: Presentation = PresentationBuilder::new(Url::parse("did:test:abc1").unwrap(), Object::new()) + .type_("ExamplePresentation") + .credential(credential_jwt) + .build() + .unwrap(); assert_eq!(presentation.context.len(), 1); assert_eq!( presentation.context.get(0).unwrap(), - JwtPresentation::::base_context() + Presentation::::base_context() ); assert_eq!(presentation.types.len(), 2); - assert_eq!( - presentation.types.get(0).unwrap(), - JwtPresentation::::base_type() - ); + assert_eq!(presentation.types.get(0).unwrap(), Presentation::::base_type()); assert_eq!(presentation.types.get(1).unwrap(), "ExamplePresentation"); assert_eq!(presentation.verifiable_credential.len(), 1); } diff --git a/identity_credential/src/validator/vc_jwt_validation/error.rs b/identity_credential/src/validator/vc_jwt_validation/error.rs index b293cbfacc..d98adf37bf 100644 --- a/identity_credential/src/validator/vc_jwt_validation/error.rs +++ b/identity_credential/src/validator/vc_jwt_validation/error.rs @@ -80,7 +80,7 @@ pub enum ValidationError { /// correct. #[error("the credential's structure is not semantically correct")] CredentialStructure(#[source] crate::Error), - /// Indicates that the structure of the [JwtPresentation](crate::presentation::JwtPresentation) is not + /// Indicates that the structure of the [Presentation](crate::presentation::Presentation) is not /// semantically correct. #[error("the presentation's structure is not semantically correct")] PresentationStructure(#[source] crate::Error), diff --git a/identity_credential/src/validator/vp_jwt_validation/decoded_jwt_presentation.rs b/identity_credential/src/validator/vp_jwt_validation/decoded_jwt_presentation.rs index 263a353049..027c62ae2d 100644 --- a/identity_credential/src/validator/vp_jwt_validation/decoded_jwt_presentation.rs +++ b/identity_credential/src/validator/vp_jwt_validation/decoded_jwt_presentation.rs @@ -6,9 +6,9 @@ use identity_core::common::Timestamp; use identity_core::common::Url; use identity_verification::jws::JwsHeader; -use crate::presentation::JwtPresentation; +use crate::presentation::Presentation; -/// Decoded [`JwtPresentation`] from a cryptographically verified JWS. +/// Decoded [`Presentation`] from a cryptographically verified JWS. /// /// Note that having an instance of this type only means the JWS it was constructed from was verified. /// It does not imply anything about a potentially present proof property on the presentation itself. @@ -16,7 +16,7 @@ use crate::presentation::JwtPresentation; #[derive(Debug, Clone)] pub struct DecodedJwtPresentation { /// The decoded presentation parsed to the [Verifiable Credentials Data model](https://www.w3.org/TR/vc-data-model/). - pub presentation: JwtPresentation, + pub presentation: Presentation, /// The protected header parsed from the JWS. pub header: Box, /// The expiration date parsed from the JWT claims. diff --git a/identity_credential/src/validator/vp_jwt_validation/error.rs b/identity_credential/src/validator/vp_jwt_validation/error.rs index 9c8fb5088c..13ecb74154 100644 --- a/identity_credential/src/validator/vp_jwt_validation/error.rs +++ b/identity_credential/src/validator/vp_jwt_validation/error.rs @@ -9,7 +9,7 @@ use crate::validator::vc_jwt_validation::CompoundCredentialValidationError; use crate::validator::vc_jwt_validation::ValidationError; #[derive(Debug)] -/// An error caused by a failure to validate a `JwtPresentation`. +/// An error caused by a failure to validate a `Presentation`. pub struct CompoundJwtPresentationValidationError { /// Errors that occurred during validation of individual credentials, mapped by index of their /// order in the presentation. diff --git a/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validation_options.rs b/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validation_options.rs index dd6c4d07af..e8d8b5f5b2 100644 --- a/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validation_options.rs +++ b/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validation_options.rs @@ -4,7 +4,7 @@ use identity_core::common::Timestamp; use identity_document::verifiable::JwsVerificationOptions; -/// Criteria for validating a [`JwtPresentation`](crate::presentation::JwtPresentation). +/// Criteria for validating a [`Presentation`](crate::presentation::Presentation). #[derive(Debug, Default, Clone, Serialize, Deserialize)] #[non_exhaustive] #[serde(rename_all = "camelCase")] diff --git a/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validator.rs b/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validator.rs index a52476d41d..b710b50bcc 100644 --- a/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validator.rs +++ b/identity_credential/src/validator/vp_jwt_validation/jwt_presentation_validator.rs @@ -15,7 +15,7 @@ use identity_verification::jws::JwsVerifier; use std::str::FromStr; use crate::credential::Jwt; -use crate::presentation::JwtPresentation; +use crate::presentation::Presentation; use crate::presentation::PresentationJwtClaims; use crate::validator::vc_jwt_validation::SignerContext; use crate::validator::vc_jwt_validation::ValidationError; @@ -24,7 +24,7 @@ use super::CompoundJwtPresentationValidationError; use super::DecodedJwtPresentation; use super::JwtPresentationValidationOptions; -/// Struct for validating [`JwtPresentation`]. +/// Struct for validating [`Presentation`]. #[derive(Debug, Clone)] #[non_exhaustive] pub struct JwtPresentationValidator(V); @@ -50,7 +50,7 @@ where Self(signature_verifier) } - /// Validates a [`JwtPresentation`]. + /// Validates a [`Presentation`]. /// /// The following properties are validated according to `options`: /// - the JWT can be decoded into a semantically valid presentation. @@ -162,7 +162,7 @@ where let aud: Option = claims.aud.clone(); - let presentation: JwtPresentation = claims.try_into_presentation().map_err(|err| { + let presentation: Presentation = claims.try_into_presentation().map_err(|err| { CompoundJwtPresentationValidationError::one_presentation_error(ValidationError::PresentationStructure(err)) })?; @@ -204,8 +204,8 @@ impl JwtPresentationValidator { Ok(holder) } - /// Validates the semantic structure of the `JwtPresentation`. - pub fn check_structure(presentation: &JwtPresentation) -> Result<(), ValidationError> { + /// Validates the semantic structure of the `Presentation`. + pub fn check_structure(presentation: &Presentation) -> Result<(), ValidationError> { presentation .check_structure() .map_err(ValidationError::PresentationStructure) diff --git a/identity_storage/src/storage/jwk_document_ext.rs b/identity_storage/src/storage/jwk_document_ext.rs index 0c39149238..fd719596a4 100644 --- a/identity_storage/src/storage/jwk_document_ext.rs +++ b/identity_storage/src/storage/jwk_document_ext.rs @@ -18,8 +18,8 @@ use async_trait::async_trait; use identity_credential::credential::Credential; use identity_credential::credential::Jws; use identity_credential::credential::Jwt; -use identity_credential::presentation::JwtPresentation; use identity_credential::presentation::JwtPresentationOptions; +use identity_credential::presentation::Presentation; use identity_did::DIDUrl; use identity_document::document::CoreDocument; use identity_verification::jose::jws::CompactJwsEncoder; @@ -105,7 +105,7 @@ pub trait JwkDocumentExt: private::Sealed { /// produced by the corresponding private key backed by the `storage` in accordance with the passed `options`. async fn sign_presentation( &self, - presentation: &JwtPresentation, + presentation: &Presentation, storage: &Storage, fragment: &str, signature_options: &JwsSignatureOptions, @@ -431,7 +431,7 @@ impl JwkDocumentExt for CoreDocument { async fn sign_presentation( &self, - presentation: &JwtPresentation, + presentation: &Presentation, storage: &Storage, fragment: &str, jws_options: &JwsSignatureOptions, @@ -558,7 +558,7 @@ mod iota_document { } async fn sign_presentation( &self, - presentation: &JwtPresentation, + presentation: &Presentation, storage: &Storage, fragment: &str, options: &JwsSignatureOptions, diff --git a/identity_storage/src/storage/tests/presentation_validation.rs b/identity_storage/src/storage/tests/presentation_validation.rs index ae90f20af7..d0da672610 100644 --- a/identity_storage/src/storage/tests/presentation_validation.rs +++ b/identity_storage/src/storage/tests/presentation_validation.rs @@ -8,9 +8,9 @@ use identity_core::common::Url; use identity_core::convert::FromJson; use identity_credential::credential::Credential; use identity_credential::credential::Jwt; -use identity_credential::presentation::JwtPresentation; -use identity_credential::presentation::JwtPresentationBuilder; use identity_credential::presentation::JwtPresentationOptions; +use identity_credential::presentation::Presentation; +use identity_credential::presentation::PresentationBuilder; use identity_credential::validator::DecodedJwtPresentation; use identity_credential::validator::JwtPresentationValidationOptions; use identity_credential::validator::JwtPresentationValidator; @@ -45,8 +45,8 @@ where let credential: CredentialSetup = generate_credential(&setup.issuer_doc, &[&setup.subject_doc], None, None); let jws = sign_credential(&setup, &credential.credential).await; - let presentation: JwtPresentation = - JwtPresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) + let presentation: Presentation = + PresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) .credential(jws) .build() .unwrap(); @@ -102,8 +102,8 @@ where let jws = sign_credential(&setup, &credential.credential).await; let jws_2 = sign_credential(&setup, &credential_2.credential).await; - let presentation: JwtPresentation = - JwtPresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) + let presentation: Presentation = + PresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) .credential(jws.clone()) .credential(jws_2.clone()) .build() @@ -160,8 +160,8 @@ where let credential: CredentialSetup = generate_credential(&setup.issuer_doc, &[&setup.subject_doc], None, None); let jws = sign_credential(&setup, &credential.credential).await; - let presentation: JwtPresentation = - JwtPresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) + let presentation: Presentation = + PresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) .credential(jws) .build() .unwrap(); @@ -241,8 +241,8 @@ where let credential: CredentialSetup = generate_credential(&setup.issuer_doc, &[&setup.subject_doc], None, None); let jws = sign_credential(&setup, &credential.credential).await; - let presentation: JwtPresentation = - JwtPresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) + let presentation: Presentation = + PresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) .credential(jws) .build() .unwrap(); @@ -306,8 +306,8 @@ where let credential: CredentialSetup = generate_credential(&setup.issuer_doc, &[&setup.subject_doc], None, None); let jws = sign_credential(&setup, &credential.credential).await; - let presentation: JwtPresentation = - JwtPresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) + let presentation: Presentation = + PresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) .credential(jws) .build() .unwrap(); @@ -371,8 +371,8 @@ where let credential: CredentialSetup = generate_credential(&setup.issuer_doc, &[&setup.subject_doc], None, None); let jws = sign_credential(&setup, &credential.credential).await; - let presentation: JwtPresentation = - JwtPresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) + let presentation: Presentation = + PresentationBuilder::new(setup.subject_doc.as_ref().id().to_url().into(), Object::new()) .credential(jws) .build() .unwrap();