From 0af29fc8a630c0c698bc745f9434fab69320aa74 Mon Sep 17 00:00:00 2001 From: Enrico Marconi <31142849+UMR1352@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:16:57 +0100 Subject: [PATCH] Feat/custom verification method (#1334) * Add support for arbitrary (custom) verification method data * wasm bindings * custom method type + wasm * workaround serde's issue * Update bindings/wasm/src/verification/wasm_method_data.rs Co-authored-by: Abdulrahim Al Methiab <31316147+abdulmth@users.noreply.github.com> * review comments * fmt * review comment --------- Co-authored-by: Abdulrahim Al Methiab <31316147+abdulmth@users.noreply.github.com> --- bindings/wasm/docs/api-reference.md | 297 ++++++++++-------- .../wasm/src/verification/wasm_method_data.rs | 50 ++- .../wasm/src/verification/wasm_method_type.rs | 7 +- identity_verification/Cargo.toml | 2 +- .../src/verification_method/material.rs | 117 ++++++- .../src/verification_method/method.rs | 46 ++- .../src/verification_method/method_type.rs | 9 +- .../src/verification_method/mod.rs | 1 + 8 files changed, 366 insertions(+), 163 deletions(-) diff --git a/bindings/wasm/docs/api-reference.md b/bindings/wasm/docs/api-reference.md index 73ff47d4c6..2f50e4ed3d 100644 --- a/bindings/wasm/docs/api-reference.md +++ b/bindings/wasm/docs/api-reference.md @@ -11,6 +11,9 @@ if the object is being concurrently modified.
A custom verification method data format.
+A method agnostic DID Url.
Controls validation behaviour when checking whether or not a credential has been revoked by its
-credentialStatus
.
Purpose of a StatusList2021.
Validate the status if supported, reject any unsupported
-credentialStatus
types.
Only RevocationBitmap2022
is currently supported.
This is the default.
+Declares how credential subjects must relate to the presentation holder.
+See also the Subject-Holder Relationship section of the specification.
Validate the status if supported, skip any unsupported
-credentialStatus
types.
The holder must always match the subject on all credentials, regardless of their nonTransferable
property.
+This variant is the default.
Skip all status checks.
+The holder must match the subject only for credentials where the nonTransferable
property is true
.
Purpose of a StatusList2021.
+The holder is not required to have any kind of relationship to any credential subject.
Return after the first error occurs.
Declares how credential subjects must relate to the presentation holder.
-See also the Subject-Holder Relationship section of the specification.
+Controls validation behaviour when checking whether or not a credential has been revoked by its
+credentialStatus
.
The holder must always match the subject on all credentials, regardless of their nonTransferable
property.
-This variant is the default.
Validate the status if supported, reject any unsupported
+credentialStatus
types.
Only RevocationBitmap2022
is currently supported.
This is the default.
The holder must match the subject only for credentials where the nonTransferable
property is true
.
Validate the status if supported, skip any unsupported
+credentialStatus
types.
The holder is not required to have any kind of relationship to any credential subject.
+Skip all status checks.
string
Encode the given bytes in url-safe base64.
-Uint8Array
Decode the given url-safe base64-encoded slice into its raw bytes.
-Verify a JWS signature secured with the EdDSA
algorithm and curve Ed25519
.
This function is useful when one is composing a IJwsVerifier
that delegates
@@ -255,6 +252,12 @@ 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.
string
Encode the given bytes in url-safe base64.
+Uint8Array
Decode the given url-safe base64-encoded slice into its raw bytes.
+Initializes the console error panic hook for better error messages
any
|
+
+
+## CustomMethodData
+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)
+
+| Param | Type |
+| --- | --- |
+| 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
@@ -4343,7 +4393,7 @@ Supported verification method data formats.
* [MethodData](#MethodData)
* _instance_
- * [.tryBlockchainAccountId()](#MethodData+tryBlockchainAccountId) ⇒ string
+ * [.tryCustom()](#MethodData+tryCustom) ⇒ [CustomMethodData
](#CustomMethodData)
* [.tryDecode()](#MethodData+tryDecode) ⇒ Uint8Array
* [.tryPublicKeyJwk()](#MethodData+tryPublicKeyJwk) ⇒ [Jwk
](#Jwk)
* [.toJSON()](#MethodData+toJSON) ⇒ any
@@ -4352,13 +4402,13 @@ Supported verification method data formats.
* [.newBase58(data)](#MethodData.newBase58) ⇒ [MethodData
](#MethodData)
* [.newMultibase(data)](#MethodData.newMultibase) ⇒ [MethodData
](#MethodData)
* [.newJwk(key)](#MethodData.newJwk) ⇒ [MethodData
](#MethodData)
- * [.newBlockchainAccountId(data)](#MethodData.newBlockchainAccountId) ⇒ [MethodData
](#MethodData)
+ * [.newCustom(name, data)](#MethodData.newCustom) ⇒ [MethodData
](#MethodData)
* [.fromJSON(json)](#MethodData.fromJSON) ⇒ [MethodData
](#MethodData)
-
+
-### methodData.tryBlockchainAccountId() ⇒ string
-Returns the wrapped blockchain account id if the format is `BlockchainAccountId`.
+### methodData.tryCustom() ⇒ [CustomMethodData
](#CustomMethodData)
+Returns the wrapped custom method data format is `Custom`.
**Kind**: instance method of [MethodData
](#MethodData)
@@ -4427,16 +4477,17 @@ An error is thrown if the given `key` contains any private components.
| --- | --- |
| key | [Jwk
](#Jwk) |
-
+
-### MethodData.newBlockchainAccountId(data) ⇒ [MethodData
](#MethodData)
-Creates a new [MethodData](#MethodData) variant in CAIP-10 format.
+### MethodData.newCustom(name, data) ⇒ [MethodData
](#MethodData)
+Creates a new custom [MethodData](#MethodData).
**Kind**: static method of [MethodData
](#MethodData)
| Param | Type |
| --- | --- |
-| data | string
|
+| name | string
|
+| data | any
|
@@ -4589,7 +4640,7 @@ Supported verification method types.
* [.Ed25519VerificationKey2018()](#MethodType.Ed25519VerificationKey2018) ⇒ [MethodType
](#MethodType)
* [.X25519KeyAgreementKey2019()](#MethodType.X25519KeyAgreementKey2019) ⇒ [MethodType
](#MethodType)
* [.JsonWebKey()](#MethodType.JsonWebKey) ⇒ [MethodType
](#MethodType)
- * [.EcdsaSecp256k1RecoverySignature2020()](#MethodType.EcdsaSecp256k1RecoverySignature2020) ⇒ [MethodType
](#MethodType)
+ * [.custom(type_)](#MethodType.custom) ⇒ [MethodType
](#MethodType)
* [.fromJSON(json)](#MethodType.fromJSON) ⇒ [MethodType
](#MethodType)
@@ -4625,12 +4676,17 @@ A verification method for use with JWT verification as prescribed by the [Jwk](#
in the `publicKeyJwk` entry.
**Kind**: static method of [MethodType
](#MethodType)
-
+
-### MethodType.EcdsaSecp256k1RecoverySignature2020() ⇒ [MethodType
](#MethodType)
-The `EcdsaSecp256k1RecoverySignature2020` method type.
+### MethodType.custom(type_) ⇒ [MethodType
](#MethodType)
+A custom method.
**Kind**: static method of [MethodType
](#MethodType)
+
+| Param | Type |
+| --- | --- |
+| type_ | string
|
+
### MethodType.fromJSON(json) ⇒ [MethodType
](#MethodType)
@@ -5032,11 +5088,9 @@ Representation of an SD-JWT of the format
* [.jwt()](#SdJwt+jwt) ⇒ string
* [.disclosures()](#SdJwt+disclosures) ⇒ Array.<string>
* [.keyBindingJwt()](#SdJwt+keyBindingJwt) ⇒ string
\| undefined
- * [.toJSON()](#SdJwt+toJSON) ⇒ any
* [.clone()](#SdJwt+clone) ⇒ [SdJwt
](#SdJwt)
* _static_
* [.parse(sd_jwt)](#SdJwt.parse) ⇒ [SdJwt
](#SdJwt)
- * [.fromJSON(json)](#SdJwt.fromJSON) ⇒ [SdJwt
](#SdJwt)
@@ -5079,12 +5133,6 @@ The disclosures part.
### sdJwt.keyBindingJwt() ⇒ string
\| undefined
The optional key binding JWT.
-**Kind**: instance method of [SdJwt
](#SdJwt)
-
-
-### sdJwt.toJSON() ⇒ any
-Serializes this to a JSON object.
-
**Kind**: instance method of [SdJwt
](#SdJwt)
@@ -5106,17 +5154,6 @@ Returns `DeserializationError` if parsing fails.
| --- | --- |
| sd_jwt | string
|
-
-
-### SdJwt.fromJSON(json) ⇒ [SdJwt
](#SdJwt)
-Deserializes an instance from a JSON object.
-
-**Kind**: static method of [SdJwt
](#SdJwt)
-
-| Param | Type |
-| --- | --- |
-| json | any
|
-
## SdJwtCredentialValidator
@@ -6159,50 +6196,38 @@ Deserializes an instance from a JSON object.
| --- | --- |
| json | any
|
-
+
-## StatusCheck
-Controls validation behaviour when checking whether or not a credential has been revoked by its
-[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).
+## StatusPurpose
+Purpose of a [StatusList2021](#StatusList2021).
**Kind**: global variable
-
-
-## Strict
-Validate the status if supported, reject any unsupported
-[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
-
-Only `RevocationBitmap2022` is currently supported.
-
-This is the default.
+
-**Kind**: global variable
-
+## SubjectHolderRelationship
+Declares how credential subjects must relate to the presentation holder.
-## SkipUnsupported
-Validate the status if supported, skip any unsupported
-[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
+See also the [Subject-Holder Relationship](https://www.w3.org/TR/vc-data-model/#subject-holder-relationships) section of the specification.
**Kind**: global variable
-
+
-## SkipAll
-Skip all status checks.
+## AlwaysSubject
+The holder must always match the subject on all credentials, regardless of their [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property.
+This variant is the default.
**Kind**: global variable
-
+
-## StatusPurpose
-Purpose of a [StatusList2021](#StatusList2021).
+## SubjectOnNonTransferable
+The holder must match the subject only for credentials where the [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property is `true`.
**Kind**: global variable
-
+
-## MethodRelationship
-**Kind**: global variable
-
+## Any
+The holder is not required to have any kind of relationship to any credential subject.
-## CredentialStatus
**Kind**: global variable
@@ -6226,55 +6251,45 @@ Return all errors that occur during validation.
Return after the first error occurs.
**Kind**: global variable
-
-
-## SubjectHolderRelationship
-Declares how credential subjects must relate to the presentation holder.
-
-See also the [Subject-Holder Relationship](https://www.w3.org/TR/vc-data-model/#subject-holder-relationships) section of the specification.
-
-**Kind**: global variable
-
-
-## AlwaysSubject
-The holder must always match the subject on all credentials, regardless of their [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property.
-This variant is the default.
+
+## MethodRelationship
**Kind**: global variable
-
-
-## SubjectOnNonTransferable
-The holder must match the subject only for credentials where the [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property is `true`.
+
+## CredentialStatus
**Kind**: global variable
-
+
-## Any
-The holder is not required to have any kind of relationship to any credential subject.
+## StatusCheck
+Controls validation behaviour when checking whether or not a credential has been revoked by its
+[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).
**Kind**: global variable
-
+
-## encodeB64(data) ⇒ string
-Encode the given bytes in url-safe base64.
+## Strict
+Validate the status if supported, reject any unsupported
+[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
-**Kind**: global function
+Only `RevocationBitmap2022` is currently supported.
-| Param | Type |
-| --- | --- |
-| data | Uint8Array
|
+This is the default.
-
+**Kind**: global variable
+
-## decodeB64(data) ⇒ Uint8Array
-Decode the given url-safe base64-encoded slice into its raw bytes.
+## SkipUnsupported
+Validate the status if supported, skip any unsupported
+[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
-**Kind**: global function
+**Kind**: global variable
+
-| Param | Type |
-| --- | --- |
-| data | Uint8Array
|
+## SkipAll
+Skip all status checks.
+**Kind**: global variable
## verifyEd25519(alg, signingInput, decodedSignature, publicKey)
@@ -6297,6 +6312,28 @@ prior to calling the function.
| decodedSignature | Uint8Array
|
| publicKey | [Jwk
](#Jwk) |
+
+
+## encodeB64(data) ⇒ string
+Encode the given bytes in url-safe base64.
+
+**Kind**: global function
+
+| Param | Type |
+| --- | --- |
+| data | Uint8Array
|
+
+
+
+## decodeB64(data) ⇒ Uint8Array
+Decode the given url-safe base64-encoded slice into its raw bytes.
+
+**Kind**: global function
+
+| Param | Type |
+| --- | --- |
+| data | Uint8Array
|
+
## start()
diff --git a/bindings/wasm/src/verification/wasm_method_data.rs b/bindings/wasm/src/verification/wasm_method_data.rs
index 809eab22e4..58a9c65820 100644
--- a/bindings/wasm/src/verification/wasm_method_data.rs
+++ b/bindings/wasm/src/verification/wasm_method_data.rs
@@ -1,6 +1,7 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
+use identity_iota::verification::CustomMethodData;
use identity_iota::verification::MethodData;
use wasm_bindgen::prelude::*;
@@ -45,22 +46,23 @@ impl WasmMethodData {
Ok(Self(MethodData::PublicKeyJwk(key.0.clone())))
}
- /// Creates a new {@link MethodData} variant in CAIP-10 format.
- #[wasm_bindgen(js_name = newBlockchainAccountId)]
- pub fn new_blockchain_account_id(data: String) -> Self {
- Self(MethodData::new_blockchain_account_id(data))
+ /// Creates a new custom {@link MethodData}.
+ #[wasm_bindgen(js_name = newCustom)]
+ pub fn new_custom(name: String, data: JsValue) -> Result