Skip to content

Commit

Permalink
fix: added generic union types for frequently used types
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed May 17, 2024
1 parent 479bea7 commit f10d0b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/client/lib/__tests__/OpenID4VCIClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ describe('OpenID4VCIClient should', () => {
'https://server.example.com/v1/auth/authorize?response_type=code&code_challenge_method=S256&code_challenge=mE2kPHmIprOqtkaYmESWj35yz-PB5vzdiSu0tAZ8sqs&authorization_details=%7B%22type%22%3A%22openid_credential%22%2C%22format%22%3A%22ldp_vc%22%2C%22credential_definition%22%3A%7B%22%40context%22%3A%5B%22https%3A%2F%2Fwww%2Ew3%2Eorg%2F2018%2Fcredentials%2Fv1%22%2C%22https%3A%2F%2Fwww%2Ew3%2Eorg%2F2018%2Fcredentials%2Fexamples%2Fv1%22%5D%2C%22types%22%3A%5B%22VerifiableCredential%22%2C%22UniversityDegreeCredential%22%5D%7D%2C%22locations%22%3A%5B%22https%3A%2F%2Fserver%2Eexample%2Ecom%22%5D%7D&redirect_uri=http%3A%2F%2Flocalhost%3A8881%2Fcb&client_id=test-client&scope=openid',
);
});

it('create an authorization request url with authorization_details and scope', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down Expand Up @@ -199,4 +200,26 @@ describe('OpenID4VCIClient should', () => {
'https://server.example.com/v1/auth/authorize?response_type=code&code_challenge_method=S256&code_challenge=mE2kPHmIprOqtkaYmESWj35yz-PB5vzdiSu0tAZ8sqs&authorization_details=%7B%22type%22%3A%22openid_credential%22%2C%22format%22%3A%22ldp_vc%22%2C%22locations%22%3A%5B%22https%3A%2F%2Ftest%2Ecom%22%2C%22https%3A%2F%2Fserver%2Eexample%2Ecom%22%5D%2C%22credential_definition%22%3A%7B%22%40context%22%3A%5B%22https%3A%2F%2Fwww%2Ew3%2Eorg%2F2018%2Fcredentials%2Fv1%22%2C%22https%3A%2F%2Fwww%2Ew3%2Eorg%2F2018%2Fcredentials%2Fexamples%2Fv1%22%5D%2C%22types%22%3A%5B%22VerifiableCredential%22%2C%22UniversityDegreeCredential%22%5D%7D%7D&redirect_uri=http%3A%2F%2Flocalhost%3A8881%2Fcb&client_id=test-client&scope=openid',
);
});

});
describe('should successfully handle isEbsi function', ()=>{
it('should return true when calling isEbsi function', async () => {
const client = await OpenID4VCIClient.fromURI({
clientId: 'test-client',
uri: 'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22%3A%22https%3A%2F%2Fserver.example.com%22%2C%22credential_configuration_ids%22%3A%5B%22TestCredential%22%5D%7D',
createAuthorizationRequestURL: false,
});
nock(MOCK_URL).get(/.*/).reply(200, {});
nock(MOCK_URL).get(WellKnownEndpoints.OAUTH_AS).reply(404, {});
nock(MOCK_URL).get(WellKnownEndpoints.OPENID_CONFIGURATION).reply(404, {});

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
client._state.endpointMetadata?.credentialIssuerMetadata?.credential_configurations_supported['TestCredential'] = {
trust_framework: {
name: 'ebsi_trust'
}
}
expect(client.isEBSI()).toBe(true)
})
})
16 changes: 14 additions & 2 deletions packages/common/lib/types/Generic.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import { ICredentialContextType, IVerifiableCredential, W3CVerifiableCredential
import { ProofOfPossession } from './CredentialIssuance.types';
import { AuthorizationServerMetadata } from './ServerMetadata';
import { CredentialOfferSession } from './StateManager.types';
import { CredentialRequestV1_0_11 } from './v1_0_11.types';
import { CredentialRequestV1_0_13 } from './v1_0_13.types';
import { IssuerMetadataV1_0_08 } from './v1_0_08.types'
import {
CredentialRequestV1_0_11,
EndpointMetadataResultV1_0_11
} from './v1_0_11.types'
import {
CredentialRequestV1_0_13,
EndpointMetadataResultV1_0_13,
IssuerMetadataV1_0_13
} from './v1_0_13.types'

export type InputCharSet = 'numeric' | 'text';
export type KeyProofType = 'jwt' | 'cwt' | 'ldp_vp';
Expand Down Expand Up @@ -353,3 +361,7 @@ export interface GrantUrnIetf {
}

export const PRE_AUTH_CODE_LITERAL = 'pre-authorized_code';

export type EndpointMetadataResult = EndpointMetadataResultV1_0_13 | EndpointMetadataResultV1_0_11

export type IssuerMetadata = IssuerMetadataV1_0_13 | IssuerMetadataV1_0_08

0 comments on commit f10d0b2

Please sign in to comment.