@sphereon/oid4vci-client 0.10.3 → 0.10.4-next.119

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +24 -5
  2. package/dist/AccessTokenClient.d.ts +5 -5
  3. package/dist/AccessTokenClient.d.ts.map +1 -1
  4. package/dist/AccessTokenClient.js +51 -37
  5. package/dist/AccessTokenClient.js.map +1 -1
  6. package/dist/AccessTokenClientV1_0_11.d.ts +29 -0
  7. package/dist/AccessTokenClientV1_0_11.d.ts.map +1 -0
  8. package/dist/AccessTokenClientV1_0_11.js +209 -0
  9. package/dist/AccessTokenClientV1_0_11.js.map +1 -0
  10. package/dist/AuthorizationCodeClient.d.ts +9 -4
  11. package/dist/AuthorizationCodeClient.d.ts.map +1 -1
  12. package/dist/AuthorizationCodeClient.js +102 -18
  13. package/dist/AuthorizationCodeClient.js.map +1 -1
  14. package/dist/AuthorizationCodeClientV1_0_11.d.ts +9 -0
  15. package/dist/AuthorizationCodeClientV1_0_11.d.ts.map +1 -0
  16. package/dist/AuthorizationCodeClientV1_0_11.js +134 -0
  17. package/dist/AuthorizationCodeClientV1_0_11.js.map +1 -0
  18. package/dist/CredentialOfferClient.d.ts.map +1 -1
  19. package/dist/CredentialOfferClient.js +18 -13
  20. package/dist/CredentialOfferClient.js.map +1 -1
  21. package/dist/CredentialOfferClientV1_0_11.d.ts +10 -0
  22. package/dist/CredentialOfferClientV1_0_11.d.ts.map +1 -0
  23. package/dist/CredentialOfferClientV1_0_11.js +101 -0
  24. package/dist/CredentialOfferClientV1_0_11.js.map +1 -0
  25. package/dist/CredentialOfferClientV1_0_13.d.ts +10 -0
  26. package/dist/CredentialOfferClientV1_0_13.d.ts.map +1 -0
  27. package/dist/CredentialOfferClientV1_0_13.js +94 -0
  28. package/dist/CredentialOfferClientV1_0_13.js.map +1 -0
  29. package/dist/CredentialRequestClient.d.ts +20 -7
  30. package/dist/CredentialRequestClient.d.ts.map +1 -1
  31. package/dist/CredentialRequestClient.js +46 -30
  32. package/dist/CredentialRequestClient.js.map +1 -1
  33. package/dist/CredentialRequestClientBuilder.d.ts +11 -6
  34. package/dist/CredentialRequestClientBuilder.d.ts.map +1 -1
  35. package/dist/CredentialRequestClientBuilder.js +22 -9
  36. package/dist/CredentialRequestClientBuilder.js.map +1 -1
  37. package/dist/CredentialRequestClientBuilderV1_0_11.d.ts +48 -0
  38. package/dist/CredentialRequestClientBuilderV1_0_11.d.ts.map +1 -0
  39. package/dist/CredentialRequestClientBuilderV1_0_11.js +121 -0
  40. package/dist/CredentialRequestClientBuilderV1_0_11.js.map +1 -0
  41. package/dist/CredentialRequestClientV1_0_11.d.ts +50 -0
  42. package/dist/CredentialRequestClientV1_0_11.d.ts.map +1 -0
  43. package/dist/CredentialRequestClientV1_0_11.js +151 -0
  44. package/dist/CredentialRequestClientV1_0_11.js.map +1 -0
  45. package/dist/MetadataClient.d.ts +5 -15
  46. package/dist/MetadataClient.d.ts.map +1 -1
  47. package/dist/MetadataClient.js +41 -44
  48. package/dist/MetadataClient.js.map +1 -1
  49. package/dist/MetadataClientV1_0_11.d.ts +31 -0
  50. package/dist/MetadataClientV1_0_11.d.ts.map +1 -0
  51. package/dist/MetadataClientV1_0_11.js +182 -0
  52. package/dist/MetadataClientV1_0_11.js.map +1 -0
  53. package/dist/MetadataClientV1_0_13.d.ts +31 -0
  54. package/dist/MetadataClientV1_0_13.d.ts.map +1 -0
  55. package/dist/MetadataClientV1_0_13.js +181 -0
  56. package/dist/MetadataClientV1_0_13.js.map +1 -0
  57. package/dist/OpenID4VCIClient.d.ts +14 -19
  58. package/dist/OpenID4VCIClient.d.ts.map +1 -1
  59. package/dist/OpenID4VCIClient.js +111 -61
  60. package/dist/OpenID4VCIClient.js.map +1 -1
  61. package/dist/OpenID4VCIClientV1_0_11.d.ts +108 -0
  62. package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -0
  63. package/dist/OpenID4VCIClientV1_0_11.js +449 -0
  64. package/dist/OpenID4VCIClientV1_0_11.js.map +1 -0
  65. package/dist/OpenID4VCIClientV1_0_13.d.ts +112 -0
  66. package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -0
  67. package/dist/OpenID4VCIClientV1_0_13.js +478 -0
  68. package/dist/OpenID4VCIClientV1_0_13.js.map +1 -0
  69. package/dist/ProofOfPossessionBuilder.d.ts +14 -3
  70. package/dist/ProofOfPossessionBuilder.d.ts.map +1 -1
  71. package/dist/ProofOfPossessionBuilder.js +20 -21
  72. package/dist/ProofOfPossessionBuilder.js.map +1 -1
  73. package/dist/functions/OpenIDUtils.d.ts +12 -0
  74. package/dist/functions/OpenIDUtils.d.ts.map +1 -0
  75. package/dist/functions/OpenIDUtils.js +37 -0
  76. package/dist/functions/OpenIDUtils.js.map +1 -0
  77. package/dist/functions/index.d.ts +2 -3
  78. package/dist/functions/index.d.ts.map +1 -1
  79. package/dist/functions/index.js +2 -3
  80. package/dist/functions/index.js.map +1 -1
  81. package/dist/functions/notifications.d.ts +4 -0
  82. package/dist/functions/notifications.d.ts.map +1 -0
  83. package/dist/functions/notifications.js +39 -0
  84. package/dist/functions/notifications.js.map +1 -0
  85. package/dist/index.d.ts +13 -1
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +14 -1
  88. package/dist/index.js.map +1 -1
  89. package/dist/types/index.d.ts +2 -0
  90. package/dist/types/index.d.ts.map +1 -1
  91. package/dist/types/index.js +5 -0
  92. package/dist/types/index.js.map +1 -1
  93. package/lib/AccessTokenClient.ts +59 -34
  94. package/lib/AccessTokenClientV1_0_11.ts +250 -0
  95. package/lib/AuthorizationCodeClient.ts +131 -28
  96. package/lib/AuthorizationCodeClientV1_0_11.ts +170 -0
  97. package/lib/CredentialOfferClient.ts +21 -8
  98. package/lib/CredentialOfferClientV1_0_11.ts +112 -0
  99. package/lib/CredentialOfferClientV1_0_13.ts +103 -0
  100. package/lib/CredentialRequestClient.ts +65 -26
  101. package/lib/CredentialRequestClientBuilder.ts +34 -16
  102. package/lib/CredentialRequestClientBuilderV1_0_11.ts +163 -0
  103. package/lib/CredentialRequestClientV1_0_11.ts +197 -0
  104. package/lib/MetadataClient.ts +64 -49
  105. package/lib/MetadataClientV1_0_11.ts +189 -0
  106. package/lib/MetadataClientV1_0_13.ts +188 -0
  107. package/lib/OpenID4VCIClient.ts +132 -68
  108. package/lib/OpenID4VCIClientV1_0_11.ts +635 -0
  109. package/lib/OpenID4VCIClientV1_0_13.ts +677 -0
  110. package/lib/ProofOfPossessionBuilder.ts +41 -11
  111. package/lib/__tests__/AccessTokenClient.spec.ts +40 -12
  112. package/lib/__tests__/AuthorizationDetailsBuilder.spec.ts +0 -12
  113. package/lib/__tests__/CredentialRequestClient.spec.ts +87 -50
  114. package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +18 -12
  115. package/lib/__tests__/CredentialRequestClientV1_0_11.spec.ts +317 -0
  116. package/lib/__tests__/EBSIE2E.spec.test.ts +2 -2
  117. package/lib/__tests__/HttpUtils.spec.ts +1 -1
  118. package/lib/__tests__/IT.spec.ts +264 -14
  119. package/lib/__tests__/IssuanceInitiation.spec.ts +59 -4
  120. package/lib/__tests__/IssuanceInitiationV1_0_11.spec.ts +62 -0
  121. package/lib/__tests__/MattrE2E.spec.test.ts +2 -2
  122. package/lib/__tests__/MetadataClient.spec.ts +53 -3
  123. package/lib/__tests__/MetadataMocks.ts +42 -2
  124. package/lib/__tests__/OpenID4VCIClient.spec.ts +58 -2
  125. package/lib/__tests__/{OpenID4VCIClientPAR.spec.ts → OpenID4VCIClientPARV1_0_11.spec.ts} +5 -5
  126. package/lib/__tests__/OpenID4VCIClientV1_0_11.spec.ts +226 -0
  127. package/lib/__tests__/OpenID4VCIClientV1_0_13.spec.ts +204 -0
  128. package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +1 -1
  129. package/lib/__tests__/SdJwt.spec.ts +36 -30
  130. package/lib/__tests__/SphereonE2E.spec.test.ts +10 -7
  131. package/lib/__tests__/data/VciDataFixtures.ts +712 -27
  132. package/lib/functions/OpenIDUtils.ts +25 -0
  133. package/lib/functions/index.ts +2 -3
  134. package/lib/functions/notifications.ts +32 -0
  135. package/lib/index.ts +16 -1
  136. package/lib/types/index.ts +6 -0
  137. package/package.json +4 -4
  138. package/dist/functions/ProofUtil.d.ts +0 -30
  139. package/dist/functions/ProofUtil.d.ts.map +0 -1
  140. package/dist/functions/ProofUtil.js +0 -106
  141. package/dist/functions/ProofUtil.js.map +0 -1
  142. package/lib/functions/ProofUtil.ts +0 -128
@@ -5,18 +5,27 @@ import {
5
5
  AuthorizationResponse,
6
6
  AuthzFlowType,
7
7
  CodeChallengeMethod,
8
+ CredentialConfigurationSupported,
9
+ CredentialConfigurationSupportedV1_0_13,
8
10
  CredentialOfferPayloadV1_0_08,
11
+ CredentialOfferPayloadV1_0_11,
9
12
  CredentialOfferRequestWithBaseUrl,
10
13
  CredentialResponse,
11
- CredentialSupported,
14
+ CredentialsSupportedLegacy,
12
15
  DefaultURISchemes,
13
- EndpointMetadataResult,
16
+ determineVersionsFromIssuerMetadata,
17
+ EndpointMetadataResultV1_0_11,
18
+ EndpointMetadataResultV1_0_13,
19
+ ExperimentalSubjectIssuance,
14
20
  getClientIdFromCredentialOfferPayload,
15
21
  getIssuerFromCredentialOfferPayload,
16
22
  getSupportedCredentials,
17
23
  getTypesFromCredentialSupported,
24
+ getTypesFromObject,
18
25
  JWK,
19
26
  KID_JWK_X5C_ERROR,
27
+ NotificationRequest,
28
+ NotificationResult,
20
29
  OID4VCICredentialFormat,
21
30
  OpenId4VCIVersion,
22
31
  PKCEOpts,
@@ -27,29 +36,24 @@ import { CredentialFormat } from '@sphereon/ssi-types';
27
36
  import Debug from 'debug';
28
37
 
29
38
  import { AccessTokenClient } from './AccessTokenClient';
39
+ import { AccessTokenClientV1_0_11 } from './AccessTokenClientV1_0_11';
30
40
  import { createAuthorizationRequestUrl } from './AuthorizationCodeClient';
41
+ import { createAuthorizationRequestUrlV1_0_11 } from './AuthorizationCodeClientV1_0_11';
31
42
  import { CredentialOfferClient } from './CredentialOfferClient';
43
+ import { CredentialRequestOpts } from './CredentialRequestClient';
32
44
  import { CredentialRequestClientBuilder } from './CredentialRequestClientBuilder';
45
+ import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11';
33
46
  import { MetadataClient } from './MetadataClient';
47
+ import { OpenID4VCIClientStateV1_0_11 } from './OpenID4VCIClientV1_0_11';
48
+ import { OpenID4VCIClientStateV1_0_13 } from './OpenID4VCIClientV1_0_13';
34
49
  import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder';
35
- import { generateMissingPKCEOpts } from './functions/AuthorizationUtil';
50
+ import { generateMissingPKCEOpts, sendNotification } from './functions';
36
51
 
37
52
  const debug = Debug('sphereon:oid4vci');
38
53
 
39
- export interface OpenID4VCIClientState {
40
- credentialIssuer: string;
41
- credentialOffer?: CredentialOfferRequestWithBaseUrl;
42
- clientId?: string;
43
- kid?: string;
44
- jwk?: JWK;
45
- alg?: Alg | string;
46
- endpointMetadata?: EndpointMetadataResult;
47
- accessTokenResponse?: AccessTokenResponse;
48
- authorizationRequestOpts?: AuthorizationRequestOpts;
49
- authorizationCodeResponse?: AuthorizationResponse;
50
- pkce: PKCEOpts;
51
- authorizationURL?: string;
52
- }
54
+ export type OpenID4VCIClientState = OpenID4VCIClientStateV1_0_11 | OpenID4VCIClientStateV1_0_13;
55
+
56
+ export type EndpointMetadataResult = EndpointMetadataResultV1_0_11 | EndpointMetadataResultV1_0_13;
53
57
 
54
58
  export class OpenID4VCIClient {
55
59
  private readonly _state: OpenID4VCIClientState;
@@ -62,6 +66,7 @@ export class OpenID4VCIClient {
62
66
  credentialIssuer,
63
67
  pkce,
64
68
  authorizationRequest,
69
+ accessToken,
65
70
  jwk,
66
71
  endpointMetadata,
67
72
  accessTokenResponse,
@@ -77,6 +82,7 @@ export class OpenID4VCIClient {
77
82
  pkce?: PKCEOpts;
78
83
  authorizationRequest?: AuthorizationRequestOpts; // Can be provided here, or when manually calling createAuthorizationUrl
79
84
  jwk?: JWK;
85
+ accessToken?: string;
80
86
  endpointMetadata?: EndpointMetadataResult;
81
87
  accessTokenResponse?: AccessTokenResponse;
82
88
  authorizationRequestOpts?: AuthorizationRequestOpts;
@@ -98,10 +104,12 @@ export class OpenID4VCIClient {
98
104
  authorizationRequestOpts,
99
105
  authorizationCodeResponse,
100
106
  jwk,
101
- endpointMetadata,
107
+ endpointMetadata: endpointMetadata?.credentialIssuerMetadata?.authorization_server
108
+ ? (endpointMetadata as EndpointMetadataResultV1_0_11)
109
+ : (endpointMetadata as EndpointMetadataResultV1_0_13 | undefined),
102
110
  accessTokenResponse,
103
111
  authorizationURL,
104
- };
112
+ } as OpenID4VCIClientState;
105
113
  // Running syncAuthorizationRequestOpts later as it is using the state
106
114
  if (!this._state.authorizationRequestOpts) {
107
115
  this._state.authorizationRequestOpts = this.syncAuthorizationRequestOpts(authorizationRequest);
@@ -218,13 +226,23 @@ export class OpenID4VCIClient {
218
226
  ) {
219
227
  this._state.endpointMetadata.authorization_endpoint = this._state.endpointMetadata.credentialIssuerMetadata.authorization_endpoint as string;
220
228
  }
221
- this._state.authorizationURL = await createAuthorizationRequestUrl({
222
- pkce: this._state.pkce,
223
- endpointMetadata: this.endpointMetadata,
224
- authorizationRequest: this._state.authorizationRequestOpts,
225
- credentialOffer: this.credentialOffer,
226
- credentialsSupported: this.getCredentialsSupported(true),
227
- });
229
+ if (this.version() <= OpenId4VCIVersion.VER_1_0_11) {
230
+ this._state.authorizationURL = await createAuthorizationRequestUrlV1_0_11({
231
+ pkce: this._state.pkce,
232
+ endpointMetadata: this.endpointMetadata as EndpointMetadataResultV1_0_11,
233
+ authorizationRequest: this._state.authorizationRequestOpts,
234
+ credentialOffer: this.credentialOffer,
235
+ credentialsSupported: Object.values(this.getCredentialsSupported(true)) as CredentialsSupportedLegacy[],
236
+ });
237
+ } else {
238
+ this._state.authorizationURL = await createAuthorizationRequestUrl({
239
+ pkce: this._state.pkce,
240
+ endpointMetadata: this.endpointMetadata as EndpointMetadataResultV1_0_13,
241
+ authorizationRequest: this._state.authorizationRequestOpts,
242
+ credentialOffer: this.credentialOffer,
243
+ credentialConfigurationSupported: this.getCredentialsSupported(false) as Record<string, CredentialConfigurationSupportedV1_0_13>,
244
+ });
245
+ }
228
246
  }
229
247
  return this._state.authorizationURL;
230
248
  }
@@ -274,7 +292,7 @@ export class OpenID4VCIClient {
274
292
  this._state.clientId = clientId;
275
293
  }
276
294
  if (!this._state.accessTokenResponse) {
277
- const accessTokenClient = new AccessTokenClient();
295
+ const accessTokenClient = this.version() <= OpenId4VCIVersion.VER_1_0_12 ? new AccessTokenClientV1_0_11() : new AccessTokenClient();
278
296
 
279
297
  if (redirectUri && redirectUri !== this._state.authorizationRequestOpts?.redirectUri) {
280
298
  console.log(
@@ -312,6 +330,7 @@ export class OpenID4VCIClient {
312
330
  );
313
331
  }
314
332
  this._state.accessTokenResponse = response.successBody;
333
+ this._state.accessToken = response.successBody.access_token;
315
334
  }
316
335
 
317
336
  return this.accessTokenResponse;
@@ -339,7 +358,8 @@ export class OpenID4VCIClient {
339
358
  jti?: string;
340
359
  deferredCredentialAwait?: boolean;
341
360
  deferredCredentialIntervalInMS?: number;
342
- }): Promise<CredentialResponse> {
361
+ experimentalHolderIssuanceSupported?: boolean;
362
+ }): Promise<CredentialResponse & { access_token: string }> {
343
363
  if ([jwk, kid].filter((v) => v !== undefined).length > 1) {
344
364
  throw new Error(KID_JWK_X5C_ERROR + `. jwk: ${jwk !== undefined}, kid: ${kid !== undefined}`);
345
365
  }
@@ -348,20 +368,36 @@ export class OpenID4VCIClient {
348
368
  if (jwk) this._state.jwk = jwk;
349
369
  if (kid) this._state.kid = kid;
350
370
 
351
- const requestBuilder = this.credentialOffer
352
- ? CredentialRequestClientBuilder.fromCredentialOffer({
353
- credentialOffer: this.credentialOffer,
354
- metadata: this.endpointMetadata,
355
- })
356
- : CredentialRequestClientBuilder.fromCredentialIssuer({
357
- credentialIssuer: this.getIssuer(),
358
- credentialTypes,
359
- metadata: this.endpointMetadata,
360
- version: this.version(),
361
- });
371
+ let requestBuilder: CredentialRequestClientBuilder | CredentialRequestClientBuilderV1_0_11;
372
+ if (this.version() < OpenId4VCIVersion.VER_1_0_13) {
373
+ requestBuilder = this.credentialOffer
374
+ ? CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({
375
+ credentialOffer: this.credentialOffer,
376
+ metadata: this.endpointMetadata,
377
+ })
378
+ : CredentialRequestClientBuilderV1_0_11.fromCredentialIssuer({
379
+ credentialIssuer: this.getIssuer(),
380
+ credentialTypes,
381
+ metadata: this.endpointMetadata,
382
+ version: this.version(),
383
+ });
384
+ } else {
385
+ requestBuilder = this.credentialOffer
386
+ ? CredentialRequestClientBuilder.fromCredentialOffer({
387
+ credentialOffer: this.credentialOffer,
388
+ metadata: this.endpointMetadata,
389
+ })
390
+ : CredentialRequestClientBuilder.fromCredentialIssuer({
391
+ credentialIssuer: this.getIssuer(),
392
+ credentialTypes,
393
+ metadata: this.endpointMetadata,
394
+ version: this.version(),
395
+ });
396
+ }
362
397
 
363
398
  requestBuilder.withTokenFromResponse(this.accessTokenResponse);
364
399
  requestBuilder.withDeferredCredentialAwait(deferredCredentialAwait ?? false, deferredCredentialIntervalInMS);
400
+ let subjectIssuance: ExperimentalSubjectIssuance | undefined;
365
401
  if (this.endpointMetadata?.credentialIssuerMetadata) {
366
402
  const metadata = this.endpointMetadata.credentialIssuerMetadata;
367
403
  const types = Array.isArray(credentialTypes) ? credentialTypes : [credentialTypes];
@@ -376,6 +412,9 @@ export class OpenID4VCIClient {
376
412
  (types.length === 1 && (types[0] === supportedCredential.id || subTypes.includes(types[0])))
377
413
  ) {
378
414
  typeSupported = true;
415
+ if (supportedCredential.credential_subject_issuance) {
416
+ subjectIssuance = { credential_subject_issuance: supportedCredential.credential_subject_issuance };
417
+ }
379
418
  }
380
419
  });
381
420
 
@@ -391,6 +430,10 @@ export class OpenID4VCIClient {
391
430
  }
392
431
  // todo: Format check? We might end up with some disjoint type / format combinations supported by the server
393
432
  }
433
+ if (subjectIssuance) {
434
+ requestBuilder.withSubjectIssuance(subjectIssuance);
435
+ }
436
+
394
437
  const credentialRequestClient = requestBuilder.build();
395
438
  const proofBuilder = ProofOfPossessionBuilder.fromAccessTokenResponse({
396
439
  accessTokenResponse: this.accessTokenResponse,
@@ -418,6 +461,7 @@ export class OpenID4VCIClient {
418
461
  credentialTypes,
419
462
  context,
420
463
  format,
464
+ subjectIssuance,
421
465
  });
422
466
  if (response.errorBody) {
423
467
  debug(`Credential request error:\r\n${JSON.stringify(response.errorBody)}`);
@@ -434,21 +478,17 @@ export class OpenID4VCIClient {
434
478
  } for issuer ${this.getIssuer()} failed as there was no success response body`,
435
479
  );
436
480
  }
437
- return response.successBody;
481
+ return { ...response.successBody, access_token: response.access_token };
438
482
  }
439
483
 
440
484
  public async exportState(): Promise<string> {
441
485
  return JSON.stringify(this._state);
442
486
  }
443
487
 
444
- // FIXME: We really should convert <v11 to v12 objects first. Right now the logic doesn't map nicely and is brittle.
445
- // We should resolve IDs to objects first in case of strings.
446
- // When < v11 convert into a v12 object. When v12 object retain it.
447
- // Then match the object array on server metadata
448
488
  getCredentialsSupported(
449
- restrictToInitiationTypes: boolean,
489
+ restrictToInitiationTypes?: boolean,
450
490
  format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[],
451
- ): CredentialSupported[] {
491
+ ): Record<string, CredentialConfigurationSupportedV1_0_13> | Array<CredentialConfigurationSupported> {
452
492
  return getSupportedCredentials({
453
493
  issuerMetadata: this.endpointMetadata.credentialIssuerMetadata,
454
494
  version: this.version(),
@@ -457,34 +497,36 @@ export class OpenID4VCIClient {
457
497
  });
458
498
  }
459
499
 
460
- getCredentialOfferTypes(): string[][] {
500
+ public async sendNotification(
501
+ credentialRequestOpts: Partial<CredentialRequestOpts>,
502
+ request: NotificationRequest,
503
+ accessToken?: string,
504
+ ): Promise<NotificationResult> {
505
+ return sendNotification(credentialRequestOpts, request, accessToken ?? this._state.accessToken ?? this._state.accessTokenResponse?.access_token);
506
+ }
507
+
508
+ getCredentialOfferTypes(): string[][] | undefined {
461
509
  if (!this.credentialOffer) {
462
510
  return [];
463
- } else if (this.credentialOffer.version < OpenId4VCIVersion.VER_1_0_11) {
511
+ } else if (this.version() < OpenId4VCIVersion.VER_1_0_11) {
464
512
  const orig = this.credentialOffer.original_credential_offer as CredentialOfferPayloadV1_0_08;
465
513
  const types: string[] = typeof orig.credential_type === 'string' ? [orig.credential_type] : orig.credential_type;
466
514
  const result: string[][] = [];
467
515
  result[0] = types;
468
516
  return result;
469
- } else {
470
- return this.credentialOffer.credential_offer.credentials.map((c) => {
471
- if (typeof c === 'string') {
472
- return [c];
473
- } else if ('types' in c) {
474
- return c.types;
475
- } else if ('vct' in c) {
476
- return [c.vct];
477
- } else {
478
- return c.credential_definition.types;
479
- }
480
- });
517
+ } else if (this.version() < OpenId4VCIVersion.VER_1_0_13) {
518
+ return (this.credentialOffer.credential_offer as CredentialOfferPayloadV1_0_11).credentials.map((c) => getTypesFromObject(c) ?? []);
481
519
  }
520
+ // we don't have this for v13. v13 only has credential_configuration_ids which is not translatable to type
521
+ return undefined;
482
522
  }
483
523
 
484
524
  issuerSupportedFlowTypes(): AuthzFlowType[] {
485
525
  return (
486
526
  this.credentialOffer?.supportedFlows ??
487
- (this._state.endpointMetadata?.credentialIssuerMetadata?.authorization_endpoint ? [AuthzFlowType.AUTHORIZATION_CODE_FLOW] : [])
527
+ (this._state.endpointMetadata?.credentialIssuerMetadata?.authorization_endpoint ?? this._state.endpointMetadata?.authorization_server
528
+ ? [AuthzFlowType.AUTHORIZATION_CODE_FLOW]
529
+ : [])
488
530
  );
489
531
  }
490
532
 
@@ -505,7 +547,17 @@ export class OpenID4VCIClient {
505
547
  }
506
548
 
507
549
  public version(): OpenId4VCIVersion {
508
- return this.credentialOffer?.version ?? OpenId4VCIVersion.VER_1_0_11;
550
+ if (this.credentialOffer?.version && this.credentialOffer.version !== OpenId4VCIVersion.VER_UNKNOWN) {
551
+ return this.credentialOffer.version;
552
+ }
553
+ const metadata = this._state.endpointMetadata;
554
+ if (metadata?.credentialIssuerMetadata) {
555
+ const versions = determineVersionsFromIssuerMetadata(metadata.credentialIssuerMetadata);
556
+ if (versions.length > 0 && !versions.includes(OpenId4VCIVersion.VER_UNKNOWN)) {
557
+ return versions[0];
558
+ }
559
+ }
560
+ return OpenId4VCIVersion.VER_1_0_13;
509
561
  }
510
562
 
511
563
  public get endpointMetadata(): EndpointMetadataResult {
@@ -555,8 +607,11 @@ export class OpenID4VCIClient {
555
607
 
556
608
  public getAccessTokenEndpoint(): string {
557
609
  this.assertIssuerData();
558
- return this.endpointMetadata
559
- ? this.endpointMetadata.token_endpoint
610
+ if (this.endpointMetadata) {
611
+ return this.endpointMetadata.token_endpoint;
612
+ }
613
+ return this.version() <= OpenId4VCIVersion.VER_1_0_12
614
+ ? AccessTokenClientV1_0_11.determineTokenURL({ issuerOpts: { issuer: this.getIssuer() } })
560
615
  : AccessTokenClient.determineTokenURL({ issuerOpts: { issuer: this.getIssuer() } });
561
616
  }
562
617
 
@@ -579,7 +634,8 @@ export class OpenID4VCIClient {
579
634
  */
580
635
  public isEBSI() {
581
636
  if (
582
- this.credentialOffer?.credential_offer.credentials.find(
637
+ this.credentialOffer &&
638
+ (this.credentialOffer?.credential_offer as CredentialOfferPayloadV1_0_11)?.credentials?.find(
583
639
  (cred) =>
584
640
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
585
641
  // @ts-ignore
@@ -588,8 +644,11 @@ export class OpenID4VCIClient {
588
644
  ) {
589
645
  return true;
590
646
  }
591
- this.assertIssuerData();
592
- return this.endpointMetadata.credentialIssuerMetadata?.authorization_endpoint?.includes('ebsi.eu');
647
+ // this.assertIssuerData();
648
+ return (
649
+ this.endpointMetadata.credentialIssuerMetadata?.authorization_endpoint?.includes('ebsi.eu') ||
650
+ this.endpointMetadata.credentialIssuerMetadata?.authorization_server?.includes('ebsi.eu')
651
+ );
593
652
  }
594
653
 
595
654
  private assertIssuerData(): void {
@@ -613,7 +672,12 @@ export class OpenID4VCIClient {
613
672
  }
614
673
 
615
674
  private syncAuthorizationRequestOpts(opts?: AuthorizationRequestOpts): AuthorizationRequestOpts {
616
- let authorizationRequestOpts = { ...this._state?.authorizationRequestOpts, ...opts } as AuthorizationRequestOpts;
675
+ const requestObjectOpts = { ...this._state?.authorizationRequestOpts?.requestObjectOpts, ...opts?.requestObjectOpts };
676
+ let authorizationRequestOpts = {
677
+ ...this._state?.authorizationRequestOpts,
678
+ ...opts,
679
+ ...(requestObjectOpts && { requestObjectOpts }),
680
+ } as AuthorizationRequestOpts;
617
681
  if (!authorizationRequestOpts) {
618
682
  // We only set a redirectUri if no options are provided.
619
683
  // Note that this only works for mobile apps, that can handle a code query param on the default openid-credential-offer deeplink.