{"version":3,"file":"issuerMetadataUtils.mjs","names":[],"sources":["../../src/shared/issuerMetadataUtils.ts"],"sourcesContent":["import type { CredentialConfigurationsSupported } from '@openid4vc/openid4vci'\nimport type {\n  OpenId4VciCredentialConfigurationsSupported,\n  OpenId4VciCredentialConfigurationsSupportedWithFormats,\n} from './models'\n\n/**\n * Returns all entries from the credential offer with the associated metadata resolved.\n */\nexport function getOfferedCredentials<\n  Configurations extends\n    | OpenId4VciCredentialConfigurationsSupported\n    | OpenId4VciCredentialConfigurationsSupportedWithFormats,\n>(\n  offeredCredentialConfigurationIds: Array<string>,\n  credentialConfigurationsSupported: Configurations,\n  { ignoreNotFoundIds = false }: { ignoreNotFoundIds?: boolean } = {}\n): Configurations extends OpenId4VciCredentialConfigurationsSupportedWithFormats\n  ? OpenId4VciCredentialConfigurationsSupportedWithFormats\n  : OpenId4VciCredentialConfigurationsSupported {\n  const offeredCredentialConfigurations: OpenId4VciCredentialConfigurationsSupported = {}\n  for (const offeredCredentialConfigurationId of offeredCredentialConfigurationIds) {\n    const foundCredentialConfiguration = credentialConfigurationsSupported[offeredCredentialConfigurationId]\n\n    // Make sure the issuer metadata includes the offered credential.\n    if (!foundCredentialConfiguration) {\n      if (!ignoreNotFoundIds) {\n        throw new Error(\n          `Offered credential configuration id '${offeredCredentialConfigurationId}' is not part of credential_configurations_supported of the issuer metadata.`\n        )\n      }\n\n      continue\n    }\n\n    offeredCredentialConfigurations[offeredCredentialConfigurationId] = foundCredentialConfiguration\n  }\n\n  return offeredCredentialConfigurations as Configurations extends OpenId4VciCredentialConfigurationsSupportedWithFormats\n    ? OpenId4VciCredentialConfigurationsSupportedWithFormats\n    : OpenId4VciCredentialConfigurationsSupported\n}\n\nexport function getScopesFromCredentialConfigurationsSupported(\n  credentialConfigurationsSupported: CredentialConfigurationsSupported\n): string[] {\n  return Array.from(\n    new Set(\n      Object.values(credentialConfigurationsSupported)\n        .map((configuration) => configuration.scope)\n        .filter((scope): scope is string => scope !== undefined)\n    )\n  )\n}\n\nexport function getAllowedAndRequestedScopeValues(options: { requestedScope: string; allowedScopes: string[] }) {\n  const requestedScopeValues = options.requestedScope.split(' ')\n  const allowedAndRequestedScopeValues = options.allowedScopes.filter((allowedScope) =>\n    requestedScopeValues.includes(allowedScope)\n  )\n\n  return allowedAndRequestedScopeValues\n}\n\nexport function getCredentialConfigurationsSupportedForScopes(\n  credentialConfigurationsSupported: CredentialConfigurationsSupported,\n  scopes: string[]\n): CredentialConfigurationsSupported {\n  return Object.fromEntries(\n    Object.entries(credentialConfigurationsSupported).filter(\n      ([, configuration]) => configuration.scope && scopes.includes(configuration.scope)\n    )\n  )\n}\n"],"mappings":";;;;AASA,SAAgB,sBAKd,mCACA,mCACA,EAAE,oBAAoB,UAA2C,EAAE,EAGrB;CAC9C,MAAM,kCAA+E,EAAE;AACvF,MAAK,MAAM,oCAAoC,mCAAmC;EAChF,MAAM,+BAA+B,kCAAkC;AAGvE,MAAI,CAAC,8BAA8B;AACjC,OAAI,CAAC,kBACH,OAAM,IAAI,MACR,wCAAwC,iCAAiC,8EAC1E;AAGH;;AAGF,kCAAgC,oCAAoC;;AAGtE,QAAO;;AAKT,SAAgB,+CACd,mCACU;AACV,QAAO,MAAM,KACX,IAAI,IACF,OAAO,OAAO,kCAAkC,CAC7C,KAAK,kBAAkB,cAAc,MAAM,CAC3C,QAAQ,UAA2B,UAAU,OAAU,CAC3D,CACF;;AAGH,SAAgB,kCAAkC,SAA8D;CAC9G,MAAM,uBAAuB,QAAQ,eAAe,MAAM,IAAI;AAK9D,QAJuC,QAAQ,cAAc,QAAQ,iBACnE,qBAAqB,SAAS,aAAa,CAC5C;;AAKH,SAAgB,8CACd,mCACA,QACmC;AACnC,QAAO,OAAO,YACZ,OAAO,QAAQ,kCAAkC,CAAC,QAC/C,GAAG,mBAAmB,cAAc,SAAS,OAAO,SAAS,cAAc,MAAM,CACnF,CACF"}