internxt-crypto 0.0.13 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -72
- package/dist/aes-B8TA-JKq.mjs +49 -0
- package/dist/aes-B8TA-JKq.mjs.map +1 -0
- package/dist/aes-CuW_SPl-.js +67 -0
- package/dist/aes-CuW_SPl-.js.map +1 -0
- package/dist/asymmetric-crypto.d.mts +8 -31
- package/dist/asymmetric-crypto.d.mts.map +1 -1
- package/dist/asymmetric-crypto.d.ts +8 -31
- package/dist/asymmetric-crypto.d.ts.map +1 -1
- package/dist/asymmetric-crypto.js +30 -7
- package/dist/asymmetric-crypto.js.map +1 -0
- package/dist/asymmetric-crypto.mjs +28 -2
- package/dist/asymmetric-crypto.mjs.map +1 -0
- package/dist/constants.d.mts +7 -14
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.d.ts +7 -14
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +11 -25
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +7 -14
- package/dist/constants.mjs.map +1 -1
- package/dist/core-Bj26rNdA.js +227 -0
- package/dist/core-Bj26rNdA.js.map +1 -0
- package/dist/core-pEGygy6S.mjs +173 -0
- package/dist/core-pEGygy6S.mjs.map +1 -0
- package/dist/derive-key.d.mts +1 -74
- package/dist/derive-key.d.mts.map +1 -1
- package/dist/derive-key.d.ts +1 -74
- package/dist/derive-key.d.ts.map +1 -1
- package/dist/derive-key.js +3 -11
- package/dist/derive-key.mjs +2 -2
- package/dist/derive-password.d.mts +22 -0
- package/dist/derive-password.d.mts.map +1 -0
- package/dist/derive-password.d.ts +22 -0
- package/dist/derive-password.d.ts.map +1 -0
- package/dist/derive-password.js +5 -0
- package/dist/derive-password.mjs +3 -0
- package/dist/deriveKeysFromKey-C4McqO6_.js +47 -0
- package/dist/deriveKeysFromKey-C4McqO6_.js.map +1 -0
- package/dist/deriveKeysFromKey-DPU_h7wr.mjs +35 -0
- package/dist/deriveKeysFromKey-DPU_h7wr.mjs.map +1 -0
- package/dist/{deriveKeysFromPassword-Ko7NxkHM.js → deriveKeysFromPassword-C7xAGGsh.js} +5 -177
- package/dist/deriveKeysFromPassword-C7xAGGsh.js.map +1 -0
- package/dist/{deriveKeysFromPassword-DJRWZ8Rw.mjs → deriveKeysFromPassword-DXgSvTNC.mjs} +7 -131
- package/dist/deriveKeysFromPassword-DXgSvTNC.mjs.map +1 -0
- package/dist/email-crypto.d.mts +24 -46
- package/dist/email-crypto.d.mts.map +1 -1
- package/dist/email-crypto.d.ts +24 -46
- package/dist/email-crypto.d.ts.map +1 -1
- package/dist/email-crypto.js +121 -12
- package/dist/email-crypto.js.map +1 -0
- package/dist/email-crypto.mjs +115 -2
- package/dist/email-crypto.mjs.map +1 -0
- package/dist/email-search.d.mts +18 -18
- package/dist/email-search.d.mts.map +1 -1
- package/dist/email-search.d.ts +18 -18
- package/dist/email-search.d.ts.map +1 -1
- package/dist/email-search.js +25 -597
- package/dist/email-search.mjs +2 -573
- package/dist/{emailEncryptionKey-27mIHh18.mjs → emailEncryptionKey-BtSPYd9M.mjs} +23 -46
- package/dist/emailEncryptionKey-BtSPYd9M.mjs.map +1 -0
- package/dist/{emailEncryptionKey-DbaDAdoW.js → emailEncryptionKey-C4X1Bwy4.js} +22 -45
- package/dist/emailEncryptionKey-C4X1Bwy4.js.map +1 -0
- package/dist/{genID-3Er5IowC.mjs → genID-D08K7JPr.mjs} +4 -40
- package/dist/genID-D08K7JPr.mjs.map +1 -0
- package/dist/{genID-YJSl3YhL.js → genID-cWOPmspk.js} +2 -50
- package/dist/genID-cWOPmspk.js.map +1 -0
- package/dist/hash.d.mts +24 -36
- package/dist/hash.d.mts.map +1 -1
- package/dist/hash.d.ts +24 -36
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +88 -10
- package/dist/hash.js.map +1 -0
- package/dist/hash.mjs +82 -2
- package/dist/hash.mjs.map +1 -0
- package/dist/index.d.mts +17 -16
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +17 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -83
- package/dist/index.mjs +13 -11
- package/dist/keystore-crypto.d.mts +6 -6
- package/dist/keystore-crypto.d.mts.map +1 -1
- package/dist/keystore-crypto.d.ts +6 -6
- package/dist/keystore-crypto.d.ts.map +1 -1
- package/dist/keystore-crypto.js +1 -1
- package/dist/keystore-crypto.mjs +1 -1
- package/dist/post-quantum-crypto.d.mts +5 -41
- package/dist/post-quantum-crypto.d.mts.map +1 -1
- package/dist/post-quantum-crypto.d.ts +5 -41
- package/dist/post-quantum-crypto.d.ts.map +1 -1
- package/dist/post-quantum-crypto.js +49 -16
- package/dist/post-quantum-crypto.js.map +1 -0
- package/dist/post-quantum-crypto.mjs +46 -2
- package/dist/post-quantum-crypto.mjs.map +1 -0
- package/dist/search-B9YM3XAA.mjs +587 -0
- package/dist/search-B9YM3XAA.mjs.map +1 -0
- package/dist/search-DUTm4-rN.js +731 -0
- package/dist/search-DUTm4-rN.js.map +1 -0
- package/dist/symmetric-crypto.d.mts +13 -42
- package/dist/symmetric-crypto.d.mts.map +1 -1
- package/dist/symmetric-crypto.d.ts +13 -42
- package/dist/symmetric-crypto.d.ts.map +1 -1
- package/dist/symmetric-crypto.js +2 -6
- package/dist/symmetric-crypto.mjs +2 -2
- package/dist/types.d.mts +16 -39
- package/dist/types.d.mts.map +1 -1
- package/dist/types.d.ts +16 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.d.mts +1 -19
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.d.ts +1 -19
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -3
- package/dist/utils.mjs +2 -2
- package/dist/xwing-CQmQX6hn.mjs +16 -0
- package/dist/xwing-CQmQX6hn.mjs.map +1 -0
- package/dist/xwing-iRWVRtNE.js +34 -0
- package/dist/xwing-iRWVRtNE.js.map +1 -0
- package/package.json +4 -2
- package/dist/aes-DSDxP8uF.mjs +0 -184
- package/dist/aes-DSDxP8uF.mjs.map +0 -1
- package/dist/aes-bOrKZuUC.js +0 -226
- package/dist/aes-bOrKZuUC.js.map +0 -1
- package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs.map +0 -1
- package/dist/deriveKeysFromPassword-Ko7NxkHM.js.map +0 -1
- package/dist/email-search.js.map +0 -1
- package/dist/email-search.mjs.map +0 -1
- package/dist/emailEncryptionKey-27mIHh18.mjs.map +0 -1
- package/dist/emailEncryptionKey-DbaDAdoW.js.map +0 -1
- package/dist/emailKeys-BJGdkLrg.js +0 -593
- package/dist/emailKeys-BJGdkLrg.js.map +0 -1
- package/dist/emailKeys-Fp9WR3wl.mjs +0 -509
- package/dist/emailKeys-Fp9WR3wl.mjs.map +0 -1
- package/dist/genID-3Er5IowC.mjs.map +0 -1
- package/dist/genID-YJSl3YhL.js.map +0 -1
- package/dist/keys-BfcaiAOv.mjs +0 -90
- package/dist/keys-BfcaiAOv.mjs.map +0 -1
- package/dist/keys-CinT7kEY.js +0 -125
- package/dist/keys-CinT7kEY.js.map +0 -1
- package/dist/kyber1024-PpwE1rki.mjs +0 -144
- package/dist/kyber1024-PpwE1rki.mjs.map +0 -1
- package/dist/kyber1024-jeKS8CXf.js +0 -173
- package/dist/kyber1024-jeKS8CXf.js.map +0 -1
- package/dist/kyber768-DGBB_RS7.d.ts +0 -32
- package/dist/kyber768-DGBB_RS7.d.ts.map +0 -1
- package/dist/kyber768-DzIcGg1i.d.mts +0 -32
- package/dist/kyber768-DzIcGg1i.d.mts.map +0 -1
- package/dist/mac-BMb1F0dN.js +0 -170
- package/dist/mac-BMb1F0dN.js.map +0 -1
- package/dist/mac-ZpRlx8Fs.mjs +0 -116
- package/dist/mac-ZpRlx8Fs.mjs.map +0 -1
package/dist/email-crypto.d.mts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmailBody, HybridEncryptedEmail, HybridKeyPair, PwdProtectedEmail, RecipientWithPublicKey } from "./types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/email-crypto/hybridEncyptedEmail.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Encrypts the email using hybrid encryption.
|
|
5
|
+
* Encrypts the email body using hybrid encryption.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param body - The email body to encrypt.
|
|
8
8
|
* @param recipientPublicKeys - The public keys of the recipient.
|
|
9
|
-
* @param
|
|
10
|
-
* @
|
|
11
|
-
* @returns The encrypted email
|
|
9
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
10
|
+
* @returns The encrypted email body
|
|
12
11
|
*/
|
|
13
|
-
declare function encryptEmailHybrid(
|
|
12
|
+
declare function encryptEmailHybrid(body: EmailBody, recipient: RecipientWithPublicKey, aux?: Uint8Array): Promise<HybridEncryptedEmail>;
|
|
14
13
|
/**
|
|
15
|
-
* Encrypts the email using hybrid encryption for multiple recipients.
|
|
14
|
+
* Encrypts the email body using hybrid encryption for multiple recipients.
|
|
16
15
|
*
|
|
17
|
-
* @param
|
|
16
|
+
* @param body - The email body to encrypt for multiple recipients.
|
|
18
17
|
* @param recipients - The recipients with corresponding public keys.
|
|
19
|
-
* @param
|
|
20
|
-
* @
|
|
21
|
-
* @returns The set of encrypted email
|
|
18
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
19
|
+
* @returns The set of encrypted email bodies
|
|
22
20
|
*/
|
|
23
|
-
declare function encryptEmailHybridForMultipleRecipients(
|
|
21
|
+
declare function encryptEmailHybridForMultipleRecipients(body: EmailBody, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<HybridEncryptedEmail[]>;
|
|
24
22
|
/**
|
|
25
23
|
* Decrypts the email using hybrid encryption.
|
|
26
24
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @returns The decrypted email
|
|
25
|
+
* @param encEmailBody - The encrypted email.
|
|
26
|
+
* @param recipientPrivateHybridKeys - The private key of the recipient.
|
|
27
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
28
|
+
* @returns The decrypted email body
|
|
31
29
|
*/
|
|
32
|
-
declare function decryptEmailHybrid(
|
|
30
|
+
declare function decryptEmailHybrid(encEmailBody: HybridEncryptedEmail, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<EmailBody>;
|
|
33
31
|
//#endregion
|
|
34
32
|
//#region src/email-crypto/pwdProtectedEmail.d.ts
|
|
35
33
|
/**
|
|
@@ -37,47 +35,27 @@ declare function decryptEmailHybrid(encryptedEmail: HybridEncryptedEmail, sender
|
|
|
37
35
|
*
|
|
38
36
|
* @param email - The email to password-protect
|
|
39
37
|
* @param password - The secret password shared among recipients
|
|
40
|
-
* @param
|
|
38
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
41
39
|
* @returns The password-protected email
|
|
42
40
|
*/
|
|
43
|
-
declare function createPwdProtectedEmail(
|
|
41
|
+
declare function createPwdProtectedEmail(emailBody: EmailBody, password: string, aux?: Uint8Array): Promise<PwdProtectedEmail>;
|
|
44
42
|
/**
|
|
45
43
|
* Opens a password-protected email.
|
|
46
44
|
*
|
|
47
45
|
* @param encryptedEmail - The encrypted email
|
|
48
46
|
* @param password - The secret password shared among recipients.
|
|
49
|
-
* @
|
|
47
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
48
|
+
* @returns The decrypted email body
|
|
50
49
|
*/
|
|
51
|
-
declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string): Promise<
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/email-crypto/converters.d.ts
|
|
54
|
-
declare function userToBytes(user: User): Uint8Array;
|
|
55
|
-
declare function recipientsToBytes(recipients: User[]): Uint8Array;
|
|
56
|
-
/**
|
|
57
|
-
* Converts an Email type into a Uint8Array array.
|
|
58
|
-
*
|
|
59
|
-
* @param email - The email.
|
|
60
|
-
* @returns The Uint8Array array representation of the Email type.
|
|
61
|
-
*/
|
|
62
|
-
declare function emailToBinary(email: Email): Uint8Array;
|
|
50
|
+
declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string, aux?: Uint8Array): Promise<EmailBody>;
|
|
63
51
|
//#endregion
|
|
64
52
|
//#region src/email-crypto/emailKeys.d.ts
|
|
65
53
|
/**
|
|
66
|
-
* Generates public and private keys for email
|
|
54
|
+
* Generates public and private keys for email encryption.
|
|
67
55
|
*
|
|
68
56
|
* @returns The user's private and public keys
|
|
69
57
|
*/
|
|
70
|
-
declare function generateEmailKeys(): Promise<
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/email-crypto/utils.d.ts
|
|
73
|
-
/**
|
|
74
|
-
* Creates an auxiliary string from public fields of the email.
|
|
75
|
-
*
|
|
76
|
-
* @param params - The email public parameters.
|
|
77
|
-
* @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
|
|
78
|
-
* @returns The resulting auxiliary string
|
|
79
|
-
*/
|
|
80
|
-
declare function getAux(params: EmailPublicParameters, isSubjectEncrypted: boolean): Uint8Array;
|
|
58
|
+
declare function generateEmailKeys(): Promise<HybridKeyPair>;
|
|
81
59
|
//#endregion
|
|
82
|
-
export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail,
|
|
60
|
+
export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys };
|
|
83
61
|
//# sourceMappingURL=email-crypto.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/
|
|
1
|
+
{"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;;;;;iBCAsB,uBAAA,CACpB,SAAA,EAAW,SAAA,EACX,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAmBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AD3BX;;;iBEHsB,iBAAA,CAAA,GAAqB,OAAA,CAAQ,aAAA"}
|
package/dist/email-crypto.d.ts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmailBody, HybridEncryptedEmail, HybridKeyPair, PwdProtectedEmail, RecipientWithPublicKey } from "./types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/email-crypto/hybridEncyptedEmail.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Encrypts the email using hybrid encryption.
|
|
5
|
+
* Encrypts the email body using hybrid encryption.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param body - The email body to encrypt.
|
|
8
8
|
* @param recipientPublicKeys - The public keys of the recipient.
|
|
9
|
-
* @param
|
|
10
|
-
* @
|
|
11
|
-
* @returns The encrypted email
|
|
9
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
10
|
+
* @returns The encrypted email body
|
|
12
11
|
*/
|
|
13
|
-
declare function encryptEmailHybrid(
|
|
12
|
+
declare function encryptEmailHybrid(body: EmailBody, recipient: RecipientWithPublicKey, aux?: Uint8Array): Promise<HybridEncryptedEmail>;
|
|
14
13
|
/**
|
|
15
|
-
* Encrypts the email using hybrid encryption for multiple recipients.
|
|
14
|
+
* Encrypts the email body using hybrid encryption for multiple recipients.
|
|
16
15
|
*
|
|
17
|
-
* @param
|
|
16
|
+
* @param body - The email body to encrypt for multiple recipients.
|
|
18
17
|
* @param recipients - The recipients with corresponding public keys.
|
|
19
|
-
* @param
|
|
20
|
-
* @
|
|
21
|
-
* @returns The set of encrypted email
|
|
18
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
19
|
+
* @returns The set of encrypted email bodies
|
|
22
20
|
*/
|
|
23
|
-
declare function encryptEmailHybridForMultipleRecipients(
|
|
21
|
+
declare function encryptEmailHybridForMultipleRecipients(body: EmailBody, recipients: RecipientWithPublicKey[], aux?: Uint8Array): Promise<HybridEncryptedEmail[]>;
|
|
24
22
|
/**
|
|
25
23
|
* Decrypts the email using hybrid encryption.
|
|
26
24
|
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @returns The decrypted email
|
|
25
|
+
* @param encEmailBody - The encrypted email.
|
|
26
|
+
* @param recipientPrivateHybridKeys - The private key of the recipient.
|
|
27
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
28
|
+
* @returns The decrypted email body
|
|
31
29
|
*/
|
|
32
|
-
declare function decryptEmailHybrid(
|
|
30
|
+
declare function decryptEmailHybrid(encEmailBody: HybridEncryptedEmail, recipientPrivateHybridKeys: Uint8Array, aux?: Uint8Array): Promise<EmailBody>;
|
|
33
31
|
//#endregion
|
|
34
32
|
//#region src/email-crypto/pwdProtectedEmail.d.ts
|
|
35
33
|
/**
|
|
@@ -37,47 +35,27 @@ declare function decryptEmailHybrid(encryptedEmail: HybridEncryptedEmail, sender
|
|
|
37
35
|
*
|
|
38
36
|
* @param email - The email to password-protect
|
|
39
37
|
* @param password - The secret password shared among recipients
|
|
40
|
-
* @param
|
|
38
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
41
39
|
* @returns The password-protected email
|
|
42
40
|
*/
|
|
43
|
-
declare function createPwdProtectedEmail(
|
|
41
|
+
declare function createPwdProtectedEmail(emailBody: EmailBody, password: string, aux?: Uint8Array): Promise<PwdProtectedEmail>;
|
|
44
42
|
/**
|
|
45
43
|
* Opens a password-protected email.
|
|
46
44
|
*
|
|
47
45
|
* @param encryptedEmail - The encrypted email
|
|
48
46
|
* @param password - The secret password shared among recipients.
|
|
49
|
-
* @
|
|
47
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
48
|
+
* @returns The decrypted email body
|
|
50
49
|
*/
|
|
51
|
-
declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string): Promise<
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/email-crypto/converters.d.ts
|
|
54
|
-
declare function userToBytes(user: User): Uint8Array;
|
|
55
|
-
declare function recipientsToBytes(recipients: User[]): Uint8Array;
|
|
56
|
-
/**
|
|
57
|
-
* Converts an Email type into a Uint8Array array.
|
|
58
|
-
*
|
|
59
|
-
* @param email - The email.
|
|
60
|
-
* @returns The Uint8Array array representation of the Email type.
|
|
61
|
-
*/
|
|
62
|
-
declare function emailToBinary(email: Email): Uint8Array;
|
|
50
|
+
declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, password: string, aux?: Uint8Array): Promise<EmailBody>;
|
|
63
51
|
//#endregion
|
|
64
52
|
//#region src/email-crypto/emailKeys.d.ts
|
|
65
53
|
/**
|
|
66
|
-
* Generates public and private keys for email
|
|
54
|
+
* Generates public and private keys for email encryption.
|
|
67
55
|
*
|
|
68
56
|
* @returns The user's private and public keys
|
|
69
57
|
*/
|
|
70
|
-
declare function generateEmailKeys(): Promise<
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/email-crypto/utils.d.ts
|
|
73
|
-
/**
|
|
74
|
-
* Creates an auxiliary string from public fields of the email.
|
|
75
|
-
*
|
|
76
|
-
* @param params - The email public parameters.
|
|
77
|
-
* @param isSubjectEncrypted - Indicates if the email subject field should be encrypted
|
|
78
|
-
* @returns The resulting auxiliary string
|
|
79
|
-
*/
|
|
80
|
-
declare function getAux(params: EmailPublicParameters, isSubjectEncrypted: boolean): Uint8Array;
|
|
58
|
+
declare function generateEmailKeys(): Promise<HybridKeyPair>;
|
|
81
59
|
//#endregion
|
|
82
|
-
export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail,
|
|
60
|
+
export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys };
|
|
83
61
|
//# sourceMappingURL=email-crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-crypto.d.ts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/
|
|
1
|
+
{"version":3,"file":"email-crypto.d.ts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;;;;;iBCAsB,uBAAA,CACpB,SAAA,EAAW,SAAA,EACX,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAmBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AD3BX;;;iBEHsB,iBAAA,CAAA,GAAqB,OAAA,CAAQ,aAAA"}
|
package/dist/email-crypto.js
CHANGED
|
@@ -1,13 +1,122 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
const require_xwing = require('./xwing-iRWVRtNE.js');
|
|
3
|
+
const require_core = require('./core-Bj26rNdA.js');
|
|
4
|
+
|
|
5
|
+
//#region src/email-crypto/hybridEncyptedEmail.ts
|
|
6
|
+
/**
|
|
7
|
+
* Encrypts the email body using hybrid encryption.
|
|
8
|
+
*
|
|
9
|
+
* @param body - The email body to encrypt.
|
|
10
|
+
* @param recipientPublicKeys - The public keys of the recipient.
|
|
11
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
12
|
+
* @returns The encrypted email body
|
|
13
|
+
*/
|
|
14
|
+
async function encryptEmailHybrid(body, recipient, aux) {
|
|
15
|
+
try {
|
|
16
|
+
const { encryptionKey, encEmailBody } = await require_core.encryptEmailBody(body, aux);
|
|
17
|
+
return {
|
|
18
|
+
encEmailBody,
|
|
19
|
+
encryptedKey: await require_core.encryptKeysHybrid(encryptionKey, recipient)
|
|
20
|
+
};
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new Error("Failed to encrypt email body with hybrid encryption", { cause: error });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Encrypts the email body using hybrid encryption for multiple recipients.
|
|
27
|
+
*
|
|
28
|
+
* @param body - The email body to encrypt for multiple recipients.
|
|
29
|
+
* @param recipients - The recipients with corresponding public keys.
|
|
30
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
31
|
+
* @returns The set of encrypted email bodies
|
|
32
|
+
*/
|
|
33
|
+
async function encryptEmailHybridForMultipleRecipients(body, recipients, aux) {
|
|
34
|
+
try {
|
|
35
|
+
const { encryptionKey, encEmailBody } = await require_core.encryptEmailBody(body, aux);
|
|
36
|
+
const encryptedEmails = [];
|
|
37
|
+
for (const recipient of recipients) {
|
|
38
|
+
const encryptedKey = await require_core.encryptKeysHybrid(encryptionKey, recipient);
|
|
39
|
+
encryptedEmails.push({
|
|
40
|
+
encEmailBody,
|
|
41
|
+
encryptedKey
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return encryptedEmails;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Decrypts the email using hybrid encryption.
|
|
51
|
+
*
|
|
52
|
+
* @param encEmailBody - The encrypted email.
|
|
53
|
+
* @param recipientPrivateHybridKeys - The private key of the recipient.
|
|
54
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
55
|
+
* @returns The decrypted email body
|
|
56
|
+
*/
|
|
57
|
+
async function decryptEmailHybrid(encEmailBody, recipientPrivateHybridKeys, aux) {
|
|
58
|
+
try {
|
|
59
|
+
const encryptionKey = await require_core.decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);
|
|
60
|
+
return await require_core.decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/email-crypto/pwdProtectedEmail.ts
|
|
68
|
+
/**
|
|
69
|
+
* Creates a password-protected email.
|
|
70
|
+
*
|
|
71
|
+
* @param email - The email to password-protect
|
|
72
|
+
* @param password - The secret password shared among recipients
|
|
73
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
74
|
+
* @returns The password-protected email
|
|
75
|
+
*/
|
|
76
|
+
async function createPwdProtectedEmail(emailBody, password, aux) {
|
|
77
|
+
try {
|
|
78
|
+
const { encryptionKey, encEmailBody } = await require_core.encryptEmailBody(emailBody, aux);
|
|
79
|
+
return {
|
|
80
|
+
encEmailBody,
|
|
81
|
+
encryptedKey: await require_core.passwordProtectKey(encryptionKey, password)
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new Error("Failed to password-protect email", { cause: error });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Opens a password-protected email.
|
|
89
|
+
*
|
|
90
|
+
* @param encryptedEmail - The encrypted email
|
|
91
|
+
* @param password - The secret password shared among recipients.
|
|
92
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
93
|
+
* @returns The decrypted email body
|
|
94
|
+
*/
|
|
95
|
+
async function decryptPwdProtectedEmail(encryptedEmail, password, aux) {
|
|
96
|
+
try {
|
|
97
|
+
const encryptionKey = await require_core.removePasswordProtection(encryptedEmail.encryptedKey, password);
|
|
98
|
+
return await require_core.decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new Error("Failed to decrypt password-protect email", { cause: error });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/email-crypto/emailKeys.ts
|
|
106
|
+
/**
|
|
107
|
+
* Generates public and private keys for email encryption.
|
|
108
|
+
*
|
|
109
|
+
* @returns The user's private and public keys
|
|
110
|
+
*/
|
|
111
|
+
async function generateEmailKeys() {
|
|
112
|
+
return require_xwing.genHybridKeys();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
exports.createPwdProtectedEmail = createPwdProtectedEmail;
|
|
117
|
+
exports.decryptEmailHybrid = decryptEmailHybrid;
|
|
118
|
+
exports.decryptPwdProtectedEmail = decryptPwdProtectedEmail;
|
|
119
|
+
exports.encryptEmailHybrid = encryptEmailHybrid;
|
|
120
|
+
exports.encryptEmailHybridForMultipleRecipients = encryptEmailHybridForMultipleRecipients;
|
|
121
|
+
exports.generateEmailKeys = generateEmailKeys;
|
|
122
|
+
//# sourceMappingURL=email-crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-crypto.js","names":["encryptEmailBody","encryptKeysHybrid","decryptKeysHybrid","decryptEmailBody","encryptEmailBody","passwordProtectKey","removePasswordProtection","decryptEmailBody","genHybridKeys"],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"sourcesContent":["import { HybridEncryptedEmail, EmailBody, RecipientWithPublicKey } from '../types';\nimport { decryptEmailBody, encryptKeysHybrid, decryptKeysHybrid, encryptEmailBody } from './core';\n\n/**\n * Encrypts the email body using hybrid encryption.\n *\n * @param body - The email body to encrypt.\n * @param recipientPublicKeys - The public keys of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The encrypted email body\n */\nexport async function encryptEmailHybrid(\n body: EmailBody,\n recipient: RecipientWithPublicKey,\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to encrypt email body with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Encrypts the email body using hybrid encryption for multiple recipients.\n *\n * @param body - The email body to encrypt for multiple recipients.\n * @param recipients - The recipients with corresponding public keys.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The set of encrypted email bodies\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n body: EmailBody,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail[]> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n\n const encryptedEmails: HybridEncryptedEmail[] = [];\n for (const recipient of recipients) {\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n encryptedEmails.push({\n encEmailBody: encEmailBody,\n encryptedKey,\n });\n }\n return encryptedEmails;\n } catch (error) {\n throw new Error('Failed to encrypt email to multiple recipients with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email using hybrid encryption.\n *\n * @param encEmailBody - The encrypted email.\n * @param recipientPrivateHybridKeys - The private key of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptEmailHybrid(\n encEmailBody: HybridEncryptedEmail,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);\n const body = await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt email with hybrid encryption', { cause: error });\n }\n}\n","import { PwdProtectedEmail, EmailBody } from '../types';\nimport { decryptEmailBody, passwordProtectKey, removePasswordProtection, encryptEmailBody } from './core';\n\n/**\n * Creates a password-protected email.\n *\n * @param email - The email to password-protect\n * @param password - The secret password shared among recipients\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The password-protected email\n */\nexport async function createPwdProtectedEmail(\n emailBody: EmailBody,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to password-protect email', { cause: error });\n }\n}\n\n/**\n * Opens a password-protected email.\n *\n * @param encryptedEmail - The encrypted email\n * @param password - The secret password shared among recipients.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n const body = await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt password-protect email', { cause: error });\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\n\n/**\n * Generates public and private keys for email encryption.\n *\n * @returns The user's private and public keys\n */\nexport async function generateEmailKeys(): Promise<HybridKeyPair> {\n return genHybridKeys();\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,eAAsB,mBACpB,MACA,WACA,KAC+B;AAC/B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAMA,8BAAiB,MAAM,IAAI;AAEzE,SAAO;GAAE;GAAc,cADF,MAAMC,+BAAkB,eAAe,UAAU;GACjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,uDAAuD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY5F,eAAsB,wCACpB,MACA,YACA,KACiC;AACjC,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAMD,8BAAiB,MAAM,IAAI;EAEzE,MAAM,kBAA0C,EAAE;AAClD,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,eAAe,MAAMC,+BAAkB,eAAe,UAAU;AACtE,mBAAgB,KAAK;IACL;IACd;IACD,CAAC;;AAEJ,SAAO;UACA,OAAO;AACd,QAAM,IAAI,MAAM,yEAAyE,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY9G,eAAsB,mBACpB,cACA,4BACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAMC,+BAAkB,aAAa,cAAc,2BAA2B;AAEpG,SADa,MAAMC,8BAAiB,aAAa,cAAc,eAAe,IAAI;UAE3E,OAAO;AACd,QAAM,IAAI,MAAM,kDAAkD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;AC9DvF,eAAsB,wBACpB,WACA,UACA,KAC4B;AAC5B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAMC,8BAAiB,WAAW,IAAI;AAG9E,SAAO;GAAE;GAAc,cAFF,MAAMC,gCAAmB,eAAe,SAAS;GAEjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAYzE,eAAsB,yBACpB,gBACA,UACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAMC,sCAAyB,eAAe,cAAc,SAAS;AAE3F,SADa,MAAMC,8BAAiB,eAAe,cAAc,eAAe,IAAI;UAE7E,OAAO;AACd,QAAM,IAAI,MAAM,4CAA4C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACpCjF,eAAsB,oBAA4C;AAChE,QAAOC,6BAAe"}
|
package/dist/email-crypto.mjs
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as genHybridKeys } from "./xwing-CQmQX6hn.mjs";
|
|
2
|
+
import { a as encryptKeysHybrid, n as decryptKeysHybrid, o as passwordProtectKey, r as encryptEmailBody, s as removePasswordProtection, t as decryptEmailBody } from "./core-pEGygy6S.mjs";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/email-crypto/hybridEncyptedEmail.ts
|
|
5
|
+
/**
|
|
6
|
+
* Encrypts the email body using hybrid encryption.
|
|
7
|
+
*
|
|
8
|
+
* @param body - The email body to encrypt.
|
|
9
|
+
* @param recipientPublicKeys - The public keys of the recipient.
|
|
10
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
11
|
+
* @returns The encrypted email body
|
|
12
|
+
*/
|
|
13
|
+
async function encryptEmailHybrid(body, recipient, aux) {
|
|
14
|
+
try {
|
|
15
|
+
const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);
|
|
16
|
+
return {
|
|
17
|
+
encEmailBody,
|
|
18
|
+
encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
|
|
19
|
+
};
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new Error("Failed to encrypt email body with hybrid encryption", { cause: error });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Encrypts the email body using hybrid encryption for multiple recipients.
|
|
26
|
+
*
|
|
27
|
+
* @param body - The email body to encrypt for multiple recipients.
|
|
28
|
+
* @param recipients - The recipients with corresponding public keys.
|
|
29
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
30
|
+
* @returns The set of encrypted email bodies
|
|
31
|
+
*/
|
|
32
|
+
async function encryptEmailHybridForMultipleRecipients(body, recipients, aux) {
|
|
33
|
+
try {
|
|
34
|
+
const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);
|
|
35
|
+
const encryptedEmails = [];
|
|
36
|
+
for (const recipient of recipients) {
|
|
37
|
+
const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);
|
|
38
|
+
encryptedEmails.push({
|
|
39
|
+
encEmailBody,
|
|
40
|
+
encryptedKey
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return encryptedEmails;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Decrypts the email using hybrid encryption.
|
|
50
|
+
*
|
|
51
|
+
* @param encEmailBody - The encrypted email.
|
|
52
|
+
* @param recipientPrivateHybridKeys - The private key of the recipient.
|
|
53
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
54
|
+
* @returns The decrypted email body
|
|
55
|
+
*/
|
|
56
|
+
async function decryptEmailHybrid(encEmailBody, recipientPrivateHybridKeys, aux) {
|
|
57
|
+
try {
|
|
58
|
+
const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);
|
|
59
|
+
return await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/email-crypto/pwdProtectedEmail.ts
|
|
67
|
+
/**
|
|
68
|
+
* Creates a password-protected email.
|
|
69
|
+
*
|
|
70
|
+
* @param email - The email to password-protect
|
|
71
|
+
* @param password - The secret password shared among recipients
|
|
72
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
73
|
+
* @returns The password-protected email
|
|
74
|
+
*/
|
|
75
|
+
async function createPwdProtectedEmail(emailBody, password, aux) {
|
|
76
|
+
try {
|
|
77
|
+
const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);
|
|
78
|
+
return {
|
|
79
|
+
encEmailBody,
|
|
80
|
+
encryptedKey: await passwordProtectKey(encryptionKey, password)
|
|
81
|
+
};
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error("Failed to password-protect email", { cause: error });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Opens a password-protected email.
|
|
88
|
+
*
|
|
89
|
+
* @param encryptedEmail - The encrypted email
|
|
90
|
+
* @param password - The secret password shared among recipients.
|
|
91
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
92
|
+
* @returns The decrypted email body
|
|
93
|
+
*/
|
|
94
|
+
async function decryptPwdProtectedEmail(encryptedEmail, password, aux) {
|
|
95
|
+
try {
|
|
96
|
+
const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);
|
|
97
|
+
return await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
throw new Error("Failed to decrypt password-protect email", { cause: error });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/email-crypto/emailKeys.ts
|
|
105
|
+
/**
|
|
106
|
+
* Generates public and private keys for email encryption.
|
|
107
|
+
*
|
|
108
|
+
* @returns The user's private and public keys
|
|
109
|
+
*/
|
|
110
|
+
async function generateEmailKeys() {
|
|
111
|
+
return genHybridKeys();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { createPwdProtectedEmail, decryptEmailHybrid, decryptPwdProtectedEmail, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, generateEmailKeys };
|
|
116
|
+
//# sourceMappingURL=email-crypto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-crypto.mjs","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts"],"sourcesContent":["import { HybridEncryptedEmail, EmailBody, RecipientWithPublicKey } from '../types';\nimport { decryptEmailBody, encryptKeysHybrid, decryptKeysHybrid, encryptEmailBody } from './core';\n\n/**\n * Encrypts the email body using hybrid encryption.\n *\n * @param body - The email body to encrypt.\n * @param recipientPublicKeys - The public keys of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The encrypted email body\n */\nexport async function encryptEmailHybrid(\n body: EmailBody,\n recipient: RecipientWithPublicKey,\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to encrypt email body with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Encrypts the email body using hybrid encryption for multiple recipients.\n *\n * @param body - The email body to encrypt for multiple recipients.\n * @param recipients - The recipients with corresponding public keys.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The set of encrypted email bodies\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n body: EmailBody,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail[]> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n\n const encryptedEmails: HybridEncryptedEmail[] = [];\n for (const recipient of recipients) {\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n encryptedEmails.push({\n encEmailBody: encEmailBody,\n encryptedKey,\n });\n }\n return encryptedEmails;\n } catch (error) {\n throw new Error('Failed to encrypt email to multiple recipients with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email using hybrid encryption.\n *\n * @param encEmailBody - The encrypted email.\n * @param recipientPrivateHybridKeys - The private key of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptEmailHybrid(\n encEmailBody: HybridEncryptedEmail,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);\n const body = await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt email with hybrid encryption', { cause: error });\n }\n}\n","import { PwdProtectedEmail, EmailBody } from '../types';\nimport { decryptEmailBody, passwordProtectKey, removePasswordProtection, encryptEmailBody } from './core';\n\n/**\n * Creates a password-protected email.\n *\n * @param email - The email to password-protect\n * @param password - The secret password shared among recipients\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The password-protected email\n */\nexport async function createPwdProtectedEmail(\n emailBody: EmailBody,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to password-protect email', { cause: error });\n }\n}\n\n/**\n * Opens a password-protected email.\n *\n * @param encryptedEmail - The encrypted email\n * @param password - The secret password shared among recipients.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n const body = await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt password-protect email', { cause: error });\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\n\n/**\n * Generates public and private keys for email encryption.\n *\n * @returns The user's private and public keys\n */\nexport async function generateEmailKeys(): Promise<HybridKeyPair> {\n return genHybridKeys();\n}\n"],"mappings":";;;;;;;;;;;;AAWA,eAAsB,mBACpB,MACA,WACA,KAC+B;AAC/B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAM,iBAAiB,MAAM,IAAI;AAEzE,SAAO;GAAE;GAAc,cADF,MAAM,kBAAkB,eAAe,UAAU;GACjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,uDAAuD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY5F,eAAsB,wCACpB,MACA,YACA,KACiC;AACjC,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAM,iBAAiB,MAAM,IAAI;EAEzE,MAAM,kBAA0C,EAAE;AAClD,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,eAAe,MAAM,kBAAkB,eAAe,UAAU;AACtE,mBAAgB,KAAK;IACL;IACd;IACD,CAAC;;AAEJ,SAAO;UACA,OAAO;AACd,QAAM,IAAI,MAAM,yEAAyE,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY9G,eAAsB,mBACpB,cACA,4BACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAM,kBAAkB,aAAa,cAAc,2BAA2B;AAEpG,SADa,MAAM,iBAAiB,aAAa,cAAc,eAAe,IAAI;UAE3E,OAAO;AACd,QAAM,IAAI,MAAM,kDAAkD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;AC9DvF,eAAsB,wBACpB,WACA,UACA,KAC4B;AAC5B,KAAI;EACF,MAAM,EAAE,eAAe,iBAAiB,MAAM,iBAAiB,WAAW,IAAI;AAG9E,SAAO;GAAE;GAAc,cAFF,MAAM,mBAAmB,eAAe,SAAS;GAEjC;UAC9B,OAAO;AACd,QAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAYzE,eAAsB,yBACpB,gBACA,UACA,KACoB;AACpB,KAAI;EACF,MAAM,gBAAgB,MAAM,yBAAyB,eAAe,cAAc,SAAS;AAE3F,SADa,MAAM,iBAAiB,eAAe,cAAc,eAAe,IAAI;UAE7E,OAAO;AACd,QAAM,IAAI,MAAM,4CAA4C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACpCjF,eAAsB,oBAA4C;AAChE,QAAO,eAAe"}
|
package/dist/email-search.d.mts
CHANGED
|
@@ -37,42 +37,42 @@ declare const deleteDatabase: (userID: string) => Promise<void>;
|
|
|
37
37
|
* Derives database encryption key for the given user
|
|
38
38
|
*
|
|
39
39
|
* @param userID - The user ID
|
|
40
|
-
* @returns The symmetric
|
|
40
|
+
* @returns The symmetric key for protecting database
|
|
41
41
|
*/
|
|
42
|
-
declare const deriveIndexKey: (baseKey: Uint8Array) => Promise<
|
|
42
|
+
declare const deriveIndexKey: (baseKey: Uint8Array) => Promise<Uint8Array>;
|
|
43
43
|
/**
|
|
44
44
|
* Encrypts the given email and stores it in the IndexedDB database
|
|
45
45
|
*
|
|
46
46
|
* @param newEmailToStore - The email for storing
|
|
47
|
-
* @param indexKey - The symmetric
|
|
47
|
+
* @param indexKey - The symmetric key for protecting database
|
|
48
48
|
* @param esDB - The database
|
|
49
49
|
*/
|
|
50
|
-
declare const encryptAndStoreEmail: (newEmailToStore: Email, indexKey:
|
|
50
|
+
declare const encryptAndStoreEmail: (newEmailToStore: Email, indexKey: Uint8Array, esDB: MailDB) => Promise<void>;
|
|
51
51
|
/**
|
|
52
52
|
* Encrypts the given set of emails and stores it in the IndexedDB database
|
|
53
53
|
*
|
|
54
54
|
* @param newEmailsToStore - The set of emails for storing
|
|
55
|
-
* @param indexKey - The symmetric
|
|
55
|
+
* @param indexKey - The symmetric key key for protecting database
|
|
56
56
|
* @param esDB - The database
|
|
57
57
|
*/
|
|
58
|
-
declare const encryptAndStoreManyEmail: (newEmailsToStore: Email[], indexKey:
|
|
58
|
+
declare const encryptAndStoreManyEmail: (newEmailsToStore: Email[], indexKey: Uint8Array, esDB: MailDB) => Promise<void>;
|
|
59
59
|
/**
|
|
60
60
|
* Fetches the email from the database and decrypts it
|
|
61
61
|
*
|
|
62
62
|
* @param emailID - The email identifier
|
|
63
|
-
* @param indexKey - The symmetric
|
|
63
|
+
* @param indexKey - The symmetric key key for protecting database
|
|
64
64
|
* @param encryptedEmail - The encrypted email
|
|
65
65
|
* @returns The decrypted email
|
|
66
66
|
*/
|
|
67
|
-
declare const getAndDecryptEmail: (emailID: string, indexKey:
|
|
67
|
+
declare const getAndDecryptEmail: (emailID: string, indexKey: Uint8Array, esDB: MailDB) => Promise<Email>;
|
|
68
68
|
/**
|
|
69
69
|
* Fetches all email from the database and decrypts them
|
|
70
70
|
*
|
|
71
|
-
* @param indexKey - The symmetric
|
|
71
|
+
* @param indexKey - The symmetric key key for protecting database
|
|
72
72
|
* @param esDB - The database
|
|
73
73
|
* @returns The decrypted emails
|
|
74
74
|
*/
|
|
75
|
-
declare const getAndDecryptAllEmails: (indexKey:
|
|
75
|
+
declare const getAndDecryptAllEmails: (indexKey: Uint8Array, esDB: MailDB) => Promise<Email[]>;
|
|
76
76
|
/**
|
|
77
77
|
* Deletes the email from the database
|
|
78
78
|
*
|
|
@@ -105,28 +105,28 @@ declare const enforceMaxEmailNumber: (esDB: MailDB, max: number) => Promise<void
|
|
|
105
105
|
* Fetches all emails from the database, decrypts them and sortes the results based on the creation time (newest first)
|
|
106
106
|
*
|
|
107
107
|
* @param esDB - The database
|
|
108
|
-
* @param indexKey - The symmetric
|
|
108
|
+
* @param indexKey - The symmetric Uint8Array key for protecting database
|
|
109
109
|
* @returns The number of stored emails
|
|
110
110
|
*/
|
|
111
|
-
declare const getAllEmailsSortedNewestFirst: (esDB: MailDB, indexKey:
|
|
111
|
+
declare const getAllEmailsSortedNewestFirst: (esDB: MailDB, indexKey: Uint8Array) => Promise<Email[]>;
|
|
112
112
|
/**
|
|
113
113
|
* Fetches all emails from the database, decrypts them and sortes the results based on the creation time (oldest first)
|
|
114
114
|
*
|
|
115
115
|
* @param esDB - The database
|
|
116
|
-
* @param indexKey - The symmetric
|
|
116
|
+
* @param indexKey - The symmetric key for protecting database
|
|
117
117
|
* @returns The number of stored emails
|
|
118
118
|
*/
|
|
119
|
-
declare const getAllEmailsSortedOldestFirst: (esDB: MailDB, indexKey:
|
|
119
|
+
declare const getAllEmailsSortedOldestFirst: (esDB: MailDB, indexKey: Uint8Array) => Promise<Email[]>;
|
|
120
120
|
/**
|
|
121
121
|
* Fetches a batch of emails from the database, decrypts them and sortes the results based on the creation time (newest first)
|
|
122
122
|
*
|
|
123
123
|
* @param esDB - The database
|
|
124
|
-
* @param indexKey - The symmetric
|
|
124
|
+
* @param indexKey - The symmetric key for protecting database
|
|
125
125
|
* @param batchSize - The size of the batch
|
|
126
126
|
* @param startCursor - The starting point (optional). If not given, starts from the beginning
|
|
127
127
|
* @returns The number of stored emails
|
|
128
128
|
*/
|
|
129
|
-
declare const getEmailBatch: (esDB: MailDB, indexKey:
|
|
129
|
+
declare const getEmailBatch: (esDB: MailDB, indexKey: Uint8Array, batchSize: number, startCursor?: IDBValidKey) => Promise<{
|
|
130
130
|
emails: Email[];
|
|
131
131
|
nextCursor?: IDBValidKey;
|
|
132
132
|
}>;
|
|
@@ -135,11 +135,11 @@ declare const getEmailBatch: (esDB: MailDB, indexKey: CryptoKey, batchSize: numb
|
|
|
135
135
|
/**
|
|
136
136
|
* Fetches all emails from the database in batches and cahces them
|
|
137
137
|
*
|
|
138
|
-
* @param indexKey - The symmetric
|
|
138
|
+
* @param indexKey - The symmetric key for protecting database
|
|
139
139
|
* @param esCache - The cache to add emails too
|
|
140
140
|
* @param esDB - The database
|
|
141
141
|
*/
|
|
142
|
-
declare const createCacheFromDB: (indexKey:
|
|
142
|
+
declare const createCacheFromDB: (indexKey: Uint8Array, esDB: MailDB) => Promise<MailCache<Email>>;
|
|
143
143
|
/**
|
|
144
144
|
* Gets an email from the cache
|
|
145
145
|
*
|