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>> => {
14 const publicKeys = await getPublicKeysForEmail(email);
15 return publicKeys?.[0];
17 const { code } = getApiError(err);
19 code === API_CUSTOM_ERROR_CODES.KEY_GET_ADDRESS_MISSING ||
20 code === API_CUSTOM_ERROR_CODES.KEY_GET_DOMAIN_EXTERNAL