-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathgetCertificate.ts
More file actions
26 lines (22 loc) · 925 Bytes
/
getCertificate.ts
File metadata and controls
26 lines (22 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
},
);