Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / lib / keys / import / helper.ts
blobb16e3bc2a78fe27f428d7304ae0a9b76236a1bbf
1 import type { ActiveKey, InactiveKey } from '../../interfaces';
2 import type { KeyReactivationData } from '../reactivation/interface';
3 import type { KeyImportData } from './interface';
5 export const getFilteredImportRecords = (
6     keyImportRecords: KeyImportData[],
7     activeKeys: ActiveKey[],
8     inactiveKeys: InactiveKey[]
9 ) => {
10     return keyImportRecords.reduce<[KeyReactivationData[], KeyImportData[], KeyImportData[]]>(
11         (acc, keyImportRecord) => {
12             const { privateKey: uploadedPrivateKey } = keyImportRecord;
13             const fingerprint = uploadedPrivateKey.getFingerprint();
14             const maybeInactiveKey = inactiveKeys.find(({ fingerprint: otherFingerprint }) => {
15                 return otherFingerprint === fingerprint;
16             });
17             const maybeActiveKey = activeKeys.find(({ fingerprint: otherFingerprint }) => {
18                 return otherFingerprint === fingerprint;
19             });
20             if (maybeActiveKey) {
21                 acc[2].push(keyImportRecord);
22             } else if (maybeInactiveKey) {
23                 acc[0].push({
24                     id: keyImportRecord.id,
25                     Key: maybeInactiveKey.Key,
26                     privateKey: uploadedPrivateKey,
27                 });
28             } else {
29                 acc[1].push(keyImportRecord);
30             }
31             return acc;
32         },
33         [[], [], []]
34     );