Skip to content

Commit

Permalink
fix: RSA fixes for suite
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Jan 14, 2023
1 parent 1f3f6b5 commit 3df79ab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> => {
return true
},
}
return new JsonWebSignature({ verifier })
}

preSigningCredModification(credential: CredentialPayload): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }) => {
Expand All @@ -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)
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -13,6 +15,7 @@ const sha256 = async (data: any) => {
export interface JsonWebSignatureOptions {
key?: JsonWebKey
date?: any
verifier?: Verifier
}

export class JsonWebSignature {
Expand All @@ -22,13 +25,17 @@ export class JsonWebSignature {
public date: any
public type: string = 'JsonWebSignature2020'
public verificationMethod?: string
public verifier?: Verifier

constructor(options: JsonWebSignatureOptions = {}) {
this.date = options.date
if (options.key) {
this.key = options.key
this.verificationMethod = this.key.id
}
if (options.verifier) {
this.verifier = options.verifier
}
}

ensureSuiteContext({ document }: any) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3df79ab

Please sign in to comment.