internxt-crypto 1.5.0 → 1.6.1
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 +9 -5
- package/dist/asymmetric-crypto.d.mts.map +1 -1
- package/dist/asymmetric-crypto.d.ts.map +1 -1
- package/dist/asymmetric-crypto.js +12 -2
- package/dist/asymmetric-crypto.js.map +1 -1
- package/dist/asymmetric-crypto.mjs +12 -2
- package/dist/asymmetric-crypto.mjs.map +1 -1
- package/dist/{email-crypto-_Wcbvr_n.mjs → email-crypto-CoRbTphp.mjs} +73 -106
- package/dist/email-crypto-CoRbTphp.mjs.map +1 -0
- package/dist/{email-crypto-CPL8ept8.js → email-crypto-DJb-I1wm.js} +90 -117
- package/dist/email-crypto-DJb-I1wm.js.map +1 -0
- package/dist/email-crypto.d.mts +33 -27
- package/dist/email-crypto.d.mts.map +1 -1
- package/dist/email-crypto.d.ts +33 -27
- package/dist/email-crypto.d.ts.map +1 -1
- package/dist/email-crypto.js +4 -3
- package/dist/email-crypto.mjs +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/index.mjs +2 -2
- package/dist/keystore-crypto.d.mts +1 -1
- package/dist/keystore-crypto.d.ts +1 -1
- package/dist/react-native/asymmetric-crypto.d.mts +21 -0
- package/dist/react-native/asymmetric-crypto.d.mts.map +1 -0
- package/dist/react-native/asymmetric-crypto.d.ts +21 -0
- package/dist/react-native/asymmetric-crypto.d.ts.map +1 -0
- package/dist/react-native/asymmetric-crypto.js +31 -0
- package/dist/react-native/asymmetric-crypto.js.map +1 -0
- package/dist/react-native/asymmetric-crypto.mjs +28 -0
- package/dist/react-native/asymmetric-crypto.mjs.map +1 -0
- package/dist/react-native/chunk-CfYAbeIz.mjs +13 -0
- package/dist/react-native/chunk-DskHE4z1.js +43 -0
- package/dist/react-native/constants.d.mts +27 -0
- package/dist/react-native/constants.d.mts.map +1 -0
- package/dist/react-native/constants.d.ts +27 -0
- package/dist/react-native/constants.d.ts.map +1 -0
- package/dist/react-native/constants.js +51 -0
- package/dist/react-native/constants.js.map +1 -0
- package/dist/react-native/constants.mjs +28 -0
- package/dist/react-native/constants.mjs.map +1 -0
- package/dist/react-native/derive-key.d.mts +32 -0
- package/dist/react-native/derive-key.d.mts.map +1 -0
- package/dist/react-native/derive-key.d.ts +32 -0
- package/dist/react-native/derive-key.d.ts.map +1 -0
- package/dist/react-native/derive-key.js +51 -0
- package/dist/react-native/derive-key.js.map +1 -0
- package/dist/react-native/derive-key.mjs +47 -0
- package/dist/react-native/derive-key.mjs.map +1 -0
- package/dist/react-native/derive-password-Bb3R3nyh.mjs +68 -0
- package/dist/react-native/derive-password-Bb3R3nyh.mjs.map +1 -0
- package/dist/react-native/derive-password-DIPrE8Mz.js +86 -0
- package/dist/react-native/derive-password-DIPrE8Mz.js.map +1 -0
- package/dist/react-native/derive-password.d.mts +28 -0
- package/dist/react-native/derive-password.d.mts.map +1 -0
- package/dist/react-native/derive-password.d.ts +28 -0
- package/dist/react-native/derive-password.d.ts.map +1 -0
- package/dist/react-native/derive-password.js +5 -0
- package/dist/react-native/derive-password.mjs +2 -0
- package/dist/react-native/email-crypto-C3ka3aAj.js +700 -0
- package/dist/react-native/email-crypto-C3ka3aAj.js.map +1 -0
- package/dist/react-native/email-crypto-CDM4iPK8.mjs +490 -0
- package/dist/react-native/email-crypto-CDM4iPK8.mjs.map +1 -0
- package/dist/react-native/email-crypto.d.mts +253 -0
- package/dist/react-native/email-crypto.d.mts.map +1 -0
- package/dist/react-native/email-crypto.d.ts +253 -0
- package/dist/react-native/email-crypto.d.ts.map +1 -0
- package/dist/react-native/email-crypto.js +35 -0
- package/dist/react-native/email-crypto.mjs +2 -0
- package/dist/react-native/hash.d.mts +50 -0
- package/dist/react-native/hash.d.mts.map +1 -0
- package/dist/react-native/hash.d.ts +50 -0
- package/dist/react-native/hash.d.ts.map +1 -0
- package/dist/react-native/hash.js +89 -0
- package/dist/react-native/hash.js.map +1 -0
- package/dist/react-native/hash.mjs +82 -0
- package/dist/react-native/hash.mjs.map +1 -0
- package/dist/react-native/index.d.mts +32 -0
- package/dist/react-native/index.d.mts.map +1 -0
- package/dist/react-native/index.d.ts +32 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +106 -0
- package/dist/react-native/index.mjs +12 -0
- package/dist/react-native/keystore-crypto-BXPEVvzq.js +238 -0
- package/dist/react-native/keystore-crypto-BXPEVvzq.js.map +1 -0
- package/dist/react-native/keystore-crypto-C6F-NQdX.mjs +185 -0
- package/dist/react-native/keystore-crypto-C6F-NQdX.mjs.map +1 -0
- package/dist/react-native/keystore-crypto.d.mts +71 -0
- package/dist/react-native/keystore-crypto.d.mts.map +1 -0
- package/dist/react-native/keystore-crypto.d.ts +71 -0
- package/dist/react-native/keystore-crypto.d.ts.map +1 -0
- package/dist/react-native/keystore-crypto.js +11 -0
- package/dist/react-native/keystore-crypto.mjs +2 -0
- package/dist/react-native/post-quantum-crypto.d.mts +32 -0
- package/dist/react-native/post-quantum-crypto.d.mts.map +1 -0
- package/dist/react-native/post-quantum-crypto.d.ts +32 -0
- package/dist/react-native/post-quantum-crypto.d.ts.map +1 -0
- package/dist/react-native/post-quantum-crypto.js +50 -0
- package/dist/react-native/post-quantum-crypto.js.map +1 -0
- package/dist/react-native/post-quantum-crypto.mjs +46 -0
- package/dist/react-native/post-quantum-crypto.mjs.map +1 -0
- package/dist/react-native/storage-service.d.mts +47 -0
- package/dist/react-native/storage-service.d.mts.map +1 -0
- package/dist/react-native/storage-service.d.ts +47 -0
- package/dist/react-native/storage-service.d.ts.map +1 -0
- package/dist/react-native/storage-service.js +66 -0
- package/dist/react-native/storage-service.js.map +1 -0
- package/dist/react-native/storage-service.mjs +54 -0
- package/dist/react-native/storage-service.mjs.map +1 -0
- package/dist/react-native/symmetric-crypto.d.mts +28 -0
- package/dist/react-native/symmetric-crypto.d.mts.map +1 -0
- package/dist/react-native/symmetric-crypto.d.ts +28 -0
- package/dist/react-native/symmetric-crypto.d.ts.map +1 -0
- package/dist/react-native/symmetric-crypto.js +52 -0
- package/dist/react-native/symmetric-crypto.js.map +1 -0
- package/dist/react-native/symmetric-crypto.mjs +48 -0
- package/dist/react-native/symmetric-crypto.mjs.map +1 -0
- package/dist/{types-fhvOo6Gw.d.ts → react-native/types-D1R4_m5r.d.mts} +6 -10
- package/dist/react-native/types-D1R4_m5r.d.mts.map +1 -0
- package/dist/{types-cEyToM9T.d.mts → react-native/types-Y0wL7HUH.d.ts} +6 -10
- package/dist/react-native/types-Y0wL7HUH.d.ts.map +1 -0
- package/dist/react-native/types.d.mts +2 -0
- package/dist/react-native/types.d.ts +2 -0
- package/dist/react-native/types.js +11 -0
- package/dist/react-native/types.js.map +1 -0
- package/dist/react-native/types.mjs +10 -0
- package/dist/react-native/types.mjs.map +1 -0
- package/dist/react-native/utils.d.mts +78 -0
- package/dist/react-native/utils.d.mts.map +1 -0
- package/dist/react-native/utils.d.ts +78 -0
- package/dist/react-native/utils.d.ts.map +1 -0
- package/dist/react-native/utils.js +123 -0
- package/dist/react-native/utils.js.map +1 -0
- package/dist/react-native/utils.mjs +109 -0
- package/dist/react-native/utils.mjs.map +1 -0
- package/dist/react-native/xwing-B34h5e3Z.mjs +15 -0
- package/dist/react-native/xwing-B34h5e3Z.mjs.map +1 -0
- package/dist/react-native/xwing-CSdiyHAt.js +33 -0
- package/dist/react-native/xwing-CSdiyHAt.js.map +1 -0
- package/dist/types-D1R4_m5r.d.mts +55 -0
- package/dist/types-D1R4_m5r.d.mts.map +1 -0
- package/dist/types-Y0wL7HUH.d.ts +55 -0
- package/dist/types-Y0wL7HUH.d.ts.map +1 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/types.js.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -8
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +3 -8
- package/dist/utils.mjs.map +1 -1
- package/package.json +4 -1
- package/dist/email-crypto-CPL8ept8.js.map +0 -1
- package/dist/email-crypto-_Wcbvr_n.mjs.map +0 -1
- package/dist/types-cEyToM9T.d.mts.map +0 -1
- package/dist/types-fhvOo6Gw.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -109,24 +109,28 @@ const { key, salt } = await getKeyFromPassword(password);
|
|
|
109
109
|
// Hybrid email encryption
|
|
110
110
|
const email: Email = {
|
|
111
111
|
text: 'email text',
|
|
112
|
+
preview: 'email preview',
|
|
113
|
+
attachmentsSessionKey: new Uint8Array([1, 2, 3, 4]),
|
|
112
114
|
};
|
|
113
115
|
const { secretKey: bobPrivateKeys, publicKey: bobPublicKeys } = await generateEmailKeys();
|
|
114
116
|
const bobWithPublicKeys = {
|
|
115
117
|
email: 'bob email',
|
|
116
118
|
publicHybridKey: bobPublicKeys,
|
|
117
119
|
};
|
|
118
|
-
const
|
|
119
|
-
const decryptedEmail = await decryptEmailHybrid(
|
|
120
|
+
const {encryptedKeys, encEmail} = await encryptEmailHybridForMultipleRecipients(email, [bobWithPublicKeys]);
|
|
121
|
+
const decryptedEmail = await decryptEmailHybrid(encEmail, encryptedKeys[0], bobPrivateKeys);
|
|
120
122
|
|
|
121
123
|
expect(decryptedEmail).toStrictEqual(email);
|
|
122
124
|
|
|
123
125
|
// Hybrid email and subject encryption
|
|
124
126
|
const emailAndSubject: EmailAndSubject = {
|
|
125
127
|
text: 'email text',
|
|
126
|
-
subject: 'email subject'
|
|
128
|
+
subject: 'email subject',
|
|
129
|
+
preview: 'email preview,',
|
|
130
|
+
attachmentsSessionKey: new Uint8Array([1, 2, 3, 4]),
|
|
127
131
|
};
|
|
128
|
-
const
|
|
129
|
-
const decryptedEmailAndSubject = await decryptEmailAndSubjectHybrid(
|
|
132
|
+
const {encryptedKeys, encEmail} = await encryptEmailAndSubjectHybridForMultipleRecipients(emailAndSubject, [bobWithPublicKeys]);
|
|
133
|
+
const decryptedEmailAndSubject = await decryptEmailAndSubjectHybrid(encEmail, encryptedKeys[0], bobPrivateKeys);
|
|
130
134
|
|
|
131
135
|
expect(encryptedEmailAndSubject.encEmail.encSubject).not.toBe(emailAndSubject.subject);
|
|
132
136
|
expect(decryptedEmailAndSubject).toStrictEqual(emailAndSubject);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asymmetric-crypto.d.mts","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"asymmetric-crypto.d.mts","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"mappings":";;AAcA;;;;;;iBAAsB,eAAA,CAAgB,cAAA,EAAgB,UAAA,EAAY,YAAA,EAAc,UAAA,GAAa,OAAA,CAAQ,UAAA;;;;;;iBAe/E,eAAA,CAAA,GAAmB,OAAA;EAAU,SAAA,EAAW,UAAA;EAAY,SAAA,EAAW,UAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asymmetric-crypto.d.ts","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"asymmetric-crypto.d.ts","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"mappings":";;AAcA;;;;;;iBAAsB,eAAA,CAAgB,cAAA,EAAgB,UAAA,EAAY,YAAA,EAAc,UAAA,GAAa,OAAA,CAAQ,UAAA;;;;;;iBAe/E,eAAA,CAAA,GAAmB,OAAA;EAAU,SAAA,EAAW,UAAA;EAAY,SAAA,EAAW,UAAA;AAAA"}
|
|
@@ -2,6 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
require("./chunk-C13QxCFV.js");
|
|
3
3
|
let _noble_curves_webcrypto_js = require("@noble/curves/webcrypto.js");
|
|
4
4
|
//#region src/asymmetric-crypto/ellipticCurve.ts
|
|
5
|
+
function asBytes(result) {
|
|
6
|
+
if (result instanceof Uint8Array) return result;
|
|
7
|
+
throw new Error("Expected raw key bytes, got JWK");
|
|
8
|
+
}
|
|
5
9
|
/**
|
|
6
10
|
* Derives secret key from the other user's public key and own private key
|
|
7
11
|
*
|
|
@@ -11,7 +15,9 @@ let _noble_curves_webcrypto_js = require("@noble/curves/webcrypto.js");
|
|
|
11
15
|
*/
|
|
12
16
|
async function deriveSecretKey(aliceSecretKey, bobPublicKey) {
|
|
13
17
|
try {
|
|
14
|
-
|
|
18
|
+
const spkiPublic = asBytes(await _noble_curves_webcrypto_js.x25519.utils.convertPublicKey(bobPublicKey, "raw", "spki"));
|
|
19
|
+
const pkcs8Secret = asBytes(await _noble_curves_webcrypto_js.x25519.utils.convertSecretKey(aliceSecretKey, "raw", "pkcs8"));
|
|
20
|
+
return await _noble_curves_webcrypto_js.x25519.getSharedSecret(pkcs8Secret, spkiPublic);
|
|
15
21
|
} catch (error) {
|
|
16
22
|
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
17
23
|
}
|
|
@@ -22,7 +28,11 @@ async function deriveSecretKey(aliceSecretKey, bobPublicKey) {
|
|
|
22
28
|
* @returns The generated key pair
|
|
23
29
|
*/
|
|
24
30
|
async function generateEccKeys() {
|
|
25
|
-
|
|
31
|
+
const { secretKey, publicKey } = await _noble_curves_webcrypto_js.x25519.keygen();
|
|
32
|
+
return {
|
|
33
|
+
secretKey: asBytes(await _noble_curves_webcrypto_js.x25519.utils.convertSecretKey(secretKey, "pkcs8", "raw")),
|
|
34
|
+
publicKey: asBytes(await _noble_curves_webcrypto_js.x25519.utils.convertPublicKey(publicKey, "spki", "raw"))
|
|
35
|
+
};
|
|
26
36
|
}
|
|
27
37
|
//#endregion
|
|
28
38
|
exports.deriveSecretKey = deriveSecretKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asymmetric-crypto.js","names":["x25519"],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"sourcesContent":["import { x25519 } from '@noble/curves/webcrypto.js';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param aliceSecretKey - The secret key of the user deriving the shared secret key\n * @param bobPublicKey - The public key of the other user\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(aliceSecretKey: Uint8Array, bobPublicKey: Uint8Array): Promise<Uint8Array> {\n try {\n return await x25519.getSharedSecret(
|
|
1
|
+
{"version":3,"file":"asymmetric-crypto.js","names":["x25519"],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"sourcesContent":["import { x25519 } from '@noble/curves/webcrypto.js';\n\nfunction asBytes(result: unknown): Uint8Array {\n if (result instanceof Uint8Array) return result;\n throw new Error('Expected raw key bytes, got JWK');\n}\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param aliceSecretKey - The secret key of the user deriving the shared secret key\n * @param bobPublicKey - The public key of the other user\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(aliceSecretKey: Uint8Array, bobPublicKey: Uint8Array): Promise<Uint8Array> {\n try {\n const spkiPublic = asBytes(await x25519.utils.convertPublicKey(bobPublicKey, 'raw', 'spki'));\n const pkcs8Secret = asBytes(await x25519.utils.convertSecretKey(aliceSecretKey, 'raw', 'pkcs8'));\n return await x25519.getSharedSecret(pkcs8Secret, spkiPublic);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<{ secretKey: Uint8Array; publicKey: Uint8Array }> {\n const { secretKey, publicKey } = await x25519.keygen();\n return {\n secretKey: asBytes(await x25519.utils.convertSecretKey(secretKey, 'pkcs8', 'raw')),\n publicKey: asBytes(await x25519.utils.convertPublicKey(publicKey, 'spki', 'raw')),\n };\n}\n"],"mappings":";;;;AAEA,SAAS,QAAQ,QAA6B;AAC5C,KAAI,kBAAkB,WAAY,QAAO;AACzC,OAAM,IAAI,MAAM,kCAAkC;;;;;;;;;AAUpD,eAAsB,gBAAgB,gBAA4B,cAA+C;AAC/G,KAAI;EACF,MAAM,aAAa,QAAQ,MAAMA,2BAAAA,OAAO,MAAM,iBAAiB,cAAc,OAAO,OAAO,CAAC;EAC5F,MAAM,cAAc,QAAQ,MAAMA,2BAAAA,OAAO,MAAM,iBAAiB,gBAAgB,OAAO,QAAQ,CAAC;AAChG,SAAO,MAAMA,2BAAAA,OAAO,gBAAgB,aAAa,WAAW;UACrD,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,kBAA6E;CACjG,MAAM,EAAE,WAAW,cAAc,MAAMA,2BAAAA,OAAO,QAAQ;AACtD,QAAO;EACL,WAAW,QAAQ,MAAMA,2BAAAA,OAAO,MAAM,iBAAiB,WAAW,SAAS,MAAM,CAAC;EAClF,WAAW,QAAQ,MAAMA,2BAAAA,OAAO,MAAM,iBAAiB,WAAW,QAAQ,MAAM,CAAC;EAClF"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { x25519 } from "@noble/curves/webcrypto.js";
|
|
2
2
|
//#region src/asymmetric-crypto/ellipticCurve.ts
|
|
3
|
+
function asBytes(result) {
|
|
4
|
+
if (result instanceof Uint8Array) return result;
|
|
5
|
+
throw new Error("Expected raw key bytes, got JWK");
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Derives secret key from the other user's public key and own private key
|
|
5
9
|
*
|
|
@@ -9,7 +13,9 @@ import { x25519 } from "@noble/curves/webcrypto.js";
|
|
|
9
13
|
*/
|
|
10
14
|
async function deriveSecretKey(aliceSecretKey, bobPublicKey) {
|
|
11
15
|
try {
|
|
12
|
-
|
|
16
|
+
const spkiPublic = asBytes(await x25519.utils.convertPublicKey(bobPublicKey, "raw", "spki"));
|
|
17
|
+
const pkcs8Secret = asBytes(await x25519.utils.convertSecretKey(aliceSecretKey, "raw", "pkcs8"));
|
|
18
|
+
return await x25519.getSharedSecret(pkcs8Secret, spkiPublic);
|
|
13
19
|
} catch (error) {
|
|
14
20
|
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
15
21
|
}
|
|
@@ -20,7 +26,11 @@ async function deriveSecretKey(aliceSecretKey, bobPublicKey) {
|
|
|
20
26
|
* @returns The generated key pair
|
|
21
27
|
*/
|
|
22
28
|
async function generateEccKeys() {
|
|
23
|
-
|
|
29
|
+
const { secretKey, publicKey } = await x25519.keygen();
|
|
30
|
+
return {
|
|
31
|
+
secretKey: asBytes(await x25519.utils.convertSecretKey(secretKey, "pkcs8", "raw")),
|
|
32
|
+
publicKey: asBytes(await x25519.utils.convertPublicKey(publicKey, "spki", "raw"))
|
|
33
|
+
};
|
|
24
34
|
}
|
|
25
35
|
//#endregion
|
|
26
36
|
export { deriveSecretKey, generateEccKeys };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asymmetric-crypto.mjs","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"sourcesContent":["import { x25519 } from '@noble/curves/webcrypto.js';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param aliceSecretKey - The secret key of the user deriving the shared secret key\n * @param bobPublicKey - The public key of the other user\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(aliceSecretKey: Uint8Array, bobPublicKey: Uint8Array): Promise<Uint8Array> {\n try {\n return await x25519.getSharedSecret(
|
|
1
|
+
{"version":3,"file":"asymmetric-crypto.mjs","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts"],"sourcesContent":["import { x25519 } from '@noble/curves/webcrypto.js';\n\nfunction asBytes(result: unknown): Uint8Array {\n if (result instanceof Uint8Array) return result;\n throw new Error('Expected raw key bytes, got JWK');\n}\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param aliceSecretKey - The secret key of the user deriving the shared secret key\n * @param bobPublicKey - The public key of the other user\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(aliceSecretKey: Uint8Array, bobPublicKey: Uint8Array): Promise<Uint8Array> {\n try {\n const spkiPublic = asBytes(await x25519.utils.convertPublicKey(bobPublicKey, 'raw', 'spki'));\n const pkcs8Secret = asBytes(await x25519.utils.convertSecretKey(aliceSecretKey, 'raw', 'pkcs8'));\n return await x25519.getSharedSecret(pkcs8Secret, spkiPublic);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<{ secretKey: Uint8Array; publicKey: Uint8Array }> {\n const { secretKey, publicKey } = await x25519.keygen();\n return {\n secretKey: asBytes(await x25519.utils.convertSecretKey(secretKey, 'pkcs8', 'raw')),\n publicKey: asBytes(await x25519.utils.convertPublicKey(publicKey, 'spki', 'raw')),\n };\n}\n"],"mappings":";;AAEA,SAAS,QAAQ,QAA6B;AAC5C,KAAI,kBAAkB,WAAY,QAAO;AACzC,OAAM,IAAI,MAAM,kCAAkC;;;;;;;;;AAUpD,eAAsB,gBAAgB,gBAA4B,cAA+C;AAC/G,KAAI;EACF,MAAM,aAAa,QAAQ,MAAM,OAAO,MAAM,iBAAiB,cAAc,OAAO,OAAO,CAAC;EAC5F,MAAM,cAAc,QAAQ,MAAM,OAAO,MAAM,iBAAiB,gBAAgB,OAAO,QAAQ,CAAC;AAChG,SAAO,MAAM,OAAO,gBAAgB,aAAa,WAAW;UACrD,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,kBAA6E;CACjG,MAAM,EAAE,WAAW,cAAc,MAAM,OAAO,QAAQ;AACtD,QAAO;EACL,WAAW,QAAQ,MAAM,OAAO,MAAM,iBAAiB,WAAW,SAAS,MAAM,CAAC;EAClF,WAAW,QAAQ,MAAM,OAAO,MAAM,iBAAiB,WAAW,QAAQ,MAAM,CAAC;EAClF"}
|
|
@@ -31,54 +31,70 @@ async function wrapKey(key, wrappingKey) {
|
|
|
31
31
|
var FailedToEncryptEmail = class FailedToEncryptEmail extends Error {
|
|
32
32
|
constructor(errorMsg) {
|
|
33
33
|
super("Failed to encrypt email: " + errorMsg);
|
|
34
|
+
this.name = this.constructor.name;
|
|
34
35
|
Object.setPrototypeOf(this, FailedToEncryptEmail.prototype);
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
var EmailSymmetricEncryptionError = class EmailSymmetricEncryptionError extends Error {
|
|
38
39
|
constructor(errorMsg) {
|
|
39
40
|
super("Failed to symmetrically encrypt email: " + errorMsg);
|
|
41
|
+
this.name = this.constructor.name;
|
|
40
42
|
Object.setPrototypeOf(this, EmailSymmetricEncryptionError.prototype);
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
45
|
var EmailSymmetricDecryptionError = class EmailSymmetricDecryptionError extends Error {
|
|
44
46
|
constructor(errorMsg) {
|
|
45
47
|
super("Failed to symmetrically decrypt email: " + errorMsg);
|
|
48
|
+
this.name = this.constructor.name;
|
|
46
49
|
Object.setPrototypeOf(this, EmailSymmetricDecryptionError.prototype);
|
|
47
50
|
}
|
|
48
51
|
};
|
|
52
|
+
var EmailPreviewSymmetricDecryptionError = class EmailPreviewSymmetricDecryptionError extends Error {
|
|
53
|
+
constructor(errorMsg) {
|
|
54
|
+
super("Failed to symmetrically decrypt email preview: " + errorMsg);
|
|
55
|
+
this.name = this.constructor.name;
|
|
56
|
+
Object.setPrototypeOf(this, EmailPreviewSymmetricDecryptionError.prototype);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
49
59
|
var EmailHybridEncryptionError = class EmailHybridEncryptionError extends Error {
|
|
50
60
|
constructor(errorMsg) {
|
|
51
61
|
super("Failed to hybridly encrypt the key: " + errorMsg);
|
|
62
|
+
this.name = this.constructor.name;
|
|
52
63
|
Object.setPrototypeOf(this, EmailHybridEncryptionError.prototype);
|
|
53
64
|
}
|
|
54
65
|
};
|
|
55
66
|
var EmailHybridDecryptionError = class EmailHybridDecryptionError extends Error {
|
|
56
67
|
constructor(errorMsg) {
|
|
57
68
|
super("Failed to hybridly decrypt the key: " + errorMsg);
|
|
69
|
+
this.name = this.constructor.name;
|
|
58
70
|
Object.setPrototypeOf(this, EmailHybridDecryptionError.prototype);
|
|
59
71
|
}
|
|
60
72
|
};
|
|
61
73
|
var EmailPasswordProtectError = class EmailPasswordProtectError extends Error {
|
|
62
74
|
constructor(errorMsg) {
|
|
63
75
|
super("Failed to password-protect the key: " + errorMsg);
|
|
76
|
+
this.name = this.constructor.name;
|
|
64
77
|
Object.setPrototypeOf(this, EmailPasswordProtectError.prototype);
|
|
65
78
|
}
|
|
66
79
|
};
|
|
67
80
|
var EmailPasswordOpenError = class EmailPasswordOpenError extends Error {
|
|
68
81
|
constructor(errorMsg) {
|
|
69
82
|
super("Failed to open password-protected key: " + errorMsg);
|
|
83
|
+
this.name = this.constructor.name;
|
|
70
84
|
Object.setPrototypeOf(this, EmailPasswordOpenError.prototype);
|
|
71
85
|
}
|
|
72
86
|
};
|
|
73
87
|
var InvalidInputEmail = class InvalidInputEmail extends Error {
|
|
74
88
|
constructor() {
|
|
75
89
|
super("Invalid input");
|
|
90
|
+
this.name = this.constructor.name;
|
|
76
91
|
Object.setPrototypeOf(this, InvalidInputEmail.prototype);
|
|
77
92
|
}
|
|
78
93
|
};
|
|
79
94
|
var FailedToDecryptEmail = class FailedToDecryptEmail extends Error {
|
|
80
95
|
constructor(errorMsg) {
|
|
81
96
|
super("Failed to decrypt email: " + errorMsg);
|
|
97
|
+
this.name = this.constructor.name;
|
|
82
98
|
Object.setPrototypeOf(this, FailedToDecryptEmail.prototype);
|
|
83
99
|
}
|
|
84
100
|
};
|
|
@@ -113,12 +129,33 @@ async function encryptEmail(email, aux) {
|
|
|
113
129
|
*/
|
|
114
130
|
async function encryptEmailWithKey(email, encryptionKey, aux) {
|
|
115
131
|
try {
|
|
116
|
-
|
|
132
|
+
const text = UTF8ToUint8(email.text);
|
|
133
|
+
const preview = UTF8ToUint8(email.preview);
|
|
134
|
+
return {
|
|
135
|
+
encText: uint8ArrayToBase64(await encryptSymmetrically(encryptionKey, text, aux)),
|
|
136
|
+
encPreview: uint8ArrayToBase64(await encryptSymmetrically(encryptionKey, preview, aux)),
|
|
137
|
+
encAttachmentsSessionKey: uint8ArrayToBase64(await encryptSymmetrically(encryptionKey, email.attachmentsSessionKey, aux))
|
|
138
|
+
};
|
|
117
139
|
} catch (error) {
|
|
118
140
|
throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
143
|
/**
|
|
144
|
+
* Decrypts symmetrically encrypted email preview.
|
|
145
|
+
*
|
|
146
|
+
* @param encEmailPreview - The email preview to decrypt.
|
|
147
|
+
* @param encryptionKey - The symmetric key to decrypt the email.
|
|
148
|
+
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
149
|
+
* @returns The resulting decrypted email
|
|
150
|
+
*/
|
|
151
|
+
async function decryptPreview(encEmailPreview, encryptionKey, aux) {
|
|
152
|
+
try {
|
|
153
|
+
return uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailPreview), aux));
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new EmailPreviewSymmetricDecryptionError(error instanceof Error ? error.message : String(error));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
122
159
|
* Decrypts symmetrically encrypted email.
|
|
123
160
|
*
|
|
124
161
|
* @param encEmail - The email to decrypt.
|
|
@@ -128,7 +165,11 @@ async function encryptEmailWithKey(email, encryptionKey, aux) {
|
|
|
128
165
|
*/
|
|
129
166
|
async function decryptEmail(encEmail, encryptionKey, aux) {
|
|
130
167
|
try {
|
|
131
|
-
return {
|
|
168
|
+
return {
|
|
169
|
+
text: uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmail.encText), aux)),
|
|
170
|
+
preview: uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmail.encPreview), aux)),
|
|
171
|
+
attachmentsSessionKey: await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmail.encAttachmentsSessionKey), aux)
|
|
172
|
+
};
|
|
132
173
|
} catch (error) {
|
|
133
174
|
throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(error));
|
|
134
175
|
}
|
|
@@ -205,72 +246,39 @@ async function removePasswordProtection(emailEncryptionKey, password) {
|
|
|
205
246
|
//#endregion
|
|
206
247
|
//#region src/email-crypto/hybridEncyptedEmail.ts
|
|
207
248
|
/**
|
|
208
|
-
* Encrypts the email using hybrid encryption.
|
|
209
|
-
*
|
|
210
|
-
* @param email - The email to encrypt.
|
|
211
|
-
* @param recipientPublicKeys - The public keys of the recipient.
|
|
212
|
-
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
213
|
-
* @returns The encrypted email
|
|
214
|
-
*/
|
|
215
|
-
async function encryptEmailHybrid(email, recipient, aux) {
|
|
216
|
-
try {
|
|
217
|
-
const { encryptionKey, encEmail } = await encryptEmail(email, aux);
|
|
218
|
-
return {
|
|
219
|
-
encEmail,
|
|
220
|
-
encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
|
|
221
|
-
};
|
|
222
|
-
} catch (error) {
|
|
223
|
-
if (error instanceof InvalidInputEmail) throw error;
|
|
224
|
-
if (error instanceof EmailSymmetricEncryptionError) throw error;
|
|
225
|
-
if (error instanceof EmailHybridEncryptionError) throw error;
|
|
226
|
-
throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
249
|
* Encrypts the email using hybrid encryption for multiple recipients.
|
|
231
250
|
*
|
|
232
251
|
* @param email - The email to encrypt for multiple recipients.
|
|
233
252
|
* @param recipients - The recipients with corresponding public keys.
|
|
234
253
|
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
235
|
-
* @returns The set of encrypted
|
|
254
|
+
* @returns The set of encrypted keys (one per user) and encrypted email
|
|
236
255
|
*/
|
|
237
256
|
async function encryptEmailHybridForMultipleRecipients(email, recipients, aux) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
encryptedEmails.push({
|
|
245
|
-
encEmail,
|
|
246
|
-
encryptedKey
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
return encryptedEmails;
|
|
250
|
-
} catch (error) {
|
|
251
|
-
if (error instanceof InvalidInputEmail) throw error;
|
|
252
|
-
if (error instanceof EmailSymmetricEncryptionError) throw error;
|
|
253
|
-
if (error instanceof EmailHybridEncryptionError) throw error;
|
|
254
|
-
throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
|
|
255
|
-
}
|
|
257
|
+
if (!recipients || recipients.length === 0) throw new InvalidInputEmail();
|
|
258
|
+
const { encryptionKey, encEmail } = await encryptEmail(email, aux);
|
|
259
|
+
return {
|
|
260
|
+
encryptedKeys: await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient))),
|
|
261
|
+
encEmail
|
|
262
|
+
};
|
|
256
263
|
}
|
|
257
264
|
/**
|
|
258
265
|
* Decrypts the email using hybrid encryption.
|
|
259
266
|
*
|
|
260
267
|
* @param encEmail - The encrypted email.
|
|
268
|
+
* @param encryptedKey - The encrypted key for this recipient.
|
|
261
269
|
* @param recipientPrivateHybridKeys - The private key of the recipient.
|
|
262
270
|
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
263
271
|
* @returns The decrypted email
|
|
264
272
|
*/
|
|
265
|
-
async function decryptEmailHybrid(encEmail, recipientPrivateHybridKeys, aux) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
273
|
+
async function decryptEmailHybrid(encEmail, encryptedKey, recipientPrivateHybridKeys, aux) {
|
|
274
|
+
return await decryptEmail(encEmail, await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys), aux);
|
|
275
|
+
}
|
|
276
|
+
async function decryptEmailPreviewHybrid(encPreview, encryptedKey, recipientPrivateHybridKeys, aux) {
|
|
277
|
+
const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);
|
|
278
|
+
return {
|
|
279
|
+
preview: await decryptPreview(encPreview, encryptionKey, aux),
|
|
280
|
+
encryptionKey
|
|
281
|
+
};
|
|
274
282
|
}
|
|
275
283
|
//#endregion
|
|
276
284
|
//#region src/email-crypto/pwdProtectedEmail.ts
|
|
@@ -378,73 +386,32 @@ async function decryptEmailAndSubject(encEmail, encryptionKey, aux) {
|
|
|
378
386
|
//#endregion
|
|
379
387
|
//#region src/email-crypto/hybridEncryptedEmailAndSubject.ts
|
|
380
388
|
/**
|
|
381
|
-
* Encrypts the email and its subject using hybrid encryption.
|
|
382
|
-
*
|
|
383
|
-
* @param email - The email and subject to encrypt.
|
|
384
|
-
* @param recipientPublicKeys - The public keys of the recipient.
|
|
385
|
-
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
386
|
-
* @returns The encrypted email and subject
|
|
387
|
-
*/
|
|
388
|
-
async function encryptEmailAndSubjectHybrid(email, recipient, aux) {
|
|
389
|
-
try {
|
|
390
|
-
const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);
|
|
391
|
-
return {
|
|
392
|
-
encEmail,
|
|
393
|
-
encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
|
|
394
|
-
};
|
|
395
|
-
} catch (error) {
|
|
396
|
-
if (error instanceof InvalidInputEmail) throw error;
|
|
397
|
-
if (error instanceof EmailSymmetricEncryptionError) throw error;
|
|
398
|
-
if (error instanceof EmailHybridEncryptionError) throw error;
|
|
399
|
-
throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
389
|
* Encrypts the email and its subject using hybrid encryption for multiple recipients.
|
|
404
390
|
*
|
|
405
391
|
* @param email - The email and subject to encrypt for multiple recipients.
|
|
406
392
|
* @param recipients - The recipients with corresponding public keys.
|
|
407
393
|
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
408
|
-
* @returns The set of encrypted
|
|
394
|
+
* @returns The set of encrypted keys and encrypted email and subject
|
|
409
395
|
*/
|
|
410
396
|
async function encryptEmailAndSubjectHybridForMultipleRecipients(email, recipients, aux) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
encryptedEmails.push({
|
|
418
|
-
encEmail,
|
|
419
|
-
encryptedKey
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
return encryptedEmails;
|
|
423
|
-
} catch (error) {
|
|
424
|
-
if (error instanceof InvalidInputEmail) throw error;
|
|
425
|
-
if (error instanceof EmailSymmetricEncryptionError) throw error;
|
|
426
|
-
if (error instanceof EmailHybridEncryptionError) throw error;
|
|
427
|
-
throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));
|
|
428
|
-
}
|
|
397
|
+
if (!recipients || recipients.length === 0) throw new InvalidInputEmail();
|
|
398
|
+
const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);
|
|
399
|
+
return {
|
|
400
|
+
encEmail,
|
|
401
|
+
encryptedKeys: await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient)))
|
|
402
|
+
};
|
|
429
403
|
}
|
|
430
404
|
/**
|
|
431
405
|
* Decrypts the email and its subject using hybrid encryption.
|
|
432
406
|
*
|
|
433
|
-
* @param
|
|
407
|
+
* @param encEmail - The encrypted email and subject.
|
|
408
|
+
* @param encryptedKey - The encrypted key for this recipient.
|
|
434
409
|
* @param recipientPrivateHybridKeys - The private key of the recipient.
|
|
435
410
|
* @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
|
|
436
411
|
* @returns The decrypted email and subject
|
|
437
412
|
*/
|
|
438
|
-
async function decryptEmailAndSubjectHybrid(
|
|
439
|
-
|
|
440
|
-
const encryptionKey = await decryptKeysHybrid(hybridEmail.encryptedKey, recipientPrivateHybridKeys);
|
|
441
|
-
return await decryptEmailAndSubject(hybridEmail.encEmail, encryptionKey, aux);
|
|
442
|
-
} catch (error) {
|
|
443
|
-
if (error instanceof InvalidInputEmail) throw error;
|
|
444
|
-
if (error instanceof EmailHybridDecryptionError) throw error;
|
|
445
|
-
if (error instanceof EmailSymmetricDecryptionError) throw error;
|
|
446
|
-
throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));
|
|
447
|
-
}
|
|
413
|
+
async function decryptEmailAndSubjectHybrid(encEmail, encryptedKey, recipientPrivateHybridKeys, aux) {
|
|
414
|
+
return await decryptEmailAndSubject(encEmail, await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys), aux);
|
|
448
415
|
}
|
|
449
416
|
//#endregion
|
|
450
417
|
//#region src/email-crypto/pwdProtectedEmailAndSubject.ts
|
|
@@ -518,6 +485,6 @@ const deriveEmailDraftKey = async (mnemonic) => {
|
|
|
518
485
|
return deriveKeyFromMnemonic(mnemonic, CONTEXT_DRAFT);
|
|
519
486
|
};
|
|
520
487
|
//#endregion
|
|
521
|
-
export {
|
|
488
|
+
export { EmailSymmetricEncryptionError as A, removePasswordProtection as C, EmailPasswordProtectError as D, EmailPasswordOpenError as E, wrapKey as F, FailedToEncryptEmail as M, InvalidInputEmail as N, EmailPreviewSymmetricDecryptionError as O, unwrapKey as P, passwordProtectKey as S, EmailHybridEncryptionError as T, decryptKeysHybrid as _, decryptPwdProtectedEmailAndSubject as a, encryptEmailWithKey as b, decryptEmailAndSubject as c, createPwdProtectedEmail as d, decryptPwdProtectedEmail as f, decryptEmail as g, encryptEmailHybridForMultipleRecipients as h, createPwdProtectedEmailAndSubject as i, FailedToDecryptEmail as j, EmailSymmetricDecryptionError as k, encryptEmailAndSubject as l, decryptEmailPreviewHybrid as m, deriveEmailDraftKey as n, decryptEmailAndSubjectHybrid as o, decryptEmailHybrid as p, generateEmailKeys as r, encryptEmailAndSubjectHybridForMultipleRecipients as s, deriveDatabaseKey as t, encryptEmailAndSubjectWithKey as u, decryptPreview as v, EmailHybridDecryptionError as w, encryptKeysHybrid as x, encryptEmail as y };
|
|
522
489
|
|
|
523
|
-
//# sourceMappingURL=email-crypto-
|
|
490
|
+
//# sourceMappingURL=email-crypto-CoRbTphp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-crypto-CoRbTphp.mjs","names":[],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/errors.ts","../src/email-crypto/core.ts","../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/coreSubject.ts","../src/email-crypto/hybridEncryptedEmailAndSubject.ts","../src/email-crypto/pwdProtectedEmailAndSubject.ts","../src/email-crypto/emailKeys.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","export class FailedToEncryptEmail extends Error {\n constructor(errorMsg?: string) {\n super('Failed to encrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, FailedToEncryptEmail.prototype);\n }\n}\n\nexport class EmailSymmetricEncryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to symmetrically encrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailSymmetricEncryptionError.prototype);\n }\n}\n\nexport class EmailSymmetricDecryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to symmetrically decrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailSymmetricDecryptionError.prototype);\n }\n}\n\nexport class EmailPreviewSymmetricDecryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to symmetrically decrypt email preview: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailPreviewSymmetricDecryptionError.prototype);\n }\n}\n\nexport class EmailHybridEncryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to hybridly encrypt the key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailHybridEncryptionError.prototype);\n }\n}\n\nexport class EmailHybridDecryptionError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to hybridly decrypt the key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailHybridDecryptionError.prototype);\n }\n}\n\nexport class EmailPasswordProtectError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to password-protect the key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailPasswordProtectError.prototype);\n }\n}\n\nexport class EmailPasswordOpenError extends Error {\n constructor(errorMsg?: string) {\n super('Failed to open password-protected key: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, EmailPasswordOpenError.prototype);\n }\n}\n\nexport class InvalidInputEmail extends Error {\n constructor() {\n super('Invalid input');\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, InvalidInputEmail.prototype);\n }\n}\n\nexport class FailedToDecryptEmail extends Error {\n constructor(errorMsg?: string) {\n super('Failed to decrypt email: ' + errorMsg);\n\n this.name = this.constructor.name;\n Object.setPrototypeOf(this, FailedToDecryptEmail.prototype);\n }\n}\n","import { HybridEncKey, PwdProtectedKey, Email, RecipientWithPublicKey, EmailEncrypted } 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';\nimport {\n EmailHybridDecryptionError,\n EmailHybridEncryptionError,\n InvalidInputEmail,\n EmailSymmetricDecryptionError,\n EmailSymmetricEncryptionError,\n EmailPasswordOpenError,\n EmailPasswordProtectError,\n EmailPreviewSymmetricDecryptionError,\n} from './errors';\n\n/**\n * Symmetrically encrypts email.\n *\n * @param email - The email to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email and symmetric key used for encryption\n */\nexport async function encryptEmail(\n email: Email,\n aux?: Uint8Array,\n): Promise<{\n encEmail: EmailEncrypted;\n encryptionKey: Uint8Array;\n}> {\n if (!email.text) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = genSymmetricKey();\n const encEmail = await encryptEmailWithKey(email, encryptionKey, aux);\n\n return { encEmail, encryptionKey };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Symmetrically encrypts email with the given key.\n *\n * @param email - The email 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 and symmetric key used for encryption\n */\nexport async function encryptEmailWithKey(\n email: Email,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailEncrypted> {\n try {\n const text = UTF8ToUint8(email.text);\n const preview = UTF8ToUint8(email.preview);\n\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n\n const encryptedPreview = await encryptSymmetrically(encryptionKey, preview, aux);\n const encPreview = uint8ArrayToBase64(encryptedPreview);\n\n const encryptedAttachmentsSessionKey = await encryptSymmetrically(encryptionKey, email.attachmentsSessionKey, aux);\n const encAttachmentsSessionKey = uint8ArrayToBase64(encryptedAttachmentsSessionKey);\n\n return { encText, encPreview, encAttachmentsSessionKey };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email preview.\n *\n * @param encEmailPreview - The email preview 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\n */\nexport async function decryptPreview(\n encEmailPreview: string,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<string> {\n try {\n const encPreview = base64ToUint8Array(encEmailPreview);\n const previewArray = await decryptSymmetrically(encryptionKey, encPreview, aux);\n const preview = uint8ToUTF8(previewArray);\n\n return preview;\n } catch (error) {\n throw new EmailPreviewSymmetricDecryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email.\n *\n * @param encEmail - The email 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\n */\nexport async function decryptEmail(\n encEmail: EmailEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<Email> {\n try {\n const encText = base64ToUint8Array(encEmail.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n\n const encPreview = base64ToUint8Array(encEmail.encPreview);\n const previewArray = await decryptSymmetrically(encryptionKey, encPreview, aux);\n const preview = uint8ToUTF8(previewArray);\n\n const encAttachementSessionKey = base64ToUint8Array(encEmail.encAttachmentsSessionKey);\n const attachmentsSessionKey = await decryptSymmetrically(encryptionKey, encAttachementSessionKey, aux);\n\n return { text, preview, attachmentsSessionKey };\n } catch (error) {\n throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(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 EmailHybridEncryptionError(error instanceof Error ? error.message : String(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 EmailHybridDecryptionError(error instanceof Error ? error.message : String(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 EmailPasswordProtectError(error instanceof Error ? error.message : String(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 EmailPasswordOpenError(error instanceof Error ? error.message : String(error));\n }\n}\n","import { Email, RecipientWithPublicKey, HybridEncKey, EmailEncrypted } from '../types';\nimport { decryptEmail, decryptPreview, encryptKeysHybrid, decryptKeysHybrid, encryptEmail } from './core';\nimport { InvalidInputEmail } from './errors';\n\n/**\n * Encrypts the email using hybrid encryption for multiple recipients.\n *\n * @param email - The email 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 keys (one per user) and encrypted email\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n email: Email,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<{ encryptedKeys: HybridEncKey[]; encEmail: EmailEncrypted }> {\n if (!recipients || recipients.length === 0) {\n throw new InvalidInputEmail();\n }\n const { encryptionKey, encEmail } = await encryptEmail(email, aux);\n\n const encryptedKeys = await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient)));\n\n return { encryptedKeys, encEmail };\n}\n\n/**\n * Decrypts the email using hybrid encryption.\n *\n * @param encEmail - The encrypted email.\n * @param encryptedKey - The encrypted key for this recipient.\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\n */\nexport async function decryptEmailHybrid(\n encEmail: EmailEncrypted,\n encryptedKey: HybridEncKey,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<Email> {\n const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);\n return await decryptEmail(encEmail, encryptionKey, aux);\n}\n\nexport async function decryptEmailPreviewHybrid(\n encPreview: string,\n encryptedKey: HybridEncKey,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<{ preview: string; encryptionKey: Uint8Array }> {\n const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);\n const preview = await decryptPreview(encPreview, encryptionKey, aux);\n return { preview, encryptionKey };\n}\n","import { PwdProtectedEmail, Email } from '../types';\nimport { decryptEmail, passwordProtectKey, removePasswordProtection, encryptEmail } from './core';\nimport {\n EmailSymmetricEncryptionError,\n FailedToDecryptEmail,\n FailedToEncryptEmail,\n EmailPasswordProtectError,\n EmailSymmetricDecryptionError,\n EmailPasswordOpenError,\n InvalidInputEmail,\n} from './errors';\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 email: Email,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmail } = await encryptEmail(email, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmail, encryptedKey };\n } catch (error) {\n if (error instanceof InvalidInputEmail) throw error;\n if (error instanceof EmailSymmetricEncryptionError) throw error;\n if (error instanceof EmailPasswordProtectError) throw error;\n throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(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\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<Email> {\n if (!encryptedEmail?.encEmail || !encryptedEmail?.encryptedKey) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n return await decryptEmail(encryptedEmail.encEmail, encryptionKey, aux);\n } catch (error) {\n if (error instanceof EmailPasswordOpenError) throw error;\n if (error instanceof EmailSymmetricDecryptionError) throw error;\n throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));\n }\n}\n","import { EmailAndSubject, EmailAndSubjectEncrypted } from '../types';\nimport { encryptSymmetrically, decryptSymmetrically, genSymmetricKey } from '../symmetric-crypto';\nimport { encryptEmailWithKey, decryptEmail } from './core';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8 } from '../utils';\nimport { InvalidInputEmail, EmailSymmetricDecryptionError, EmailSymmetricEncryptionError } from './errors';\n\n/**\n * Symmetrically encrypts email and subject.\n *\n * @param email - The email and subject to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email and symmetric key used for encryption\n */\nexport async function encryptEmailAndSubject(\n email: EmailAndSubject,\n aux?: Uint8Array,\n): Promise<{\n encEmail: EmailAndSubjectEncrypted;\n encryptionKey: Uint8Array;\n}> {\n if (!email.text || !email.subject) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = genSymmetricKey();\n const encEmail = await encryptEmailAndSubjectWithKey(email, encryptionKey, aux);\n\n return { encEmail, encryptionKey };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Symmetrically encrypts email and subject with the given key.\n *\n * @param email - The email and subject 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 and symmetric key used for encryption\n */\nexport async function encryptEmailAndSubjectWithKey(\n email: EmailAndSubject,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailAndSubjectEncrypted> {\n try {\n const enc = await encryptEmailWithKey(email, encryptionKey, aux);\n const subject = UTF8ToUint8(email.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n\n return { ...enc, encSubject };\n } catch (error) {\n throw new EmailSymmetricEncryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email and email subject.\n *\n * @param encEmail - The encrypted email and subject 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 and subject\n */\nexport async function decryptEmailAndSubject(\n encEmail: EmailAndSubjectEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailAndSubject> {\n try {\n const encSubject = base64ToUint8Array(encEmail.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const email = await decryptEmail(encEmail, encryptionKey, aux);\n\n return { ...email, subject };\n } catch (error) {\n throw new EmailSymmetricDecryptionError(error instanceof Error ? error.message : String(error));\n }\n}\n","import { RecipientWithPublicKey, EmailAndSubject, EmailAndSubjectEncrypted, HybridEncKey } from '../types';\nimport { encryptKeysHybrid, decryptKeysHybrid } from './core';\nimport { encryptEmailAndSubject, decryptEmailAndSubject } from './coreSubject';\nimport {\n InvalidInputEmail,\n} from './errors';\n\n/**\n * Encrypts the email and its subject using hybrid encryption for multiple recipients.\n *\n * @param email - The email and subject 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 keys and encrypted email and subject\n */\nexport async function encryptEmailAndSubjectHybridForMultipleRecipients(\n email: EmailAndSubject,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<{ encryptedKeys: HybridEncKey[]; encEmail: EmailAndSubjectEncrypted }> {\n if (!recipients || recipients.length === 0) {\n throw new InvalidInputEmail();\n }\n const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);\n\n const encryptedKeys = await Promise.all(recipients.map((recipient) => encryptKeysHybrid(encryptionKey, recipient)));\n\n return { encEmail, encryptedKeys };\n}\n\n/**\n * Decrypts the email and its subject using hybrid encryption.\n *\n * @param encEmail - The encrypted email and subject.\n * @param encryptedKey - The encrypted key for this recipient.\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 and subject\n */\nexport async function decryptEmailAndSubjectHybrid(\n encEmail: EmailAndSubjectEncrypted,\n encryptedKey: HybridEncKey,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailAndSubject> {\n const encryptionKey = await decryptKeysHybrid(encryptedKey, recipientPrivateHybridKeys);\n return await decryptEmailAndSubject(encEmail, encryptionKey, aux);\n}\n","import { EmailAndSubject, PwdProtectedEmailAndSubject } from '../types';\nimport { passwordProtectKey, removePasswordProtection } from './core';\nimport { encryptEmailAndSubject, decryptEmailAndSubject } from './coreSubject';\nimport {\n FailedToDecryptEmail,\n FailedToEncryptEmail,\n InvalidInputEmail,\n EmailPasswordOpenError,\n EmailPasswordProtectError,\n EmailSymmetricDecryptionError,\n EmailSymmetricEncryptionError,\n} from './errors';\n\n/**\n * Creates a password-protected email and subject.\n *\n * @param email - The email and subject 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 createPwdProtectedEmailAndSubject(\n email: EmailAndSubject,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmailAndSubject> {\n try {\n const { encryptionKey, encEmail } = await encryptEmailAndSubject(email, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmail, encryptedKey };\n } catch (error) {\n if (error instanceof InvalidInputEmail) throw error;\n if (error instanceof EmailSymmetricEncryptionError) throw error;\n if (error instanceof EmailPasswordProtectError) throw error;\n throw new FailedToEncryptEmail(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Opens a password-protected email and subject.\n *\n * @param encryptedEmail - The encrypted email and subject\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 and subject\n */\nexport async function decryptPwdProtectedEmailAndSubject(\n encryptedEmail: PwdProtectedEmailAndSubject,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailAndSubject> {\n if (!encryptedEmail?.encEmail || !encryptedEmail?.encryptedKey) {\n throw new InvalidInputEmail();\n }\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n return await decryptEmailAndSubject(encryptedEmail.encEmail, encryptionKey, aux);\n } catch (error) {\n if (error instanceof EmailPasswordOpenError) throw error;\n if (error instanceof EmailSymmetricDecryptionError) throw error;\n throw new FailedToDecryptEmail(error instanceof Error ? error.message : String(error));\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\nimport { deriveKeyFromMnemonic } from '../derive-key';\nimport { CONTEXT_DATABASE, CONTEXT_DRAFT } from '../constants';\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\n/**\n * Derives database encryption key for the given user\n *\n * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)\n * @returns The symmetric key for protecting database\n */\nexport const deriveDatabaseKey = async (mnemonic: string): Promise<Uint8Array> => {\n return deriveKeyFromMnemonic(mnemonic, CONTEXT_DATABASE);\n};\n\n/**\n * Derives email draft encryption key for the given user\n *\n * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)\n * @returns The symmetric key for protecting email drafts\n */\nexport const deriveEmailDraftKey = async (mnemonic: string): Promise<Uint8Array> => {\n return deriveKeyFromMnemonic(mnemonic, CONTEXT_DRAFT);\n};\n"],"mappings":";;;;;;;;;;;;;;;AASA,eAAsB,UAAU,cAA0B,aAA8C;AACtG,QAAO,MAAM,YAAY,CAAC,QAAQ,aAAa;;;;;;;;;AAUjD,eAAsB,QAAQ,KAAiB,aAA8C;AAC3F,QAAO,MAAM,YAAY,CAAC,QAAQ,IAAI;;;;ACrBxC,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC9C,YAAY,UAAmB;AAC7B,QAAM,8BAA8B,SAAS;AAE7C,OAAK,OAAO,KAAK,YAAY;AAC7B,SAAO,eAAe,MAAM,qBAAqB,UAAU;;;AAI/D,IAAa,gCAAb,MAAa,sCAAsC,MAAM;CACvD,YAAY,UAAmB;AAC7B,QAAM,4CAA4C,SAAS;AAE3D,OAAK,OAAO,KAAK,YAAY;AAC7B,SAAO,eAAe,MAAM,8BAA8B,UAAU;;;AAIxE,IAAa,gCAAb,MAAa,sCAAsC,MAAM;CACvD,YAAY,UAAmB;AAC7B,QAAM,4CAA4C,SAAS;AAE3D,OAAK,OAAO,KAAK,YAAY;AAC7B,SAAO,eAAe,MAAM,8BAA8B,UAAU;;;AAIxE,IAAa,uCAAb,MAAa,6CAA6C,MAAM;CAC9D,YAAY,UAAmB;AAC7B,QAAM,oDAAoD,SAAS;AAEnE,OAAK,OAAO,KAAK,YAAY;AAC7B,SAAO,eAAe,MAAM,qCAAqC,UAAU;;;AAI/E,IAAa,6BAAb,MAAa,mCAAmC,MAAM;CACpD,YAAY,UAAmB;AAC7B,QAAM,yCAAyC,SAAS;AAExD,OAAK,OAAO,KAAK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