|
1 | | -import { |
2 | | - CredentialDefinitionV1_0_13, |
3 | | - CredentialOfferFormat, |
4 | | - CredentialOfferPayload, |
5 | | - JsonLdIssuerCredentialDefinition, |
6 | | - UniformCredentialOfferPayload, |
7 | | - UniformCredentialOfferRequest, |
8 | | - VCI_LOG_COMMON, |
9 | | -} from '../index'; |
| 1 | +import { getTypesFromObject, VCI_LOG_COMMON } from '../index'; |
10 | 2 | import { |
11 | 3 | AuthorizationServerMetadata, |
12 | 4 | CredentialConfigurationSupported, |
@@ -157,33 +149,6 @@ export function getSupportedCredential(opts?: { |
157 | 149 | throw Error(`Either < v11 configurations or V13 configurations should have been filtered at this point`); |
158 | 150 | } |
159 | 151 |
|
160 | | -export function getTypesFromCredentialSupported( |
161 | | - credentialSupported: CredentialConfigurationSupported, |
162 | | - opts?: { filterVerifiableCredential: boolean }, |
163 | | -) { |
164 | | - let types: string[] = []; |
165 | | - if ( |
166 | | - credentialSupported.format === 'jwt_vc_json' || |
167 | | - credentialSupported.format === 'jwt_vc' || |
168 | | - credentialSupported.format === 'jwt_vc_json-ld' || |
169 | | - credentialSupported.format === 'ldp_vc' |
170 | | - ) { |
171 | | - types = getTypesFromObject(credentialSupported) ?? []; |
172 | | - } else if (credentialSupported.format === 'vc+sd-jwt') { |
173 | | - // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
174 | | - // @ts-ignore |
175 | | - types = [credentialSupported.vct]; |
176 | | - } |
177 | | - |
178 | | - if (!types || types.length === 0) { |
179 | | - throw Error('Could not deduce types from credential supported'); |
180 | | - } |
181 | | - if (opts?.filterVerifiableCredential) { |
182 | | - return types.filter((type) => type !== 'VerifiableCredential'); |
183 | | - } |
184 | | - return types; |
185 | | -} |
186 | | - |
187 | 152 | export function credentialsSupportedV8ToV13(supportedV8: CredentialSupportedTypeV1_0_08): Record<string, CredentialConfigurationSupported> { |
188 | 153 | const credentialConfigsSupported: Record<string, CredentialConfigurationSupported> = {}; |
189 | 154 | Object.entries(supportedV8).flatMap((entry) => { |
@@ -238,47 +203,3 @@ export function getIssuerName( |
238 | 203 | } |
239 | 204 | return url; |
240 | 205 | } |
241 | | - |
242 | | -/** |
243 | | - * The specs had many places where types could be expressed. This method ensures we get them in any way possible |
244 | | - * @param subject |
245 | | - */ |
246 | | -export function getTypesFromObject( |
247 | | - subject: CredentialConfigurationSupported | CredentialOfferFormat | CredentialDefinitionV1_0_13 | JsonLdIssuerCredentialDefinition | string, |
248 | | -): string[] | undefined { |
249 | | - if (subject === undefined) { |
250 | | - return undefined; |
251 | | - } else if (typeof subject === 'string') { |
252 | | - return [subject]; |
253 | | - } else if ('credential_definition' in subject && subject.credential_definition) { |
254 | | - return getTypesFromObject(subject.credential_definition); |
255 | | - } else if ('types' in subject && subject.types) { |
256 | | - return Array.isArray(subject.types) ? subject.types : [subject.types]; |
257 | | - } else if ('type' in subject && subject.type) { |
258 | | - return Array.isArray(subject.type) ? subject.type : [subject.type]; |
259 | | - } else if ('vct' in subject && subject.vct) { |
260 | | - return [subject.vct]; |
261 | | - } |
262 | | - VCI_LOG_COMMON.warning('Could not deduce credential types. Probably a failure down the line will happen!'); |
263 | | - return undefined; |
264 | | -} |
265 | | - |
266 | | -export function getTypesFromCredentialOffer( |
267 | | - offer: UniformCredentialOfferRequest | CredentialOfferPayload | UniformCredentialOfferPayload, |
268 | | -): Array<Array<string>> | undefined { |
269 | | - if ('credentials' in offer && Array.isArray(offer.credentials)) { |
270 | | - return offer.credentials.map((cred) => getTypesFromObject(cred)).filter((cred): cred is string[] => cred !== undefined); |
271 | | - } else if ('credential_configuration_ids' in offer && Array.isArray(offer.credential_configuration_ids)) { |
272 | | - return offer.credential_configuration_ids.map((id) => [id]); |
273 | | - } else if ('credential_offer' in offer && offer.credential_offer) { |
274 | | - return getTypesFromCredentialOffer(offer.credential_offer); |
275 | | - } else if ('credential_type' in offer && offer.credential_type) { |
276 | | - if (typeof offer.credential_type === 'string') { |
277 | | - return [[offer.credential_type]]; |
278 | | - } else if (Array.isArray(offer.credential_type)) { |
279 | | - return [offer.credential_type]; |
280 | | - } |
281 | | - } |
282 | | - VCI_LOG_COMMON.warning('Could not deduce credential types from offer. Probably a failure down the line will happen!'); |
283 | | - return undefined; |
284 | | -} |
0 commit comments