Skip to content

Commit

Permalink
chore: PR feedback (partly)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Oct 10, 2024
1 parent d0b4ad4 commit d484513
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
VERIFIERZ_PURPOSE_TO_VERIFY,
VERIFIERZ_PURPOSE_TO_VERIFY_NL
} from './data/mockedData'
import { IPresentationDefinition } from '@sphereon/pex'

const EXAMPLE_REDIRECT_URL = 'https://acme.com/hello'
const EXAMPLE_REFERENCE_URL = 'https://rp.acme.com/siop/jwts'
Expand Down Expand Up @@ -549,6 +550,23 @@ describe('create Request JWT should', () => {
response_type: 'id_token',
redirect_uri: EXAMPLE_REDIRECT_URL,
request_object_signing_alg_values_supported: [SigningAlgo.EDDSA, SigningAlgo.ES256],
claims: {
vp_token: {
presentation_definition: {
id: 'Insurance Plans',
input_descriptors: [
{
id: 'Ontario Health Insurance Plan',
schema: [
{
uri: 'https://did.itsourweb.org:3000/smartcredential/Ontario-Health-Insurance-Plan',
},
],
},
],
},
},
},
},
},
clientMetadata: {
Expand Down Expand Up @@ -578,7 +596,8 @@ describe('create Request JWT should', () => {
const uriRequest = await URI.fromOpts(opts)

const uriDecoded = decodeURIComponent(uriRequest.encodedUri)
expect(uriDecoded).toEqual(`openid4vp://?client_id=https://www.example.com/.well-known/openid-federation&scope=test&response_type=id_token&request_object_signing_alg_values_supported=["ES256","EdDSA"]&redirect_uri=https://acme.com/hello&claims={"vp_token":{"presentation_definition":{"id":"Ontario Health Insurance Plan","name":"Ontario","purpose":"purpose","input_descriptors":[{"id":"Ontario Health Insurance Plan","name":"Ontario","schema":[{"uri":"https://did.itsourweb.org:3000/smartcredential/Ontario-Health-Insurance-Plan"}]}]}}}&request_uri=https://rp.acme.com/siop/jwts`)
expect(uriDecoded.startsWith('openid4vp://?')).toBeTruthy()
expect(uriDecoded).toContain(`request_uri=https://rp.acme.com/siop/jwts`)
expect((await (await uriRequest.toAuthorizationRequest())?.requestObject?.getPayload())?.claims.vp_token).toBeDefined()
})

Expand All @@ -604,7 +623,7 @@ describe('create Request JWT should', () => {
kid: KID,
alg: SigningAlgo.ES256K,
}),
/* payload: {
payload: {
client_id: 'test_client_id',
scope: 'test',
response_type: 'id_token',
Expand All @@ -626,7 +645,7 @@ describe('create Request JWT should', () => {
} as IPresentationDefinition,
},
},
},*/
},
},
clientMetadata: {
idTokenSigningAlgValuesSupported: [SigningAlgo.EDDSA, SigningAlgo.ES256],
Expand Down
37 changes: 20 additions & 17 deletions packages/siop-oid4vp/lib/helpers/Revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@sphereon/ssi-types';

import { RevocationStatus, RevocationVerification, RevocationVerificationCallback, VerifiableCredentialTypeFormat } from '../types'
import { LOG } from '../types';

export const verifyRevocation = async (
vpToken: WrappedVerifiablePresentation,
Expand All @@ -16,27 +17,29 @@ export const verifyRevocation = async (
if (!vpToken) {
throw new Error(`VP token not provided`)
}
if (isWrappedW3CVerifiablePresentation(vpToken) || isWrappedSdJwtVerifiablePresentation(vpToken)) { // Only W3C support for now
if (!revocationVerificationCallback) {
throw new Error(`Revocation callback not provided`)
}

if (!(isWrappedW3CVerifiablePresentation(vpToken) || isWrappedSdJwtVerifiablePresentation(vpToken))) {
LOG.debug('verifyRevocation does not support non-w3c presentations at the moment')
return
}
if (!revocationVerificationCallback) {
throw new Error(`Revocation callback not provided`)
}

const vcs =
CredentialMapper.isWrappedSdJwtVerifiablePresentation(vpToken) || CredentialMapper.isWrappedMdocPresentation(vpToken)
? [vpToken.vcs[0]]
: vpToken.presentation.verifiableCredential
for (const vc of vcs) {
if (
revocationVerification === RevocationVerification.ALWAYS ||
(revocationVerification === RevocationVerification.IF_PRESENT && credentialHasStatus(vc))
) {
const result = await revocationVerificationCallback(
vc.original as W3CVerifiableCredential,
originalTypeToVerifiableCredentialTypeFormat(vc.format),
)
if (result.status === RevocationStatus.INVALID) {
throw new Error(`Revocation invalid for vc. Error: ${result.error}`)
}
for (const vc of vcs) {
if (
revocationVerification === RevocationVerification.ALWAYS ||
(revocationVerification === RevocationVerification.IF_PRESENT && credentialHasStatus(vc))
) {
const result = await revocationVerificationCallback(
vc.original as W3CVerifiableCredential,
originalTypeToVerifiableCredentialTypeFormat(vc.format)
)
if (result.status === RevocationStatus.INVALID) {
throw new Error(`Revocation invalid for vc. Error: ${result.error}`)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/siop-oid4vp/lib/op/OPBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class OPBuilder {
expiresIn?: number
issuer?: IIssuerId | ResponseIss
responseMode?: ResponseMode = ResponseMode.DIRECT_POST
responseRegistration?: Partial<ResponseRegistrationOpts> //= {}
responseRegistration?: Partial<ResponseRegistrationOpts> = {}
createJwtCallback?: CreateJwtCallback
verifyJwtCallback?: VerifyJwtCallback
presentationSignCallback?: PresentationSignCallback
Expand Down
7 changes: 7 additions & 0 deletions packages/siop-oid4vp/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { VCI_LOGGERS } from '@sphereon/oid4vc-common'
import { ISimpleLogger, LogMethod } from '@sphereon/ssi-types'

import SIOPErrors from './Errors'

export const LOG: ISimpleLogger<string> = VCI_LOGGERS.options('sphereon:siop-oid4vp', { methods: [LogMethod.EVENT, LogMethod.DEBUG_PKG] }).get(
'sphereon:siop-oid4vp',
)

export { SIOPErrors }
export * from './JWT.types'
export * from './SIOP.types'
Expand Down

0 comments on commit d484513

Please sign in to comment.