From 834642a3881b14195ac47f5bdd639bdaae35c7a5 Mon Sep 17 00:00:00 2001 From: nklomp Date: Sat, 14 Jan 2023 07:12:07 +0100 Subject: [PATCH] fix: RSA fixes for suite --- .../vc-handler-ld-local/src/suites/JsonWebSignature2020.ts | 2 +- .../src/suites/impl/JsonWebKeyWithRSASupport.ts | 2 +- .../src/suites/impl/JsonWebSignatureWithRSASupport.ts | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts b/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts index d4254c7e6..d349aff81 100644 --- a/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts +++ b/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts @@ -89,7 +89,7 @@ export class SphereonJsonWebSignature2020 extends SphereonLdSignature { getSuiteForVerification(): any { const verifier = { // returns a JWS detached - verify: async (args: { data: Uint8Array }): Promise => { + verify: async (args: { data: Uint8Array; signature: Uint8Array }): Promise => { return true }, } diff --git a/packages/vc-handler-ld-local/src/suites/impl/JsonWebKeyWithRSASupport.ts b/packages/vc-handler-ld-local/src/suites/impl/JsonWebKeyWithRSASupport.ts index 4fe3dd3a4..7f5e04b1b 100644 --- a/packages/vc-handler-ld-local/src/suites/impl/JsonWebKeyWithRSASupport.ts +++ b/packages/vc-handler-ld-local/src/suites/impl/JsonWebKeyWithRSASupport.ts @@ -123,7 +123,7 @@ const applyJwa = async (k: any, options?: any) => { const verifier = options?.verifier !== undefined ? options.verifier : await getVerifier(k, options) k.verifier = () => verifier as any if (k.privateKey || options?.signer !== undefined) { - const signer = options?.signer ? options.signer : await getSigner(k, options) + const signer = options?.signer !== undefined ? options.signer : await getSigner(k, options) k.signer = () => signer as any } return k diff --git a/packages/vc-handler-ld-local/src/suites/impl/JsonWebSignatureWithRSASupport.ts b/packages/vc-handler-ld-local/src/suites/impl/JsonWebSignatureWithRSASupport.ts index 3c83d8bea..3def8abd7 100644 --- a/packages/vc-handler-ld-local/src/suites/impl/JsonWebSignatureWithRSASupport.ts +++ b/packages/vc-handler-ld-local/src/suites/impl/JsonWebSignatureWithRSASupport.ts @@ -230,6 +230,10 @@ export class JsonWebSignature { } async verifySignature({ verifyData, verificationMethod, proof }: any) { + if (verificationMethod.publicKeyJwk) { + const key = verificationMethod.publicKeyJwk as CryptoKey + return await crypto.subtle.verify(key.algorithm?.name ? key.algorithm.name : 'SHA-256', key, new Uint8Array(proof.jws), verifyData) + } const verifier = await verificationMethod.verifier() return verifier.verify({ data: verifyData, signature: proof.jws }) }