@sphereon/oid4vci-common 0.7.1-next.9 → 0.7.1

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.
@@ -1,9 +1,15 @@
1
- import { CredentialIssuerMetadata, CredentialOfferFormat, CredentialSupported, CredentialSupportedTypeV1_0_08, CredentialSupportedV1_0_08, IssuerMetadataV1_0_08, MetadataDisplay, OpenId4VCIVersion } from '../types';
1
+ import { CredentialIssuerMetadata, CredentialSupported, CredentialSupportedTypeV1_0_08, CredentialSupportedV1_0_08, IssuerMetadataV1_0_08, MetadataDisplay, OID4VCICredentialFormat, OpenId4VCIVersion } from '../types';
2
2
  export declare function getSupportedCredentials(opts?: {
3
3
  issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
4
4
  version: OpenId4VCIVersion;
5
- credentialTypes?: (CredentialOfferFormat | string)[];
6
- supportedType?: CredentialOfferFormat | string;
5
+ types?: string[][];
6
+ format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[];
7
+ }): CredentialSupported[];
8
+ export declare function getSupportedCredential(opts?: {
9
+ issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
10
+ version: OpenId4VCIVersion;
11
+ types?: string | string[];
12
+ format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[];
7
13
  }): CredentialSupported[];
8
14
  export declare function credentialsSupportedV8ToV11(supportedV8: CredentialSupportedTypeV1_0_08): CredentialSupported[];
9
15
  export declare function credentialSupportedV8ToV11(key: string, supportedV8: CredentialSupportedV1_0_08): CredentialSupported[];
@@ -1 +1 @@
1
- {"version":3,"file":"IssuerMetadataUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,8BAA8B,EAC9B,0BAA0B,EAC1B,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACl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sB,CAAC,IAAI,CAAC,EAAE;IAC5C,cAAc,CAAC,EAAE,wBAAwB,GAAG,qBAAqB,CAAC;IAClE,OAAO,EAAE,iBAAiB,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,CAAC,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,GAAG,MAAM,CAAC,EAAE,CAAC;CACpF,GAAG,mBAAmB,EAAE,CA2ExB;AAaD,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,8BAA8B,GAAG,mBAAmB,EAAE,CAM9G;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,0BAA0B,GAAG,mBAAmB,EAAE,CAgBtH;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,qBAAqB,EAAE,IAAI,CAAC,EAAE;IAAE,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,eAAe,EAAE,CAMjJ"}
@@ -1,26 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIssuerDisplays = exports.credentialSupportedV8ToV11 = exports.credentialsSupportedV8ToV11 = exports.getSupportedCredentials = void 0;
3
+ exports.getIssuerDisplays = exports.credentialSupportedV8ToV11 = exports.credentialsSupportedV8ToV11 = exports.getSupportedCredential = exports.getSupportedCredentials = void 0;
4
4
  const types_1 = require("../types");
5
5
  function getSupportedCredentials(opts) {
6
+ if ((opts === null || opts === void 0 ? void 0 : opts.types) && Array.isArray(opts === null || opts === void 0 ? void 0 : opts.types)) {
7
+ return opts.types.flatMap((types) => getSupportedCredential(Object.assign(Object.assign({}, opts), { types })));
8
+ }
9
+ return getSupportedCredential(opts ? Object.assign(Object.assign({}, opts), { types: undefined }) : undefined);
10
+ }
11
+ exports.getSupportedCredentials = getSupportedCredentials;
12
+ function getSupportedCredential(opts) {
6
13
  const { issuerMetadata } = opts !== null && opts !== void 0 ? opts : {};
14
+ let formats;
15
+ if ((opts === null || opts === void 0 ? void 0 : opts.format) && Array.isArray(opts.format)) {
16
+ formats = opts.format;
17
+ }
18
+ else if ((opts === null || opts === void 0 ? void 0 : opts.format) && !Array.isArray(opts.format)) {
19
+ formats = [opts.format];
20
+ }
21
+ else {
22
+ formats = [];
23
+ }
7
24
  let credentialsSupported;
8
25
  if (!issuerMetadata) {
9
26
  return [];
10
27
  }
11
- const { version, credentialTypes, supportedType } = opts !== null && opts !== void 0 ? opts : { version: types_1.OpenId4VCIVersion.VER_1_0_11 };
28
+ const { version, types } = opts !== null && opts !== void 0 ? opts : { version: types_1.OpenId4VCIVersion.VER_1_0_11 };
12
29
  if (version === types_1.OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) {
13
30
  credentialsSupported = credentialsSupportedV8ToV11(issuerMetadata.credentials_supported);
14
- /* const credentialsSupportedV8: CredentialSupportedV1_0_08 = credentialsSupported as CredentialSupportedV1_0_08
15
- // const initiationTypes = credentialTypes.map(type => typeof type === 'string' ? [type] : type.types)
16
- const supported: IssuerCredentialSubject = {}
17
- for (const [key, value] of Object.entries(credentialsSupportedV8)) {
18
- if (initiationTypes.find((type) => (typeof type === 'string' ? type === key : type.types.includes(key)))) {
19
- supported[key] = value
20
- }
21
- }
22
- // todo: fix this later. we're returning CredentialSupportedV1_0_08 as a list of CredentialSupported (for v09 onward)
23
- return supported as unknown as CredentialSupported[]*/
24
31
  }
25
32
  else {
26
33
  credentialsSupported = issuerMetadata.credentials_supported;
@@ -28,31 +35,59 @@ function getSupportedCredentials(opts) {
28
35
  if (credentialsSupported === undefined || credentialsSupported.length === 0) {
29
36
  return [];
30
37
  }
31
- else if (!credentialTypes || credentialTypes.length === 0) {
38
+ else if (!types || types.length === 0) {
32
39
  return credentialsSupported;
33
40
  }
34
41
  /**
35
42
  * the following (not array part is a legacy code from version 1_0-08 which JFF plugfest 2 implementors used)
36
43
  */
37
- const initiationTypes = supportedType ? [supportedType] : credentialTypes;
38
- const credentialSupportedOverlap = [];
39
- for (const offerType of initiationTypes) {
40
- if (typeof offerType === 'string') {
41
- const supported = credentialsSupported.filter((sup) => sup.id === offerType || sup.types.includes(offerType));
42
- if (supported) {
43
- credentialSupportedOverlap.push(...supported);
44
- }
44
+ let initiationTypes;
45
+ if (opts === null || opts === void 0 ? void 0 : opts.types) {
46
+ if (typeof opts.types === 'string') {
47
+ initiationTypes = [opts.types];
45
48
  }
46
49
  else {
47
- const supported = credentialsSupported.filter((sup) => arrayEqualsIgnoreOrder(sup.types, offerType.types) && sup.format === offerType.format);
48
- if (supported) {
49
- credentialSupportedOverlap.push(...supported);
50
+ initiationTypes = opts.types;
51
+ }
52
+ }
53
+ if (version === types_1.OpenId4VCIVersion.VER_1_0_08 && (!initiationTypes || (initiationTypes === null || initiationTypes === void 0 ? void 0 : initiationTypes.length) === 0)) {
54
+ initiationTypes = formats;
55
+ }
56
+ const supportedFormats = formats && formats.length > 0 ? formats : ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc'];
57
+ const credentialSupportedOverlap = [];
58
+ if ((opts === null || opts === void 0 ? void 0 : opts.types) && typeof (opts === null || opts === void 0 ? void 0 : opts.types) === 'string') {
59
+ const supported = credentialsSupported.filter((sup) => sup.id === opts.types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes)));
60
+ if (supported) {
61
+ credentialSupportedOverlap.push(...supported);
62
+ }
63
+ } /*else if (initiationTypes && Array.isArray(initiationTypes) && initiationTypes.length === 1) {
64
+
65
+ const supported = credentialsSupported.filter(
66
+ (sup) => sup.id === initiationTypes![0] || (arrayEqualsIgnoreOrder(sup.types, initiationTypes!) && sup.types.includes(initiationTypes![0])),
67
+ );
68
+ if (supported) {
69
+ credentialSupportedOverlap.push(...supported);
70
+ }
71
+ }*/
72
+ else {
73
+ // Make sure we include Verifiable Credential both on the offer side as well as in the metadata side, to ensure consistency of the issuer does not.
74
+ if (initiationTypes && !initiationTypes.includes('VerifiableCredential')) {
75
+ initiationTypes.push('VerifiableCredential');
76
+ }
77
+ const supported = credentialsSupported.filter((sup) => {
78
+ const supTypes = sup.types;
79
+ if (!supTypes.includes('VerifiableCredential')) {
80
+ supTypes.push('VerifiableCredential');
50
81
  }
82
+ return (!initiationTypes || arrayEqualsIgnoreOrder(supTypes, initiationTypes)) && supportedFormats.includes(sup.format);
83
+ });
84
+ if (supported) {
85
+ credentialSupportedOverlap.push(...supported);
51
86
  }
52
87
  }
53
88
  return credentialSupportedOverlap;
54
89
  }
55
- exports.getSupportedCredentials = getSupportedCredentials;
90
+ exports.getSupportedCredential = getSupportedCredential;
56
91
  function arrayEqualsIgnoreOrder(a, b) {
57
92
  if (a.length !== b.length)
58
93
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"IssuerMetadataUtils.js","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":";;;AAAA,oCASkB;AAElB,SAAgB,uBAAuB,CAAC,IAKvC;IACC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;IACtC,IAAI,oBAA2C,CAAC;IAChD,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAC;KACX;IACD,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,OAAO,EAAE,yBAAiB,CAAC,UAAU,EAAE,CAAC;IACtG,IAAI,OAAO,KAAK,yBAAiB,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,qBAAqB,CAAC,EAAE;QACpG,oBAAoB,GAAG,2BAA2B,CAAE,cAAwC,CAAC,qBAAqB,CAAC,CAAC;QACpH;;;;;;;;;kEAS0D;KAC3D;SAAM;QACL,oBAAoB,GAAI,cAA2C,CAAC,qBAAqB,CAAC;KAC3F;IAED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BAAiB,CAAC,QAA0D,EAAE,IAAgC;;IAC5H,MAAM,eAAe,GACnB,MAAA,MAAA,QAAQ,CAAC,OAAO,0CAAE,MAAM,CACtB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAA,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CACzI,mCAAI,EAAE,CAAC;IACV,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,mCAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA,EAAA,CAAC,CAAC;AACxH,CAAC;AAND,8CAMC"}
@@ -6,59 +6,99 @@ import {
6
6
  CredentialSupportedV1_0_08,
7
7
  IssuerMetadataV1_0_08,
8
8
  MetadataDisplay,
9
+ OID4VCICredentialFormat,
9
10
  OpenId4VCIVersion,
10
11
  } from '../types';
11
12
 
12
13
  export function getSupportedCredentials(opts?: {
13
14
  issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
14
15
  version: OpenId4VCIVersion;
15
- credentialTypes?: (CredentialOfferFormat | string)[];
16
- supportedType?: CredentialOfferFormat | string;
16
+ types?: string[][];
17
+ format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[];
18
+ }): CredentialSupported[] {
19
+ if (opts?.types && Array.isArray(opts?.types)) {
20
+ return opts.types.flatMap((types) => getSupportedCredential({ ...opts, types }));
21
+ }
22
+ return getSupportedCredential(opts ? { ...opts, types: undefined } : undefined);
23
+ }
24
+
25
+ export function getSupportedCredential(opts?: {
26
+ issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
27
+ version: OpenId4VCIVersion;
28
+ types?: string | string[];
29
+ format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[];
17
30
  }): CredentialSupported[] {
18
31
  const { issuerMetadata } = opts ?? {};
32
+ let formats: (OID4VCICredentialFormat | string)[];
33
+ if (opts?.format && Array.isArray(opts.format)) {
34
+ formats = opts.format;
35
+ } else if (opts?.format && !Array.isArray(opts.format)) {
36
+ formats = [opts.format];
37
+ } else {
38
+ formats = [];
39
+ }
19
40
  let credentialsSupported: CredentialSupported[];
20
41
  if (!issuerMetadata) {
21
42
  return [];
22
43
  }
23
- const { version, credentialTypes, supportedType } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 };
44
+ const { version, types } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 };
24
45
  if (version === OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) {
25
46
  credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported);
26
- /* const credentialsSupportedV8: CredentialSupportedV1_0_08 = credentialsSupported as CredentialSupportedV1_0_08
27
- // const initiationTypes = credentialTypes.map(type => typeof type === 'string' ? [type] : type.types)
28
- const supported: IssuerCredentialSubject = {}
29
- for (const [key, value] of Object.entries(credentialsSupportedV8)) {
30
- if (initiationTypes.find((type) => (typeof type === 'string' ? type === key : type.types.includes(key)))) {
31
- supported[key] = value
32
- }
33
- }
34
- // todo: fix this later. we're returning CredentialSupportedV1_0_08 as a list of CredentialSupported (for v09 onward)
35
- return supported as unknown as CredentialSupported[]*/
36
47
  } else {
37
48
  credentialsSupported = (issuerMetadata as CredentialIssuerMetadata).credentials_supported;
38
49
  }
39
50
 
40
51
  if (credentialsSupported === undefined || credentialsSupported.length === 0) {
41
52
  return [];
42
- } else if (!credentialTypes || credentialTypes.length === 0) {
53
+ } else if (!types || types.length === 0) {
43
54
  return credentialsSupported;
44
55
  }
45
56
  /**
46
57
  * the following (not array part is a legacy code from version 1_0-08 which JFF plugfest 2 implementors used)
47
58
  */
48
- const initiationTypes = supportedType ? [supportedType] : credentialTypes;
59
+ let initiationTypes: string[] | undefined;
60
+ if (opts?.types) {
61
+ if (typeof opts.types === 'string') {
62
+ initiationTypes = [opts.types];
63
+ } else {
64
+ initiationTypes = opts.types;
65
+ }
66
+ }
67
+ if (version === OpenId4VCIVersion.VER_1_0_08 && (!initiationTypes || initiationTypes?.length === 0)) {
68
+ initiationTypes = formats;
69
+ }
70
+ const supportedFormats: (CredentialOfferFormat | string)[] = formats && formats.length > 0 ? formats : ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc'];
49
71
 
50
72
  const credentialSupportedOverlap: CredentialSupported[] = [];
51
- for (const offerType of initiationTypes) {
52
- if (typeof offerType === 'string') {
53
- const supported = credentialsSupported.filter((sup) => sup.id === offerType || sup.types.includes(offerType));
54
- if (supported) {
55
- credentialSupportedOverlap.push(...supported);
56
- }
57
- } else {
58
- const supported = credentialsSupported.filter((sup) => arrayEqualsIgnoreOrder(sup.types, offerType.types) && sup.format === offerType.format);
59
- if (supported) {
60
- credentialSupportedOverlap.push(...supported);
73
+ if (opts?.types && typeof opts?.types === 'string') {
74
+ const supported = credentialsSupported.filter(
75
+ (sup) => sup.id === opts.types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes)),
76
+ );
77
+ if (supported) {
78
+ credentialSupportedOverlap.push(...supported);
79
+ }
80
+ } /*else if (initiationTypes && Array.isArray(initiationTypes) && initiationTypes.length === 1) {
81
+
82
+ const supported = credentialsSupported.filter(
83
+ (sup) => sup.id === initiationTypes![0] || (arrayEqualsIgnoreOrder(sup.types, initiationTypes!) && sup.types.includes(initiationTypes![0])),
84
+ );
85
+ if (supported) {
86
+ credentialSupportedOverlap.push(...supported);
87
+ }
88
+ }*/ else {
89
+ // Make sure we include Verifiable Credential both on the offer side as well as in the metadata side, to ensure consistency of the issuer does not.
90
+ if (initiationTypes && !initiationTypes.includes('VerifiableCredential')) {
91
+ initiationTypes.push('VerifiableCredential');
92
+ }
93
+ const supported = credentialsSupported.filter((sup) => {
94
+ const supTypes = sup.types;
95
+ if (!supTypes.includes('VerifiableCredential')) {
96
+ supTypes.push('VerifiableCredential');
61
97
  }
98
+ return (!initiationTypes || arrayEqualsIgnoreOrder(supTypes, initiationTypes)) && supportedFormats.includes(sup.format);
99
+ });
100
+ if (supported) {
101
+ credentialSupportedOverlap.push(...supported);
62
102
  }
63
103
  }
64
104
  return credentialSupportedOverlap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-common",
3
- "version": "0.7.1-next.9+a9bc4e2",
3
+ "version": "0.7.1",
4
4
  "description": "OpenID 4 Verifiable Credential Issuance Common Types",
5
5
  "source": "lib/index.ts",
6
6
  "main": "dist/index.js",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "a9bc4e23233f024ac5140a6ec0dd569d0c66ab09"
48
+ "gitHead": "6b555dfb10fbf0b171f0b9735e0fa95e59e603f5"
49
49
  }