1 import type { PrivateKeyReference, PublicKeyReference } from '@proton/crypto';
3 import type { Attachment, Message } from '../../interfaces/mail/Message';
4 import type { AttachmentDirect, PackageDirect, SendPreferences } from '../../interfaces/mail/crypto';
5 import type { RequireOnly, SimpleMap } from '../../interfaces/utils';
6 import { encryptPackages } from './sendEncrypt';
7 import { attachSubPackages } from './sendSubPackages';
8 import { generateTopPackages } from './sendTopPackages';
10 const generatePackages = async ({
19 message: RequireOnly<Message, 'Body' | 'MIMEType'>;
21 sendPreferencesMap: SimpleMap<SendPreferences>;
22 attachments: Attachment[];
23 attachmentData: { attachment: AttachmentDirect; data: string };
24 publicKeys: PublicKeyReference[];
25 privateKeys: PrivateKeyReference[];
26 }): Promise<SimpleMap<PackageDirect>> => {
27 // There are two packages to be generated for the payload.
28 // The Packages in the request body, called here top-level packages
29 // The Packages inside Packages.addresses, called subpackages here
30 let packages = generateTopPackages({
35 packages = await attachSubPackages({
41 return encryptPackages({
50 export default generatePackages;