1 import type { Item, ItemExtraField, ItemType, UnsafeItem, UnsafeItemExtraField } from '@proton/pass/types';
2 import { deobfuscate, obfuscate } from '@proton/pass/utils/obfuscate/xor';
4 export const obfuscateExtraFields = (extraFields?: UnsafeItemExtraField[]): ItemExtraField[] =>
5 extraFields?.map((field) =>
7 ? { ...field, data: { totpUri: obfuscate(field.data.totpUri) } }
8 : { ...field, data: { content: obfuscate(field.data.content) } }
11 export const deobfuscateExtraFields = (extraFields?: ItemExtraField[]): UnsafeItemExtraField[] =>
12 extraFields?.map((extraField): UnsafeItemExtraField => {
13 switch (extraField.type) {
17 data: { totpUri: deobfuscate(extraField.data.totpUri) },
22 data: { content: deobfuscate(extraField.data.content) },
27 export const obfuscateItem = <T extends ItemType = ItemType>(item: UnsafeItem): Item<T> => {
29 metadata: { ...item.metadata, note: obfuscate(item.metadata.note) },
30 extraFields: obfuscateExtraFields(item.extraFields),
40 itemEmail: obfuscate(item.content.itemEmail),
41 itemUsername: obfuscate(item.content.itemUsername),
42 password: obfuscate(item.content.password),
43 totpUri: obfuscate(item.content.totpUri),
45 } satisfies Item<'login'> as Item<T>;
52 number: obfuscate(item.content.number),
53 verificationNumber: obfuscate(item.content.verificationNumber),
54 pin: obfuscate(item.content.pin),
56 } satisfies Item<'creditCard'> as Item<T>;
59 return { ...item, ...base } satisfies Item<'note'> as Item<T>;
61 return { ...item, ...base } satisfies Item<'alias'> as Item<T>;
63 return { ...item, ...base } satisfies Item<'identity'> as Item<T>;
67 export const deobfuscateItem = <T extends ItemType>(item: Item): UnsafeItem<T> => {
69 metadata: { ...item.metadata, note: deobfuscate(item.metadata.note) },
70 extraFields: deobfuscateExtraFields(item.extraFields),
80 itemEmail: deobfuscate(item.content.itemEmail),
81 itemUsername: deobfuscate(item.content.itemUsername),
82 password: deobfuscate(item.content.password),
83 totpUri: deobfuscate(item.content.totpUri),
85 } satisfies UnsafeItem<'login'> as UnsafeItem<T>;
92 number: deobfuscate(item.content.number),
93 verificationNumber: deobfuscate(item.content.verificationNumber),
94 pin: deobfuscate(item.content.pin),
96 } satisfies UnsafeItem<'creditCard'> as UnsafeItem<T>;
99 return { ...item, ...base } satisfies UnsafeItem<'note'> as UnsafeItem<T>;
101 return { ...item, ...base } satisfies UnsafeItem<'alias'> as UnsafeItem<T>;
103 return { ...item, ...base } satisfies UnsafeItem<'identity'> as UnsafeItem<T>;