Skip to content

Commit

Permalink
refactor: Removed the OIDF library and added the client metadata to t…
Browse files Browse the repository at this point in the history
…he constructor functions
  • Loading branch information
Zoe Maas committed Nov 26, 2024
1 parent 4060fe7 commit e04c3d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
31 changes: 9 additions & 22 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateDPoPClientOpts, JWK, parseJWT } from '@sphereon/oid4vc-common';
import { CreateDPoPClientOpts, JWK } from '@sphereon/oid4vc-common';
import {
AccessTokenRequestOpts,
AccessTokenResponse,
Expand Down Expand Up @@ -35,7 +35,6 @@ import {
ProofOfPossessionCallbacks,
toAuthorizationResponsePayload,
} from '@sphereon/oid4vci-common';
import { FederationClient } from '@sphereon/openid-federation-client';
import { CredentialFormat } from '@sphereon/ssi-types';
import Debug from 'debug';

Expand All @@ -55,9 +54,7 @@ import { generateMissingPKCEOpts, sendNotification } from './functions';

const debug = Debug('sphereon:oid4vci');

export type OpenID4VCIClientState =
| (OpenID4VCIClientStateV1_0_11 & { trustChains?: Array<string> })
| (OpenID4VCIClientStateV1_0_13 & { trustChains?: Array<string> });
export type OpenID4VCIClientState = OpenID4VCIClientStateV1_0_11 | OpenID4VCIClientStateV1_0_13;

export type EndpointMetadataResult = EndpointMetadataResultV1_0_11 | EndpointMetadataResultV1_0_13;

Expand All @@ -79,7 +76,6 @@ export class OpenID4VCIClient {
authorizationRequestOpts,
authorizationCodeResponse,
authorizationURL,
trustChains,
}: {
credentialOffer?: CredentialOfferRequestWithBaseUrl;
kid?: string;
Expand All @@ -95,7 +91,6 @@ export class OpenID4VCIClient {
authorizationRequestOpts?: AuthorizationRequestOpts;
authorizationCodeResponse?: AuthorizationResponse;
authorizationURL?: string;
trustChains?: Array<string>;
}) {
const issuer = credentialIssuer ?? (credentialOffer ? getIssuerFromCredentialOfferPayload(credentialOffer.credential_offer) : undefined);
if (!issuer) {
Expand All @@ -118,7 +113,6 @@ export class OpenID4VCIClient {
: (endpointMetadata as EndpointMetadataResultV1_0_13 | undefined),
accessTokenResponse,
authorizationURL,
trustChains,
} as OpenID4VCIClientState;
// Running syncAuthorizationRequestOpts later as it is using the state
if (!this._state.authorizationRequestOpts) {
Expand All @@ -136,7 +130,7 @@ export class OpenID4VCIClient {
pkce,
authorizationRequest,
createAuthorizationRequestURL,
trustChains,
endpointMetadata
}: {
credentialIssuer: string;
kid?: string;
Expand All @@ -146,7 +140,7 @@ export class OpenID4VCIClient {
createAuthorizationRequestURL?: boolean;
authorizationRequest?: AuthorizationRequestOpts; // Can be provided here, or when manually calling createAuthorizationUrl
pkce?: PKCEOpts;
trustChains?: Array<string>;
endpointMetadata?: EndpointMetadataResult
}) {
const client = new OpenID4VCIClient({
kid,
Expand All @@ -155,7 +149,7 @@ export class OpenID4VCIClient {
credentialIssuer,
pkce,
authorizationRequest,
trustChains,
endpointMetadata
});
if (retrieveServerMetadata === undefined || retrieveServerMetadata) {
await client.retrieveServerMetadata();
Expand All @@ -182,6 +176,7 @@ export class OpenID4VCIClient {
createAuthorizationRequestURL,
authorizationRequest,
resolveOfferUri,
endpointMetadata
}: {
uri: string;
kid?: string;
Expand All @@ -192,6 +187,7 @@ export class OpenID4VCIClient {
pkce?: PKCEOpts;
clientId?: string;
authorizationRequest?: AuthorizationRequestOpts; // Can be provided here, or when manually calling createAuthorizationUrl
endpointMetadata?: EndpointMetadataResult
}): Promise<OpenID4VCIClient> {
const credentialOfferClient = await CredentialOfferClient.fromURI(uri, { resolve: resolveOfferUri });
const client = new OpenID4VCIClient({
Expand All @@ -201,6 +197,7 @@ export class OpenID4VCIClient {
clientId: clientId ?? authorizationRequest?.clientId ?? credentialOfferClient.clientId,
pkce,
authorizationRequest,
endpointMetadata
});

if (retrieveServerMetadata === undefined || retrieveServerMetadata) {
Expand Down Expand Up @@ -266,11 +263,7 @@ export class OpenID4VCIClient {
if (this.credentialOffer) {
this._state.endpointMetadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(this.credentialOffer);
} else if (this._state.credentialIssuer) {
if (this._state.trustChains !== undefined && this._state.trustChains !== null && this._state.trustChains.length !== 0) {
this._state.endpointMetadata = await this.retrieveTrustChainMetadata(this._state.credentialIssuer, this._state.trustChains);
} else {
this._state.endpointMetadata = await MetadataClient.retrieveAllMetadata(this._state.credentialIssuer);
}
this._state.endpointMetadata = await MetadataClient.retrieveAllMetadata(this._state.credentialIssuer);
} else {
throw Error(`Cannot retrieve issuer metadata without either a credential offer, or issuer value`);
}
Expand All @@ -279,12 +272,6 @@ export class OpenID4VCIClient {
return this.endpointMetadata;
}

private async retrieveTrustChainMetadata(credentialIssuer: string, trustChains: Array<string>): Promise<EndpointMetadataResult | undefined> {
const oidfClient = new FederationClient(null, null);
const resolvedTrustChain = await oidfClient.resolveTrustChain(credentialIssuer, trustChains);
return resolvedTrustChain?.trustChain?.asJsReadonlyArrayView().map((s) => parseJWT(s))[1].payload as EndpointMetadataResult | undefined;
}

private calculatePKCEOpts(pkce?: PKCEOpts) {
this._state.pkce = generateMissingPKCEOpts({ ...this._state.pkce, ...pkce });
}
Expand Down
5 changes: 0 additions & 5 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
"uint8arrays": "3.1.1",
"uuid": "^9.0.1"
},
"peerDependencies": {
"@sphereon/openid-federation-client": "^0.1.1-unstable.21e8440",
"@sphereon/openid-federation-common": "^0.1.1-unstable.21e8440",
"@sphereon/openid-federation-open-api": "^0.1.1-unstable.21e8440"
},
"engines": {
"node": ">=18"
},
Expand Down

0 comments on commit e04c3d1

Please sign in to comment.