internxt-crypto 0.0.14 → 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 +3 -10
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.d.ts +3 -10
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -17
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +3 -10
- 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-BYaiSGKL.js → deriveKeysFromPassword-C7xAGGsh.js} +5 -172
- package/dist/deriveKeysFromPassword-C7xAGGsh.js.map +1 -0
- package/dist/{deriveKeysFromPassword-XIwzErlL.mjs → deriveKeysFromPassword-DXgSvTNC.mjs} +6 -125
- 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.map +1 -1
- 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-B9xHw1h_.mjs → emailEncryptionKey-BtSPYd9M.mjs} +22 -45
- package/dist/emailEncryptionKey-BtSPYd9M.mjs.map +1 -0
- package/dist/{emailEncryptionKey-CQNe5W_T.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 +9 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -79
- 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.js +49 -4
- 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 +11 -40
- package/dist/symmetric-crypto.d.mts.map +1 -1
- package/dist/symmetric-crypto.d.ts +11 -40
- 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 +13 -40
- package/dist/types.d.mts.map +1 -1
- package/dist/types.d.ts +13 -40
- 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 +3 -2
- package/dist/aes-DCb9dJqb.mjs +0 -161
- package/dist/aes-DCb9dJqb.mjs.map +0 -1
- package/dist/aes-DQo1MyCz.js +0 -203
- package/dist/aes-DQo1MyCz.js.map +0 -1
- package/dist/deriveKeysFromPassword-BYaiSGKL.js.map +0 -1
- package/dist/deriveKeysFromPassword-XIwzErlL.mjs.map +0 -1
- package/dist/email-search.js.map +0 -1
- package/dist/email-search.mjs.map +0 -1
- package/dist/emailEncryptionKey-B9xHw1h_.mjs.map +0 -1
- package/dist/emailEncryptionKey-CQNe5W_T.js.map +0 -1
- package/dist/emailKeys-C0KhtfNP.js +0 -572
- package/dist/emailKeys-C0KhtfNP.js.map +0 -1
- package/dist/emailKeys-D4lp9NRv.mjs +0 -488
- package/dist/emailKeys-D4lp9NRv.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/kyber768-SXnIo-Nw.mjs +0 -47
- package/dist/kyber768-SXnIo-Nw.mjs.map +0 -1
- package/dist/kyber768-WUVc2fIR.js +0 -65
- package/dist/kyber768-WUVc2fIR.js.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/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const AES_KEY_BYTE_LENGTH = 32;\nexport const IV_LEN_BYTES = 12;\n\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n\nexport const XWING_PUBLIC_KEY_LENGTH = 1216;\nexport const XWING_SECRET_KEY_LENGTH = 32;\nexport const XWING_SEED_BYTE_LENGTH = 32;\nexport const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;\n"],"mappings":";;;AAAA,MAAa,sBAAsB;AACnC,MAAa,eAAe;AAE5B,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAG9B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAE3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAC1C,MAAa,oBAAoB;AAEjC,MAAa,iBAAiB;AAC9B,MAAa,sBAAsB;AACnC,MAAa,WAAW;AACxB,MAAa,aAAa;AAE1B,MAAa,0BAA0B;AACvC,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;AACtC,MAAa,+BAA+B"}
|
package/dist/constants.mjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
//#region src/constants.ts
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const AUX_BYTE_LEN = 16;
|
|
5
|
-
const IV_LEN_BYTES = 16;
|
|
6
|
-
const KEY_WRAPPING_ALGORITHM = "AES-KW";
|
|
7
|
-
const KEY_FORMAT = "raw";
|
|
8
|
-
const CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
|
|
9
|
-
const ECC_ALGORITHM = "X25519";
|
|
2
|
+
const AES_KEY_BYTE_LENGTH = 32;
|
|
3
|
+
const IV_LEN_BYTES = 12;
|
|
10
4
|
const CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
|
|
11
5
|
const CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
|
|
12
6
|
const CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
|
|
@@ -19,7 +13,6 @@ const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
|
|
|
19
13
|
const KYBER768_PUBLIC_KEY_LENGTH = 1184;
|
|
20
14
|
const KYBER768_SECRET_KEY_LENGTH = 2400;
|
|
21
15
|
const KYBER_SEED_LENGTH = 64;
|
|
22
|
-
const HASH_BIT_LEN = 256;
|
|
23
16
|
const MAX_CACHE_SIZE = 6e8;
|
|
24
17
|
const MAX_EMAIL_PER_BATCH = 100;
|
|
25
18
|
const DB_LABEL = "email";
|
|
@@ -30,5 +23,5 @@ const XWING_SEED_BYTE_LENGTH = 32;
|
|
|
30
23
|
const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;
|
|
31
24
|
|
|
32
25
|
//#endregion
|
|
33
|
-
export {
|
|
26
|
+
export { AES_KEY_BYTE_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, CONTEXT_DERIVE, CONTEXT_ENC_KEYSTORE, CONTEXT_INDEX, CONTEXT_RECOVERY, DB_LABEL, DB_VERSION, IV_LEN_BYTES, KYBER768_PUBLIC_KEY_LENGTH, KYBER768_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH, MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH, XWING_CIPHERTEXT_BYTE_LENGTH, XWING_PUBLIC_KEY_LENGTH, XWING_SECRET_KEY_LENGTH, XWING_SEED_BYTE_LENGTH };
|
|
34
27
|
//# sourceMappingURL=constants.mjs.map
|
package/dist/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["export const AES_KEY_BYTE_LENGTH = 32;\nexport const IV_LEN_BYTES = 12;\n\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n\nexport const XWING_PUBLIC_KEY_LENGTH = 1216;\nexport const XWING_SECRET_KEY_LENGTH = 32;\nexport const XWING_SEED_BYTE_LENGTH = 32;\nexport const XWING_CIPHERTEXT_BYTE_LENGTH = 1120;\n"],"mappings":";AAAA,MAAa,sBAAsB;AACnC,MAAa,eAAe;AAE5B,MAAa,uBAAuB;AACpC,MAAa,mBAAmB;AAChC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAG9B,MAAa,uBAAuB;AACpC,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAE3C,MAAa,6BAA6B;AAC1C,MAAa,6BAA6B;AAC1C,MAAa,oBAAoB;AAEjC,MAAa,iBAAiB;AAC9B,MAAa,sBAAsB;AACnC,MAAa,WAAW;AACxB,MAAa,aAAa;AAE1B,MAAa,0BAA0B;AACvC,MAAa,0BAA0B;AACvC,MAAa,yBAAyB;AACtC,MAAa,+BAA+B"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-EbLFQX5m.js');
|
|
2
|
+
const require_genID = require('./genID-cWOPmspk.js');
|
|
3
|
+
const require_deriveKeysFromPassword = require('./deriveKeysFromPassword-C7xAGGsh.js');
|
|
4
|
+
const require_aes = require('./aes-CuW_SPl-.js');
|
|
5
|
+
const require_xwing = require('./xwing-iRWVRtNE.js');
|
|
6
|
+
let _noble_ciphers_aes_js = require("@noble/ciphers/aes.js");
|
|
7
|
+
|
|
8
|
+
//#region src/key-wrapper/aesWrapper.ts
|
|
9
|
+
/**
|
|
10
|
+
* Unwraps the given wrapped key
|
|
11
|
+
*
|
|
12
|
+
* @param encryptedKey - The wrapped key
|
|
13
|
+
* @param wrappingKey - The secret key used for unwrapping
|
|
14
|
+
* @returns The resulting key
|
|
15
|
+
*/
|
|
16
|
+
async function unwrapKey(encryptedKey, wrappingKey) {
|
|
17
|
+
return (0, _noble_ciphers_aes_js.aeskw)(wrappingKey).decrypt(encryptedKey);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wraps the given key
|
|
21
|
+
*
|
|
22
|
+
* @param key - The key to be wrapped
|
|
23
|
+
* @param wrappingKey - The secret key used for wrapping
|
|
24
|
+
* @returns The resulting ciphertext
|
|
25
|
+
*/
|
|
26
|
+
async function wrapKey(key, wrappingKey) {
|
|
27
|
+
return (0, _noble_ciphers_aes_js.aeskw)(wrappingKey).encrypt(key);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/email-crypto/core.ts
|
|
32
|
+
/**
|
|
33
|
+
* Symmetrically encrypts email body.
|
|
34
|
+
*
|
|
35
|
+
* @param body - The email body to encrypt.
|
|
36
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
37
|
+
* @returns The resulting encrypted email body and symmetric key used for encryption
|
|
38
|
+
*/
|
|
39
|
+
async function encryptEmailBody(body, aux) {
|
|
40
|
+
try {
|
|
41
|
+
if (!body.text || !body.subject) throw new Error("Invalid input");
|
|
42
|
+
const encryptionKey = require_aes.genSymmetricKey();
|
|
43
|
+
return {
|
|
44
|
+
encEmailBody: await encryptEmailBodyWithKey(body, encryptionKey, aux),
|
|
45
|
+
encryptionKey
|
|
46
|
+
};
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error("Failed to symmetrically encrypt email body", { cause: error });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Symmetrically encrypts email body with the given key.
|
|
53
|
+
*
|
|
54
|
+
* @param body - The email body to encrypt.
|
|
55
|
+
* @param encryptionKey - The symmetric key to encrypt the email.
|
|
56
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
57
|
+
* @returns The resulting encrypted email body and symmetric key used for encryption
|
|
58
|
+
*/
|
|
59
|
+
async function encryptEmailBodyWithKey(body, encryptionKey, aux) {
|
|
60
|
+
try {
|
|
61
|
+
const text = require_genID.UTF8ToUint8(body.text);
|
|
62
|
+
const subjectEnc = await require_aes.encryptSymmetrically(encryptionKey, require_genID.UTF8ToUint8(body.subject), aux);
|
|
63
|
+
const enc = {
|
|
64
|
+
encText: require_genID.uint8ArrayToBase64(await require_aes.encryptSymmetrically(encryptionKey, text, aux)),
|
|
65
|
+
encSubject: require_genID.uint8ArrayToBase64(subjectEnc)
|
|
66
|
+
};
|
|
67
|
+
if (body.attachments) {
|
|
68
|
+
const promises = body.attachments.map((attachment) => {
|
|
69
|
+
return require_aes.encryptSymmetrically(encryptionKey, require_genID.UTF8ToUint8(attachment), aux);
|
|
70
|
+
});
|
|
71
|
+
enc.encAttachments = (await Promise.all(promises))?.map(require_genID.uint8ArrayToBase64);
|
|
72
|
+
}
|
|
73
|
+
return enc;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new Error("Failed to encrypt email body", { cause: error });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Decrypts symmetrically encrypted email body.
|
|
80
|
+
*
|
|
81
|
+
* @param encEmailBody - The email body to decrypt.
|
|
82
|
+
* @param encryptionKey - The symmetric key to decrypt the email.
|
|
83
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
84
|
+
* @returns The resulting decrypted email body
|
|
85
|
+
*/
|
|
86
|
+
async function decryptEmailBody(encEmailBody, encryptionKey, aux) {
|
|
87
|
+
try {
|
|
88
|
+
const subject = require_genID.uint8ToUTF8(await require_aes.decryptSymmetrically(encryptionKey, require_genID.base64ToUint8Array(encEmailBody.encSubject), aux));
|
|
89
|
+
const body = {
|
|
90
|
+
text: require_genID.uint8ToUTF8(await require_aes.decryptSymmetrically(encryptionKey, require_genID.base64ToUint8Array(encEmailBody.encText), aux)),
|
|
91
|
+
subject
|
|
92
|
+
};
|
|
93
|
+
if (encEmailBody.encAttachments) {
|
|
94
|
+
const promises = (encEmailBody.encAttachments?.map(require_genID.base64ToUint8Array))?.map((encAtt) => require_aes.decryptSymmetrically(encryptionKey, encAtt, aux));
|
|
95
|
+
body.attachments = (await Promise.all(promises))?.map((att) => require_genID.uint8ToUTF8(att));
|
|
96
|
+
}
|
|
97
|
+
return body;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
throw new Error("Failed to symmetrically decrypt email body", { cause: error });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Encrypts the email symmetric key using hybrid encryption.
|
|
104
|
+
*
|
|
105
|
+
* @param emailEncryptionKey - The symmetric key used for email encryption.
|
|
106
|
+
* @param recipient - The recipient with a public hybrid key.
|
|
107
|
+
* @returns The encrypted email symmetric key
|
|
108
|
+
*/
|
|
109
|
+
async function encryptKeysHybrid(emailEncryptionKey, recipient) {
|
|
110
|
+
try {
|
|
111
|
+
const { cipherText, sharedSecret } = require_xwing.encapsulateHybrid(recipient.publicHybridKey);
|
|
112
|
+
return {
|
|
113
|
+
encryptedKey: require_genID.uint8ArrayToBase64(await wrapKey(emailEncryptionKey, sharedSecret)),
|
|
114
|
+
hybridCiphertext: require_genID.uint8ArrayToBase64(cipherText),
|
|
115
|
+
encryptedForEmail: recipient.email
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Decrypts the email symmetric key encrypted via hybrid encryption.
|
|
123
|
+
*
|
|
124
|
+
* @param encryptedKey - The encrypted email key.
|
|
125
|
+
* @param recipientPrivateKey - The private key of the recipient.
|
|
126
|
+
* @returns The email encryption key
|
|
127
|
+
*/
|
|
128
|
+
async function decryptKeysHybrid(encryptedKey, recipientPrivateKey) {
|
|
129
|
+
try {
|
|
130
|
+
const kyberCiphertext = require_genID.base64ToUint8Array(encryptedKey.hybridCiphertext);
|
|
131
|
+
return await unwrapKey(require_genID.base64ToUint8Array(encryptedKey.encryptedKey), require_xwing.decapsulateHybrid(kyberCiphertext, recipientPrivateKey));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Password-protects the email symmetric key.
|
|
138
|
+
*
|
|
139
|
+
* @param emailEncryptionKey - The symmetric key used for email encryption.
|
|
140
|
+
* @param password - The secret password for key protection.
|
|
141
|
+
* @returns The password-protected email symmetric key
|
|
142
|
+
*/
|
|
143
|
+
async function passwordProtectKey(emailEncryptionKey, password) {
|
|
144
|
+
try {
|
|
145
|
+
const { key, salt } = await require_deriveKeysFromPassword.getKeyFromPassword(password);
|
|
146
|
+
const encryptedKey = await wrapKey(emailEncryptionKey, key);
|
|
147
|
+
const saltStr = require_genID.uint8ArrayToBase64(salt);
|
|
148
|
+
return {
|
|
149
|
+
encryptedKey: require_genID.uint8ArrayToBase64(encryptedKey),
|
|
150
|
+
salt: saltStr
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
throw new Error("Failed to password-protect email key", { cause: error });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Removes passoword-protection and exposes the email symmetric key.
|
|
158
|
+
*
|
|
159
|
+
* @param emailEncryptionKey - The password-protected email key.
|
|
160
|
+
* @param password - The secret password for key protection.
|
|
161
|
+
* @returns The email encryption key
|
|
162
|
+
*/
|
|
163
|
+
async function removePasswordProtection(emailEncryptionKey, password) {
|
|
164
|
+
try {
|
|
165
|
+
const salt = require_genID.base64ToUint8Array(emailEncryptionKey.salt);
|
|
166
|
+
return await unwrapKey(require_genID.base64ToUint8Array(emailEncryptionKey.encryptedKey), await require_deriveKeysFromPassword.getKeyFromPasswordAndSalt(password, salt));
|
|
167
|
+
} catch (error) {
|
|
168
|
+
throw new Error("Failed to remove password-protection from email key", { cause: error });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
Object.defineProperty(exports, 'decryptEmailBody', {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () {
|
|
176
|
+
return decryptEmailBody;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(exports, 'decryptKeysHybrid', {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function () {
|
|
182
|
+
return decryptKeysHybrid;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
Object.defineProperty(exports, 'encryptEmailBody', {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get: function () {
|
|
188
|
+
return encryptEmailBody;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(exports, 'encryptEmailBodyWithKey', {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
get: function () {
|
|
194
|
+
return encryptEmailBodyWithKey;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(exports, 'encryptKeysHybrid', {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () {
|
|
200
|
+
return encryptKeysHybrid;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
Object.defineProperty(exports, 'passwordProtectKey', {
|
|
204
|
+
enumerable: true,
|
|
205
|
+
get: function () {
|
|
206
|
+
return passwordProtectKey;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(exports, 'removePasswordProtection', {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
get: function () {
|
|
212
|
+
return removePasswordProtection;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
Object.defineProperty(exports, 'unwrapKey', {
|
|
216
|
+
enumerable: true,
|
|
217
|
+
get: function () {
|
|
218
|
+
return unwrapKey;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
Object.defineProperty(exports, 'wrapKey', {
|
|
222
|
+
enumerable: true,
|
|
223
|
+
get: function () {
|
|
224
|
+
return wrapKey;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
//# sourceMappingURL=core-Bj26rNdA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-Bj26rNdA.js","names":["genSymmetricKey","UTF8ToUint8","encryptSymmetrically","uint8ArrayToBase64","uint8ToUTF8","decryptSymmetrically","base64ToUint8Array","encapsulateHybrid","decapsulateHybrid","getKeyFromPassword","getKeyFromPasswordAndSalt"],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/core.ts"],"sourcesContent":["import { aeskw } from '@noble/ciphers/aes.js';\n\n/**\n * Unwraps the given wrapped key\n *\n * @param encryptedKey - The wrapped key\n * @param wrappingKey - The secret key used for unwrapping\n * @returns The resulting key\n */\nexport async function unwrapKey(encryptedKey: Uint8Array, wrappingKey: Uint8Array): Promise<Uint8Array> {\n return aeskw(wrappingKey).decrypt(encryptedKey);\n}\n\n/**\n * Wraps the given key\n *\n * @param key - The key to be wrapped\n * @param wrappingKey - The secret key used for wrapping\n * @returns The resulting ciphertext\n */\nexport async function wrapKey(key: Uint8Array, wrappingKey: Uint8Array): Promise<Uint8Array> {\n return aeskw(wrappingKey).encrypt(key);\n}\n","import { HybridEncKey, PwdProtectedKey, EmailBody, EmailBodyEncrypted, RecipientWithPublicKey } from '../types';\nimport { encryptSymmetrically, decryptSymmetrically, genSymmetricKey } from '../symmetric-crypto';\nimport { encapsulateHybrid, decapsulateHybrid } from '../hybrid-crypto';\nimport { wrapKey, unwrapKey } from '../key-wrapper';\nimport { getKeyFromPassword, getKeyFromPasswordAndSalt } from '../derive-password';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8 } from '../utils';\n\n/**\n * Symmetrically encrypts email body.\n *\n * @param body - The email body to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBody(\n body: EmailBody,\n aux?: Uint8Array,\n): Promise<{\n encEmailBody: EmailBodyEncrypted;\n encryptionKey: Uint8Array;\n}> {\n try {\n if (!body.text || !body.subject) {\n throw new Error('Invalid input');\n }\n const encryptionKey = genSymmetricKey();\n const encEmailBody = await encryptEmailBodyWithKey(body, encryptionKey, aux);\n\n return { encEmailBody, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email body', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts email body with the given key.\n *\n * @param body - The email body to encrypt.\n * @param encryptionKey - The symmetric key to encrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBodyWithKey(\n body: EmailBody,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBodyEncrypted> {\n try {\n const text = UTF8ToUint8(body.text);\n const subject = UTF8ToUint8(body.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n const enc: EmailBodyEncrypted = { encText, encSubject };\n\n if (body.attachments) {\n const promises = body.attachments.map((attachment) => {\n const binaryAttachment = UTF8ToUint8(attachment);\n return encryptSymmetrically(encryptionKey, binaryAttachment, aux);\n });\n const encryptedAttachments = await Promise.all(promises);\n enc.encAttachments = encryptedAttachments?.map(uint8ArrayToBase64);\n }\n\n return enc;\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email body.\n *\n * @param encEmailBody - The email body to decrypt.\n * @param encryptionKey - The symmetric key to decrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting decrypted email body\n */\nexport async function decryptEmailBody(\n encEmailBody: EmailBodyEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encSubject = base64ToUint8Array(encEmailBody.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const encText = base64ToUint8Array(encEmailBody.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n const body: EmailBody = { text, subject };\n\n if (encEmailBody.encAttachments) {\n const encAttachments = encEmailBody.encAttachments?.map(base64ToUint8Array);\n const promises = encAttachments?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));\n const decryptedAttachments = await Promise.all(promises);\n body.attachments = decryptedAttachments?.map((att) => uint8ToUTF8(att));\n }\n\n return body;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email body', { cause: error });\n }\n}\n\n/**\n * Encrypts the email symmetric key using hybrid encryption.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param recipient - The recipient with a public hybrid key.\n * @returns The encrypted email symmetric key\n */\nexport async function encryptKeysHybrid(\n emailEncryptionKey: Uint8Array,\n recipient: RecipientWithPublicKey,\n): Promise<HybridEncKey> {\n try {\n const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);\n const encryptedKey = await wrapKey(emailEncryptionKey, sharedSecret);\n const encryptedKeyBase64 = uint8ArrayToBase64(encryptedKey);\n const kyberCiphertextBase64 = uint8ArrayToBase64(cipherText);\n\n return {\n encryptedKey: encryptedKeyBase64,\n hybridCiphertext: kyberCiphertextBase64,\n encryptedForEmail: recipient.email,\n };\n } catch (error) {\n throw new Error('Failed to encrypt email key using hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email symmetric key encrypted via hybrid encryption.\n *\n * @param encryptedKey - The encrypted email key.\n * @param recipientPrivateKey - The private key of the recipient.\n * @returns The email encryption key\n */\nexport async function decryptKeysHybrid(\n encryptedKey: HybridEncKey,\n recipientPrivateKey: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);\n const encKey = base64ToUint8Array(encryptedKey.encryptedKey);\n const sharedSecret = decapsulateHybrid(kyberCiphertext, recipientPrivateKey);\n const encryptionKey = await unwrapKey(encKey, sharedSecret);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to decrypt email key encrypted via hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param password - The secret password for key protection.\n * @returns The password-protected email symmetric key\n */\nexport async function passwordProtectKey(emailEncryptionKey: Uint8Array, password: string): Promise<PwdProtectedKey> {\n try {\n const { key, salt } = await getKeyFromPassword(password);\n const encryptedKey = await wrapKey(emailEncryptionKey, key);\n const saltStr = uint8ArrayToBase64(salt);\n const encryptedKeyStr = uint8ArrayToBase64(encryptedKey);\n return { encryptedKey: encryptedKeyStr, salt: saltStr };\n } catch (error) {\n throw new Error('Failed to password-protect email key', { cause: error });\n }\n}\n\n/**\n * Removes passoword-protection and exposes the email symmetric key.\n *\n * @param emailEncryptionKey - The password-protected email key.\n * @param password - The secret password for key protection.\n * @returns The email encryption key\n */\nexport async function removePasswordProtection(\n emailEncryptionKey: PwdProtectedKey,\n password: string,\n): Promise<Uint8Array> {\n try {\n const salt = base64ToUint8Array(emailEncryptionKey.salt);\n const encryptedKey = base64ToUint8Array(emailEncryptionKey.encryptedKey);\n const key = await getKeyFromPasswordAndSalt(password, salt);\n const encryptionKey = await unwrapKey(encryptedKey, key);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to remove password-protection from email key', { cause: error });\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { c as base64ToUint8Array, f as uint8ToUTF8, s as UTF8ToUint8, u as uint8ArrayToBase64 } from "./genID-D08K7JPr.mjs";
|
|
2
|
+
import { n as getKeyFromPasswordAndSalt, t as getKeyFromPassword } from "./deriveKeysFromPassword-DXgSvTNC.mjs";
|
|
3
|
+
import { n as encryptSymmetrically, r as genSymmetricKey, t as decryptSymmetrically } from "./aes-B8TA-JKq.mjs";
|
|
4
|
+
import { n as encapsulateHybrid, t as decapsulateHybrid } from "./xwing-CQmQX6hn.mjs";
|
|
5
|
+
import { aeskw } from "@noble/ciphers/aes.js";
|
|
6
|
+
|
|
7
|
+
//#region src/key-wrapper/aesWrapper.ts
|
|
8
|
+
/**
|
|
9
|
+
* Unwraps the given wrapped key
|
|
10
|
+
*
|
|
11
|
+
* @param encryptedKey - The wrapped key
|
|
12
|
+
* @param wrappingKey - The secret key used for unwrapping
|
|
13
|
+
* @returns The resulting key
|
|
14
|
+
*/
|
|
15
|
+
async function unwrapKey(encryptedKey, wrappingKey) {
|
|
16
|
+
return aeskw(wrappingKey).decrypt(encryptedKey);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Wraps the given key
|
|
20
|
+
*
|
|
21
|
+
* @param key - The key to be wrapped
|
|
22
|
+
* @param wrappingKey - The secret key used for wrapping
|
|
23
|
+
* @returns The resulting ciphertext
|
|
24
|
+
*/
|
|
25
|
+
async function wrapKey(key, wrappingKey) {
|
|
26
|
+
return aeskw(wrappingKey).encrypt(key);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/email-crypto/core.ts
|
|
31
|
+
/**
|
|
32
|
+
* Symmetrically encrypts email body.
|
|
33
|
+
*
|
|
34
|
+
* @param body - The email body to encrypt.
|
|
35
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
36
|
+
* @returns The resulting encrypted email body and symmetric key used for encryption
|
|
37
|
+
*/
|
|
38
|
+
async function encryptEmailBody(body, aux) {
|
|
39
|
+
try {
|
|
40
|
+
if (!body.text || !body.subject) throw new Error("Invalid input");
|
|
41
|
+
const encryptionKey = genSymmetricKey();
|
|
42
|
+
return {
|
|
43
|
+
encEmailBody: await encryptEmailBodyWithKey(body, encryptionKey, aux),
|
|
44
|
+
encryptionKey
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error("Failed to symmetrically encrypt email body", { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Symmetrically encrypts email body with the given key.
|
|
52
|
+
*
|
|
53
|
+
* @param body - The email body to encrypt.
|
|
54
|
+
* @param encryptionKey - The symmetric key to encrypt the email.
|
|
55
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
56
|
+
* @returns The resulting encrypted email body and symmetric key used for encryption
|
|
57
|
+
*/
|
|
58
|
+
async function encryptEmailBodyWithKey(body, encryptionKey, aux) {
|
|
59
|
+
try {
|
|
60
|
+
const text = UTF8ToUint8(body.text);
|
|
61
|
+
const subjectEnc = await encryptSymmetrically(encryptionKey, UTF8ToUint8(body.subject), aux);
|
|
62
|
+
const enc = {
|
|
63
|
+
encText: uint8ArrayToBase64(await encryptSymmetrically(encryptionKey, text, aux)),
|
|
64
|
+
encSubject: uint8ArrayToBase64(subjectEnc)
|
|
65
|
+
};
|
|
66
|
+
if (body.attachments) {
|
|
67
|
+
const promises = body.attachments.map((attachment) => {
|
|
68
|
+
return encryptSymmetrically(encryptionKey, UTF8ToUint8(attachment), aux);
|
|
69
|
+
});
|
|
70
|
+
enc.encAttachments = (await Promise.all(promises))?.map(uint8ArrayToBase64);
|
|
71
|
+
}
|
|
72
|
+
return enc;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error("Failed to encrypt email body", { cause: error });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Decrypts symmetrically encrypted email body.
|
|
79
|
+
*
|
|
80
|
+
* @param encEmailBody - The email body to decrypt.
|
|
81
|
+
* @param encryptionKey - The symmetric key to decrypt the email.
|
|
82
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
83
|
+
* @returns The resulting decrypted email body
|
|
84
|
+
*/
|
|
85
|
+
async function decryptEmailBody(encEmailBody, encryptionKey, aux) {
|
|
86
|
+
try {
|
|
87
|
+
const subject = uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailBody.encSubject), aux));
|
|
88
|
+
const body = {
|
|
89
|
+
text: uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailBody.encText), aux)),
|
|
90
|
+
subject
|
|
91
|
+
};
|
|
92
|
+
if (encEmailBody.encAttachments) {
|
|
93
|
+
const promises = (encEmailBody.encAttachments?.map(base64ToUint8Array))?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));
|
|
94
|
+
body.attachments = (await Promise.all(promises))?.map((att) => uint8ToUTF8(att));
|
|
95
|
+
}
|
|
96
|
+
return body;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new Error("Failed to symmetrically decrypt email body", { cause: error });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Encrypts the email symmetric key using hybrid encryption.
|
|
103
|
+
*
|
|
104
|
+
* @param emailEncryptionKey - The symmetric key used for email encryption.
|
|
105
|
+
* @param recipient - The recipient with a public hybrid key.
|
|
106
|
+
* @returns The encrypted email symmetric key
|
|
107
|
+
*/
|
|
108
|
+
async function encryptKeysHybrid(emailEncryptionKey, recipient) {
|
|
109
|
+
try {
|
|
110
|
+
const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);
|
|
111
|
+
return {
|
|
112
|
+
encryptedKey: uint8ArrayToBase64(await wrapKey(emailEncryptionKey, sharedSecret)),
|
|
113
|
+
hybridCiphertext: uint8ArrayToBase64(cipherText),
|
|
114
|
+
encryptedForEmail: recipient.email
|
|
115
|
+
};
|
|
116
|
+
} catch (error) {
|
|
117
|
+
throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Decrypts the email symmetric key encrypted via hybrid encryption.
|
|
122
|
+
*
|
|
123
|
+
* @param encryptedKey - The encrypted email key.
|
|
124
|
+
* @param recipientPrivateKey - The private key of the recipient.
|
|
125
|
+
* @returns The email encryption key
|
|
126
|
+
*/
|
|
127
|
+
async function decryptKeysHybrid(encryptedKey, recipientPrivateKey) {
|
|
128
|
+
try {
|
|
129
|
+
const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);
|
|
130
|
+
return await unwrapKey(base64ToUint8Array(encryptedKey.encryptedKey), decapsulateHybrid(kyberCiphertext, recipientPrivateKey));
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Password-protects the email symmetric key.
|
|
137
|
+
*
|
|
138
|
+
* @param emailEncryptionKey - The symmetric key used for email encryption.
|
|
139
|
+
* @param password - The secret password for key protection.
|
|
140
|
+
* @returns The password-protected email symmetric key
|
|
141
|
+
*/
|
|
142
|
+
async function passwordProtectKey(emailEncryptionKey, password) {
|
|
143
|
+
try {
|
|
144
|
+
const { key, salt } = await getKeyFromPassword(password);
|
|
145
|
+
const encryptedKey = await wrapKey(emailEncryptionKey, key);
|
|
146
|
+
const saltStr = uint8ArrayToBase64(salt);
|
|
147
|
+
return {
|
|
148
|
+
encryptedKey: uint8ArrayToBase64(encryptedKey),
|
|
149
|
+
salt: saltStr
|
|
150
|
+
};
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw new Error("Failed to password-protect email key", { cause: error });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Removes passoword-protection and exposes the email symmetric key.
|
|
157
|
+
*
|
|
158
|
+
* @param emailEncryptionKey - The password-protected email key.
|
|
159
|
+
* @param password - The secret password for key protection.
|
|
160
|
+
* @returns The email encryption key
|
|
161
|
+
*/
|
|
162
|
+
async function removePasswordProtection(emailEncryptionKey, password) {
|
|
163
|
+
try {
|
|
164
|
+
const salt = base64ToUint8Array(emailEncryptionKey.salt);
|
|
165
|
+
return await unwrapKey(base64ToUint8Array(emailEncryptionKey.encryptedKey), await getKeyFromPasswordAndSalt(password, salt));
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new Error("Failed to remove password-protection from email key", { cause: error });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
export { encryptKeysHybrid as a, unwrapKey as c, encryptEmailBodyWithKey as i, wrapKey as l, decryptKeysHybrid as n, passwordProtectKey as o, encryptEmailBody as r, removePasswordProtection as s, decryptEmailBody as t };
|
|
173
|
+
//# sourceMappingURL=core-pEGygy6S.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-pEGygy6S.mjs","names":[],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/core.ts"],"sourcesContent":["import { aeskw } from '@noble/ciphers/aes.js';\n\n/**\n * Unwraps the given wrapped key\n *\n * @param encryptedKey - The wrapped key\n * @param wrappingKey - The secret key used for unwrapping\n * @returns The resulting key\n */\nexport async function unwrapKey(encryptedKey: Uint8Array, wrappingKey: Uint8Array): Promise<Uint8Array> {\n return aeskw(wrappingKey).decrypt(encryptedKey);\n}\n\n/**\n * Wraps the given key\n *\n * @param key - The key to be wrapped\n * @param wrappingKey - The secret key used for wrapping\n * @returns The resulting ciphertext\n */\nexport async function wrapKey(key: Uint8Array, wrappingKey: Uint8Array): Promise<Uint8Array> {\n return aeskw(wrappingKey).encrypt(key);\n}\n","import { HybridEncKey, PwdProtectedKey, EmailBody, EmailBodyEncrypted, RecipientWithPublicKey } from '../types';\nimport { encryptSymmetrically, decryptSymmetrically, genSymmetricKey } from '../symmetric-crypto';\nimport { encapsulateHybrid, decapsulateHybrid } from '../hybrid-crypto';\nimport { wrapKey, unwrapKey } from '../key-wrapper';\nimport { getKeyFromPassword, getKeyFromPasswordAndSalt } from '../derive-password';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8 } from '../utils';\n\n/**\n * Symmetrically encrypts email body.\n *\n * @param body - The email body to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBody(\n body: EmailBody,\n aux?: Uint8Array,\n): Promise<{\n encEmailBody: EmailBodyEncrypted;\n encryptionKey: Uint8Array;\n}> {\n try {\n if (!body.text || !body.subject) {\n throw new Error('Invalid input');\n }\n const encryptionKey = genSymmetricKey();\n const encEmailBody = await encryptEmailBodyWithKey(body, encryptionKey, aux);\n\n return { encEmailBody, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email body', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts email body with the given key.\n *\n * @param body - The email body to encrypt.\n * @param encryptionKey - The symmetric key to encrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBodyWithKey(\n body: EmailBody,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBodyEncrypted> {\n try {\n const text = UTF8ToUint8(body.text);\n const subject = UTF8ToUint8(body.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n const enc: EmailBodyEncrypted = { encText, encSubject };\n\n if (body.attachments) {\n const promises = body.attachments.map((attachment) => {\n const binaryAttachment = UTF8ToUint8(attachment);\n return encryptSymmetrically(encryptionKey, binaryAttachment, aux);\n });\n const encryptedAttachments = await Promise.all(promises);\n enc.encAttachments = encryptedAttachments?.map(uint8ArrayToBase64);\n }\n\n return enc;\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email body.\n *\n * @param encEmailBody - The email body to decrypt.\n * @param encryptionKey - The symmetric key to decrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting decrypted email body\n */\nexport async function decryptEmailBody(\n encEmailBody: EmailBodyEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encSubject = base64ToUint8Array(encEmailBody.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const encText = base64ToUint8Array(encEmailBody.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n const body: EmailBody = { text, subject };\n\n if (encEmailBody.encAttachments) {\n const encAttachments = encEmailBody.encAttachments?.map(base64ToUint8Array);\n const promises = encAttachments?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));\n const decryptedAttachments = await Promise.all(promises);\n body.attachments = decryptedAttachments?.map((att) => uint8ToUTF8(att));\n }\n\n return body;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email body', { cause: error });\n }\n}\n\n/**\n * Encrypts the email symmetric key using hybrid encryption.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param recipient - The recipient with a public hybrid key.\n * @returns The encrypted email symmetric key\n */\nexport async function encryptKeysHybrid(\n emailEncryptionKey: Uint8Array,\n recipient: RecipientWithPublicKey,\n): Promise<HybridEncKey> {\n try {\n const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);\n const encryptedKey = await wrapKey(emailEncryptionKey, sharedSecret);\n const encryptedKeyBase64 = uint8ArrayToBase64(encryptedKey);\n const kyberCiphertextBase64 = uint8ArrayToBase64(cipherText);\n\n return {\n encryptedKey: encryptedKeyBase64,\n hybridCiphertext: kyberCiphertextBase64,\n encryptedForEmail: recipient.email,\n };\n } catch (error) {\n throw new Error('Failed to encrypt email key using hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email symmetric key encrypted via hybrid encryption.\n *\n * @param encryptedKey - The encrypted email key.\n * @param recipientPrivateKey - The private key of the recipient.\n * @returns The email encryption key\n */\nexport async function decryptKeysHybrid(\n encryptedKey: HybridEncKey,\n recipientPrivateKey: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);\n const encKey = base64ToUint8Array(encryptedKey.encryptedKey);\n const sharedSecret = decapsulateHybrid(kyberCiphertext, recipientPrivateKey);\n const encryptionKey = await unwrapKey(encKey, sharedSecret);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to decrypt email key encrypted via hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param password - The secret password for key protection.\n * @returns The password-protected email symmetric key\n */\nexport async function passwordProtectKey(emailEncryptionKey: Uint8Array, password: string): Promise<PwdProtectedKey> {\n try {\n const { key, salt } = await getKeyFromPassword(password);\n const encryptedKey = await wrapKey(emailEncryptionKey, key);\n const saltStr = uint8ArrayToBase64(salt);\n const encryptedKeyStr = uint8ArrayToBase64(encryptedKey);\n return { encryptedKey: encryptedKeyStr, salt: saltStr };\n } catch (error) {\n throw new Error('Failed to password-protect email key', { cause: error });\n }\n}\n\n/**\n * Removes passoword-protection and exposes the email symmetric key.\n *\n * @param emailEncryptionKey - The password-protected email key.\n * @param password - The secret password for key protection.\n * @returns The email encryption key\n */\nexport async function removePasswordProtection(\n emailEncryptionKey: PwdProtectedKey,\n password: string,\n): Promise<Uint8Array> {\n try {\n const salt = base64ToUint8Array(emailEncryptionKey.salt);\n const encryptedKey = base64ToUint8Array(emailEncryptionKey.encryptedKey);\n const key = await getKeyFromPasswordAndSalt(password, salt);\n const encryptionKey = await unwrapKey(encryptedKey, key);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to remove password-protection from email key', { cause: error });\n }\n}\n"],"mappings":"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"}
|
package/dist/derive-key.d.mts
CHANGED
|
@@ -8,15 +8,6 @@
|
|
|
8
8
|
* @returns The derived secret key
|
|
9
9
|
*/
|
|
10
10
|
declare function deriveSymmetricKeyFromContext(context: string, baseKey: Uint8Array): Uint8Array;
|
|
11
|
-
/**
|
|
12
|
-
* Derives a symmetric CryptoKey from the base key and context string
|
|
13
|
-
*
|
|
14
|
-
* @param context - The context string.
|
|
15
|
-
* The context string should be hardcoded, globally unique, and application-specific.
|
|
16
|
-
* @param baseKey - The base key (NOT PASSWORD!)
|
|
17
|
-
* @returns The derived secret CryptoKey
|
|
18
|
-
*/
|
|
19
|
-
declare function deriveSymmetricCryptoKeyFromContext(context: string, baseKey: Uint8Array): Promise<CryptoKey>;
|
|
20
11
|
/**
|
|
21
12
|
* Derives a symmetric key from two keys
|
|
22
13
|
*
|
|
@@ -25,70 +16,6 @@ declare function deriveSymmetricCryptoKeyFromContext(context: string, baseKey: U
|
|
|
25
16
|
* @returns The derived secret key
|
|
26
17
|
*/
|
|
27
18
|
declare function deriveSymmetricKeyFromTwoKeys(key1: Uint8Array, key2: Uint8Array): Uint8Array;
|
|
28
|
-
/**
|
|
29
|
-
* Derives a symmetric CryptoKey from two keys
|
|
30
|
-
*
|
|
31
|
-
* @param key1 - The 32-bytes key
|
|
32
|
-
* @param key2 - The 32-bytes key
|
|
33
|
-
* @returns The derived secret CryptoKey
|
|
34
|
-
*/
|
|
35
|
-
declare function deriveSymmetricCryptoKeyFromTwoKeys(key1: Uint8Array, key2: Uint8Array): Promise<CryptoKey>;
|
|
36
|
-
/**
|
|
37
|
-
* Derives a symmetric key from two keys and context
|
|
38
|
-
*
|
|
39
|
-
* @param key1 - The 32-bytes key
|
|
40
|
-
* @param key2 - The 32-bytes key
|
|
41
|
-
* @param context - The context string
|
|
42
|
-
* @returns The derived symmetric key
|
|
43
|
-
*/
|
|
44
|
-
declare function deriveSymmetricKeyFromTwoKeysAndContext(key1: Uint8Array, key2: Uint8Array, context: string): Uint8Array;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/derive-key/deriveKeysFromPassword.d.ts
|
|
47
|
-
/**
|
|
48
|
-
* Derives a symmetric key from a user's password with a randomly sampled salt
|
|
49
|
-
*
|
|
50
|
-
* @param password - The user's password
|
|
51
|
-
* @returns The derived secret key and randomly sampled salt
|
|
52
|
-
*/
|
|
53
|
-
declare function getKeyFromPassword(password: string): Promise<{
|
|
54
|
-
key: Uint8Array;
|
|
55
|
-
salt: Uint8Array;
|
|
56
|
-
}>;
|
|
57
|
-
/**
|
|
58
|
-
* Derives a symmetric key from a user's password and salt
|
|
59
|
-
*
|
|
60
|
-
* @param password - The user's password
|
|
61
|
-
* @param salt - The given salt
|
|
62
|
-
* @returns The derived secret key
|
|
63
|
-
*/
|
|
64
|
-
declare function getKeyFromPasswordAndSalt(password: string, salt: Uint8Array): Promise<Uint8Array>;
|
|
65
|
-
/**
|
|
66
|
-
* Derives a HEX symmetric key from a user's password with a randomly sampled salt
|
|
67
|
-
*
|
|
68
|
-
* @param password - The user's password
|
|
69
|
-
* @returns The derived HEX secret key and randomly sampled HEX salt
|
|
70
|
-
*/
|
|
71
|
-
declare function getKeyFromPasswordHex(password: string): Promise<{
|
|
72
|
-
keyHex: string;
|
|
73
|
-
saltHex: string;
|
|
74
|
-
}>;
|
|
75
|
-
/**
|
|
76
|
-
* Derives a HEX symmetric key from a user's password and salt
|
|
77
|
-
*
|
|
78
|
-
* @param password - The user's password
|
|
79
|
-
* @param saltHex - The given HEX salt
|
|
80
|
-
* @returns The derived HEX secret key
|
|
81
|
-
*/
|
|
82
|
-
declare function getKeyFromPasswordAndSaltHex(password: string, saltHex: string): Promise<string>;
|
|
83
|
-
/**
|
|
84
|
-
* Verifies the derived key
|
|
85
|
-
*
|
|
86
|
-
* @param password - The user's password
|
|
87
|
-
* @param saltHex - The given HEX salt
|
|
88
|
-
* @param keyHex - The derived HEX key
|
|
89
|
-
* @returns The result of the key verification
|
|
90
|
-
*/
|
|
91
|
-
declare function verifyKeyFromPasswordHex(password: string, saltHex: string, keyHex: string): Promise<boolean>;
|
|
92
19
|
//#endregion
|
|
93
|
-
export {
|
|
20
|
+
export { deriveSymmetricKeyFromContext, deriveSymmetricKeyFromTwoKeys };
|
|
94
21
|
//# sourceMappingURL=derive-key.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-key.d.mts","names":[],"sources":["../src/derive-key/deriveKeysFromKey.ts"
|
|
1
|
+
{"version":3,"file":"derive-key.d.mts","names":[],"sources":["../src/derive-key/deriveKeysFromKey.ts"],"mappings":";;AAYA;;;;;;;iBAAgB,6BAAA,CAA8B,OAAA,UAAiB,OAAA,EAAS,UAAA,GAAa,UAAA;;;AAWrF;;;;;iBAAgB,6BAAA,CAA8B,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,UAAA,GAAa,UAAA"}
|