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[]
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;
17 const maybeActiveKey = activeKeys.find(({ fingerprint: otherFingerprint }) => {
18 return otherFingerprint === fingerprint;
21 acc[2].push(keyImportRecord);
22 } else if (maybeInactiveKey) {
24 id: keyImportRecord.id,
25 Key: maybeInactiveKey.Key,
26 privateKey: uploadedPrivateKey,
29 acc[1].push(keyImportRecord);