From b634ead1fa3575fe25fa383e63782141ec023ebd Mon Sep 17 00:00:00 2001 From: Enrico Marconi <31142849+UMR1352@users.noreply.github.com> Date: Fri, 24 May 2024 11:59:34 +0200 Subject: [PATCH] Support for specification-compliant verification method type `JsonWebKey2020` (#1367) * deprecate `MethodType::JSON_WEB_KEY` in favor of `MethodType::JSON_WEB_KEY_2020` * deprecate old method type in wasm bindings * fix tests in wasm-bindings --- bindings/wasm/src/verification/wasm_method_type.rs | 12 +++++++++--- bindings/wasm/tests/core.ts | 2 +- bindings/wasm/tests/iota.ts | 2 +- .../src/verification_method/method.rs | 2 +- .../src/verification_method/method_type.rs | 12 +++++++++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/bindings/wasm/src/verification/wasm_method_type.rs b/bindings/wasm/src/verification/wasm_method_type.rs index 4b7d297a62..c143b7e53f 100644 --- a/bindings/wasm/src/verification/wasm_method_type.rs +++ b/bindings/wasm/src/verification/wasm_method_type.rs @@ -20,13 +20,19 @@ impl WasmMethodType { WasmMethodType(MethodType::X25519_KEY_AGREEMENT_KEY_2019) } - /// A verification method for use with JWT verification as prescribed by the {@link Jwk} - /// in the `publicKeyJwk` entry. - #[wasm_bindgen(js_name = JsonWebKey)] + /// @deprecated Use {@link JsonWebKey2020} instead. + #[wasm_bindgen(js_name = JsonWebKey, skip_jsdoc)] pub fn json_web_key() -> WasmMethodType { WasmMethodType(MethodType::JSON_WEB_KEY) } + /// A verification method for use with JWT verification as prescribed by the {@link Jwk} + /// in the `publicKeyJwk` entry. + #[wasm_bindgen(js_name = JsonWebKey2020)] + pub fn json_web_key_2020() -> WasmMethodType { + WasmMethodType(MethodType::JSON_WEB_KEY_2020) + } + /// A custom method. pub fn custom(type_: String) -> WasmMethodType { WasmMethodType(MethodType::custom(type_)) diff --git a/bindings/wasm/tests/core.ts b/bindings/wasm/tests/core.ts index 396ef146d9..9bde0e335d 100644 --- a/bindings/wasm/tests/core.ts +++ b/bindings/wasm/tests/core.ts @@ -225,7 +225,7 @@ describe("CoreDocument", function() { // Resolve. const resolved = doc.resolveMethod(fragment, scope)!; assert.deepStrictEqual(resolved.id().fragment(), fragment); - assert.deepStrictEqual(resolved.type().toString(), MethodType.JsonWebKey().toString()); + assert.deepStrictEqual(resolved.type().toString(), MethodType.JsonWebKey2020().toString()); assert.deepStrictEqual(resolved.controller().toString(), doc.id().toString()); assert.deepStrictEqual(resolved.data().tryPublicKeyJwk().toJSON(), JWK.toJSON()); assert.deepStrictEqual(resolved.toJSON(), method.toJSON()); diff --git a/bindings/wasm/tests/iota.ts b/bindings/wasm/tests/iota.ts index b32279c3ae..9037dd5af4 100644 --- a/bindings/wasm/tests/iota.ts +++ b/bindings/wasm/tests/iota.ts @@ -100,7 +100,7 @@ describe("IotaDocument", function() { // Resolve. const resolved = doc.resolveMethod(fragment, scope)!; assert.deepStrictEqual(resolved.id().fragment(), fragment); - assert.deepStrictEqual(resolved.type().toString(), MethodType.JsonWebKey().toString()); + assert.deepStrictEqual(resolved.type().toString(), MethodType.JsonWebKey2020().toString()); assert.deepStrictEqual(resolved.controller().toString(), doc.id().toString()); assert.deepStrictEqual(resolved.data().tryPublicKeyJwk().toJSON(), JWK.toJSON()); assert.deepStrictEqual(resolved.toJSON(), method.toJSON()); diff --git a/identity_verification/src/verification_method/method.rs b/identity_verification/src/verification_method/method.rs index 8c48e06893..65c838639f 100644 --- a/identity_verification/src/verification_method/method.rs +++ b/identity_verification/src/verification_method/method.rs @@ -220,7 +220,7 @@ impl VerificationMethod { MethodBuilder::default() .id(id) .controller(did.into()) - .type_(MethodType::JSON_WEB_KEY) + .type_(MethodType::JSON_WEB_KEY_2020) .data(MethodData::PublicKeyJwk(key)) .build() } diff --git a/identity_verification/src/verification_method/method_type.rs b/identity_verification/src/verification_method/method_type.rs index ae3877948d..5a3eadd4f1 100644 --- a/identity_verification/src/verification_method/method_type.rs +++ b/identity_verification/src/verification_method/method_type.rs @@ -12,6 +12,7 @@ use crate::error::Result; const ED25519_VERIFICATION_KEY_2018_STR: &str = "Ed25519VerificationKey2018"; const X25519_KEY_AGREEMENT_KEY_2019_STR: &str = "X25519KeyAgreementKey2019"; const JSON_WEB_KEY_METHOD_TYPE: &str = "JsonWebKey"; +const JSON_WEB_KEY_2020_STR: &str = "JsonWebKey2020"; /// verification method types. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] @@ -24,7 +25,11 @@ impl MethodType { pub const X25519_KEY_AGREEMENT_KEY_2019: Self = Self(Cow::Borrowed(X25519_KEY_AGREEMENT_KEY_2019_STR)); /// A verification method for use with JWT verification as prescribed by the [`Jwk`](::identity_jose::jwk::Jwk) /// in the [`publicKeyJwk`](crate::MethodData::PublicKeyJwk) entry. + #[deprecated(since = "1.3.0", note = "use JSON_WEB_KEY_2020 instead")] pub const JSON_WEB_KEY: Self = Self(Cow::Borrowed(JSON_WEB_KEY_METHOD_TYPE)); + /// A verification method for use with JWT verification as prescribed by the [`Jwk`](::identity_jose::jwk::Jwk) + /// in the [`publicKeyJwk`](crate::MethodData::PublicKeyJwk) entry. + pub const JSON_WEB_KEY_2020: Self = Self(Cow::Borrowed(JSON_WEB_KEY_2020_STR)); /// Construct a custom method type. pub fn custom(type_: impl AsRef) -> Self { Self(Cow::Owned(type_.as_ref().to_owned())) @@ -57,7 +62,11 @@ impl FromStr for MethodType { match string { ED25519_VERIFICATION_KEY_2018_STR => Ok(Self::ED25519_VERIFICATION_KEY_2018), X25519_KEY_AGREEMENT_KEY_2019_STR => Ok(Self::X25519_KEY_AGREEMENT_KEY_2019), - JSON_WEB_KEY_METHOD_TYPE => Ok(Self::JSON_WEB_KEY), + JSON_WEB_KEY_METHOD_TYPE => Ok( + #[allow(deprecated)] + Self::JSON_WEB_KEY, + ), + JSON_WEB_KEY_2020_STR => Ok(Self::JSON_WEB_KEY_2020), _ => Ok(Self(Cow::Owned(string.to_owned()))), } } @@ -74,6 +83,7 @@ mod tests { for method_type in [ MethodType::ED25519_VERIFICATION_KEY_2018, MethodType::X25519_KEY_AGREEMENT_KEY_2019, + MethodType::JSON_WEB_KEY_2020, ] { let ser: Value = serde_json::to_value(method_type.clone()).unwrap(); assert_eq!(ser.as_str().unwrap(), method_type.as_str());