crypto-pro-js/src/api/getCertificate.ts
2020-03-28 21:11:00 +03:00

27 lines
925 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
},
);