1 import { c } from 'ttag';
3 import { ktKeyVerificationFailureTelemetryAndMetrics, ktSentryReport } from '@proton/key-transparency/lib';
5 import type { Api, ApiKeysConfig, VerifyOutboundPublicKeys } from '../../interfaces';
6 import { KT_VERIFICATION_STATUS, KeyTransparencyActivation } from '../../interfaces';
7 import getPublicKeysEmailHelperWithKT from './getPublicKeysEmailHelperWithKT';
9 export const KEY_VERIFICATION_ERROR_MESSAGE = c('loc_nightly: Key verification error')
10 .t`Unable to verify this address at this time`;
13 * Ask the API for public keys for a given email address. The response will contain keys both
14 * for internal users and for external users with e.g. WKD keys
16 const getPublicKeysEmailHelper = async ({
18 internalKeysOnly = false,
19 includeInternalKeysWithE2EEDisabledForMail = false,
22 verifyOutboundPublicKeys,
27 internalKeysOnly?: boolean;
29 ktActivation: KeyTransparencyActivation;
30 verifyOutboundPublicKeys: VerifyOutboundPublicKeys;
32 * Whether to return internal keys which cannot be used for email encryption, as the owner has disabled E2EE.
33 * These keys may still be used for e.g. calendar sharing or message verification.
35 includeInternalKeysWithE2EEDisabledForMail?: boolean;
38 }): Promise<ApiKeysConfig> => {
39 if (ktActivation === KeyTransparencyActivation.DISABLED) {
40 const { ktVerificationResult, ...resultWithoutKT } = await getPublicKeysEmailHelperWithKT({
43 includeInternalKeysWithE2EEDisabledForMail,
45 verifyOutboundPublicKeys: null, // skip KT verification
50 return resultWithoutKT;
52 const result = await getPublicKeysEmailHelperWithKT({
55 includeInternalKeysWithE2EEDisabledForMail,
57 verifyOutboundPublicKeys,
61 if (result.ktVerificationResult?.status === KT_VERIFICATION_STATUS.VERIFICATION_FAILED) {
62 const visible = ktActivation === KeyTransparencyActivation.SHOW_UI;
63 ktSentryReport('Key verification error', { email });
64 await ktKeyVerificationFailureTelemetryAndMetrics(api, visible);
68 ktVerificationResult: result.ktVerificationResult,
69 Errors: [KEY_VERIFICATION_ERROR_MESSAGE],
73 if (ktActivation === KeyTransparencyActivation.LOG_ONLY) {
76 ktVerificationResult: undefined,
82 export default getPublicKeysEmailHelper;