mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2024-11-24 09:04:59 +03:00
27 lines
925 B
TypeScript
27 lines
925 B
TypeScript
|
import { Certificate } from './certificate';
|
|||
|
import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded';
|
|||
|
import { getUserCertificates } from './getUserCertificates';
|
|||
|
|
|||
|
/**
|
|||
|
* Возвращает сертификат по отпечатку
|
|||
|
*
|
|||
|
* @param thumbprint - отпечаток сертификата
|
|||
|
* @returns сертификат
|
|||
|
*/
|
|||
|
export const getCertificate = _afterPluginsLoaded(
|
|||
|
async (thumbprint: string): Promise<Certificate> => {
|
|||
|
if (!thumbprint) {
|
|||
|
throw new Error('Отпечаток не указан');
|
|||
|
}
|
|||
|
|
|||
|
const availableCertificates: Certificate[] = await getUserCertificates();
|
|||
|
const foundCertificate: Certificate = availableCertificates.find((cert) => cert.thumbprint === thumbprint);
|
|||
|
|
|||
|
if (!foundCertificate) {
|
|||
|
throw new Error(`Сертификат с отпечатком: "${thumbprint}" не найден`);
|
|||
|
}
|
|||
|
|
|||
|
return foundCertificate;
|
|||
|
},
|
|||
|
);
|