Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Brummos committed Sep 18, 2024
1 parent c5f419c commit 7771d25
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/sd-jwt/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { IAgentPlugin } from '@veramo/core'
import { _ExtendedIKey } from '@veramo/utils'
import Debug from 'debug'
import { defaultGenerateDigest, defaultGenerateSalt, defaultVerifySignature } from './defaultCallbacks'

import { SdJwtVerifySignature, SignKeyArgs, SignKeyResult } from './index'
import { sphereonCA } from './trustAnchors'
import { SdJwtVerifySignature, SignKeyArgs, SignKeyResult } from './index'
import {
Claims,
ICreateSdJwtPresentationArgs,
Expand Down Expand Up @@ -87,6 +86,8 @@ export class SDJwtPlugin implements IAgentPlugin {
const { key, alg } = signingKey

const signer: Signer = async (data: string): Promise<string> => {
console.log('AHAAAAAAA')

return context.agent.keyManagerSign({ keyRef: key.kmsKeyRef, data })
}
return { signer, alg, signingKey }
Expand Down Expand Up @@ -117,6 +118,7 @@ export class SDJwtPlugin implements IAgentPlugin {
...(signingKey?.key.kmsKeyRef !== undefined && { kid: signingKey.key.kmsKeyRef }),
},
})

return { credential }
}

Expand Down Expand Up @@ -193,6 +195,7 @@ export class SDJwtPlugin implements IAgentPlugin {
kbSignAlg: alg ?? 'ES256',
})
const credential = await sdjwt.present(args.presentation, args.presentationFrame as PresentationFrame<SdJwtVcPayload>, { kb: args.kb })

return { presentation: credential }
}

Expand All @@ -205,7 +208,6 @@ export class SDJwtPlugin implements IAgentPlugin {
async verifySdJwtVc(args: IVerifySdJwtVcArgs, context: IRequiredContext): Promise<IVerifySdJwtVcResult> {
// callback
const verifier: Verifier = async (data: string, signature: string) => this.verify(sdjwt, context, data, signature)

const sdjwt = new SDJwtVcInstance({ verifier, hasher: this.registeredImplementations.hasher })
const { header = {}, payload, kb } = await sdjwt.verify(args.credential)

Expand All @@ -226,6 +228,7 @@ export class SDJwtPlugin implements IAgentPlugin {
throw Error('other method than cnf is not supported yet')
}
const key = payload.cnf.jwk as JsonWebKey

return this.verifySignatureCallback(context)(data, signature, key)
}

Expand Down Expand Up @@ -290,9 +293,11 @@ export class SDJwtPlugin implements IAgentPlugin {
// needs more checks. some DID methods do not expose the keys as publicKeyJwk
jwk = didDocumentKey.publicKeyJwk as JsonWebKey
}

if (!jwk) {
throw new Error('No valid public key found for signature verification')
}

return this.verifySignatureCallback(context)(data, signature, jwk)
}

Expand All @@ -312,15 +317,15 @@ export class SDJwtPlugin implements IAgentPlugin {
hasher: this.registeredImplementations.hasher,
kbVerifier: verifierKb,
})
const verifiedPayloads = await sdjwt.verify(args.presentation, args.requiredClaimKeys, args.kb)

return verifiedPayloads
return sdjwt.verify(args.presentation, args.requiredClaimKeys, args.kb)
}

private verifySignatureCallback(context: IRequiredContext): SdJwtVerifySignature {
if (typeof this.registeredImplementations.verifySignature === 'function') {
return this.registeredImplementations.verifySignature
}

return defaultVerifySignature(context)
}
}

0 comments on commit 7771d25

Please sign in to comment.