From 162af3828b3dc826dc3cd5adffe3dab61925ad33 Mon Sep 17 00:00:00 2001 From: sksadjad Date: Wed, 5 Apr 2023 10:27:20 +0200 Subject: [PATCH] fix: prettier, plus some type casting in test/mock files for v9 --- packages/client/lib/CredentialOffer.ts | 19 +++++++++++-------- .../lib/__tests__/AuthzFlowType.spec.ts | 11 ++++++----- .../client/lib/__tests__/MetadataMocks.ts | 4 ++-- .../lib/functions/CredentialOfferUtil.ts | 6 +++--- packages/issuer-rest/lib/api.ts | 4 ++-- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/client/lib/CredentialOffer.ts b/packages/client/lib/CredentialOffer.ts index 4ee3fb98..b17e6670 100644 --- a/packages/client/lib/CredentialOffer.ts +++ b/packages/client/lib/CredentialOffer.ts @@ -7,7 +7,7 @@ import { } from '@sphereon/openid4vci-common'; import Debug from 'debug'; -import {convertJsonToURI, convertURIToJsonObject, determineSpecVersionFromURI} from './functions'; +import { convertJsonToURI, convertURIToJsonObject, determineSpecVersionFromURI } from './functions'; const debug = Debug('sphereon:openid4vci:initiation'); @@ -20,13 +20,16 @@ export class CredentialOffer { } const baseUrl = uri.split('?')[0]; const version = determineSpecVersionFromURI(uri); - const issuanceInitiationRequest: CredentialOfferPayload = (version < OpenId4VCIVersion.VER_1_0_11)? convertURIToJsonObject(uri, { - arrayTypeProperties: ['credential_type'], - requiredProperties: ['issuer', 'credential_type'], - }) as CredentialOfferV1_0_09: convertURIToJsonObject(uri, { - arrayTypeProperties: ['credentials'], - requiredProperties: ['credentials', 'credential_issuer'] - }) as CredentialOfferPayloadV1_0_11 + const issuanceInitiationRequest: CredentialOfferPayload = + version < OpenId4VCIVersion.VER_1_0_11 + ? (convertURIToJsonObject(uri, { + arrayTypeProperties: ['credential_type'], + requiredProperties: ['issuer', 'credential_type'], + }) as CredentialOfferV1_0_09) + : (convertURIToJsonObject(uri, { + arrayTypeProperties: ['credentials'], + requiredProperties: ['credentials', 'credential_issuer'], + }) as CredentialOfferPayloadV1_0_11); const request = version < OpenId4VCIVersion.VER_1_0_11.valueOf() diff --git a/packages/client/lib/__tests__/AuthzFlowType.spec.ts b/packages/client/lib/__tests__/AuthzFlowType.spec.ts index 4ebb6ec7..1bf8b5df 100644 --- a/packages/client/lib/__tests__/AuthzFlowType.spec.ts +++ b/packages/client/lib/__tests__/AuthzFlowType.spec.ts @@ -1,12 +1,13 @@ -import { AuthzFlowType } from '@sphereon/openid4vci-common'; +import { AuthzFlowType, CredentialOfferV1_0_09 } from '@sphereon/openid4vci-common'; +//todo: this file is just testing v9, we probably want to add v11 tests here as well describe('Authorization Flow Type determination', () => { it('should return authorization code flow type with a single credential_type', () => { expect( AuthzFlowType.valueOf({ issuer: 'test', credential_type: 'test', - }) + } as CredentialOfferV1_0_09) ).toEqual(AuthzFlowType.AUTHORIZATION_CODE_FLOW); }); it('should return authorization code flow type with a credential_type array', () => { @@ -14,7 +15,7 @@ describe('Authorization Flow Type determination', () => { AuthzFlowType.valueOf({ issuer: 'test', credential_type: ['test', 'test1'], - }) + } as CredentialOfferV1_0_09) ).toEqual(AuthzFlowType.AUTHORIZATION_CODE_FLOW); }); it('should return pre-authorized code flow with a single credential_type', () => { @@ -23,7 +24,7 @@ describe('Authorization Flow Type determination', () => { issuer: 'test', credential_type: 'test', 'pre-authorized_code': 'test', - }) + } as CredentialOfferV1_0_09) ).toEqual(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW); }); it('should return pre-authorized code flow with a credential_type array', () => { @@ -32,7 +33,7 @@ describe('Authorization Flow Type determination', () => { issuer: 'test', credential_type: ['test', 'test1'], 'pre-authorized_code': 'test', - }) + } as CredentialOfferV1_0_09) ).toEqual(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW); }); }); diff --git a/packages/client/lib/__tests__/MetadataMocks.ts b/packages/client/lib/__tests__/MetadataMocks.ts index e10de3ed..3f70b1ab 100644 --- a/packages/client/lib/__tests__/MetadataMocks.ts +++ b/packages/client/lib/__tests__/MetadataMocks.ts @@ -1,4 +1,4 @@ -import { CredentialOfferRequestWithBaseUrl, OpenId4VCIVersion } from '@sphereon/openid4vci-common'; +import { CredentialOfferRequestWithBaseUrl, CredentialOfferV1_0_09, OpenId4VCIVersion } from '@sphereon/openid4vci-common'; export const IDENTIPROOF_ISSUER_URL = 'https://issuer.research.identiproof.io'; export const IDENTIPROOF_AS_URL = 'https://auth.research.identiproof.io'; @@ -18,7 +18,7 @@ export const INITIATION_TEST: CredentialOfferRequestWithBaseUrl = { 'pre-authorized_code': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhOTUyZjUxNi1jYWVmLTQ4YjMtODIxYy00OTRkYzgyNjljZjAiLCJwcmUtYXV0aG9yaXplZCI6dHJ1ZX0.YE5DlalcLC2ChGEg47CQDaN1gTxbaQqSclIVqsSAUHE', user_pin_required: 'false', - }, + } as CredentialOfferV1_0_09, version: OpenId4VCIVersion.VER_1_0_09, }; export const IDENTIPROOF_AS_METADATA = { diff --git a/packages/common/lib/functions/CredentialOfferUtil.ts b/packages/common/lib/functions/CredentialOfferUtil.ts index 25c42998..9bde52f8 100644 --- a/packages/common/lib/functions/CredentialOfferUtil.ts +++ b/packages/common/lib/functions/CredentialOfferUtil.ts @@ -1,4 +1,4 @@ -import {CredentialOfferPayload, DefaultURISchemes, OpenId4VCIVersion, TokenErrorResponse} from '../types'; +import { CredentialOfferPayload, DefaultURISchemes, OpenId4VCIVersion, TokenErrorResponse } from '../types'; export function determineSpecVersionFromURI(uri: string): OpenId4VCIVersion { let version: OpenId4VCIVersion = OpenId4VCIVersion.VER_UNKNOWN; @@ -51,8 +51,8 @@ function recordVersion(determinedVersion: OpenId4VCIVersion, potentialVersion: O } export function getIssuerFromCredentialOfferPayload(request: CredentialOfferPayload): string { - if (!request || !('issuer' in request) || ('credential_issuer' in request)) { - throw new Error(TokenErrorResponse.invalid_request) + if (!request || !('issuer' in request) || 'credential_issuer' in request) { + throw new Error(TokenErrorResponse.invalid_request); } return 'issuer' in request ? request.issuer : request['credential_issuer']; } diff --git a/packages/issuer-rest/lib/api.ts b/packages/issuer-rest/lib/api.ts index 96775b4f..6469cc49 100644 --- a/packages/issuer-rest/lib/api.ts +++ b/packages/issuer-rest/lib/api.ts @@ -113,8 +113,8 @@ export class RestAPI { private registerCredentialRequestEndpoint() { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - this.express.post('/credential-request', async (request, response) => { - this._vcIssuer.issueCredentialFromIssueRequest(request as unknown as CredentialRequest) + this.express.post('/credential-request', async (request: CredentialRequest, response) => { + return response.send(await this._vcIssuer.issueCredentialFromIssueRequest(request as unknown as CredentialRequest)) }) }