1 import { getNewKeyFlags } from '@proton/components/containers/keys/shared/flags';
2 import { FlagAction } from '@proton/components/containers/keys/shared/interface';
3 import { updateAddressFlags } from '@proton/shared/lib/api/members';
4 import type { Address, Api, DecryptedAddressKey, KeyTransparencyVerify } from '@proton/shared/lib/interfaces';
5 import { getSignedKeyListWithDeferredPublish } from '@proton/shared/lib/keys';
6 import { getActiveKeys, getNormalizedActiveKeys } from '@proton/shared/lib/keys/getActiveKeys';
8 export const setAddressFlags = async ({
10 expectSignatureDisabled,
12 keyTransparencyVerify,
16 encryptionDisabled: boolean;
17 expectSignatureDisabled: boolean;
19 keyTransparencyVerify: KeyTransparencyVerify;
23 keys: DecryptedAddressKey[];
25 }): Promise<void> => {
26 const { ID: addressID, SignedKeyList: currentSignedKeyList, Keys: currentKeys } = address;
27 const addressWithKeys = addressesKeys?.find(({ address: { ID } }) => ID === addressID);
28 if (addressWithKeys === undefined) {
29 throw new Error('addressWithKeys is undefined!');
32 const { keys } = addressWithKeys;
34 const activeKeys = await getActiveKeys(address, currentSignedKeyList, currentKeys, keys);
35 const newActiveKeys = getNormalizedActiveKeys(
37 activeKeys.map((activeKey) => ({
39 flags: getNewKeyFlags(
42 encryptionDisabled ? FlagAction.DISABLE_ENCRYPTION : FlagAction.ENABLE_ENCRYPTION
44 expectSignatureDisabled ? FlagAction.DISABLE_EXPECT_SIGNED : FlagAction.ENABLE_EXPECT_SIGNED
48 const [newSignedKeyList, onSKLPublishSuccess] = await getSignedKeyListWithDeferredPublish(
53 await api(updateAddressFlags(address.ID, !encryptionDisabled, !expectSignatureDisabled, newSignedKeyList));
54 await onSKLPublishSuccess();