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';
10 } from '@proton/shared/lib/interfaces';
11 import { getSignedKeyListWithDeferredPublish } from '@proton/shared/lib/keys';
12 import { getActiveAddressKeys, getNormalizedActiveAddressKeys } from '@proton/shared/lib/keys/getActiveKeys';
14 export const setAddressFlags = async ({
16 expectSignatureDisabled,
18 keyTransparencyVerify,
22 encryptionDisabled: boolean;
23 expectSignatureDisabled: boolean;
25 keyTransparencyVerify: KeyTransparencyVerify;
29 keys: DecryptedAddressKey[];
31 }): Promise<void> => {
32 const { ID: addressID, SignedKeyList: currentSignedKeyList, Keys: currentKeys } = address;
33 const addressWithKeys = addressesKeys?.find(({ address: { ID } }) => ID === addressID);
34 if (addressWithKeys === undefined) {
35 throw new Error('addressWithKeys is undefined!');
38 const { keys } = addressWithKeys;
40 const activeKeys = await getActiveAddressKeys(address, currentSignedKeyList, currentKeys, keys);
42 const setFlags = <V extends ActiveKeyWithVersion>(activeKey: V) => ({
44 flags: getNewKeyFlags(
47 encryptionDisabled ? FlagAction.DISABLE_ENCRYPTION : FlagAction.ENABLE_ENCRYPTION
49 expectSignatureDisabled ? FlagAction.DISABLE_EXPECT_SIGNED : FlagAction.ENABLE_EXPECT_SIGNED
52 const newActiveKeys = getNormalizedActiveAddressKeys(address, {
53 v4: activeKeys.v4.map(setFlags),
54 v6: activeKeys.v6.map(setFlags),
56 const [newSignedKeyList, onSKLPublishSuccess] = await getSignedKeyListWithDeferredPublish(
61 await api(updateAddressFlags(address.ID, !encryptionDisabled, !expectSignatureDisabled, newSignedKeyList));
62 await onSKLPublishSuccess();