@sphereon/oid4vci-common
Advanced tools
Comparing version 0.7.1-next.14 to 0.7.1-next.15
@@ -1,14 +0,8 @@ | ||
import { CredentialIssuerMetadata, CredentialSupported, CredentialSupportedTypeV1_0_08, CredentialSupportedV1_0_08, IssuerMetadataV1_0_08, MetadataDisplay, OID4VCICredentialFormat, OpenId4VCIVersion } from '../types'; | ||
import { CredentialIssuerMetadata, CredentialOfferFormat, CredentialSupported, CredentialSupportedTypeV1_0_08, CredentialSupportedV1_0_08, IssuerMetadataV1_0_08, MetadataDisplay, OpenId4VCIVersion } from '../types'; | ||
export declare function getSupportedCredentials(opts?: { | ||
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08; | ||
version: OpenId4VCIVersion; | ||
types?: string[][]; | ||
format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[]; | ||
credentialTypes?: (CredentialOfferFormat | string)[]; | ||
supportedType?: CredentialOfferFormat | string; | ||
}): CredentialSupported[]; | ||
export declare function getSupportedCredential(opts?: { | ||
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08; | ||
version: OpenId4VCIVersion; | ||
types?: string | string[]; | ||
format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[]; | ||
}): CredentialSupported[]; | ||
export declare function credentialsSupportedV8ToV11(supportedV8: CredentialSupportedTypeV1_0_08): CredentialSupported[]; | ||
@@ -15,0 +9,0 @@ export declare function credentialSupportedV8ToV11(key: string, supportedV8: CredentialSupportedV1_0_08): CredentialSupported[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIssuerDisplays = exports.credentialSupportedV8ToV11 = exports.credentialsSupportedV8ToV11 = exports.getSupportedCredential = exports.getSupportedCredentials = void 0; | ||
exports.getIssuerDisplays = exports.credentialSupportedV8ToV11 = exports.credentialsSupportedV8ToV11 = exports.getSupportedCredentials = void 0; | ||
const types_1 = require("../types"); | ||
function getSupportedCredentials(opts) { | ||
if ((opts === null || opts === void 0 ? void 0 : opts.types) && Array.isArray(opts === null || opts === void 0 ? void 0 : opts.types)) { | ||
return opts.types.flatMap((types) => getSupportedCredential(Object.assign(Object.assign({}, opts), { types }))); | ||
} | ||
return getSupportedCredential(opts ? Object.assign(Object.assign({}, opts), { types: undefined }) : undefined); | ||
} | ||
exports.getSupportedCredentials = getSupportedCredentials; | ||
function getSupportedCredential(opts) { | ||
const { issuerMetadata } = opts !== null && opts !== void 0 ? opts : {}; | ||
let formats; | ||
if ((opts === null || opts === void 0 ? void 0 : opts.format) && Array.isArray(opts.format)) { | ||
formats = opts.format; | ||
} | ||
else if ((opts === null || opts === void 0 ? void 0 : opts.format) && !Array.isArray(opts.format)) { | ||
formats = [opts.format]; | ||
} | ||
else { | ||
formats = []; | ||
} | ||
let credentialsSupported; | ||
@@ -28,5 +11,15 @@ if (!issuerMetadata) { | ||
} | ||
const { version, types } = opts !== null && opts !== void 0 ? opts : { version: types_1.OpenId4VCIVersion.VER_1_0_11 }; | ||
const { version, credentialTypes, supportedType } = opts !== null && opts !== void 0 ? opts : { version: types_1.OpenId4VCIVersion.VER_1_0_11 }; | ||
if (version === types_1.OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) { | ||
credentialsSupported = credentialsSupportedV8ToV11(issuerMetadata.credentials_supported); | ||
/* const credentialsSupportedV8: CredentialSupportedV1_0_08 = credentialsSupported as CredentialSupportedV1_0_08 | ||
// const initiationTypes = credentialTypes.map(type => typeof type === 'string' ? [type] : type.types) | ||
const supported: IssuerCredentialSubject = {} | ||
for (const [key, value] of Object.entries(credentialsSupportedV8)) { | ||
if (initiationTypes.find((type) => (typeof type === 'string' ? type === key : type.types.includes(key)))) { | ||
supported[key] = value | ||
} | ||
} | ||
// todo: fix this later. we're returning CredentialSupportedV1_0_08 as a list of CredentialSupported (for v09 onward) | ||
return supported as unknown as CredentialSupported[]*/ | ||
} | ||
@@ -39,3 +32,3 @@ else { | ||
} | ||
else if (!types || types.length === 0) { | ||
else if (!credentialTypes || credentialTypes.length === 0) { | ||
return credentialsSupported; | ||
@@ -46,44 +39,16 @@ } | ||
*/ | ||
let initiationTypes; | ||
if (opts === null || opts === void 0 ? void 0 : opts.types) { | ||
if (typeof opts.types === 'string') { | ||
initiationTypes = [opts.types]; | ||
const initiationTypes = supportedType ? [supportedType] : credentialTypes; | ||
const credentialSupportedOverlap = []; | ||
for (const offerType of initiationTypes) { | ||
if (typeof offerType === 'string') { | ||
const supported = credentialsSupported.filter((sup) => sup.id === offerType || sup.types.includes(offerType)); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
} | ||
else { | ||
initiationTypes = opts.types; | ||
} | ||
} | ||
if (version === types_1.OpenId4VCIVersion.VER_1_0_08 && (!initiationTypes || (initiationTypes === null || initiationTypes === void 0 ? void 0 : initiationTypes.length) === 0)) { | ||
initiationTypes = formats; | ||
} | ||
const supportedFormats = formats && formats.length > 0 ? formats : ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc']; | ||
const credentialSupportedOverlap = []; | ||
if ((opts === null || opts === void 0 ? void 0 : opts.types) && typeof (opts === null || opts === void 0 ? void 0 : opts.types) === 'string') { | ||
const supported = credentialsSupported.filter((sup) => sup.id === opts.types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes))); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
} /*else if (initiationTypes && Array.isArray(initiationTypes) && initiationTypes.length === 1) { | ||
const supported = credentialsSupported.filter( | ||
(sup) => sup.id === initiationTypes![0] || (arrayEqualsIgnoreOrder(sup.types, initiationTypes!) && sup.types.includes(initiationTypes![0])), | ||
); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
}*/ | ||
else { | ||
// 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. | ||
if (initiationTypes && !initiationTypes.includes('VerifiableCredential')) { | ||
initiationTypes.push('VerifiableCredential'); | ||
} | ||
const supported = credentialsSupported.filter((sup) => { | ||
const supTypes = sup.types; | ||
if (!supTypes.includes('VerifiableCredential')) { | ||
supTypes.push('VerifiableCredential'); | ||
const supported = credentialsSupported.filter((sup) => arrayEqualsIgnoreOrder(sup.types, offerType.types) && sup.format === offerType.format); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
return (!initiationTypes || arrayEqualsIgnoreOrder(supTypes, initiationTypes)) && supportedFormats.includes(sup.format); | ||
}); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
@@ -93,3 +58,3 @@ } | ||
} | ||
exports.getSupportedCredential = getSupportedCredential; | ||
exports.getSupportedCredentials = getSupportedCredentials; | ||
function arrayEqualsIgnoreOrder(a, b) { | ||
@@ -96,0 +61,0 @@ if (a.length !== b.length) |
@@ -9,5 +9,4 @@ import { | ||
MetadataDisplay, | ||
OID4VCICredentialFormat, | ||
OpenId4VCIVersion | ||
} from '../types' | ||
OpenId4VCIVersion, | ||
} from '../types'; | ||
@@ -17,26 +16,6 @@ export function getSupportedCredentials(opts?: { | ||
version: OpenId4VCIVersion; | ||
types?: string[][]; | ||
format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[]; | ||
credentialTypes?: (CredentialOfferFormat | string)[]; | ||
supportedType?: CredentialOfferFormat | string; | ||
}): CredentialSupported[] { | ||
if (opts?.types && Array.isArray(opts?.types)) { | ||
return opts.types.flatMap((types) => getSupportedCredential({ ...opts, types })); | ||
} | ||
return getSupportedCredential(opts ? { ...opts, types: undefined } : undefined); | ||
} | ||
export function getSupportedCredential(opts?: { | ||
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08; | ||
version: OpenId4VCIVersion; | ||
types?: string | string[]; | ||
format?: (OID4VCICredentialFormat | string) | (OID4VCICredentialFormat | string)[]; | ||
}): CredentialSupported[] { | ||
const { issuerMetadata } = opts ?? {}; | ||
let formats: (OID4VCICredentialFormat | string)[]; | ||
if (opts?.format && Array.isArray(opts.format)) { | ||
formats = opts.format; | ||
} else if (opts?.format && !Array.isArray(opts.format)) { | ||
formats = [opts.format]; | ||
} else { | ||
formats = []; | ||
} | ||
let credentialsSupported: CredentialSupported[]; | ||
@@ -46,5 +25,15 @@ if (!issuerMetadata) { | ||
} | ||
const { version, types } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 }; | ||
const { version, credentialTypes, supportedType } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 }; | ||
if (version === OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) { | ||
credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported); | ||
/* const credentialsSupportedV8: CredentialSupportedV1_0_08 = credentialsSupported as CredentialSupportedV1_0_08 | ||
// const initiationTypes = credentialTypes.map(type => typeof type === 'string' ? [type] : type.types) | ||
const supported: IssuerCredentialSubject = {} | ||
for (const [key, value] of Object.entries(credentialsSupportedV8)) { | ||
if (initiationTypes.find((type) => (typeof type === 'string' ? type === key : type.types.includes(key)))) { | ||
supported[key] = value | ||
} | ||
} | ||
// todo: fix this later. we're returning CredentialSupportedV1_0_08 as a list of CredentialSupported (for v09 onward) | ||
return supported as unknown as CredentialSupported[]*/ | ||
} else { | ||
@@ -56,3 +45,3 @@ credentialsSupported = (issuerMetadata as CredentialIssuerMetadata).credentials_supported; | ||
return []; | ||
} else if (!types || types.length === 0) { | ||
} else if (!credentialTypes || credentialTypes.length === 0) { | ||
return credentialsSupported; | ||
@@ -63,45 +52,16 @@ } | ||
*/ | ||
let initiationTypes :string[] | undefined | ||
if (opts?.types) { | ||
if (typeof opts.types === 'string') { | ||
initiationTypes = [opts.types] | ||
} else { | ||
initiationTypes = opts.types | ||
} | ||
} | ||
if (version === OpenId4VCIVersion.VER_1_0_08 && (!initiationTypes || initiationTypes?.length === 0)) { | ||
initiationTypes = formats | ||
} | ||
const supportedFormats: (CredentialOfferFormat | string)[] = formats && formats.length > 0 ? formats : ['jwt_vc_json', 'jwt_vc_json-ld', 'ldp_vc']; | ||
const initiationTypes = supportedType ? [supportedType] : credentialTypes; | ||
const credentialSupportedOverlap: CredentialSupported[] = []; | ||
if (opts?.types && typeof opts?.types === 'string') { | ||
const supported = credentialsSupported.filter( | ||
(sup) => sup.id === opts.types || (initiationTypes && arrayEqualsIgnoreOrder(sup.types, initiationTypes)), | ||
) | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
} /*else if (initiationTypes && Array.isArray(initiationTypes) && initiationTypes.length === 1) { | ||
const supported = credentialsSupported.filter( | ||
(sup) => sup.id === initiationTypes![0] || (arrayEqualsIgnoreOrder(sup.types, initiationTypes!) && sup.types.includes(initiationTypes![0])), | ||
); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
}*/ else { | ||
// 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. | ||
if (initiationTypes && !initiationTypes.includes('VerifiableCredential')) { | ||
initiationTypes.push('VerifiableCredential'); | ||
} | ||
const supported = credentialsSupported.filter((sup) => { | ||
const supTypes = sup.types; | ||
if (!supTypes.includes('VerifiableCredential')) { | ||
supTypes.push('VerifiableCredential'); | ||
for (const offerType of initiationTypes) { | ||
if (typeof offerType === 'string') { | ||
const supported = credentialsSupported.filter((sup) => sup.id === offerType || sup.types.includes(offerType)); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
return (!initiationTypes || arrayEqualsIgnoreOrder(supTypes, initiationTypes)) && supportedFormats.includes(sup.format); | ||
}); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} else { | ||
const supported = credentialsSupported.filter((sup) => arrayEqualsIgnoreOrder(sup.types, offerType.types) && sup.format === offerType.format); | ||
if (supported) { | ||
credentialSupportedOverlap.push(...supported); | ||
} | ||
} | ||
@@ -108,0 +68,0 @@ } |
{ | ||
"name": "@sphereon/oid4vci-common", | ||
"version": "0.7.1-next.14+3c23bab", | ||
"version": "0.7.1-next.15+2d5ec9c", | ||
"description": "OpenID 4 Verifiable Credential Issuance Common Types", | ||
@@ -48,3 +48,3 @@ "source": "lib/index.ts", | ||
}, | ||
"gitHead": "3c23bab83569e04a4b5846fed83ce00d68e8ddce" | ||
"gitHead": "2d5ec9c60277c672022b43d7d980ffcbe8029561" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
237044
3785
3546