From 158bce6a16352bc67b2b8c2e1ac8efefa14244f6 Mon Sep 17 00:00:00 2001 From: Enrico Marconi Date: Mon, 18 Mar 2024 16:22:14 +0100 Subject: [PATCH] review comment --- bindings/wasm/docs/api-reference.md | 178 +++++++++++------- .../src/verification_method/method.rs | 15 +- 2 files changed, 115 insertions(+), 78 deletions(-) diff --git a/bindings/wasm/docs/api-reference.md b/bindings/wasm/docs/api-reference.md index 38d3645c5f..2f50e4ed3d 100644 --- a/bindings/wasm/docs/api-reference.md +++ b/bindings/wasm/docs/api-reference.md @@ -190,8 +190,9 @@ working with storage backed DID documents.

## Members
-
MethodRelationship
-
+
StatusPurpose
+

Purpose of a StatusList2021.

+
SubjectHolderRelationship

Declares how credential subjects must relate to the presentation holder.

See also the Subject-Holder Relationship section of the specification.

@@ -206,11 +207,21 @@ This variant is the default.

Any

The holder is not required to have any kind of relationship to any credential subject.

-
StatusPurpose
-

Purpose of a StatusList2021.

-
StateMetadataEncoding
+
FailFast
+

Declares when validation should return if an error occurs.

+
+
AllErrors
+

Return all errors that occur during validation.

+
+
FirstError
+

Return after the first error occurs.

+
+
MethodRelationship
+
+
CredentialStatus
+
StatusCheck

Controls validation behaviour when checking whether or not a credential has been revoked by its credentialStatus.

@@ -228,31 +239,11 @@ This variant is the default.

SkipAll

Skip all status checks.

-
FailFast
-

Declares when validation should return if an error occurs.

-
-
AllErrors
-

Return all errors that occur during validation.

-
-
FirstError
-

Return after the first error occurs.

-
-
CredentialStatus
-
## Functions
-
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.

-
verifyEd25519(alg, signingInput, decodedSignature, publicKey)

Verify a JWS signature secured with the EdDSA algorithm and curve Ed25519.

This function is useful when one is composing a IJwsVerifier that delegates @@ -261,6 +252,15 @@ This variant is the default.

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.

+
+
start()
+

Initializes the console error panic hook for better error messages

+
@@ -1147,6 +1147,15 @@ Deserializes an instance from a JSON object. A custom verification method data format. **Kind**: global class + +* [CustomMethodData](#CustomMethodData) + * [new CustomMethodData(name, data)](#new_CustomMethodData_new) + * _instance_ + * [.clone()](#CustomMethodData+clone) ⇒ [CustomMethodData](#CustomMethodData) + * [.toJSON()](#CustomMethodData+toJSON) ⇒ any + * _static_ + * [.fromJSON(json)](#CustomMethodData.fromJSON) ⇒ [CustomMethodData](#CustomMethodData) + ### new CustomMethodData(name, data) @@ -1156,6 +1165,29 @@ A custom verification method data format. | name | string | | data | any | + + +### customMethodData.clone() ⇒ [CustomMethodData](#CustomMethodData) +Deep clones the object. + +**Kind**: instance method of [CustomMethodData](#CustomMethodData) + + +### customMethodData.toJSON() ⇒ any +Serializes this to a JSON object. + +**Kind**: instance method of [CustomMethodData](#CustomMethodData) + + +### CustomMethodData.fromJSON(json) ⇒ [CustomMethodData](#CustomMethodData) +Deserializes an instance from a JSON object. + +**Kind**: static method of [CustomMethodData](#CustomMethodData) + +| Param | Type | +| --- | --- | +| json | any | + ## DIDUrl @@ -4448,7 +4480,7 @@ An error is thrown if the given `key` contains any private components. ### MethodData.newCustom(name, data) ⇒ [MethodData](#MethodData) -Creates a new [MethodData](#MethodData) variant in CAIP-10 format. +Creates a new custom [MethodData](#MethodData). **Kind**: static method of [MethodData](#MethodData) @@ -6164,9 +6196,11 @@ Deserializes an instance from a JSON object. | --- | --- | | json | any | - + + +## StatusPurpose +Purpose of a [StatusList2021](#StatusList2021). -## MethodRelationship **Kind**: global variable @@ -6195,15 +6229,35 @@ The holder must match the subject only for credentials where the [`nonTransferab The holder is not required to have any kind of relationship to any credential subject. **Kind**: global variable - + -## StatusPurpose -Purpose of a [StatusList2021](#StatusList2021). +## StateMetadataEncoding +**Kind**: global variable + + +## FailFast +Declares when validation should return if an error occurs. **Kind**: global variable - + + +## AllErrors +Return all errors that occur during validation. -## StateMetadataEncoding +**Kind**: global variable + + +## FirstError +Return after the first error occurs. + +**Kind**: global variable + + +## MethodRelationship +**Kind**: global variable + + +## CredentialStatus **Kind**: global variable @@ -6236,34 +6290,28 @@ Validate the status if supported, skip any unsupported Skip all status checks. **Kind**: global variable - - -## FailFast -Declares when validation should return if an error occurs. - -**Kind**: global variable - + -## AllErrors -Return all errors that occur during validation. +## verifyEd25519(alg, signingInput, decodedSignature, publicKey) +Verify a JWS signature secured with the `EdDSA` algorithm and curve `Ed25519`. -**Kind**: global variable - +This function is useful when one is composing a `IJwsVerifier` that delegates +`EdDSA` verification with curve `Ed25519` to this function. -## FirstError -Return after the first error occurs. +# Warning -**Kind**: global variable - +This function does not check whether `alg = EdDSA` in the protected header. Callers are expected to assert this +prior to calling the function. -## CredentialStatus -**Kind**: global variable - +**Kind**: global function -## start() -Initializes the console error panic hook for better error messages +| Param | Type | +| --- | --- | +| alg | JwsAlgorithm | +| signingInput | Uint8Array | +| decodedSignature | Uint8Array | +| publicKey | [Jwk](#Jwk) | -**Kind**: global function ## encodeB64(data) ⇒ string @@ -6286,25 +6334,9 @@ Decode the given url-safe base64-encoded slice into its raw bytes. | --- | --- | | data | Uint8Array | - - -## verifyEd25519(alg, signingInput, decodedSignature, publicKey) -Verify a JWS signature secured with the `EdDSA` algorithm and curve `Ed25519`. - -This function is useful when one is composing a `IJwsVerifier` that delegates -`EdDSA` verification with curve `Ed25519` to this function. - -# Warning + -This function does not check whether `alg = EdDSA` in the protected header. Callers are expected to assert this -prior to calling the function. +## start() +Initializes the console error panic hook for better error messages **Kind**: global function - -| Param | Type | -| --- | --- | -| alg | JwsAlgorithm | -| signingInput | Uint8Array | -| decodedSignature | Uint8Array | -| publicKey | [Jwk](#Jwk) | - diff --git a/identity_verification/src/verification_method/method.rs b/identity_verification/src/verification_method/method.rs index 5baa36f1b6..8c48e06893 100644 --- a/identity_verification/src/verification_method/method.rs +++ b/identity_verification/src/verification_method/method.rs @@ -20,6 +20,7 @@ use crate::verification_method::MethodBuilder; use crate::verification_method::MethodData; use crate::verification_method::MethodRef; use crate::verification_method::MethodType; +use crate::CustomMethodData; use identity_did::CoreDID; use identity_did::DIDUrl; use identity_did::DID; @@ -247,8 +248,8 @@ impl KeyComparable for VerificationMethod { } // Horrible workaround for a tracked serde issue https://github.com/serde-rs/serde/issues/2200. Serde doesn't "consume" -// the input when deserializing flattened enums (MethodData in this case) cousing duplication of data (in this case -// it ends up in the properties object). This workaround simply remove the duplication. +// the input when deserializing flattened enums (MethodData in this case) causing duplication of data (in this case +// it ends up in the properties object). This workaround simply removes the duplication. #[derive(Deserialize)] struct _VerificationMethod { #[serde(deserialize_with = "deserialize_id_with_fragment")] @@ -271,9 +272,13 @@ impl From<_VerificationMethod> for VerificationMethod { data, mut properties, } = value; - let data_json = serde_json::to_value(&data).unwrap(); - let data_type = data_json.as_object().unwrap().into_iter().next().unwrap().0; - properties.remove(data_type); + let key = match &data { + MethodData::PublicKeyBase58(_) => "publicKeyBase58", + MethodData::PublicKeyJwk(_) => "publicKeyJwk", + MethodData::PublicKeyMultibase(_) => "publicKeyMultibase", + MethodData::Custom(CustomMethodData { name, .. }) => name.as_str(), + }; + properties.remove(key); VerificationMethod { id,