Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / lib / auth / address.ts
blobee1bf66a09e08f5f352548951d4679bbf97727fb
1 import { api } from '@proton/pass/lib/api/api';
2 import type { GetAllPublicKeysResponse, Maybe } from '@proton/pass/types';
3 import { getApiError } from '@proton/shared/lib/api/helpers/apiErrorHelper';
4 import { getAllPublicKeys } from '@proton/shared/lib/api/keys';
5 import { API_CUSTOM_ERROR_CODES } from '@proton/shared/lib/errors';
7 export const getPublicKeysForEmail = async (email: string): Promise<string[]> => {
8     const { Address } = await api<GetAllPublicKeysResponse>(getAllPublicKeys({ Email: email, InternalOnly: 1 }));
9     return Address.Keys.map((key) => key.PublicKey);
12 export const getPrimaryPublicKeyForEmail = async (email: string): Promise<Maybe<string>> => {
13     try {
14         const publicKeys = await getPublicKeysForEmail(email);
15         return publicKeys?.[0];
16     } catch (err) {
17         const { code } = getApiError(err);
18         if (
19             code === API_CUSTOM_ERROR_CODES.KEY_GET_ADDRESS_MISSING ||
20             code === API_CUSTOM_ERROR_CODES.KEY_GET_DOMAIN_EXTERNAL
21         ) {
22             return undefined;
23         }
24         throw err;
25     }