Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const { key, salt } = await getKeyFromPassword(password);
// Hybrid email encryption
const email: Email = {
text: 'email text',
attachments: ['email attachements'],
};
const { secretKey: bobPrivateKeys, publicKey: bobPublicKeys } = await generateEmailKeys();
const bobWithPublicKeys = {
Expand All @@ -125,7 +124,6 @@ expect(decryptedEmail).toStrictEqual(email);
const emailAndSubject: EmailAndSubject = {
text: 'email text',
subject: 'email subject'
attachments: ['email attachements'],
};
const encryptedEmailAndSubject = await encryptEmailAndSubjectHybrid(emailAndSubject, bobWithPublicKeys);
const decryptedEmailAndSubject = await decryptEmailAndSubjectHybrid(encryptedEmailAndSubject, bobPrivateKeys);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internxt-crypto",
"version": "1.4.0",
"version": "1.5.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"module": "dist/index.js",
Expand Down
21 changes: 2 additions & 19 deletions src/email-crypto/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,7 @@ export async function encryptEmailWithKey(

const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);
const encText = uint8ArrayToBase64(encryptedText);
const enc: EmailEncrypted = { encText };
if (email.attachments) {
const promises = email.attachments.map((attachment) => {
const binaryAttachment = UTF8ToUint8(attachment);
return encryptSymmetrically(encryptionKey, binaryAttachment, aux);
});
const encryptedAttachments = await Promise.all(promises);
enc.encAttachments = encryptedAttachments?.map(uint8ArrayToBase64);
}
return enc;
return { encText };
} catch (error) {
throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));
}
Expand All @@ -91,16 +82,8 @@ export async function decryptEmail(
const encText = base64ToUint8Array(encEmail.encText);
const textArray = await decryptSymmetrically(encryptionKey, encText, aux);
const text = uint8ToUTF8(textArray);
const email: Email = { text };

if (encEmail.encAttachments) {
const encAttachments = encEmail.encAttachments?.map(base64ToUint8Array);
const promises = encAttachments?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));
const decryptedAttachments = await Promise.all(promises);
email.attachments = decryptedAttachments?.map((att) => uint8ToUTF8(att));
}

return email;
return { text };
} catch (error) {
throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(error));
}
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export type PwdProtectedKey = {

export type EmailEncrypted = {
encText: string;
encAttachments?: string[];
};

export type EmailAndSubjectEncrypted = EmailEncrypted & {
Expand All @@ -57,7 +56,6 @@ export type EmailAndSubjectEncrypted = EmailEncrypted & {

export type Email = {
text: string;
attachments?: string[];
};

export type EmailAndSubject = Email & {
Expand Down
2 changes: 0 additions & 2 deletions tests/email-crypto/pwdProtectedEmailCoreErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ describe('Test email crypto functions', () => {

const email: Email = {
text: 'Hi Bob, This is a test message. -Alice.',
attachments: ['file1.txt', 'file2.txt'],
};

const emailAndSubject: EmailAndSubject = {
text: 'Hi Bob, This is a test message. -Alice.',
attachments: ['file1.txt', 'file2.txt'],
subject: 'test subject',
};

Expand Down
Loading