Skip to content

Commit

Permalink
fix: prettier, plus some type casting in test/mock files for v9
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Apr 5, 2023
1 parent 091786e commit 162af38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
19 changes: 11 additions & 8 deletions packages/client/lib/CredentialOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions packages/client/lib/__tests__/AuthzFlowType.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
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', () => {
expect(
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', () => {
Expand All @@ -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', () => {
Expand All @@ -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);
});
});
4 changes: 2 additions & 2 deletions packages/client/lib/__tests__/MetadataMocks.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions packages/common/lib/functions/CredentialOfferUtil.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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'];
}
4 changes: 2 additions & 2 deletions packages/issuer-rest/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}

Expand Down

0 comments on commit 162af38

Please sign in to comment.