1 import type { PrivateKeyReference } from '@proton/crypto';
2 import { CryptoProxy } from '@proton/crypto';
4 import { CONTACT_CARD_TYPE } from '../constants';
5 import type { ContactCard } from '../interfaces/contacts';
8 * Re-sign contact cards
9 * Private keys (typically only the primary one) need to be passed to re-sign the contact cards
10 * No public key is needed as we don't do signature verification (since we are re-signing anyway)
13 contactCards: ContactCard[];
14 privateKeys: PrivateKeyReference[];
16 export const resignCards = async ({ contactCards, privateKeys }: Params): Promise<ContactCard[]> => {
17 const signedCards = contactCards.filter((card) => card.Type === CONTACT_CARD_TYPE.SIGNED);
18 const otherCards = contactCards.filter((card) => card.Type !== CONTACT_CARD_TYPE.SIGNED);
19 const reSignedCards = await Promise.all(
20 signedCards.map(async ({ Data }) => {
21 const signature = await CryptoProxy.signMessage({
23 stripTrailingSpaces: true,
24 signingKeys: privateKeys,
28 Type: CONTACT_CARD_TYPE.SIGNED,
34 return [...reSignedCards, ...otherCards];