@sphereon/oid4vci-common 0.12.1-next.2 → 0.12.1-next.4
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.
- package/dist/functions/IssuerMetadataUtils.d.ts +0 -9
- package/dist/functions/IssuerMetadataUtils.d.ts.map +1 -1
- package/dist/functions/IssuerMetadataUtils.js +2 -58
- package/dist/functions/IssuerMetadataUtils.js.map +1 -1
- package/dist/functions/TypeConversionUtils.d.ts +16 -0
- package/dist/functions/TypeConversionUtils.d.ts.map +1 -1
- package/dist/functions/TypeConversionUtils.js +89 -1
- package/dist/functions/TypeConversionUtils.js.map +1 -1
- package/lib/functions/IssuerMetadataUtils.ts +1 -71
- package/lib/functions/TypeConversionUtils.ts +89 -0
- package/package.json +2 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CredentialDefinitionV1_0_13, CredentialOfferFormat, CredentialOfferPayload, JsonLdIssuerCredentialDefinition, UniformCredentialOfferRequest } from '../index';
|
|
2
1
|
import { AuthorizationServerMetadata, CredentialConfigurationSupported, CredentialConfigurationSupportedV1_0_13, CredentialIssuerMetadata, CredentialSupportedTypeV1_0_08, CredentialSupportedV1_0_08, IssuerMetadata, MetadataDisplay, OID4VCICredentialFormat, OpenId4VCIVersion } from '../types';
|
|
3
2
|
export declare function getSupportedCredentials(opts?: {
|
|
4
3
|
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadata;
|
|
@@ -13,9 +12,6 @@ export declare function getSupportedCredential(opts?: {
|
|
|
13
12
|
types?: string | string[];
|
|
14
13
|
format?: OID4VCICredentialFormat | string | (OID4VCICredentialFormat | string)[];
|
|
15
14
|
}): Record<string, CredentialConfigurationSupportedV1_0_13> | Array<CredentialConfigurationSupported>;
|
|
16
|
-
export declare function getTypesFromCredentialSupported(credentialSupported: CredentialConfigurationSupported, opts?: {
|
|
17
|
-
filterVerifiableCredential: boolean;
|
|
18
|
-
}): string[];
|
|
19
15
|
export declare function credentialsSupportedV8ToV13(supportedV8: CredentialSupportedTypeV1_0_08): Record<string, CredentialConfigurationSupported>;
|
|
20
16
|
export declare function credentialSupportedV8ToV13(key: string, supportedV8: CredentialSupportedV1_0_08): Record<string, CredentialConfigurationSupported>;
|
|
21
17
|
export declare function getIssuerDisplays(metadata: CredentialIssuerMetadata | IssuerMetadata, opts?: {
|
|
@@ -25,9 +21,4 @@ export declare function getIssuerDisplays(metadata: CredentialIssuerMetadata | I
|
|
|
25
21
|
* TODO check again when WAL-617 is done to replace how we get the issuer name.
|
|
26
22
|
*/
|
|
27
23
|
export declare function getIssuerName(url: string, credentialIssuerMetadata?: Partial<AuthorizationServerMetadata> & (CredentialIssuerMetadata | IssuerMetadata)): string;
|
|
28
|
-
/**
|
|
29
|
-
* The specs had many places where types could be expressed. This method ensures we get them in any way possible
|
|
30
|
-
* @param subject
|
|
31
|
-
*/
|
|
32
|
-
export declare function getTypesFromObject(subject: CredentialConfigurationSupported | CredentialOfferFormat | CredentialOfferPayload | CredentialDefinitionV1_0_13 | JsonLdIssuerCredentialDefinition | UniformCredentialOfferRequest | string): string[] | undefined;
|
|
33
24
|
//# sourceMappingURL=IssuerMetadataUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IssuerMetadataUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IssuerMetadataUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,uCAAuC,EACvC,wBAAwB,EACxB,8BAA8B,EAC9B,0BAA0B,EAC1B,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE;IAC7C,cAAc,CAAC,EAAE,wBAAwB,GAAG,cAAc,CAA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C,GAAG,CAAC,wBAAwB,GAAG,cAAc,CAAC,GAC5G,MAAM,CAUR"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getIssuerName = exports.getIssuerDisplays = exports.credentialSupportedV8ToV13 = exports.credentialsSupportedV8ToV13 = exports.getSupportedCredential = exports.determineVersionsFromIssuerMetadata = exports.getSupportedCredentials = void 0;
|
|
4
4
|
const index_1 = require("../index");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
function getSupportedCredentials(opts) {
|
|
@@ -85,7 +85,7 @@ function getSupportedCredential(opts) {
|
|
|
85
85
|
const normalizedFormats = Array.isArray(format) ? format : format ? [format] : [];
|
|
86
86
|
function filterMatchingConfig(config) {
|
|
87
87
|
let isTypeMatch = normalizedTypes.length === 0;
|
|
88
|
-
const types = getTypesFromObject(config);
|
|
88
|
+
const types = (0, index_1.getTypesFromObject)(config);
|
|
89
89
|
if (!isTypeMatch) {
|
|
90
90
|
if (normalizedTypes.length === 1 && config.id === normalizedTypes[0]) {
|
|
91
91
|
isTypeMatch = true;
|
|
@@ -128,29 +128,6 @@ function getSupportedCredential(opts) {
|
|
|
128
128
|
throw Error(`Either < v11 configurations or V13 configurations should have been filtered at this point`);
|
|
129
129
|
}
|
|
130
130
|
exports.getSupportedCredential = getSupportedCredential;
|
|
131
|
-
function getTypesFromCredentialSupported(credentialSupported, opts) {
|
|
132
|
-
var _a;
|
|
133
|
-
let types = [];
|
|
134
|
-
if (credentialSupported.format === 'jwt_vc_json' ||
|
|
135
|
-
credentialSupported.format === 'jwt_vc' ||
|
|
136
|
-
credentialSupported.format === 'jwt_vc_json-ld' ||
|
|
137
|
-
credentialSupported.format === 'ldp_vc') {
|
|
138
|
-
types = (_a = getTypesFromObject(credentialSupported)) !== null && _a !== void 0 ? _a : [];
|
|
139
|
-
}
|
|
140
|
-
else if (credentialSupported.format === 'vc+sd-jwt') {
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
142
|
-
// @ts-ignore
|
|
143
|
-
types = [credentialSupported.vct];
|
|
144
|
-
}
|
|
145
|
-
if (!types || types.length === 0) {
|
|
146
|
-
throw Error('Could not deduce types from credential supported');
|
|
147
|
-
}
|
|
148
|
-
if (opts === null || opts === void 0 ? void 0 : opts.filterVerifiableCredential) {
|
|
149
|
-
return types.filter((type) => type !== 'VerifiableCredential');
|
|
150
|
-
}
|
|
151
|
-
return types;
|
|
152
|
-
}
|
|
153
|
-
exports.getTypesFromCredentialSupported = getTypesFromCredentialSupported;
|
|
154
131
|
function credentialsSupportedV8ToV13(supportedV8) {
|
|
155
132
|
const credentialConfigsSupported = {};
|
|
156
133
|
Object.entries(supportedV8).flatMap((entry) => {
|
|
@@ -196,37 +173,4 @@ function getIssuerName(url, credentialIssuerMetadata) {
|
|
|
196
173
|
return url;
|
|
197
174
|
}
|
|
198
175
|
exports.getIssuerName = getIssuerName;
|
|
199
|
-
/**
|
|
200
|
-
* The specs had many places where types could be expressed. This method ensures we get them in any way possible
|
|
201
|
-
* @param subject
|
|
202
|
-
*/
|
|
203
|
-
function getTypesFromObject(subject) {
|
|
204
|
-
if (subject === undefined) {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
else if (typeof subject === 'string') {
|
|
208
|
-
return [subject];
|
|
209
|
-
}
|
|
210
|
-
else if ('credential_definition' in subject && subject.credential_definition) {
|
|
211
|
-
return getTypesFromObject(subject.credential_definition);
|
|
212
|
-
}
|
|
213
|
-
else if ('types' in subject && subject.types) {
|
|
214
|
-
return Array.isArray(subject.types) ? subject.types : [subject.types];
|
|
215
|
-
}
|
|
216
|
-
else if ('type' in subject && subject.type) {
|
|
217
|
-
return Array.isArray(subject.type) ? subject.type : [subject.type];
|
|
218
|
-
}
|
|
219
|
-
else if ('vct' in subject && subject.vct) {
|
|
220
|
-
return [subject.vct];
|
|
221
|
-
}
|
|
222
|
-
else if ('credentials' in subject && subject.credentials) {
|
|
223
|
-
return getTypesFromObject(subject.credentials);
|
|
224
|
-
}
|
|
225
|
-
else if ('credential_offer' in subject && subject.credential_offer) {
|
|
226
|
-
return getTypesFromObject(subject.credential_offer);
|
|
227
|
-
}
|
|
228
|
-
index_1.VCI_LOG_COMMON.warning('Could not deduce credential types. Probably a failure down the line will happen!');
|
|
229
|
-
return undefined;
|
|
230
|
-
}
|
|
231
|
-
exports.getTypesFromObject = getTypesFromObject;
|
|
232
176
|
//# sourceMappingURL=IssuerMetadataUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IssuerMetadataUtils.js","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"IssuerMetadataUtils.js","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":";;;AAAA,oCAA8D;AAC9D,oCAWkB;AAElB,SAAgB,uBAAuB,CAAC,IAKvC;IACC,MAAM,EAAE,OAAO,GAAG,yBAAiB,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;IACrE,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,IAAI,OAAO,GAAG,yBAAiB,CAAC,UAAU,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,sBAAsB,iCAAM,IAAI,KAAE,OAAO,EAAE,KAAK,EAAE,OAAO,IAA8C,CAAC,CAAC;QAC7I,CAAC;aAAM,CAAC;YACN,OAAO,KAAK;iBACT,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;gBACf,OAAO,sBAAsB,iCAAM,IAAI,KAAE,OAAO,EAAE,KAAK,EAAE,OAAO,IAAG,CAAC;YACtE,CAAC,CAA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G;AACH,SAAgB,aAAa,CAC3B,GAAW,EACX,wBAA6G;IAE7G,IAAI,wBAAwB,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAA2B,wBAAwB,CAAC,CAAC,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACrH,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;gBACjB,OAAO,OAAO,CAAC,IAAI,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAbD,sCAaC"}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
import { AuthorizationDetails, CredentialOfferPayload, UniformCredentialOfferPayload, UniformCredentialOfferRequest } from '../index';
|
|
2
|
+
import { CredentialConfigurationSupported, CredentialDefinitionV1_0_13, CredentialOfferFormat, JsonLdIssuerCredentialDefinition } from '../types';
|
|
1
3
|
export declare const getNumberOrUndefined: (input?: string) => number | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* The specs had many places where types could be expressed. This method ensures we get them in any way possible
|
|
6
|
+
* @param subject
|
|
7
|
+
*/
|
|
8
|
+
export declare function getTypesFromObject(subject: CredentialConfigurationSupported | CredentialOfferFormat | CredentialDefinitionV1_0_13 | JsonLdIssuerCredentialDefinition | string): string[] | undefined;
|
|
9
|
+
export declare function getTypesFromCredentialOffer(offer: UniformCredentialOfferRequest | CredentialOfferPayload | UniformCredentialOfferPayload, opts?: {
|
|
10
|
+
configIdAsType?: boolean;
|
|
11
|
+
}): Array<Array<string>> | undefined;
|
|
12
|
+
export declare function getTypesFromAuthorizationDetails(authDetails: AuthorizationDetails, opts?: {
|
|
13
|
+
configIdAsType?: boolean;
|
|
14
|
+
}): string[] | undefined;
|
|
15
|
+
export declare function getTypesFromCredentialSupported(credentialSupported: CredentialConfigurationSupported, opts?: {
|
|
16
|
+
filterVerifiableCredential: boolean;
|
|
17
|
+
}): string[];
|
|
2
18
|
//# sourceMappingURL=TypeConversionUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeConversionUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/TypeConversionUtils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAAM,GAAG,SAE9D,CAAC"}
|
|
1
|
+
{"version":3,"file":"TypeConversionUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/TypeConversionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,6BAA6B,EAAkB,MAAM,UAAU,CAAC;AACtJ,OAAO,EAAE,gCAAgC,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAElJ,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAAM,GAAG,SAE9D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,gCAAgC,GAAG,qBAAqB,GAAG,2BAA2B,GAAG,gCAAgC,GAAG,MAAM,GAC1I,MAAM,EAAE,GAAG,SAAS,CAgBtB;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,6BAA6B,GAAG,sBAAsB,GAAG,6BAA6B,EAC7F,IAAI,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,GAClC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAiBlC;AAED,wBAAgB,gCAAgC,CAAC,WAAW,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,EAAE,GAAG,SAAS,CAW7I;AAED,wBAAgB,+BAA+B,CAC7C,mBAAmB,EAAE,gCAAgC,EACrD,IAAI,CAAC,EAAE;IAAE,0BAA0B,EAAE,OAAO,CAAA;CAAE,YAuB/C"}
|
|
@@ -1,8 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNumberOrUndefined = void 0;
|
|
3
|
+
exports.getTypesFromCredentialSupported = exports.getTypesFromAuthorizationDetails = exports.getTypesFromCredentialOffer = exports.getTypesFromObject = exports.getNumberOrUndefined = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
4
5
|
const getNumberOrUndefined = (input) => {
|
|
5
6
|
return input && !isNaN(+input) ? +input : undefined;
|
|
6
7
|
};
|
|
7
8
|
exports.getNumberOrUndefined = getNumberOrUndefined;
|
|
9
|
+
/**
|
|
10
|
+
* The specs had many places where types could be expressed. This method ensures we get them in any way possible
|
|
11
|
+
* @param subject
|
|
12
|
+
*/
|
|
13
|
+
function getTypesFromObject(subject) {
|
|
14
|
+
if (subject === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
else if (typeof subject === 'string') {
|
|
18
|
+
return [subject];
|
|
19
|
+
}
|
|
20
|
+
else if ('credential_definition' in subject && subject.credential_definition) {
|
|
21
|
+
return getTypesFromObject(subject.credential_definition);
|
|
22
|
+
}
|
|
23
|
+
else if ('types' in subject && subject.types) {
|
|
24
|
+
return Array.isArray(subject.types) ? subject.types : [subject.types];
|
|
25
|
+
}
|
|
26
|
+
else if ('type' in subject && subject.type) {
|
|
27
|
+
return Array.isArray(subject.type) ? subject.type : [subject.type];
|
|
28
|
+
}
|
|
29
|
+
else if ('vct' in subject && subject.vct) {
|
|
30
|
+
return [subject.vct];
|
|
31
|
+
}
|
|
32
|
+
index_1.VCI_LOG_COMMON.warning('Could not deduce credential types. Probably a failure down the line will happen!');
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
exports.getTypesFromObject = getTypesFromObject;
|
|
36
|
+
function getTypesFromCredentialOffer(offer, opts) {
|
|
37
|
+
const { configIdAsType = false } = Object.assign({}, opts);
|
|
38
|
+
if ('credentials' in offer && Array.isArray(offer.credentials)) {
|
|
39
|
+
return offer.credentials.map((cred) => getTypesFromObject(cred)).filter((cred) => cred !== undefined);
|
|
40
|
+
}
|
|
41
|
+
else if (configIdAsType && 'credential_configuration_ids' in offer && Array.isArray(offer.credential_configuration_ids)) {
|
|
42
|
+
return offer.credential_configuration_ids.map((id) => [id]);
|
|
43
|
+
}
|
|
44
|
+
else if ('credential_offer' in offer && offer.credential_offer) {
|
|
45
|
+
return getTypesFromCredentialOffer(offer.credential_offer, opts);
|
|
46
|
+
}
|
|
47
|
+
else if ('credential_type' in offer && offer.credential_type) {
|
|
48
|
+
if (typeof offer.credential_type === 'string') {
|
|
49
|
+
return [[offer.credential_type]];
|
|
50
|
+
}
|
|
51
|
+
else if (Array.isArray(offer.credential_type)) {
|
|
52
|
+
return [offer.credential_type];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
index_1.VCI_LOG_COMMON.warning('Could not deduce credential types from offer. Probably a failure down the line will happen!');
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
exports.getTypesFromCredentialOffer = getTypesFromCredentialOffer;
|
|
59
|
+
function getTypesFromAuthorizationDetails(authDetails, opts) {
|
|
60
|
+
const { configIdAsType = false } = Object.assign({}, opts);
|
|
61
|
+
if (typeof authDetails === 'string') {
|
|
62
|
+
return [authDetails];
|
|
63
|
+
}
|
|
64
|
+
else if ('types' in authDetails && Array.isArray(authDetails.types)) {
|
|
65
|
+
return authDetails.types;
|
|
66
|
+
}
|
|
67
|
+
else if (configIdAsType && authDetails.credential_configuration_id) {
|
|
68
|
+
return [authDetails.credential_configuration_id];
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
exports.getTypesFromAuthorizationDetails = getTypesFromAuthorizationDetails;
|
|
73
|
+
function getTypesFromCredentialSupported(credentialSupported, opts) {
|
|
74
|
+
var _a;
|
|
75
|
+
let types = [];
|
|
76
|
+
if (credentialSupported.format === 'jwt_vc_json' ||
|
|
77
|
+
credentialSupported.format === 'jwt_vc' ||
|
|
78
|
+
credentialSupported.format === 'jwt_vc_json-ld' ||
|
|
79
|
+
credentialSupported.format === 'ldp_vc') {
|
|
80
|
+
types = (_a = getTypesFromObject(credentialSupported)) !== null && _a !== void 0 ? _a : [];
|
|
81
|
+
}
|
|
82
|
+
else if (credentialSupported.format === 'vc+sd-jwt') {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
types = [credentialSupported.vct];
|
|
86
|
+
}
|
|
87
|
+
if (!types || types.length === 0) {
|
|
88
|
+
throw Error('Could not deduce types from credential supported');
|
|
89
|
+
}
|
|
90
|
+
if (opts === null || opts === void 0 ? void 0 : opts.filterVerifiableCredential) {
|
|
91
|
+
return types.filter((type) => type !== 'VerifiableCredential');
|
|
92
|
+
}
|
|
93
|
+
return types;
|
|
94
|
+
}
|
|
95
|
+
exports.getTypesFromCredentialSupported = getTypesFromCredentialSupported;
|
|
8
96
|
//# sourceMappingURL=TypeConversionUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeConversionUtils.js","sourceRoot":"","sources":["../../lib/functions/TypeConversionUtils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TypeConversionUtils.js","sourceRoot":"","sources":["../../lib/functions/TypeConversionUtils.ts"],"names":[],"mappings":";;;AAAA,oCAAsJ;AAG/I,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAsB,EAAE;IACzE,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B;AAEF;;;GAGG;AACH,SAAgB,kBAAkB,CAChC,OAA2I;IAE3I,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;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|
3
|
-
CredentialOfferFormat,
|
|
4
|
-
CredentialOfferPayload,
|
|
5
|
-
JsonLdIssuerCredentialDefinition,
|
|
6
|
-
UniformCredentialOfferRequest,
|
|
7
|
-
VCI_LOG_COMMON,
|
|
8
|
-
} from '../index';
|
|
1
|
+
import { getTypesFromObject, VCI_LOG_COMMON } from '../index';
|
|
9
2
|
import {
|
|
10
3
|
AuthorizationServerMetadata,
|
|
11
4
|
CredentialConfigurationSupported,
|
|
@@ -156,33 +149,6 @@ export function getSupportedCredential(opts?: {
|
|
|
156
149
|
throw Error(`Either < v11 configurations or V13 configurations should have been filtered at this point`);
|
|
157
150
|
}
|
|
158
151
|
|
|
159
|
-
export function getTypesFromCredentialSupported(
|
|
160
|
-
credentialSupported: CredentialConfigurationSupported,
|
|
161
|
-
opts?: { filterVerifiableCredential: boolean },
|
|
162
|
-
) {
|
|
163
|
-
let types: string[] = [];
|
|
164
|
-
if (
|
|
165
|
-
credentialSupported.format === 'jwt_vc_json' ||
|
|
166
|
-
credentialSupported.format === 'jwt_vc' ||
|
|
167
|
-
credentialSupported.format === 'jwt_vc_json-ld' ||
|
|
168
|
-
credentialSupported.format === 'ldp_vc'
|
|
169
|
-
) {
|
|
170
|
-
types = getTypesFromObject(credentialSupported) ?? [];
|
|
171
|
-
} else if (credentialSupported.format === 'vc+sd-jwt') {
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
types = [credentialSupported.vct];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (!types || types.length === 0) {
|
|
178
|
-
throw Error('Could not deduce types from credential supported');
|
|
179
|
-
}
|
|
180
|
-
if (opts?.filterVerifiableCredential) {
|
|
181
|
-
return types.filter((type) => type !== 'VerifiableCredential');
|
|
182
|
-
}
|
|
183
|
-
return types;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
152
|
export function credentialsSupportedV8ToV13(supportedV8: CredentialSupportedTypeV1_0_08): Record<string, CredentialConfigurationSupported> {
|
|
187
153
|
const credentialConfigsSupported: Record<string, CredentialConfigurationSupported> = {};
|
|
188
154
|
Object.entries(supportedV8).flatMap((entry) => {
|
|
@@ -237,39 +203,3 @@ export function getIssuerName(
|
|
|
237
203
|
}
|
|
238
204
|
return url;
|
|
239
205
|
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* The specs had many places where types could be expressed. This method ensures we get them in any way possible
|
|
243
|
-
* @param subject
|
|
244
|
-
*/
|
|
245
|
-
export function getTypesFromObject(
|
|
246
|
-
subject:
|
|
247
|
-
| CredentialConfigurationSupported
|
|
248
|
-
| CredentialOfferFormat
|
|
249
|
-
| CredentialOfferPayload
|
|
250
|
-
| CredentialDefinitionV1_0_13
|
|
251
|
-
| JsonLdIssuerCredentialDefinition
|
|
252
|
-
| UniformCredentialOfferRequest
|
|
253
|
-
| string,
|
|
254
|
-
): string[] | undefined {
|
|
255
|
-
if (subject === undefined) {
|
|
256
|
-
return undefined;
|
|
257
|
-
} else if (typeof subject === 'string') {
|
|
258
|
-
return [subject];
|
|
259
|
-
} else if ('credential_definition' in subject && subject.credential_definition) {
|
|
260
|
-
return getTypesFromObject(subject.credential_definition);
|
|
261
|
-
} else if ('types' in subject && subject.types) {
|
|
262
|
-
return Array.isArray(subject.types) ? subject.types : [subject.types];
|
|
263
|
-
} else if ('type' in subject && subject.type) {
|
|
264
|
-
return Array.isArray(subject.type) ? subject.type : [subject.type];
|
|
265
|
-
} else if ('vct' in subject && subject.vct) {
|
|
266
|
-
return [subject.vct];
|
|
267
|
-
} else if ('credentials' in subject && subject.credentials) {
|
|
268
|
-
return getTypesFromObject(subject.credentials);
|
|
269
|
-
} else if ('credential_offer' in subject && subject.credential_offer) {
|
|
270
|
-
return getTypesFromObject(subject.credential_offer);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
VCI_LOG_COMMON.warning('Could not deduce credential types. Probably a failure down the line will happen!');
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
@@ -1,3 +1,92 @@
|
|
|
1
|
+
import { AuthorizationDetails, CredentialOfferPayload, UniformCredentialOfferPayload, UniformCredentialOfferRequest, VCI_LOG_COMMON } from '../index';
|
|
2
|
+
import { CredentialConfigurationSupported, CredentialDefinitionV1_0_13, CredentialOfferFormat, JsonLdIssuerCredentialDefinition } from '../types';
|
|
3
|
+
|
|
1
4
|
export const getNumberOrUndefined = (input?: string): number | undefined => {
|
|
2
5
|
return input && !isNaN(+input) ? +input : undefined;
|
|
3
6
|
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The specs had many places where types could be expressed. This method ensures we get them in any way possible
|
|
10
|
+
* @param subject
|
|
11
|
+
*/
|
|
12
|
+
export function getTypesFromObject(
|
|
13
|
+
subject: CredentialConfigurationSupported | CredentialOfferFormat | CredentialDefinitionV1_0_13 | JsonLdIssuerCredentialDefinition | string,
|
|
14
|
+
): string[] | undefined {
|
|
15
|
+
if (subject === undefined) {
|
|
16
|
+
return undefined;
|
|
17
|
+
} else if (typeof subject === 'string') {
|
|
18
|
+
return [subject];
|
|
19
|
+
} else if ('credential_definition' in subject && subject.credential_definition) {
|
|
20
|
+
return getTypesFromObject(subject.credential_definition);
|
|
21
|
+
} else if ('types' in subject && subject.types) {
|
|
22
|
+
return Array.isArray(subject.types) ? subject.types : [subject.types];
|
|
23
|
+
} else if ('type' in subject && subject.type) {
|
|
24
|
+
return Array.isArray(subject.type) ? subject.type : [subject.type];
|
|
25
|
+
} else if ('vct' in subject && subject.vct) {
|
|
26
|
+
return [subject.vct];
|
|
27
|
+
}
|
|
28
|
+
VCI_LOG_COMMON.warning('Could not deduce credential types. Probably a failure down the line will happen!');
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getTypesFromCredentialOffer(
|
|
33
|
+
offer: UniformCredentialOfferRequest | CredentialOfferPayload | UniformCredentialOfferPayload,
|
|
34
|
+
opts?: { configIdAsType?: boolean },
|
|
35
|
+
): Array<Array<string>> | undefined {
|
|
36
|
+
const { configIdAsType = false } = { ...opts };
|
|
37
|
+
if ('credentials' in offer && Array.isArray(offer.credentials)) {
|
|
38
|
+
return offer.credentials.map((cred) => getTypesFromObject(cred)).filter((cred): cred is string[] => cred !== undefined);
|
|
39
|
+
} else if (configIdAsType && 'credential_configuration_ids' in offer && Array.isArray(offer.credential_configuration_ids)) {
|
|
40
|
+
return offer.credential_configuration_ids.map((id) => [id]);
|
|
41
|
+
} else if ('credential_offer' in offer && offer.credential_offer) {
|
|
42
|
+
return getTypesFromCredentialOffer(offer.credential_offer, opts);
|
|
43
|
+
} else if ('credential_type' in offer && offer.credential_type) {
|
|
44
|
+
if (typeof offer.credential_type === 'string') {
|
|
45
|
+
return [[offer.credential_type]];
|
|
46
|
+
} else if (Array.isArray(offer.credential_type)) {
|
|
47
|
+
return [offer.credential_type];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
VCI_LOG_COMMON.warning('Could not deduce credential types from offer. Probably a failure down the line will happen!');
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function getTypesFromAuthorizationDetails(authDetails: AuthorizationDetails, opts?: { configIdAsType?: boolean }): string[] | undefined {
|
|
55
|
+
const { configIdAsType = false } = { ...opts };
|
|
56
|
+
if (typeof authDetails === 'string') {
|
|
57
|
+
return [authDetails];
|
|
58
|
+
} else if ('types' in authDetails && Array.isArray(authDetails.types)) {
|
|
59
|
+
return authDetails.types;
|
|
60
|
+
} else if (configIdAsType && authDetails.credential_configuration_id) {
|
|
61
|
+
return [authDetails.credential_configuration_id];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getTypesFromCredentialSupported(
|
|
68
|
+
credentialSupported: CredentialConfigurationSupported,
|
|
69
|
+
opts?: { filterVerifiableCredential: boolean },
|
|
70
|
+
) {
|
|
71
|
+
let types: string[] = [];
|
|
72
|
+
if (
|
|
73
|
+
credentialSupported.format === 'jwt_vc_json' ||
|
|
74
|
+
credentialSupported.format === 'jwt_vc' ||
|
|
75
|
+
credentialSupported.format === 'jwt_vc_json-ld' ||
|
|
76
|
+
credentialSupported.format === 'ldp_vc'
|
|
77
|
+
) {
|
|
78
|
+
types = getTypesFromObject(credentialSupported) ?? [];
|
|
79
|
+
} else if (credentialSupported.format === 'vc+sd-jwt') {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
types = [credentialSupported.vct];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!types || types.length === 0) {
|
|
86
|
+
throw Error('Could not deduce types from credential supported');
|
|
87
|
+
}
|
|
88
|
+
if (opts?.filterVerifiableCredential) {
|
|
89
|
+
return types.filter((type) => type !== 'VerifiableCredential');
|
|
90
|
+
}
|
|
91
|
+
return types;
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/oid4vci-common",
|
|
3
|
-
"version": "0.12.1-next.
|
|
3
|
+
"version": "0.12.1-next.4+40ad1de",
|
|
4
4
|
"description": "OpenID 4 Verifiable Credential Issuance Common Types",
|
|
5
5
|
"source": "lib/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "40ad1ded998168e2703daeddc3a3afc78c9b19a1"
|
|
53
53
|
}
|