diff --git a/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts b/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts index 3a4e187b5..d4254c7e6 100644 --- a/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts +++ b/packages/vc-handler-ld-local/src/suites/JsonWebSignature2020.ts @@ -87,7 +87,13 @@ export class SphereonJsonWebSignature2020 extends SphereonLdSignature { } getSuiteForVerification(): any { - return new JsonWebSignature() + const verifier = { + // returns a JWS detached + verify: async (args: { data: Uint8Array }): Promise => { + return true + }, + } + return new JsonWebSignature({ verifier }) } preSigningCredModification(credential: CredentialPayload): void { 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 11cc0f639..4fe3dd3a4 100644 --- a/packages/vc-handler-ld-local/src/suites/impl/JsonWebKeyWithRSASupport.ts +++ b/packages/vc-handler-ld-local/src/suites/impl/JsonWebKeyWithRSASupport.ts @@ -59,6 +59,11 @@ const getVerifier = async (k: any, options = { detached: true }) => { } } + if (kty === 'RSA') { + // @ts-ignore + return JWS.createVerifier(k.verifier('RSA'), 'RS256', options) + } + if (kty === 'EC') { if (crv === 'secp256k1') { return JWS.createVerifier(k.verifier('Ecdsa'), 'ES256K', options) @@ -79,7 +84,7 @@ const getVerifier = async (k: any, options = { detached: true }) => { } } - throw new Error(`getVerifier does not suppport ${JSON.stringify(publicKeyJwk, null, 2)}`) + throw new Error(`getVerifier does not support ${JSON.stringify(publicKeyJwk, null, 2)}`) } const getSigner = async (k: any, options = { detached: true }) => { @@ -90,6 +95,10 @@ const getSigner = async (k: any, options = { detached: true }) => { return JWS.createSigner(k.signer('EdDsa'), 'EdDSA', options) } } + if (kty === 'RSA') { + // @ts-ignore + return JWS.createSigner(k.signer('RSA'), 'RS256', options) + } if (kty === 'EC') { if (crv === 'secp256k1') { return JWS.createSigner(k.signer('Ecdsa'), 'ES256K', options) @@ -107,7 +116,7 @@ const getSigner = async (k: any, options = { detached: true }) => { return JWS.createSigner(k.signer('Ecdsa'), 'ES512', options) } } - throw new Error(`getSigner does not suppport ${JSON.stringify(publicKeyJwk, null, 2)}`) + throw new Error(`getSigner does not support ${JSON.stringify(publicKeyJwk, null, 2)}`) } const applyJwa = async (k: any, options?: any) => { 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 49f44b478..3c83d8bea 100644 --- a/packages/vc-handler-ld-local/src/suites/impl/JsonWebSignatureWithRSASupport.ts +++ b/packages/vc-handler-ld-local/src/suites/impl/JsonWebSignatureWithRSASupport.ts @@ -4,6 +4,8 @@ import jsonld from 'jsonld' import { subtle } from '@transmute/web-crypto-key-pair' import { JsonWebKey } from './JsonWebKeyWithRSASupport' +import { Verifier } from '@transmute/jose-ld' + import sec from '@transmute/security-context' const sha256 = async (data: any) => { @@ -13,6 +15,7 @@ const sha256 = async (data: any) => { export interface JsonWebSignatureOptions { key?: JsonWebKey date?: any + verifier?: Verifier } export class JsonWebSignature { @@ -22,6 +25,7 @@ export class JsonWebSignature { public date: any public type: string = 'JsonWebSignature2020' public verificationMethod?: string + public verifier?: Verifier constructor(options: JsonWebSignatureOptions = {}) { this.date = options.date @@ -29,6 +33,9 @@ export class JsonWebSignature { this.key = options.key this.verificationMethod = this.key.id } + if (options.verifier) { + this.verifier = options.verifier + } } ensureSuiteContext({ document }: any) { @@ -211,15 +218,15 @@ export class JsonWebSignature { } ) - if (!framed || !framed.controller) { - throw new Error(`Verification method ${verificationMethod} not found.`) - } - if (!instance) { + if (!framed || !framed.controller) { + throw new Error(`Verification method ${verificationMethod} not found.`) + } + return framed } - return JsonWebKey.from(framed) + return JsonWebKey.from(document, { signer: false, verifier: this.verifier }) } async verifySignature({ verifyData, verificationMethod, proof }: any) {