Skip to content

Commit f608d24

Browse files
authored
Resolve credential offer is throwing an error (#836)
* fix. update controller * fix: update usecases * fix: get rid of more anys * fix: properly parse message
1 parent 7f1b597 commit f608d24

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

packages/consumption/src/modules/openid4vc/OpenId4VcController.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
99
super(ConsumptionControllerName.OpenId4VcController, parent);
1010
}
1111

12-
public async fetchCredentialOffer(credentialOfferUrl: string): Promise<any> {
12+
public async fetchCredentialOffer(credentialOfferUrl: string): Promise<{ data: string }> {
1313
const holder = new Holder(this.parent.accountController, this.parent.attributes);
1414
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
1515
const res = await holder.resolveCredentialOffer(credentialOfferUrl);
@@ -40,19 +40,25 @@ export class OpenId4VcController extends ConsumptionBaseController {
4040
};
4141
}
4242

43-
public async processCredentialOffer(credentialOffer: string): Promise<any> {
43+
public async processCredentialOffer(credentialOffer: string): Promise<{ data: string; id: string; type: string; displayInformation: string | undefined }> {
4444
const holder = new Holder(this.parent.accountController, this.parent.attributes);
4545
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
4646
const res = await holder.resolveCredentialOffer(credentialOffer);
47-
const credentials = await holder.requestAndStoreCredentials(res, { credentialsToRequest: ["EmployeeIdCard-sdjwt"] });
47+
const credentials = await holder.requestAndStoreCredentials(res, { credentialsToRequest: Object.keys(res.offeredCredentialConfigurations) });
48+
49+
// TODO: support multiple credentials
50+
const credential = credentials[0].content.value as VerifiableCredential;
4851

4952
return {
50-
id: credentials.length > 0 ? credentials[0].id : undefined,
51-
data: JSON.stringify(credentials)
53+
data: credential.value,
54+
// multi credentials not supported yet
55+
id: credentials[0].id.toString(),
56+
type: credential.type,
57+
displayInformation: credential.displayInformation
5258
};
5359
}
5460

55-
public async fetchProofRequest(proofRequestUrl: string): Promise<any> {
61+
public async fetchProofRequest(proofRequestUrl: string): Promise<{ data: string }> {
5662
const holder = new Holder(this.parent.accountController, this.parent.attributes);
5763
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
5864
const res = await holder.resolveProofRequest(proofRequestUrl);
@@ -61,17 +67,16 @@ export class OpenId4VcController extends ConsumptionBaseController {
6167
};
6268
}
6369

64-
public async acceptProofRequest(jsonEncodedRequest: string): Promise<any> {
70+
public async acceptProofRequest(jsonEncodedRequest: string): Promise<{ status: number; message: string | Record<string, unknown> | null }> {
6571
const holder = new Holder(this.parent.accountController, this.parent.attributes);
6672
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
6773
const fetchedRequest = JSON.parse(jsonEncodedRequest);
6874
// parse the credential type to be sdjwt
6975

7076
const serverResponse = await holder.acceptPresentationRequest(fetchedRequest);
71-
return {
72-
status: serverResponse.status,
73-
message: serverResponse.body
74-
};
77+
if (!serverResponse) throw new Error("No response from server");
78+
79+
return { status: serverResponse.status, message: serverResponse.body };
7580
}
7681

7782
public async getVerifiableCredentials(ids: string[] | undefined): Promise<any[]> {

packages/consumption/src/modules/openid4vc/local/Holder.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
OpenId4VcModule,
1717
OpenId4VciAuthorizationFlow,
18+
OpenId4VciDpopRequestOptions,
1819
authorizationCodeGrantIdentifier,
1920
preAuthorizedCodeGrantIdentifier,
2021
type OpenId4VciMetadata,
@@ -66,7 +67,29 @@ export class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>>
6667
return await this.agent.openid4vc.holder.resolveIssuerMetadata(credentialIssuer);
6768
}
6869

69-
public async initiateAuthorization(resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer, credentialsToRequest: string[]): Promise<any> {
70+
public async initiateAuthorization(
71+
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer,
72+
credentialsToRequest: string[]
73+
): Promise<
74+
| {
75+
readonly authorizationFlow: "PreAuthorized";
76+
readonly preAuthorizedCode: string;
77+
}
78+
| {
79+
readonly authorizationFlow: "PresentationDuringIssuance";
80+
readonly openid4vpRequestUrl: string;
81+
readonly authSession: string;
82+
readonly dpop?: OpenId4VciDpopRequestOptions;
83+
readonly preAuthorizedCode?: undefined;
84+
}
85+
| {
86+
readonly authorizationFlow: "Oauth2Redirect";
87+
readonly authorizationRequestUrl: string;
88+
readonly codeVerifier?: string;
89+
readonly dpop?: OpenId4VciDpopRequestOptions;
90+
readonly preAuthorizedCode?: undefined;
91+
}
92+
> {
7093
const grants = resolvedCredentialOffer.credentialOfferPayload.grants;
7194
if (grants?.[preAuthorizedCodeGrantIdentifier]) {
7295
return {
@@ -232,13 +255,23 @@ export class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>>
232255
return storedCredentials;
233256
}
234257

235-
public async resolveProofRequest(proofRequest: string): Promise<any> {
258+
public async resolveProofRequest(proofRequest: string): Promise<OpenId4VpResolvedAuthorizationRequest> {
236259
const resolvedProofRequest = await this.agent.openid4vc.holder.resolveOpenId4VpAuthorizationRequest(proofRequest);
237260

238261
return resolvedProofRequest;
239262
}
240263

241-
public async acceptPresentationRequest(resolvedPresentationRequest: OpenId4VpResolvedAuthorizationRequest): Promise<any> {
264+
public async acceptPresentationRequest(resolvedPresentationRequest: OpenId4VpResolvedAuthorizationRequest): Promise<
265+
| {
266+
readonly status: number;
267+
readonly body: string | Record<string, unknown> | null;
268+
}
269+
| {
270+
readonly status: number;
271+
readonly body: Record<string, unknown>;
272+
}
273+
| undefined
274+
> {
242275
if (!resolvedPresentationRequest.presentationExchange && !resolvedPresentationRequest.dcql) {
243276
throw new Error("Missing presentation exchange or dcql on resolved authorization request");
244277
}
@@ -293,12 +326,11 @@ export class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>>
293326
return submissionResult.serverResponse;
294327
}
295328

296-
public async exit(): Promise<any> {
329+
public async exit(): Promise<void> {
297330
await this.shutdown();
298-
process.exit(0);
299331
}
300332

301-
public async restart(): Promise<any> {
333+
public async restart(): Promise<void> {
302334
await this.shutdown();
303335
}
304336
}

packages/runtime/src/useCases/consumption/openid4vc/AcceptProofRequestUseCase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export class AcceptProofRequestUseCase extends UseCase<AcceptProofRequestRequest
2424

2525
protected override async executeInternal(request: AcceptProofRequestRequest): Promise<Result<AcceptProofRequestDTO>> {
2626
const result = await this.openId4VcContoller.acceptProofRequest(request.jsonEncodedRequest);
27-
return Result.ok({ status: result.status, message: result.success } as AcceptProofRequestDTO);
27+
return Result.ok({ status: result.status, message: JSON.stringify(result.message) } as AcceptProofRequestDTO);
2828
}
2929
}

packages/runtime/src/useCases/consumption/openid4vc/FetchCredentialOfferUseCase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface FetchCredentialOfferRequest {
1010

1111
class Validator extends SchemaValidator<FetchCredentialOfferRequest> {
1212
public constructor(@Inject schemaRepository: SchemaRepository) {
13-
super(schemaRepository.getSchema("ResolveCredentialOfferRequest"));
13+
super(schemaRepository.getSchema("FetchCredentialOfferRequest"));
1414
}
1515
}
1616

packages/runtime/src/useCases/consumption/openid4vc/ResolveCredentialOfferUseCase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export class ResolveCredentialOfferUseCase extends UseCase<ResolveCredentialOffe
2424

2525
protected override async executeInternal(request: ResolveCredentialOfferRequest): Promise<Result<VerifiableCredentialDTO>> {
2626
const result = await this.openId4VcContoller.processCredentialOffer(request.credentialOfferUrl);
27-
return Result.ok({ id: result.value.id, data: result.value.data } as VerifiableCredentialDTO);
27+
return Result.ok(result);
2828
}
2929
}

0 commit comments

Comments
 (0)