@sphereon/oid4vci-common 0.8.2-next.4 → 0.8.2-next.46

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 (76) hide show
  1. package/dist/functions/CredentialOfferUtil.d.ts +3 -0
  2. package/dist/functions/CredentialOfferUtil.d.ts.map +1 -1
  3. package/dist/functions/CredentialOfferUtil.js +29 -1
  4. package/dist/functions/CredentialOfferUtil.js.map +1 -1
  5. package/dist/functions/CredentialRequestUtil.d.ts +3 -2
  6. package/dist/functions/CredentialRequestUtil.d.ts.map +1 -1
  7. package/dist/functions/CredentialRequestUtil.js +26 -2
  8. package/dist/functions/CredentialRequestUtil.js.map +1 -1
  9. package/dist/functions/CredentialResponseUtil.d.ts +11 -0
  10. package/dist/functions/CredentialResponseUtil.d.ts.map +1 -0
  11. package/dist/functions/CredentialResponseUtil.js +80 -0
  12. package/dist/functions/CredentialResponseUtil.js.map +1 -0
  13. package/dist/functions/Encoding.js.map +1 -1
  14. package/dist/functions/FormatUtils.d.ts +15 -0
  15. package/dist/functions/FormatUtils.d.ts.map +1 -0
  16. package/dist/functions/FormatUtils.js +44 -0
  17. package/dist/functions/FormatUtils.js.map +1 -0
  18. package/dist/functions/HttpUtils.d.ts +3 -3
  19. package/dist/functions/HttpUtils.d.ts.map +1 -1
  20. package/dist/functions/HttpUtils.js +1 -1
  21. package/dist/functions/HttpUtils.js.map +1 -1
  22. package/dist/functions/IssuerMetadataUtils.d.ts +3 -0
  23. package/dist/functions/IssuerMetadataUtils.d.ts.map +1 -1
  24. package/dist/functions/IssuerMetadataUtils.js +27 -7
  25. package/dist/functions/IssuerMetadataUtils.js.map +1 -1
  26. package/dist/functions/index.d.ts +3 -0
  27. package/dist/functions/index.d.ts.map +1 -1
  28. package/dist/functions/index.js +3 -0
  29. package/dist/functions/index.js.map +1 -1
  30. package/dist/types/Authorization.types.d.ts +17 -6
  31. package/dist/types/Authorization.types.d.ts.map +1 -1
  32. package/dist/types/Authorization.types.js +6 -6
  33. package/dist/types/Authorization.types.js.map +1 -1
  34. package/dist/types/CredentialIssuance.types.d.ts +1 -0
  35. package/dist/types/CredentialIssuance.types.d.ts.map +1 -1
  36. package/dist/types/CredentialIssuance.types.js +2 -2
  37. package/dist/types/CredentialIssuance.types.js.map +1 -1
  38. package/dist/types/Generic.types.d.ts +46 -18
  39. package/dist/types/Generic.types.d.ts.map +1 -1
  40. package/dist/types/Generic.types.js.map +1 -1
  41. package/dist/types/OpenID4VCIVersions.types.js +2 -2
  42. package/dist/types/OpenID4VCIVersions.types.js.map +1 -1
  43. package/dist/types/QRCode.types.js +0 -2
  44. package/dist/types/QRCode.types.js.map +1 -1
  45. package/dist/types/ServerMetadata.d.ts +2 -0
  46. package/dist/types/ServerMetadata.d.ts.map +1 -1
  47. package/dist/types/ServerMetadata.js +1 -1
  48. package/dist/types/ServerMetadata.js.map +1 -1
  49. package/dist/types/StateManager.types.d.ts +4 -4
  50. package/dist/types/StateManager.types.d.ts.map +1 -1
  51. package/dist/types/StateManager.types.js +1 -1
  52. package/dist/types/StateManager.types.js.map +1 -1
  53. package/dist/types/Token.types.d.ts +1 -1
  54. package/dist/types/Token.types.d.ts.map +1 -1
  55. package/dist/types/Token.types.js +1 -1
  56. package/dist/types/Token.types.js.map +1 -1
  57. package/dist/types/v1_0_08.types.d.ts +6 -2
  58. package/dist/types/v1_0_08.types.d.ts.map +1 -1
  59. package/dist/types/v1_0_11.types.d.ts +3 -15
  60. package/dist/types/v1_0_11.types.d.ts.map +1 -1
  61. package/dist/types/v1_0_11.types.js.map +1 -1
  62. package/lib/functions/CredentialOfferUtil.ts +27 -0
  63. package/lib/functions/CredentialRequestUtil.ts +31 -3
  64. package/lib/functions/CredentialResponseUtil.ts +90 -0
  65. package/lib/functions/FormatUtils.ts +52 -0
  66. package/lib/functions/HttpUtils.ts +5 -5
  67. package/lib/functions/IssuerMetadataUtils.ts +26 -4
  68. package/lib/functions/index.ts +3 -0
  69. package/lib/types/Authorization.types.ts +30 -6
  70. package/lib/types/CredentialIssuance.types.ts +2 -1
  71. package/lib/types/Generic.types.ts +63 -16
  72. package/lib/types/QRCode.types.ts +2 -2
  73. package/lib/types/ServerMetadata.ts +2 -0
  74. package/lib/types/v1_0_08.types.ts +7 -2
  75. package/lib/types/v1_0_11.types.ts +6 -20
  76. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"v1_0_11.types.d.ts","sourceRoot":"","sources":["../../lib/types/v1_0_11.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAClG,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,EACL,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,CAAC,EAAE,6BAA6B,CAAC;IACjD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;CAC3D;AAED,MAAM,WAAW,mCAAmC;IAClD;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;;;;;;;OAQG;IACH,WAAW,EAAE,CAAC,qBAAqB,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,WAAW,2BAA4B,SAAQ,mCAAmC;IACtF;;;;;;OAMG;IACH,qBAAqB,EAAE,0BAA0B,CAAC;CACnD;AAED,MAAM,MAAM,2BAA2B,GAAG,mCAAmC,CAAC;AAE9E,MAAM,MAAM,6BAA6B,GAAG,mCAAmC,GAAG,CAAC,2BAA2B,GAAG,2BAA2B,CAAC,CAAC;AAE9I,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,GAAG,CAAC,sBAAsB,GAAG,sBAAsB,CAAC,CAAC;AAEnH,MAAM,WAAW,2BAA4B,SAAQ,6BAA6B,EAAE,6BAA6B;IAC/G,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAE1F"}
1
+ {"version":3,"file":"v1_0_11.types.d.ts","sourceRoot":"","sources":["../../lib/types/v1_0_11.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAClG,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,0BAA0B,EAC1B,oCAAoC,EACpC,wBAAwB,EACxB,KAAK,EACN,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,CAAC,EAAE,6BAA6B,CAAC;IACjD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;CAC3D;AAED,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAE1B;;;;;;;;OAQG;IACH,WAAW,EAAE,CAAC,qBAAqB,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,GAC5D,CAAC,0BAA0B,GAAG,oCAAoC,GAAG,wBAAwB,CAAC,CAAC;AAEjG,MAAM,WAAW,2BAA4B,SAAQ,6BAA6B,EAAE,6BAA6B;IAC/G,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAE1F"}
@@ -1 +1 @@
1
- {"version":3,"file":"v1_0_11.types.js","sourceRoot":"","sources":["../../lib/types/v1_0_11.types.ts"],"names":[],"mappings":";;;AAyEA,qDAAqD;AACrD,SAAgB,6BAA6B,CAAC,OAAmC;IAC/E,OAAO,OAAO,IAAI,cAAc,IAAI,OAAO,CAAC;AAC9C,CAAC;AAFD,sEAEC"}
1
+ {"version":3,"file":"v1_0_11.types.js","sourceRoot":"","sources":["../../lib/types/v1_0_11.types.ts"],"names":[],"mappings":";;;AA2DA,qDAAqD;AACrD,SAAgB,6BAA6B,CAAC,OAAmC;IAC/E,OAAO,OAAO,IAAI,cAAc,IAAI,OAAO,CAAC;AAC9C,CAAC;AAFD,sEAEC"}
@@ -340,3 +340,30 @@ function recordVersion(currentVersion: OpenId4VCIVersion, matchingVersion: OpenI
340
340
  `Invalid param. Some keys have been used from version: ${currentVersion} version while '${key}' is used from version: ${matchingVersion}`,
341
341
  );
342
342
  }
343
+
344
+ export function getTypesFromOffer(credentialOffer: UniformCredentialOfferPayload, opts?: { filterVerifiableCredential: boolean }) {
345
+ const types = credentialOffer.credentials.reduce<string[]>((prev, curr) => {
346
+ // FIXME returning the string value is wrong (as it's an id), but just matching the current behavior of this library
347
+ // The credential_type (from draft 8) and the actual 'type' value in a VC (from draft 11) are mixed up
348
+ // Fix for this here: https://github.com/Sphereon-Opensource/OID4VCI/pull/54
349
+ if (typeof curr === 'string') {
350
+ return [...prev, curr];
351
+ } else if (curr.format === 'jwt_vc_json-ld' || curr.format === 'ldp_vc') {
352
+ return [...prev, ...curr.credential_definition.types];
353
+ } else if (curr.format === 'jwt_vc_json' || curr.format === 'jwt_vc') {
354
+ return [...prev, ...curr.types];
355
+ } else if (curr.format === 'vc+sd-jwt') {
356
+ return [...prev, curr.vct];
357
+ }
358
+
359
+ return prev;
360
+ }, []);
361
+
362
+ if (!types || types.length === 0) {
363
+ throw Error('Could not deduce types from credential offer');
364
+ }
365
+ if (opts?.filterVerifiableCredential) {
366
+ return types.filter((type) => type !== 'VerifiableCredential');
367
+ }
368
+ return types;
369
+ }
@@ -1,7 +1,17 @@
1
- import { CredentialRequestV1_0_11 } from '../types';
1
+ import { CredentialRequestV1_0_08, OpenId4VCIVersion, UniformCredentialRequest } from '../types';
2
+
3
+ import { getFormatForVersion } from './FormatUtils';
4
+
5
+ export function getTypesFromRequest(credentialRequest: UniformCredentialRequest, opts?: { filterVerifiableCredential: boolean }) {
6
+ let types: string[] = [];
7
+ if (credentialRequest.format === 'jwt_vc_json' || credentialRequest.format === 'jwt_vc') {
8
+ types = credentialRequest.types;
9
+ } else if (credentialRequest.format === 'jwt_vc_json-ld' || credentialRequest.format === 'ldp_vc') {
10
+ types = credentialRequest.credential_definition.types;
11
+ } else if (credentialRequest.format === 'vc+sd-jwt') {
12
+ types = [credentialRequest.vct];
13
+ }
2
14
 
3
- export function getTypesFromRequest(credentialRequest: CredentialRequestV1_0_11, opts?: { filterVerifiableCredential: boolean }) {
4
- const types = 'types' in credentialRequest ? credentialRequest.types : credentialRequest.credential_definition.types;
5
15
  if (!types || types.length === 0) {
6
16
  throw Error('Could not deduce types from credential request');
7
17
  }
@@ -10,3 +20,21 @@ export function getTypesFromRequest(credentialRequest: CredentialRequestV1_0_11,
10
20
  }
11
21
  return types;
12
22
  }
23
+
24
+ export function getCredentialRequestForVersion(
25
+ credentialRequest: UniformCredentialRequest,
26
+ version: OpenId4VCIVersion,
27
+ ): UniformCredentialRequest | CredentialRequestV1_0_08 {
28
+ if (version === OpenId4VCIVersion.VER_1_0_08) {
29
+ const draft8Format = getFormatForVersion(credentialRequest.format, version);
30
+ const types = getTypesFromRequest(credentialRequest, { filterVerifiableCredential: true });
31
+
32
+ return {
33
+ format: draft8Format,
34
+ proof: credentialRequest.proof,
35
+ type: types[0],
36
+ } satisfies CredentialRequestV1_0_08;
37
+ }
38
+
39
+ return credentialRequest;
40
+ }
@@ -0,0 +1,90 @@
1
+ import { CredentialResponse, OpenIDResponse } from '../types';
2
+
3
+ import { post } from './HttpUtils';
4
+
5
+ export function isDeferredCredentialResponse(credentialResponse: OpenIDResponse<CredentialResponse>) {
6
+ const orig = credentialResponse.successBody;
7
+ // Specs mention 202, but some implementations like EBSI return 200
8
+ return credentialResponse.origResponse.status % 200 <= 2 && !!orig && !orig.credential && (!!orig.acceptance_token || !!orig.transaction_id);
9
+ }
10
+ function assertNonFatalError(credentialResponse: OpenIDResponse<CredentialResponse>) {
11
+ if (credentialResponse.origResponse.status === 400 && credentialResponse.errorBody?.error) {
12
+ if (credentialResponse.errorBody.error === 'invalid_transaction_id' || credentialResponse.errorBody.error.includes('acceptance_token')) {
13
+ throw Error('Invalid transaction id. Probably the deferred credential request expired');
14
+ }
15
+ }
16
+ }
17
+
18
+ export function isDeferredCredentialIssuancePending(credentialResponse: OpenIDResponse<CredentialResponse>) {
19
+ if (isDeferredCredentialResponse(credentialResponse)) {
20
+ return !!credentialResponse?.successBody?.transaction_id ?? !!credentialResponse?.successBody?.acceptance_token;
21
+ }
22
+ if (credentialResponse.origResponse.status === 400 && credentialResponse.errorBody?.error) {
23
+ if (credentialResponse.errorBody.error === 'issuance_pending') {
24
+ return true;
25
+ } else if (credentialResponse.errorBody.error_description?.toLowerCase().includes('not available yet')) {
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ }
31
+
32
+ function sleep(ms: number) {
33
+ return new Promise((resolve) => {
34
+ setTimeout(resolve, ms);
35
+ });
36
+ }
37
+
38
+ export async function acquireDeferredCredential({
39
+ bearerToken,
40
+ transactionId,
41
+ deferredCredentialEndpoint,
42
+ deferredCredentialIntervalInMS,
43
+ deferredCredentialAwait,
44
+ }: {
45
+ bearerToken: string;
46
+ transactionId?: string;
47
+ deferredCredentialIntervalInMS?: number;
48
+ deferredCredentialAwait?: boolean;
49
+ deferredCredentialEndpoint: string;
50
+ }): Promise<OpenIDResponse<CredentialResponse>> {
51
+ let credentialResponse: OpenIDResponse<CredentialResponse> = await acquireDeferredCredentialImpl({
52
+ bearerToken,
53
+ transactionId,
54
+ deferredCredentialEndpoint,
55
+ });
56
+
57
+ const DEFAULT_SLEEP_IN_MS = 5000;
58
+ while (!credentialResponse.successBody?.credential && deferredCredentialAwait) {
59
+ assertNonFatalError(credentialResponse);
60
+ const pending = isDeferredCredentialIssuancePending(credentialResponse);
61
+ console.log(`Issuance still pending?: ${pending}`);
62
+ if (!pending) {
63
+ throw Error(`Issuance isn't pending anymore: ${credentialResponse}`);
64
+ }
65
+
66
+ await sleep(deferredCredentialIntervalInMS ?? DEFAULT_SLEEP_IN_MS);
67
+ credentialResponse = await acquireDeferredCredentialImpl({ bearerToken, transactionId, deferredCredentialEndpoint });
68
+ }
69
+ return credentialResponse;
70
+ }
71
+
72
+ async function acquireDeferredCredentialImpl({
73
+ bearerToken,
74
+ transactionId,
75
+ deferredCredentialEndpoint,
76
+ }: {
77
+ bearerToken: string;
78
+ transactionId?: string;
79
+ deferredCredentialEndpoint: string;
80
+ }): Promise<OpenIDResponse<CredentialResponse>> {
81
+ const response: OpenIDResponse<CredentialResponse> = await post(
82
+ deferredCredentialEndpoint,
83
+ JSON.stringify(transactionId ? { transaction_id: transactionId } : ''),
84
+ { bearerToken },
85
+ );
86
+ console.log(JSON.stringify(response, null, 2));
87
+ assertNonFatalError(response);
88
+
89
+ return response;
90
+ }
@@ -0,0 +1,52 @@
1
+ import { CredentialFormat } from '@sphereon/ssi-types';
2
+
3
+ import { OID4VCICredentialFormat, OpenId4VCIVersion } from '../types';
4
+
5
+ export function isFormat<T extends { format?: OID4VCICredentialFormat }, Format extends OID4VCICredentialFormat>(
6
+ formatObject: T,
7
+ format: Format,
8
+ ): formatObject is T & { format: Format } {
9
+ return formatObject.format === format;
10
+ }
11
+
12
+ export function isNotFormat<T extends { format?: OID4VCICredentialFormat }, Format extends OID4VCICredentialFormat>(
13
+ formatObject: T,
14
+ format: Format,
15
+ ): formatObject is T & { format: Exclude<OID4VCICredentialFormat, Format> } {
16
+ return formatObject.format !== format;
17
+ }
18
+
19
+ const isUniformFormat = (format: string): format is OID4VCICredentialFormat => {
20
+ return ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc', 'vc+sd-jwt'].includes(format);
21
+ };
22
+
23
+ export function getUniformFormat(format: string | OID4VCICredentialFormat | CredentialFormat): OID4VCICredentialFormat {
24
+ // Already valid format
25
+ if (isUniformFormat(format)) {
26
+ return format;
27
+ }
28
+
29
+ // Older formats
30
+ if (format === 'jwt_vc' || format === 'jwt') {
31
+ return 'jwt_vc';
32
+ }
33
+ if (format === 'ldp_vc' || format === 'ldp') {
34
+ return 'ldp_vc';
35
+ }
36
+
37
+ throw new Error(`Invalid format: ${format}`);
38
+ }
39
+
40
+ export function getFormatForVersion(format: string, version: OpenId4VCIVersion) {
41
+ const uniformFormat = isUniformFormat(format) ? format : getUniformFormat(format);
42
+
43
+ if (version === OpenId4VCIVersion.VER_1_0_08) {
44
+ if (uniformFormat === 'jwt_vc_json') {
45
+ return 'jwt_vc' as const;
46
+ } else if (uniformFormat === 'ldp_vc' || uniformFormat === 'jwt_vc_json-ld') {
47
+ return 'ldp_vc' as const;
48
+ }
49
+ }
50
+
51
+ return uniformFormat;
52
+ }
@@ -8,7 +8,7 @@ const debug = Debug('sphereon:openid4vci:http');
8
8
  export const getJson = async <T>(
9
9
  URL: string,
10
10
  opts?: {
11
- bearerToken?: string;
11
+ bearerToken?: (() => Promise<string>) | string;
12
12
  contentType?: string;
13
13
  accept?: string;
14
14
  customHeaders?: Record<string, string>;
@@ -22,7 +22,7 @@ export const formPost = async <T>(
22
22
  url: string,
23
23
  body: BodyInit,
24
24
  opts?: {
25
- bearerToken?: string;
25
+ bearerToken?: (() => Promise<string>) | string;
26
26
  contentType?: string;
27
27
  accept?: string;
28
28
  customHeaders?: Record<string, string>;
@@ -36,7 +36,7 @@ export const post = async <T>(
36
36
  url: string,
37
37
  body?: BodyInit,
38
38
  opts?: {
39
- bearerToken?: string;
39
+ bearerToken?: (() => Promise<string>) | string;
40
40
  contentType?: string;
41
41
  accept?: string;
42
42
  customHeaders?: Record<string, string>;
@@ -51,7 +51,7 @@ const openIdFetch = async <T>(
51
51
  body?: BodyInit,
52
52
  opts?: {
53
53
  method?: string;
54
- bearerToken?: string;
54
+ bearerToken?: (() => Promise<string>) | string;
55
55
  contentType?: string;
56
56
  accept?: string;
57
57
  customHeaders?: Record<string, string>;
@@ -60,7 +60,7 @@ const openIdFetch = async <T>(
60
60
  ): Promise<OpenIDResponse<T>> => {
61
61
  const headers: Record<string, string> = opts?.customHeaders ?? {};
62
62
  if (opts?.bearerToken) {
63
- headers['Authorization'] = `Bearer ${opts.bearerToken}`;
63
+ headers['Authorization'] = `Bearer ${typeof opts.bearerToken === 'function' ? await opts.bearerToken() : opts.bearerToken}`;
64
64
  }
65
65
  const method = opts?.method ? opts.method : body ? 'POST' : 'GET';
66
66
  const accept = opts?.accept ? opts.accept : 'application/json';
@@ -43,7 +43,7 @@ export function getSupportedCredential(opts?: {
43
43
  }
44
44
  const { version, types } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 };
45
45
  if (version === OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) {
46
- credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported);
46
+ credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported ?? {});
47
47
  } else {
48
48
  credentialsSupported = (issuerMetadata as CredentialIssuerMetadata).credentials_supported;
49
49
  }
@@ -73,7 +73,7 @@ export function getSupportedCredential(opts?: {
73
73
  if ((opts?.types && typeof opts?.types === 'string') || opts?.types?.length === 1) {
74
74
  const types = Array.isArray(opts.types) ? opts.types[0] : opts.types;
75
75
  const supported = credentialsSupported.filter(
76
- (sup) => sup.id === types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes)),
76
+ (sup) => sup.id === types || (initiationTypes && arrayEqualsIgnoreOrder(getTypesFromCredentialSupported(sup), initiationTypes)),
77
77
  );
78
78
  if (supported) {
79
79
  credentialSupportedOverlap.push(...supported);
@@ -86,7 +86,7 @@ export function getSupportedCredential(opts?: {
86
86
  initiationTypes.push('VerifiableCredential');
87
87
  }
88
88
  const supported = credentialsSupported.filter((sup) => {
89
- const supTypes = sup.types;
89
+ const supTypes = getTypesFromCredentialSupported(sup);
90
90
  if (!supTypes.includes('VerifiableCredential')) {
91
91
  supTypes.push('VerifiableCredential');
92
92
  }
@@ -99,6 +99,28 @@ export function getSupportedCredential(opts?: {
99
99
  return credentialSupportedOverlap;
100
100
  }
101
101
 
102
+ export function getTypesFromCredentialSupported(credentialSupported: CredentialSupported, opts?: { filterVerifiableCredential: boolean }) {
103
+ let types: string[] = [];
104
+ if (
105
+ credentialSupported.format === 'jwt_vc_json' ||
106
+ credentialSupported.format === 'jwt_vc' ||
107
+ credentialSupported.format === 'jwt_vc_json-ld' ||
108
+ credentialSupported.format === 'ldp_vc'
109
+ ) {
110
+ types = credentialSupported.types;
111
+ } else if (credentialSupported.format === 'vc+sd-jwt') {
112
+ types = [credentialSupported.vct];
113
+ }
114
+
115
+ if (!types || types.length === 0) {
116
+ throw Error('Could not deduce types from credential supported');
117
+ }
118
+ if (opts?.filterVerifiableCredential) {
119
+ return types.filter((type) => type !== 'VerifiableCredential');
120
+ }
121
+ return types;
122
+ }
123
+
102
124
  function arrayEqualsIgnoreOrder(a: string[], b: string[]) {
103
125
  if (a.length !== b.length) return false;
104
126
  const uniqueValues = new Set([...a, ...b]);
@@ -127,7 +149,7 @@ export function credentialSupportedV8ToV11(key: string, supportedV8: CredentialS
127
149
  }
128
150
  let credentialSupport: Partial<CredentialSupported> = {};
129
151
  credentialSupport = {
130
- format,
152
+ format: format as OID4VCICredentialFormat,
131
153
  display: supportedV8.display,
132
154
  ...credentialSupportBrief,
133
155
  credentialSubject: supportedV8.claims,
@@ -1,4 +1,7 @@
1
1
  export * from './CredentialRequestUtil';
2
+ export * from './CredentialResponseUtil';
2
3
  export * from './CredentialOfferUtil';
3
4
  export * from './Encoding';
4
5
  export * from './TypeConversionUtils';
6
+ export * from './IssuerMetadataUtils';
7
+ export * from './FormatUtils';
@@ -1,5 +1,11 @@
1
1
  import { CredentialOfferPayload, UniformCredentialOffer } from './CredentialIssuance.types';
2
- import { ErrorResponse, IssuerCredentialDefinition, IssuerCredentialSubject, OID4VCICredentialFormat, PRE_AUTH_CODE_LITERAL } from './Generic.types';
2
+ import {
3
+ ErrorResponse,
4
+ IssuerCredentialSubject,
5
+ JsonLdIssuerCredentialDefinition,
6
+ OID4VCICredentialFormat,
7
+ PRE_AUTH_CODE_LITERAL,
8
+ } from './Generic.types';
3
9
  import { EndpointMetadata } from './ServerMetadata';
4
10
 
5
11
  export interface CommonAuthorizationRequest {
@@ -64,9 +70,9 @@ export interface CommonAuthorizationRequest {
64
70
  /**
65
71
  * string type added for conformity with our previous code in the client
66
72
  */
67
- export type AuthorizationDetails = AuthorizationDetailsJwtVcJson | AuthorizationRequestJwtVcJsonLdAndLdpVc | string;
73
+ export type AuthorizationDetails = AuthorizationDetailsJwtVcJson | AuthorizationDetailsJwtVcJsonLdAndLdpVc | AuthorizationDetailsSdJwtVc | string;
68
74
 
69
- export type AuthorizationRequest = AuthorizationRequestJwtVcJson | AuthorizationDetailsJwtVcJsonLdAndLdpVc;
75
+ export type AuthorizationRequest = AuthorizationRequestJwtVcJson | AuthorizationRequestJwtVcJsonLdAndLdpVc | AuthorizationRequestSdJwtVc;
70
76
 
71
77
  export interface AuthorizationRequestJwtVcJson extends CommonAuthorizationRequest {
72
78
  authorization_details?: AuthorizationDetailsJwtVcJson[];
@@ -76,6 +82,10 @@ export interface AuthorizationRequestJwtVcJsonLdAndLdpVc extends CommonAuthoriza
76
82
  authorization_details?: AuthorizationDetailsJwtVcJsonLdAndLdpVc[];
77
83
  }
78
84
 
85
+ export interface AuthorizationRequestSdJwtVc extends CommonAuthorizationRequest {
86
+ authorization_details?: AuthorizationDetailsSdJwtVc[];
87
+ }
88
+
79
89
  export interface CommonAuthorizationDetails {
80
90
  /**
81
91
  * REQUIRED. JSON string that determines the authorization details type.
@@ -94,12 +104,14 @@ export interface CommonAuthorizationDetails {
94
104
  * the authorization detail's locations common data field MUST be set to the Credential Issuer Identifier value.
95
105
  */
96
106
  locations?: string[];
97
- types: string[]; // This claim contains the type values the Wallet requests authorization for at the issuer.
107
+
98
108
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
109
  [key: string]: any;
100
110
  }
101
111
 
102
112
  export interface AuthorizationDetailsJwtVcJson extends CommonAuthorizationDetails {
113
+ format: 'jwt_vc_json' | 'jwt_vc'; // jwt_vc added for backward compat
114
+
103
115
  /**
104
116
  * A JSON object containing a list of key value pairs, where the key identifies the claim offered in the Credential.
105
117
  * The value MAY be a dictionary, which allows to represent the full (potentially deeply nested) structure of the
@@ -107,9 +119,13 @@ export interface AuthorizationDetailsJwtVcJson extends CommonAuthorizationDetail
107
119
  * credential to be issued.
108
120
  */
109
121
  credentialSubject?: IssuerCredentialSubject;
122
+
123
+ types: string[]; // This claim contains the type values the Wallet requests authorization for at the issuer.
110
124
  }
111
125
 
112
126
  export interface AuthorizationDetailsJwtVcJsonLdAndLdpVc extends CommonAuthorizationDetails {
127
+ format: 'ldp_vc' | 'jwt_vc_json-ld';
128
+
113
129
  /**
114
130
  * REQUIRED. JSON object containing (and isolating) the detailed description of the credential type.
115
131
  * This object MUST be processed using full JSON-LD processing. It consists of the following sub-claims:
@@ -117,7 +133,14 @@ export interface AuthorizationDetailsJwtVcJsonLdAndLdpVc extends CommonAuthoriza
117
133
  * - types: REQUIRED. JSON array as defined in Appendix E.1.3.2.
118
134
  * This claim contains the type values the Wallet shall request in the subsequent Credential Request
119
135
  */
120
- credential_definition: IssuerCredentialDefinition;
136
+ credential_definition: JsonLdIssuerCredentialDefinition;
137
+ }
138
+
139
+ export interface AuthorizationDetailsSdJwtVc extends CommonAuthorizationDetails {
140
+ format: 'vc+sd-jwt';
141
+
142
+ vct: string;
143
+ claims?: IssuerCredentialSubject;
121
144
  }
122
145
 
123
146
  export enum GrantTypes {
@@ -154,7 +177,8 @@ export interface IssuerOpts {
154
177
  }
155
178
 
156
179
  export interface AccessTokenRequestOpts {
157
- credentialOffer: UniformCredentialOffer;
180
+ credentialOffer?: UniformCredentialOffer;
181
+ credentialIssuer?: string;
158
182
  asOpts?: AuthorizationServerOpts;
159
183
  metadata?: EndpointMetadata;
160
184
  codeVerifier?: string; // only required for authorization flow
@@ -10,7 +10,8 @@ import { CredentialOfferPayloadV1_0_11, CredentialOfferV1_0_11 } from './v1_0_11
10
10
  export interface CredentialResponse {
11
11
  credential?: W3CVerifiableCredential; // OPTIONAL. Contains issued Credential. MUST be present when acceptance_token is not returned. MAY be a JSON string or a JSON object, depending on the Credential format. See Appendix E for the Credential format specific encoding requirements
12
12
  format: OID4VCICredentialFormat /* | OID4VCICredentialFormat[]*/; // REQUIRED. JSON string denoting the format of the issued Credential
13
- acceptance_token?: string; // OPTIONAL. A JSON string containing a security token subsequently used to obtain a Credential. MUST be present when credential is not returned
13
+ transaction_id?: string; //OPTIONAL. A string identifying a Deferred Issuance transaction. This claim is contained in the response if the Credential Issuer was unable to immediately issue the credential. The value is subsequently used to obtain the respective Credential with the Deferred Credential Endpoint (see Section 9). It MUST be present when the credential parameter is not returned. It MUST be invalidated after the credential for which it was meant has been obtained by the Wallet.
14
+ acceptance_token?: string; //deprecated // OPTIONAL. A JSON string containing a security token subsequently used to obtain a Credential. MUST be present when credential is not returned
14
15
  c_nonce?: string; // OPTIONAL. JSON string containing a nonce to be used to create a proof of possession of key material when requesting a Credential (see Section 7.2). When received, the Wallet MUST use this nonce value for its subsequent credential requests until the Credential Issuer provides a fresh nonce
15
16
  c_nonce_expires_in?: number; // OPTIONAL. JSON integer denoting the lifetime in seconds of the c_nonce
16
17
  }
@@ -15,7 +15,7 @@ export interface ImageInfo {
15
15
  [key: string]: unknown;
16
16
  }
17
17
 
18
- export type OID4VCICredentialFormat = 'jwt_vc_json' | 'jwt_vc_json-ld' | 'ldp_vc' /*| 'mso_mdoc'*/; // we do not support mdocs at this point
18
+ export type OID4VCICredentialFormat = 'jwt_vc_json' | 'jwt_vc_json-ld' | 'ldp_vc' | 'vc+sd-jwt' | 'jwt_vc'; // jwt_vc is added for backwards compat /*| 'mso_mdoc'*/; // we do not support mdocs at this point
19
19
 
20
20
  export interface NameAndLocale {
21
21
  name?: string; // REQUIRED. String value of a display name for the Credential.
@@ -62,8 +62,6 @@ export interface CredentialIssuerMetadata extends CredentialIssuerMetadataOpts,
62
62
  }
63
63
 
64
64
  export interface CredentialSupportedBrief {
65
- name?: string; // fixme: Probably should not be here, is part of the display object
66
- types: string[]; // REQUIRED. JSON array designating the types a certain credential type supports
67
65
  cryptographic_binding_methods_supported?: string[]; // OPTIONAL. Array of case sensitive strings that identify how the Credential is bound to the identifier of the End-User who possesses the Credential
68
66
  cryptographic_suites_supported?: string[]; // OPTIONAL. Array of case sensitive strings that identify the cryptographic suites that are supported for the cryptographic_binding_methods_supported
69
67
  }
@@ -75,25 +73,63 @@ export type CommonCredentialSupported = CredentialSupportedBrief & {
75
73
  /**
76
74
  * following properties are non-mso_mdoc specific and we might wanna rethink them when we're going to support mso_mdoc
77
75
  */
78
- credentialSubject?: IssuerCredentialSubject; // OPTIONAL. A JSON object containing a list of key value pairs, where the key identifies the claim offered in the Credential. The value MAY be a dictionary, which allows to represent the full (potentially deeply nested) structure of the verifiable credential to be issued.
79
- order?: string[]; //An array of claims.display.name values that lists them in the order they should be displayed by the Wallet.
80
76
  };
81
77
 
82
78
  export interface CredentialSupportedJwtVcJsonLdAndLdpVc extends CommonCredentialSupported {
79
+ types: string[]; // REQUIRED. JSON array designating the types a certain credential type supports
83
80
  '@context': ICredentialContextType[]; // REQUIRED. JSON array as defined in [VC_DATA], Section 4.1.
81
+ credentialSubject?: IssuerCredentialSubject; // OPTIONAL. A JSON object containing a list of key value pairs, where the key identifies the claim offered in the Credential. The value MAY be a dictionary, which allows to represent the full (potentially deeply nested) structure of the verifiable credential to be issued.
82
+ order?: string[]; //An array of claims.display.name values that lists them in the order they should be displayed by the Wallet.
83
+ format: 'ldp_vc' | 'jwt_vc_json-ld';
84
84
  }
85
85
 
86
86
  export interface CredentialSupportedJwtVcJson extends CommonCredentialSupported {
87
- format: 'jwt_vc_json';
87
+ types: string[]; // REQUIRED. JSON array designating the types a certain credential type supports
88
+ credentialSubject?: IssuerCredentialSubject; // OPTIONAL. A JSON object containing a list of key value pairs, where the key identifies the claim offered in the Credential. The value MAY be a dictionary, which allows to represent the full (potentially deeply nested) structure of the verifiable credential to be issued.
89
+ order?: string[]; //An array of claims.display.name values that lists them in the order they should be displayed by the Wallet.
90
+ format: 'jwt_vc_json' | 'jwt_vc'; // jwt_vc added for backwards compat
91
+ }
92
+
93
+ export interface CredentialSupportedSdJwtVc extends CommonCredentialSupported {
94
+ format: 'vc+sd-jwt';
95
+
96
+ vct: string;
97
+ claims?: IssuerCredentialSubject;
98
+
99
+ order?: string[]; //An array of claims.display.name values that lists them in the order they should be displayed by the Wallet.
88
100
  }
89
101
 
90
- export type CredentialSupported = CommonCredentialSupported & (CredentialSupportedJwtVcJson | CredentialSupportedJwtVcJsonLdAndLdpVc);
102
+ export type CredentialSupported = CommonCredentialSupported &
103
+ (CredentialSupportedJwtVcJson | CredentialSupportedJwtVcJsonLdAndLdpVc | CredentialSupportedSdJwtVc);
91
104
 
92
- export interface CredentialOfferFormat {
105
+ export interface CommonCredentialOfferFormat {
93
106
  format: OID4VCICredentialFormat | string;
94
- types: string[];
95
107
  }
96
108
 
109
+ export interface CredentialOfferFormatJwtVcJsonLdAndLdpVc extends CommonCredentialOfferFormat {
110
+ format: 'ldp_vc' | 'jwt_vc_json-ld';
111
+ // REQUIRED. JSON object containing (and isolating) the detailed description of the credential type. This object MUST be processed using full JSON-LD processing.
112
+ credential_definition: JsonLdIssuerCredentialDefinition;
113
+ }
114
+
115
+ export interface CredentialOfferFormatJwtVcJson extends CommonCredentialOfferFormat {
116
+ format: 'jwt_vc_json' | 'jwt_vc'; // jwt_vc is added for backwards compat
117
+ types: string[]; // REQUIRED. JSON array as defined in Appendix E.1.1.2. This claim contains the type values the Wallet shall request in the subsequent Credential Request.
118
+ }
119
+
120
+ // NOTE: the sd-jwt format is added to oid4vci in a later draft version than currently
121
+ // supported, so there's no defined offer format. However, based on the request structure
122
+ // we support sd-jwt for older drafts of oid4vci as well
123
+ export interface CredentialOfferFormatSdJwtVc extends CommonCredentialOfferFormat {
124
+ format: 'vc+sd-jwt';
125
+
126
+ vct: string;
127
+ claims?: IssuerCredentialSubject;
128
+ }
129
+
130
+ export type CredentialOfferFormat = CommonCredentialOfferFormat &
131
+ (CredentialOfferFormatJwtVcJsonLdAndLdpVc | CredentialOfferFormatJwtVcJson | CredentialOfferFormatSdJwtVc);
132
+
97
133
  /**
98
134
  * Optional storage that can help the credential Data Supplier. For instance to store credential input data during offer creation, if no additional data can be supplied later on
99
135
  */
@@ -108,10 +144,10 @@ export type CreateCredentialOfferURIResult = {
108
144
  userPinRequired: boolean;
109
145
  };
110
146
 
111
- export interface IssuerCredentialDefinition {
147
+ export interface JsonLdIssuerCredentialDefinition {
112
148
  '@context': ICredentialContextType[];
113
149
  types: string[];
114
- credentialSubject: IssuerCredentialSubject;
150
+ credentialSubject?: IssuerCredentialSubject;
115
151
  }
116
152
 
117
153
  export interface ErrorResponse extends Response {
@@ -128,15 +164,21 @@ export interface CommonCredentialRequest {
128
164
  proof?: ProofOfPossession;
129
165
  }
130
166
 
131
- export interface CredentialRequestJwtVc extends CommonCredentialRequest {
132
- format: 'jwt_vc_json' | 'jwt_vc_json-ld';
167
+ export interface CredentialRequestJwtVcJson extends CommonCredentialRequest {
168
+ format: 'jwt_vc_json' | 'jwt_vc'; // jwt_vc for backwards compat
133
169
  types: string[];
134
170
  credentialSubject?: IssuerCredentialSubject;
135
171
  }
136
172
 
137
- export interface CredentialRequestLdpVc extends CommonCredentialRequest {
138
- format: 'ldp_vc';
139
- credential_definition: IssuerCredentialDefinition;
173
+ export interface CredentialRequestJwtVcJsonLdAndLdpVc extends CommonCredentialRequest {
174
+ format: 'ldp_vc' | 'jwt_vc_json-ld';
175
+ credential_definition: JsonLdIssuerCredentialDefinition;
176
+ }
177
+
178
+ export interface CredentialRequestSdJwtVc extends CommonCredentialRequest {
179
+ format: 'vc+sd-jwt';
180
+ vct: string;
181
+ claims?: IssuerCredentialSubject;
140
182
  }
141
183
 
142
184
  export interface CommonCredentialResponse {
@@ -157,6 +199,11 @@ export interface CredentialResponseJwtVc {
157
199
  credential: string;
158
200
  }
159
201
 
202
+ export interface CredentialResponseSdJwtVc {
203
+ format: 'vc+sd-jwt';
204
+ credential: string;
205
+ }
206
+
160
207
  // export type CredentialSubjectDisplay = NameAndLocale[];
161
208
 
162
209
  export type IssuerCredentialSubjectDisplay = CredentialSubjectDisplay & { [key: string]: CredentialSubjectDisplay };
@@ -60,7 +60,7 @@ export interface ComponentOptions {
60
60
  */
61
61
  protectors?: boolean;
62
62
  };
63
- };
63
+ }
64
64
 
65
65
  export interface QRCodeOpts {
66
66
  /**
@@ -224,4 +224,4 @@ export interface QRCodeOpts {
224
224
  * @deafultValue 0.4
225
225
  */
226
226
  dotScale?: number;
227
- };
227
+ }
@@ -49,6 +49,7 @@ export interface AuthorizationServerMetadata {
49
49
 
50
50
  // VCI values. In case an AS provides a credential_endpoint itself
51
51
  credential_endpoint?: string;
52
+ deferred_credential_endpoint?: string;
52
53
 
53
54
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
55
  [x: string]: any; //We use any, so you can access properties if you know the structure
@@ -66,6 +67,7 @@ export interface EndpointMetadata {
66
67
  issuer: string;
67
68
  token_endpoint: string;
68
69
  credential_endpoint: string;
70
+ deferred_credential_endpoint?: string;
69
71
  authorization_server?: string;
70
72
  authorization_endpoint?: string; // Can be undefined in pre-auth flow
71
73
  }
@@ -6,7 +6,7 @@ import { CredentialsSupportedDisplay, CredentialSupportedBrief, IssuerCredential
6
6
  export interface CredentialRequestV1_0_08 {
7
7
  type: string;
8
8
  format: CredentialFormat;
9
- proof: ProofOfPossession;
9
+ proof?: ProofOfPossession;
10
10
  }
11
11
 
12
12
  export interface IssuerMetadataV1_0_08 {
@@ -34,11 +34,16 @@ export interface CredentialSupportedTypeV1_0_08 {
34
34
  [credentialType: string]: CredentialSupportedV1_0_08;
35
35
  }
36
36
 
37
+ export interface CredentialSupportedFormatV1_0_08 extends CredentialSupportedBrief {
38
+ name?: string;
39
+ types: string[];
40
+ }
41
+
37
42
  export interface CredentialSupportedV1_0_08 {
38
43
  display?: CredentialsSupportedDisplay[];
39
44
  formats: {
40
45
  // REQUIRED. A JSON object containing a list of key value pairs, where the key is a string identifying the format of the Credential. Below is a non-exhaustive list of valid key values defined by this specification:
41
- [credentialFormat: string]: CredentialSupportedBrief;
46
+ [credentialFormat: string]: CredentialSupportedFormatV1_0_08;
42
47
  };
43
48
  claims?: IssuerCredentialSubject; // REQUIRED. A JSON object containing a list of key value pairs, where the key identifies the claim offered in the Credential. The value is a JSON object detailing the specifics about the support for the claim with a following non-exhaustive list of parameters that MAY be included:
44
49
  }