internxt-crypto 1.1.0 → 1.2.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 +11 -7
- package/dist/constants.d.mts +4 -3
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.d.ts +4 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -4
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +4 -3
- package/dist/constants.mjs.map +1 -1
- package/dist/derive-key.d.mts +8 -4
- package/dist/derive-key.d.mts.map +1 -1
- package/dist/derive-key.d.ts +8 -4
- package/dist/derive-key.d.ts.map +1 -1
- package/dist/derive-key.js +4 -4
- package/dist/derive-key.mjs +2 -2
- package/dist/derive-password.d.mts +7 -1
- package/dist/derive-password.d.mts.map +1 -1
- package/dist/derive-password.d.ts +7 -1
- package/dist/derive-password.d.ts.map +1 -1
- package/dist/derive-password.js +2 -1
- package/dist/derive-password.mjs +2 -2
- package/dist/deriveKeysFromMnemonic-DB0UHE-y.mjs +49 -0
- package/dist/deriveKeysFromMnemonic-DB0UHE-y.mjs.map +1 -0
- package/dist/{deriveKeysFromKey-GTRMuxDj.js → deriveKeysFromMnemonic-Dbx7VSBQ.js} +14 -9
- package/dist/deriveKeysFromMnemonic-Dbx7VSBQ.js.map +1 -0
- package/dist/{deriveKeysFromPassword-DXgSvTNC.mjs → deriveKeysFromPassword-DFzo2OII.mjs} +7 -7
- package/dist/{deriveKeysFromPassword-DXgSvTNC.mjs.map → deriveKeysFromPassword-DFzo2OII.mjs.map} +1 -1
- package/dist/{deriveKeysFromPassword-C7xAGGsh.js → deriveKeysFromPassword-iMHv-tIA.js} +12 -6
- package/dist/{deriveKeysFromPassword-C7xAGGsh.js.map → deriveKeysFromPassword-iMHv-tIA.js.map} +1 -1
- package/dist/email-crypto.d.mts +15 -1
- package/dist/email-crypto.d.mts.map +1 -1
- package/dist/email-crypto.d.ts +15 -1
- package/dist/email-crypto.d.ts.map +1 -1
- package/dist/email-crypto.js +3 -1
- package/dist/email-crypto.mjs +2 -2
- package/dist/emailEncryptionKey-Cw-vW_Oq.js +248 -0
- package/dist/emailEncryptionKey-Cw-vW_Oq.js.map +1 -0
- package/dist/emailEncryptionKey-D9sk_WKj.mjs +201 -0
- package/dist/emailEncryptionKey-D9sk_WKj.mjs.map +1 -0
- package/dist/{emailKeys-DWvKANTZ.js → emailKeys-BFI-paQq.js} +34 -2
- package/dist/emailKeys-BFI-paQq.js.map +1 -0
- package/dist/{emailKeys-nzn7U7HQ.mjs → emailKeys-BjIeINfC.mjs} +23 -3
- package/dist/{emailKeys-nzn7U7HQ.mjs.map → emailKeys-BjIeINfC.mjs.map} +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +21 -9
- package/dist/index.mjs +6 -6
- package/dist/keystore-crypto.d.mts +42 -7
- package/dist/keystore-crypto.d.mts.map +1 -1
- package/dist/keystore-crypto.d.ts +42 -7
- package/dist/keystore-crypto.d.ts.map +1 -1
- package/dist/keystore-crypto.js +6 -1
- package/dist/keystore-crypto.mjs +2 -2
- package/package.json +1 -1
- package/dist/deriveKeysFromKey-CseBjg0n.mjs +0 -44
- package/dist/deriveKeysFromKey-CseBjg0n.mjs.map +0 -1
- package/dist/deriveKeysFromKey-GTRMuxDj.js.map +0 -1
- package/dist/emailEncryptionKey-F_YuJu1H.js +0 -144
- package/dist/emailEncryptionKey-F_YuJu1H.js.map +0 -1
- package/dist/emailEncryptionKey-kIsseFo6.mjs +0 -127
- package/dist/emailEncryptionKey-kIsseFo6.mjs.map +0 -1
- package/dist/emailKeys-DWvKANTZ.js.map +0 -1
package/dist/email-crypto.d.mts
CHANGED
|
@@ -56,6 +56,20 @@ declare function decryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, pas
|
|
|
56
56
|
* @returns The user's private and public keys
|
|
57
57
|
*/
|
|
58
58
|
declare function generateEmailKeys(): Promise<HybridKeyPair>;
|
|
59
|
+
/**
|
|
60
|
+
* Derives database encryption key for the given user
|
|
61
|
+
*
|
|
62
|
+
* @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)
|
|
63
|
+
* @returns The symmetric key for protecting database
|
|
64
|
+
*/
|
|
65
|
+
declare const deriveDatabaseKey: (mnemonic: string) => Promise<Uint8Array>;
|
|
66
|
+
/**
|
|
67
|
+
* Derives email draft encryption key for the given user
|
|
68
|
+
*
|
|
69
|
+
* @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)
|
|
70
|
+
* @returns The symmetric key for protecting email drafts
|
|
71
|
+
*/
|
|
72
|
+
declare const deriveEmailDraftKey: (mnemonic: string) => Promise<Uint8Array>;
|
|
59
73
|
//#endregion
|
|
60
74
|
//#region src/email-crypto/core.d.ts
|
|
61
75
|
/**
|
|
@@ -120,5 +134,5 @@ declare function passwordProtectKey(emailEncryptionKey: Uint8Array, password: st
|
|
|
120
134
|
*/
|
|
121
135
|
declare function removePasswordProtection(emailEncryptionKey: PwdProtectedKey, password: string): Promise<Uint8Array>;
|
|
122
136
|
//#endregion
|
|
123
|
-
export { createPwdProtectedEmail, decryptEmailBody, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, encryptEmailBody, encryptEmailBodyWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
|
|
137
|
+
export { createPwdProtectedEmail, decryptEmailBody, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, deriveDatabaseKey, deriveEmailDraftKey, encryptEmailBody, encryptEmailBodyWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
|
|
124
138
|
//# sourceMappingURL=email-crypto.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/core.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;;;;;iBCAsB,uBAAA,CACpB,SAAA,EAAW,SAAA,EACX,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAmBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AD3BX;;;
|
|
1
|
+
{"version":3,"file":"email-crypto.d.mts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/core.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;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ryptPwdProtectedEmail(encryptedEmail: PwdProtectedEmail, pas
|
|
|
56
56
|
* @returns The user's private and public keys
|
|
57
57
|
*/
|
|
58
58
|
declare function generateEmailKeys(): Promise<HybridKeyPair>;
|
|
59
|
+
/**
|
|
60
|
+
* Derives database encryption key for the given user
|
|
61
|
+
*
|
|
62
|
+
* @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)
|
|
63
|
+
* @returns The symmetric key for protecting database
|
|
64
|
+
*/
|
|
65
|
+
declare const deriveDatabaseKey: (mnemonic: string) => Promise<Uint8Array>;
|
|
66
|
+
/**
|
|
67
|
+
* Derives email draft encryption key for the given user
|
|
68
|
+
*
|
|
69
|
+
* @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)
|
|
70
|
+
* @returns The symmetric key for protecting email drafts
|
|
71
|
+
*/
|
|
72
|
+
declare const deriveEmailDraftKey: (mnemonic: string) => Promise<Uint8Array>;
|
|
59
73
|
//#endregion
|
|
60
74
|
//#region src/email-crypto/core.d.ts
|
|
61
75
|
/**
|
|
@@ -120,5 +134,5 @@ declare function passwordProtectKey(emailEncryptionKey: Uint8Array, password: st
|
|
|
120
134
|
*/
|
|
121
135
|
declare function removePasswordProtection(emailEncryptionKey: PwdProtectedKey, password: string): Promise<Uint8Array>;
|
|
122
136
|
//#endregion
|
|
123
|
-
export { createPwdProtectedEmail, decryptEmailBody, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, encryptEmailBody, encryptEmailBodyWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
|
|
137
|
+
export { createPwdProtectedEmail, decryptEmailBody, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, deriveDatabaseKey, deriveEmailDraftKey, encryptEmailBody, encryptEmailBodyWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
|
|
124
138
|
//# sourceMappingURL=email-crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-crypto.d.ts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/core.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;AAJX;;;;iBA8BsB,kBAAA,CACpB,YAAA,EAAc,oBAAA,EACd,0BAAA,EAA4B,UAAA,EAC5B,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AAxDX;;;;;;iBCAsB,uBAAA,CACpB,SAAA,EAAW,SAAA,EACX,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,iBAAA;;;;;;;;;iBAmBW,wBAAA,CACpB,cAAA,EAAgB,iBAAA,EAChB,QAAA,UACA,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,SAAA;;;;;AD3BX;;;
|
|
1
|
+
{"version":3,"file":"email-crypto.d.ts","names":[],"sources":["../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.ts","../src/email-crypto/emailKeys.ts","../src/email-crypto/core.ts"],"mappings":";;;;;AAWA;;;;;;iBAAsB,kBAAA,CACpB,IAAA,EAAM,SAAA,EACN,SAAA,EAAW,sBAAA,EACX,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA;;;;;;;;;iBAkBW,uCAAA,CACpB,IAAA,EAAM,SAAA,EACN,UAAA,EAAY,sBAAA,IACZ,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,oBAAA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;;;;;;;iBAmB9E,wBAAA,CACpB,kBAAA,EAAoB,eAAA,EACpB,QAAA,WACC,OAAA,CAAQ,UAAA"}
|
package/dist/email-crypto.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_emailKeys = require('./emailKeys-
|
|
2
|
+
const require_emailKeys = require('./emailKeys-BFI-paQq.js');
|
|
3
3
|
|
|
4
4
|
exports.createPwdProtectedEmail = require_emailKeys.createPwdProtectedEmail;
|
|
5
5
|
exports.decryptEmailBody = require_emailKeys.decryptEmailBody;
|
|
6
6
|
exports.decryptEmailHybrid = require_emailKeys.decryptEmailHybrid;
|
|
7
7
|
exports.decryptKeysHybrid = require_emailKeys.decryptKeysHybrid;
|
|
8
8
|
exports.decryptPwdProtectedEmail = require_emailKeys.decryptPwdProtectedEmail;
|
|
9
|
+
exports.deriveDatabaseKey = require_emailKeys.deriveDatabaseKey;
|
|
10
|
+
exports.deriveEmailDraftKey = require_emailKeys.deriveEmailDraftKey;
|
|
9
11
|
exports.encryptEmailBody = require_emailKeys.encryptEmailBody;
|
|
10
12
|
exports.encryptEmailBodyWithKey = require_emailKeys.encryptEmailBodyWithKey;
|
|
11
13
|
exports.encryptEmailHybrid = require_emailKeys.encryptEmailHybrid;
|
package/dist/email-crypto.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as decryptPwdProtectedEmail, c as encryptEmailHybridForMultipleRecipients, d as encryptEmailBody, f as encryptEmailBodyWithKey, h as removePasswordProtection, i as createPwdProtectedEmail, l as decryptEmailBody, m as passwordProtectKey, n as deriveEmailDraftKey, o as decryptEmailHybrid, p as encryptKeysHybrid, r as generateEmailKeys, s as encryptEmailHybrid, t as deriveDatabaseKey, u as decryptKeysHybrid } from "./emailKeys-BjIeINfC.mjs";
|
|
2
2
|
|
|
3
|
-
export { createPwdProtectedEmail, decryptEmailBody, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, encryptEmailBody, encryptEmailBodyWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
|
|
3
|
+
export { createPwdProtectedEmail, decryptEmailBody, decryptEmailHybrid, decryptKeysHybrid, decryptPwdProtectedEmail, deriveDatabaseKey, deriveEmailDraftKey, encryptEmailBody, encryptEmailBodyWithKey, encryptEmailHybrid, encryptEmailHybridForMultipleRecipients, encryptKeysHybrid, generateEmailKeys, passwordProtectKey, removePasswordProtection };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
const require_constants = require('./constants.js');
|
|
2
|
+
const require_genID = require('./genID-cWOPmspk.js');
|
|
3
|
+
const require_deriveKeysFromMnemonic = require('./deriveKeysFromMnemonic-Dbx7VSBQ.js');
|
|
4
|
+
const require_deriveKeysFromPassword = require('./deriveKeysFromPassword-iMHv-tIA.js');
|
|
5
|
+
const require_aes = require('./aes-CuW_SPl-.js');
|
|
6
|
+
const require_xwing = require('./xwing-iRWVRtNE.js');
|
|
7
|
+
const require_types = require('./types.js');
|
|
8
|
+
|
|
9
|
+
//#region src/keystore-crypto/core.ts
|
|
10
|
+
/**
|
|
11
|
+
* Encrypts the user's hybrid key using symmetric encryption to get a keystore
|
|
12
|
+
*
|
|
13
|
+
* @param secretKey - The symmetric key to encrypt the keystore content
|
|
14
|
+
* @param key - The hybrid key pair
|
|
15
|
+
* @param userEmail - The email of the user
|
|
16
|
+
* @param type - The keystore type
|
|
17
|
+
* @returns The encrypted keystore
|
|
18
|
+
*/
|
|
19
|
+
async function encryptKeystoreContent(secretKey, keys, userEmail, type) {
|
|
20
|
+
try {
|
|
21
|
+
const aux = require_genID.UTF8ToUint8(userEmail + type);
|
|
22
|
+
return {
|
|
23
|
+
userEmail,
|
|
24
|
+
type,
|
|
25
|
+
publicKey: require_genID.uint8ArrayToBase64(keys.publicKey),
|
|
26
|
+
privateKeyEncrypted: require_genID.uint8ArrayToBase64(await require_aes.encryptSymmetrically(secretKey, keys.secretKey, aux))
|
|
27
|
+
};
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error("Failed to encrypt keystore content", { cause: error });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decrypts the keystore content using symmetric encryption
|
|
34
|
+
*
|
|
35
|
+
* @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content
|
|
36
|
+
* @param encryptedKeys - The encrypted keystore content
|
|
37
|
+
* @returns The decrypted hybrid key pair contained in the keystore
|
|
38
|
+
*/
|
|
39
|
+
async function decryptKeystoreContent(kesytoreOpeningKey, encryptedKeystore) {
|
|
40
|
+
try {
|
|
41
|
+
const aux = require_genID.UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);
|
|
42
|
+
return {
|
|
43
|
+
publicKey: require_genID.base64ToUint8Array(encryptedKeystore.publicKey),
|
|
44
|
+
secretKey: await require_aes.decryptSymmetrically(kesytoreOpeningKey, require_genID.base64ToUint8Array(encryptedKeystore.privateKeyEncrypted), aux)
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error("Failed to decrypt keystore content", { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Derives a secret key for protecting the recovery keystore
|
|
52
|
+
*
|
|
53
|
+
* @param recoveryCodes - The recovery codes (machine-generated with secure PRNG)
|
|
54
|
+
* @returns The derived secret key for protecting the recovery keystore
|
|
55
|
+
*/
|
|
56
|
+
async function deriveRecoveryKey(recoveryCodes) {
|
|
57
|
+
return require_deriveKeysFromMnemonic.deriveKeyFromMnemonic(recoveryCodes, require_constants.CONTEXT_RECOVERY);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Derives a secret key for protecting the encryption keystore
|
|
61
|
+
*
|
|
62
|
+
* @param password - The user's password
|
|
63
|
+
* @param salt - The keystore salt
|
|
64
|
+
* @returns The derived secret key for protecting the encryption keystore
|
|
65
|
+
*/
|
|
66
|
+
async function deriveEncryptionKeystoreKey(password, salt) {
|
|
67
|
+
return require_deriveKeysFromMnemonic.deriveSymmetricKeyFromContext(require_constants.CONTEXT_ENC_KEYSTORE, await require_deriveKeysFromPassword.getKeyFromPasswordAndSalt(password, salt));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Derives a secret key for protecting the encryption keystore
|
|
71
|
+
*
|
|
72
|
+
* @param password - The user's password
|
|
73
|
+
* @param salt - The keystore salt
|
|
74
|
+
* @returns The derived secret key for protecting the encryption keystore
|
|
75
|
+
*/
|
|
76
|
+
async function deriveNewEncryptionKeystoreKey(password) {
|
|
77
|
+
const { key, salt } = await require_deriveKeysFromPassword.getKeyFromPassword(password);
|
|
78
|
+
return {
|
|
79
|
+
secretKey: require_deriveKeysFromMnemonic.deriveSymmetricKeyFromContext(require_constants.CONTEXT_ENC_KEYSTORE, key),
|
|
80
|
+
salt
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/keystore-crypto/errors.ts
|
|
86
|
+
var FailedToCreateKeyStores = class FailedToCreateKeyStores extends Error {
|
|
87
|
+
constructor(errorMsg) {
|
|
88
|
+
super("Failed to create encryption and recovery keystores: " + errorMsg);
|
|
89
|
+
Object.setPrototypeOf(this, FailedToCreateKeyStores.prototype);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var FailedToOpenEncryptionKeyStore = class FailedToOpenEncryptionKeyStore extends Error {
|
|
93
|
+
constructor(errorMsg) {
|
|
94
|
+
super("Failed to open encryption keystore: " + errorMsg);
|
|
95
|
+
Object.setPrototypeOf(this, FailedToOpenEncryptionKeyStore.prototype);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var FailedToOpenRecoveryKeyStore = class FailedToOpenRecoveryKeyStore extends Error {
|
|
99
|
+
constructor(errorMsg) {
|
|
100
|
+
super("Failed to open recovery keystore: " + errorMsg);
|
|
101
|
+
Object.setPrototypeOf(this, FailedToOpenRecoveryKeyStore.prototype);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var FailedToChangePasswordForKeyStore = class FailedToChangePasswordForKeyStore extends Error {
|
|
105
|
+
constructor(errorMsg) {
|
|
106
|
+
super("Error while fetching message: " + errorMsg);
|
|
107
|
+
Object.setPrototypeOf(this, FailedToChangePasswordForKeyStore.prototype);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/keystore-crypto/emailEncryptionKey.ts
|
|
113
|
+
/**
|
|
114
|
+
* Generates hybrid keys and creates encrypted main and recovery keystores
|
|
115
|
+
* The main keystore encryption key is derived from the user's password
|
|
116
|
+
* The recovery keystore encryption key is derived from the recovery codes
|
|
117
|
+
*
|
|
118
|
+
* @param userEmail - The user's email
|
|
119
|
+
* @param password - The user's password
|
|
120
|
+
* @returns The encryption keys
|
|
121
|
+
*
|
|
122
|
+
* @returns The encryption and recovery keystores, recovery codes and hybrid keys
|
|
123
|
+
*/
|
|
124
|
+
async function createEncryptionAndRecoveryKeystores(userEmail, password) {
|
|
125
|
+
try {
|
|
126
|
+
const keys = require_xwing.genHybridKeys();
|
|
127
|
+
const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(password);
|
|
128
|
+
const encryptionKeystore = await encryptKeystoreContent(secretKey, keys, userEmail, require_types.KeystoreType.ENCRYPTION);
|
|
129
|
+
const recoveryCodes = require_genID.genMnemonic();
|
|
130
|
+
return {
|
|
131
|
+
encryptionKeystore,
|
|
132
|
+
recoveryKeystore: await encryptKeystoreContent(await deriveRecoveryKey(recoveryCodes), keys, userEmail, require_types.KeystoreType.RECOVERY),
|
|
133
|
+
recoveryCodes,
|
|
134
|
+
keys,
|
|
135
|
+
salt
|
|
136
|
+
};
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new FailedToCreateKeyStores(error instanceof Error ? error.message : String(error));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Opens the encryption keystore and returns the email encryption keys
|
|
143
|
+
* The decryption key is derived from the user password
|
|
144
|
+
*
|
|
145
|
+
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
146
|
+
* @param password - The user's password
|
|
147
|
+
* @param salt - The keystore's salt
|
|
148
|
+
* @returns The encryption keys
|
|
149
|
+
*/
|
|
150
|
+
async function openEncryptionKeystore(encryptedKeystore, password, salt) {
|
|
151
|
+
try {
|
|
152
|
+
if (encryptedKeystore.type !== require_types.KeystoreType.ENCRYPTION) throw new Error("Input is invalid");
|
|
153
|
+
return await decryptKeystoreContent(await deriveEncryptionKeystoreKey(password, salt), encryptedKeystore);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new FailedToOpenEncryptionKeyStore(error instanceof Error ? error.message : String(error));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Opens the recovery keystore and returns the email encryption keys
|
|
160
|
+
* The decryption key is derived from the recovery codes (machine-generated mnemonic)
|
|
161
|
+
*
|
|
162
|
+
* @param recoveryCodes - The user's recovery codes
|
|
163
|
+
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
164
|
+
* @returns The encryption keys
|
|
165
|
+
*/
|
|
166
|
+
async function openRecoveryKeystore(recoveryCodes, encryptedKeystore) {
|
|
167
|
+
try {
|
|
168
|
+
if (encryptedKeystore.type !== require_types.KeystoreType.RECOVERY) throw new Error("Input is invalid");
|
|
169
|
+
return await decryptKeystoreContent(await deriveRecoveryKey(recoveryCodes), encryptedKeystore);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
throw new FailedToOpenRecoveryKeyStore(error instanceof Error ? error.message : String(error));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Re-encrypts the encryption keystore with a new password
|
|
176
|
+
* The decryption key is derived from the user password
|
|
177
|
+
*
|
|
178
|
+
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
179
|
+
* @param oldPassword - The user's old password
|
|
180
|
+
* @param newPassword - The user's new password
|
|
181
|
+
* @param oldSalt - The keystore's old salt
|
|
182
|
+
* @returns The keys, re-encrypted keystore, and new salt
|
|
183
|
+
*/
|
|
184
|
+
async function changePasswordForEncryptionKeystore(encryptedKeystore, oldPassword, newPassword, oldSalt) {
|
|
185
|
+
try {
|
|
186
|
+
if (encryptedKeystore.type !== require_types.KeystoreType.ENCRYPTION) throw new Error("Input is invalid");
|
|
187
|
+
const keys = await openEncryptionKeystore(encryptedKeystore, oldPassword, oldSalt);
|
|
188
|
+
const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(newPassword);
|
|
189
|
+
return {
|
|
190
|
+
newKeystore: await encryptKeystoreContent(secretKey, keys, encryptedKeystore.userEmail, require_types.KeystoreType.ENCRYPTION),
|
|
191
|
+
newSalt: salt,
|
|
192
|
+
keys
|
|
193
|
+
};
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw new FailedToChangePasswordForKeyStore(error instanceof Error ? error.message : String(error));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
Object.defineProperty(exports, 'FailedToChangePasswordForKeyStore', {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
get: function () {
|
|
203
|
+
return FailedToChangePasswordForKeyStore;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(exports, 'FailedToCreateKeyStores', {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function () {
|
|
209
|
+
return FailedToCreateKeyStores;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(exports, 'FailedToOpenEncryptionKeyStore', {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function () {
|
|
215
|
+
return FailedToOpenEncryptionKeyStore;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(exports, 'FailedToOpenRecoveryKeyStore', {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
get: function () {
|
|
221
|
+
return FailedToOpenRecoveryKeyStore;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(exports, 'changePasswordForEncryptionKeystore', {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function () {
|
|
227
|
+
return changePasswordForEncryptionKeystore;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(exports, 'createEncryptionAndRecoveryKeystores', {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function () {
|
|
233
|
+
return createEncryptionAndRecoveryKeystores;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, 'openEncryptionKeystore', {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function () {
|
|
239
|
+
return openEncryptionKeystore;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(exports, 'openRecoveryKeystore', {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function () {
|
|
245
|
+
return openRecoveryKeystore;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
//# sourceMappingURL=emailEncryptionKey-Cw-vW_Oq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emailEncryptionKey-Cw-vW_Oq.js","names":["UTF8ToUint8","uint8ArrayToBase64","encryptSymmetrically","base64ToUint8Array","decryptSymmetrically","deriveKeyFromMnemonic","CONTEXT_RECOVERY","deriveSymmetricKeyFromContext","CONTEXT_ENC_KEYSTORE","getKeyFromPasswordAndSalt","getKeyFromPassword","genHybridKeys","KeystoreType","genMnemonic"],"sources":["../src/keystore-crypto/core.ts","../src/keystore-crypto/errors.ts","../src/keystore-crypto/emailEncryptionKey.ts"],"sourcesContent":["import { encryptSymmetrically, decryptSymmetrically } from '../symmetric-crypto';\nimport { base64ToUint8Array, uint8ArrayToBase64, UTF8ToUint8 } from '../utils';\nimport { deriveKeyFromMnemonic, deriveSymmetricKeyFromContext } from '../derive-key';\nimport { CONTEXT_ENC_KEYSTORE, CONTEXT_RECOVERY } from '../constants';\nimport { EncryptedKeystore, HybridKeyPair, KeystoreType } from '../types';\nimport { getKeyFromPasswordAndSalt, getKeyFromPassword } from '../derive-password';\n\n/**\n * Encrypts the user's hybrid key using symmetric encryption to get a keystore\n *\n * @param secretKey - The symmetric key to encrypt the keystore content\n * @param key - The hybrid key pair\n * @param userEmail - The email of the user\n * @param type - The keystore type\n * @returns The encrypted keystore\n */\nexport async function encryptKeystoreContent(\n secretKey: Uint8Array,\n keys: HybridKeyPair,\n userEmail: string,\n type: KeystoreType,\n): Promise<EncryptedKeystore> {\n try {\n const aux = UTF8ToUint8(userEmail + type);\n const publicKey = uint8ArrayToBase64(keys.publicKey);\n const secretKeyEncrypted = await encryptSymmetrically(secretKey, keys.secretKey, aux);\n\n const keystore: EncryptedKeystore = {\n userEmail,\n type,\n publicKey,\n privateKeyEncrypted: uint8ArrayToBase64(secretKeyEncrypted),\n };\n return keystore;\n } catch (error) {\n throw new Error('Failed to encrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Decrypts the keystore content using symmetric encryption\n *\n * @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content\n * @param encryptedKeys - The encrypted keystore content\n * @returns The decrypted hybrid key pair contained in the keystore\n */\nexport async function decryptKeystoreContent(\n kesytoreOpeningKey: Uint8Array,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n const aux = UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);\n const publicKey = base64ToUint8Array(encryptedKeystore.publicKey);\n const ciphertext = base64ToUint8Array(encryptedKeystore.privateKeyEncrypted);\n const secretKey = await decryptSymmetrically(kesytoreOpeningKey, ciphertext, aux);\n return {\n publicKey,\n secretKey,\n };\n } catch (error) {\n throw new Error('Failed to decrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Derives a secret key for protecting the recovery keystore\n *\n * @param recoveryCodes - The recovery codes (machine-generated with secure PRNG)\n * @returns The derived secret key for protecting the recovery keystore\n */\nexport async function deriveRecoveryKey(recoveryCodes: string): Promise<Uint8Array> {\n return deriveKeyFromMnemonic(recoveryCodes, CONTEXT_RECOVERY);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore from user's mnemonic\n *\n * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveEncryptionKeystoreKeyFromMnemonic(mnemonic: string): Promise<Uint8Array> {\n return deriveKeyFromMnemonic(mnemonic, CONTEXT_ENC_KEYSTORE);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore\n *\n * @param password - The user's password\n * @param salt - The keystore salt\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveEncryptionKeystoreKey(password: string, salt: Uint8Array): Promise<Uint8Array> {\n const baseKey = await getKeyFromPasswordAndSalt(password, salt);\n return deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, baseKey);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore\n *\n * @param password - The user's password\n * @param salt - The keystore salt\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveNewEncryptionKeystoreKey(\n password: string,\n): Promise<{ secretKey: Uint8Array; salt: Uint8Array }> {\n const { key, salt } = await getKeyFromPassword(password);\n const secretKey = deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, key);\n return { secretKey, salt };\n}\n","export class FailedToCreateKeyStores extends Error {\n constructor(errorMsg?: string) {\n super('Failed to create encryption and recovery keystores: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToCreateKeyStores.prototype);\n }\n}\n\nexport class FailedToOpenEncryptionKeyStore extends Error {\n constructor(errorMsg?: string) {\n super('Failed to open encryption keystore: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToOpenEncryptionKeyStore.prototype);\n }\n}\n\nexport class FailedToOpenRecoveryKeyStore extends Error {\n constructor(errorMsg?: string) {\n super('Failed to open recovery keystore: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToOpenRecoveryKeyStore.prototype);\n }\n}\n\nexport class FailedToChangePasswordForKeyStore extends Error {\n constructor(errorMsg?: string) {\n super('Error while fetching message: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToChangePasswordForKeyStore.prototype);\n }\n}\n","import { EncryptedKeystore, KeystoreType, HybridKeyPair } from '../types';\nimport { genMnemonic } from '../utils';\nimport {\n encryptKeystoreContent,\n decryptKeystoreContent,\n deriveEncryptionKeystoreKey,\n deriveNewEncryptionKeystoreKey,\n deriveRecoveryKey,\n} from './core';\nimport { genHybridKeys } from '../hybrid-crypto';\nimport {\n FailedToOpenEncryptionKeyStore,\n FailedToCreateKeyStores,\n FailedToOpenRecoveryKeyStore,\n FailedToChangePasswordForKeyStore,\n} from './errors';\n\n/**\n * Generates hybrid keys and creates encrypted main and recovery keystores\n * The main keystore encryption key is derived from the user's password\n * The recovery keystore encryption key is derived from the recovery codes\n *\n * @param userEmail - The user's email\n * @param password - The user's password\n * @returns The encryption keys\n *\n * @returns The encryption and recovery keystores, recovery codes and hybrid keys\n */\nexport async function createEncryptionAndRecoveryKeystores(\n userEmail: string,\n password: string,\n): Promise<{\n encryptionKeystore: EncryptedKeystore;\n recoveryKeystore: EncryptedKeystore;\n recoveryCodes: string;\n keys: HybridKeyPair;\n salt: Uint8Array;\n}> {\n try {\n const keys = genHybridKeys();\n\n const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(password);\n const encryptionKeystore = await encryptKeystoreContent(secretKey, keys, userEmail, KeystoreType.ENCRYPTION);\n\n const recoveryCodes = genMnemonic();\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const recoveryKeystore = await encryptKeystoreContent(recoveryKey, keys, userEmail, KeystoreType.RECOVERY);\n\n return { encryptionKeystore, recoveryKeystore, recoveryCodes, keys, salt };\n } catch (error) {\n throw new FailedToCreateKeyStores(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Opens the encryption keystore and returns the email encryption keys\n * The decryption key is derived from the user password\n *\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @param password - The user's password\n * @param salt - The keystore's salt\n * @returns The encryption keys\n */\nexport async function openEncryptionKeystore(\n encryptedKeystore: EncryptedKeystore,\n password: string,\n salt: Uint8Array,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type !== KeystoreType.ENCRYPTION) {\n throw new Error('Input is invalid');\n }\n const secretKey = await deriveEncryptionKeystoreKey(password, salt);\n const keys = await decryptKeystoreContent(secretKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new FailedToOpenEncryptionKeyStore(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Opens the recovery keystore and returns the email encryption keys\n * The decryption key is derived from the recovery codes (machine-generated mnemonic)\n *\n * @param recoveryCodes - The user's recovery codes\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @returns The encryption keys\n */\nexport async function openRecoveryKeystore(\n recoveryCodes: string,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type !== KeystoreType.RECOVERY) {\n throw new Error('Input is invalid');\n }\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const keys = await decryptKeystoreContent(recoveryKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new FailedToOpenRecoveryKeyStore(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Re-encrypts the encryption keystore with a new password\n * The decryption key is derived from the user password\n *\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @param oldPassword - The user's old password\n * @param newPassword - The user's new password\n * @param oldSalt - The keystore's old salt\n * @returns The keys, re-encrypted keystore, and new salt\n */\nexport async function changePasswordForEncryptionKeystore(\n encryptedKeystore: EncryptedKeystore,\n oldPassword: string,\n newPassword: string,\n oldSalt: Uint8Array,\n): Promise<{ keys: HybridKeyPair; newSalt: Uint8Array; newKeystore: EncryptedKeystore }> {\n try {\n if (encryptedKeystore.type !== KeystoreType.ENCRYPTION) {\n throw new Error('Input is invalid');\n }\n const keys = await openEncryptionKeystore(encryptedKeystore, oldPassword, oldSalt);\n\n const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(newPassword);\n const newKeystore = await encryptKeystoreContent(\n secretKey,\n keys,\n encryptedKeystore.userEmail,\n KeystoreType.ENCRYPTION,\n );\n\n return { newKeystore, newSalt: salt, keys };\n } catch (error) {\n throw new FailedToChangePasswordForKeyStore(error instanceof Error ? error.message : String(error));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,eAAsB,uBACpB,WACA,MACA,WACA,MAC4B;AAC5B,KAAI;EACF,MAAM,MAAMA,0BAAY,YAAY,KAAK;AAUzC,SANoC;GAClC;GACA;GACA,WANgBC,iCAAmB,KAAK,UAAU;GAOlD,qBAAqBA,iCANI,MAAMC,iCAAqB,WAAW,KAAK,WAAW,IAAI,CAMxB;GAC5D;UAEM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW3E,eAAsB,uBACpB,oBACA,mBACwB;AACxB,KAAI;EACF,MAAM,MAAMF,0BAAY,kBAAkB,YAAY,kBAAkB,KAAK;AAI7E,SAAO;GACL,WAJgBG,iCAAmB,kBAAkB,UAAU;GAK/D,WAHgB,MAAMC,iCAAqB,oBAD1BD,iCAAmB,kBAAkB,oBAAoB,EACC,IAAI;GAIhF;UACM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU3E,eAAsB,kBAAkB,eAA4C;AAClF,QAAOE,qDAAsB,eAAeC,mCAAiB;;;;;;;;;AAoB/D,eAAsB,4BAA4B,UAAkB,MAAuC;AAEzG,QAAOC,6DAA8BC,wCADrB,MAAMC,yDAA0B,UAAU,KAAK,CACI;;;;;;;;;AAUrE,eAAsB,+BACpB,UACsD;CACtD,MAAM,EAAE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U,KAAK,EACd,kBAAkB;UAEhE,OAAO;AACd,QAAM,IAAI,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;;;;;;;;;;AAYpG,eAAsB,qBACpB,eACA,mBACwB;AACxB,KAAI;AACF,MAAI,kBAAkB,SAASA,2BAAa,SAC1C,OAAM,IAAI,MAAM,mBAAmB;AAIrC,SADa,MAAM,uBADC,MAAM,kBAAkB,cAAc,EACH,kBAAkB;UAElE,OAAO;AACd,QAAM,IAAI,6BAA6B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;;;;;;;;;;;;AAclG,eAAsB,oCACpB,mBACA,aACA,aACA,SACuF;AACvF,KAAI;AACF,MAAI,kBAAkB,SAASA,2BAAa,WAC1C,OAAM,IAAI,MAAM,mBAAmB;EAErC,MAAM,OAAO,MAAM,uBAAuB,mBAAmB,aAAa,QAAQ;EAElF,MAAM,EAAE,WAAW,SAAS,MAAM,+BAA+B,YAAY;AAQ7E,SAAO;GAAE,aAPW,MAAM,uBACxB,WACA,MACA,kBAAkB,WAClBA,2BAAa,WACd;GAEqB,SAAS;GAAM;GAAM;UACpC,OAAO;AACd,QAAM,IAAI,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { CONTEXT_ENC_KEYSTORE, CONTEXT_RECOVERY } from "./constants.mjs";
|
|
2
|
+
import { a as genMnemonic, c as base64ToUint8Array, s as UTF8ToUint8, u as uint8ArrayToBase64 } from "./genID-D08K7JPr.mjs";
|
|
3
|
+
import { n as deriveSymmetricKeyFromContext, t as deriveKeyFromMnemonic } from "./deriveKeysFromMnemonic-DB0UHE-y.mjs";
|
|
4
|
+
import { n as getKeyFromPassword, r as getKeyFromPasswordAndSalt } from "./deriveKeysFromPassword-DFzo2OII.mjs";
|
|
5
|
+
import { n as encryptSymmetrically, t as decryptSymmetrically } from "./aes-B8TA-JKq.mjs";
|
|
6
|
+
import { r as genHybridKeys } from "./xwing-CQmQX6hn.mjs";
|
|
7
|
+
import { KeystoreType } from "./types.mjs";
|
|
8
|
+
|
|
9
|
+
//#region src/keystore-crypto/core.ts
|
|
10
|
+
/**
|
|
11
|
+
* Encrypts the user's hybrid key using symmetric encryption to get a keystore
|
|
12
|
+
*
|
|
13
|
+
* @param secretKey - The symmetric key to encrypt the keystore content
|
|
14
|
+
* @param key - The hybrid key pair
|
|
15
|
+
* @param userEmail - The email of the user
|
|
16
|
+
* @param type - The keystore type
|
|
17
|
+
* @returns The encrypted keystore
|
|
18
|
+
*/
|
|
19
|
+
async function encryptKeystoreContent(secretKey, keys, userEmail, type) {
|
|
20
|
+
try {
|
|
21
|
+
const aux = UTF8ToUint8(userEmail + type);
|
|
22
|
+
return {
|
|
23
|
+
userEmail,
|
|
24
|
+
type,
|
|
25
|
+
publicKey: uint8ArrayToBase64(keys.publicKey),
|
|
26
|
+
privateKeyEncrypted: uint8ArrayToBase64(await encryptSymmetrically(secretKey, keys.secretKey, aux))
|
|
27
|
+
};
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error("Failed to encrypt keystore content", { cause: error });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decrypts the keystore content using symmetric encryption
|
|
34
|
+
*
|
|
35
|
+
* @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content
|
|
36
|
+
* @param encryptedKeys - The encrypted keystore content
|
|
37
|
+
* @returns The decrypted hybrid key pair contained in the keystore
|
|
38
|
+
*/
|
|
39
|
+
async function decryptKeystoreContent(kesytoreOpeningKey, encryptedKeystore) {
|
|
40
|
+
try {
|
|
41
|
+
const aux = UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);
|
|
42
|
+
return {
|
|
43
|
+
publicKey: base64ToUint8Array(encryptedKeystore.publicKey),
|
|
44
|
+
secretKey: await decryptSymmetrically(kesytoreOpeningKey, base64ToUint8Array(encryptedKeystore.privateKeyEncrypted), aux)
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error("Failed to decrypt keystore content", { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Derives a secret key for protecting the recovery keystore
|
|
52
|
+
*
|
|
53
|
+
* @param recoveryCodes - The recovery codes (machine-generated with secure PRNG)
|
|
54
|
+
* @returns The derived secret key for protecting the recovery keystore
|
|
55
|
+
*/
|
|
56
|
+
async function deriveRecoveryKey(recoveryCodes) {
|
|
57
|
+
return deriveKeyFromMnemonic(recoveryCodes, CONTEXT_RECOVERY);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Derives a secret key for protecting the encryption keystore
|
|
61
|
+
*
|
|
62
|
+
* @param password - The user's password
|
|
63
|
+
* @param salt - The keystore salt
|
|
64
|
+
* @returns The derived secret key for protecting the encryption keystore
|
|
65
|
+
*/
|
|
66
|
+
async function deriveEncryptionKeystoreKey(password, salt) {
|
|
67
|
+
return deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, await getKeyFromPasswordAndSalt(password, salt));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Derives a secret key for protecting the encryption keystore
|
|
71
|
+
*
|
|
72
|
+
* @param password - The user's password
|
|
73
|
+
* @param salt - The keystore salt
|
|
74
|
+
* @returns The derived secret key for protecting the encryption keystore
|
|
75
|
+
*/
|
|
76
|
+
async function deriveNewEncryptionKeystoreKey(password) {
|
|
77
|
+
const { key, salt } = await getKeyFromPassword(password);
|
|
78
|
+
return {
|
|
79
|
+
secretKey: deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, key),
|
|
80
|
+
salt
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/keystore-crypto/errors.ts
|
|
86
|
+
var FailedToCreateKeyStores = class FailedToCreateKeyStores extends Error {
|
|
87
|
+
constructor(errorMsg) {
|
|
88
|
+
super("Failed to create encryption and recovery keystores: " + errorMsg);
|
|
89
|
+
Object.setPrototypeOf(this, FailedToCreateKeyStores.prototype);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var FailedToOpenEncryptionKeyStore = class FailedToOpenEncryptionKeyStore extends Error {
|
|
93
|
+
constructor(errorMsg) {
|
|
94
|
+
super("Failed to open encryption keystore: " + errorMsg);
|
|
95
|
+
Object.setPrototypeOf(this, FailedToOpenEncryptionKeyStore.prototype);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var FailedToOpenRecoveryKeyStore = class FailedToOpenRecoveryKeyStore extends Error {
|
|
99
|
+
constructor(errorMsg) {
|
|
100
|
+
super("Failed to open recovery keystore: " + errorMsg);
|
|
101
|
+
Object.setPrototypeOf(this, FailedToOpenRecoveryKeyStore.prototype);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var FailedToChangePasswordForKeyStore = class FailedToChangePasswordForKeyStore extends Error {
|
|
105
|
+
constructor(errorMsg) {
|
|
106
|
+
super("Error while fetching message: " + errorMsg);
|
|
107
|
+
Object.setPrototypeOf(this, FailedToChangePasswordForKeyStore.prototype);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/keystore-crypto/emailEncryptionKey.ts
|
|
113
|
+
/**
|
|
114
|
+
* Generates hybrid keys and creates encrypted main and recovery keystores
|
|
115
|
+
* The main keystore encryption key is derived from the user's password
|
|
116
|
+
* The recovery keystore encryption key is derived from the recovery codes
|
|
117
|
+
*
|
|
118
|
+
* @param userEmail - The user's email
|
|
119
|
+
* @param password - The user's password
|
|
120
|
+
* @returns The encryption keys
|
|
121
|
+
*
|
|
122
|
+
* @returns The encryption and recovery keystores, recovery codes and hybrid keys
|
|
123
|
+
*/
|
|
124
|
+
async function createEncryptionAndRecoveryKeystores(userEmail, password) {
|
|
125
|
+
try {
|
|
126
|
+
const keys = genHybridKeys();
|
|
127
|
+
const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(password);
|
|
128
|
+
const encryptionKeystore = await encryptKeystoreContent(secretKey, keys, userEmail, KeystoreType.ENCRYPTION);
|
|
129
|
+
const recoveryCodes = genMnemonic();
|
|
130
|
+
return {
|
|
131
|
+
encryptionKeystore,
|
|
132
|
+
recoveryKeystore: await encryptKeystoreContent(await deriveRecoveryKey(recoveryCodes), keys, userEmail, KeystoreType.RECOVERY),
|
|
133
|
+
recoveryCodes,
|
|
134
|
+
keys,
|
|
135
|
+
salt
|
|
136
|
+
};
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new FailedToCreateKeyStores(error instanceof Error ? error.message : String(error));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Opens the encryption keystore and returns the email encryption keys
|
|
143
|
+
* The decryption key is derived from the user password
|
|
144
|
+
*
|
|
145
|
+
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
146
|
+
* @param password - The user's password
|
|
147
|
+
* @param salt - The keystore's salt
|
|
148
|
+
* @returns The encryption keys
|
|
149
|
+
*/
|
|
150
|
+
async function openEncryptionKeystore(encryptedKeystore, password, salt) {
|
|
151
|
+
try {
|
|
152
|
+
if (encryptedKeystore.type !== KeystoreType.ENCRYPTION) throw new Error("Input is invalid");
|
|
153
|
+
return await decryptKeystoreContent(await deriveEncryptionKeystoreKey(password, salt), encryptedKeystore);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new FailedToOpenEncryptionKeyStore(error instanceof Error ? error.message : String(error));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Opens the recovery keystore and returns the email encryption keys
|
|
160
|
+
* The decryption key is derived from the recovery codes (machine-generated mnemonic)
|
|
161
|
+
*
|
|
162
|
+
* @param recoveryCodes - The user's recovery codes
|
|
163
|
+
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
164
|
+
* @returns The encryption keys
|
|
165
|
+
*/
|
|
166
|
+
async function openRecoveryKeystore(recoveryCodes, encryptedKeystore) {
|
|
167
|
+
try {
|
|
168
|
+
if (encryptedKeystore.type !== KeystoreType.RECOVERY) throw new Error("Input is invalid");
|
|
169
|
+
return await decryptKeystoreContent(await deriveRecoveryKey(recoveryCodes), encryptedKeystore);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
throw new FailedToOpenRecoveryKeyStore(error instanceof Error ? error.message : String(error));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Re-encrypts the encryption keystore with a new password
|
|
176
|
+
* The decryption key is derived from the user password
|
|
177
|
+
*
|
|
178
|
+
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
179
|
+
* @param oldPassword - The user's old password
|
|
180
|
+
* @param newPassword - The user's new password
|
|
181
|
+
* @param oldSalt - The keystore's old salt
|
|
182
|
+
* @returns The keys, re-encrypted keystore, and new salt
|
|
183
|
+
*/
|
|
184
|
+
async function changePasswordForEncryptionKeystore(encryptedKeystore, oldPassword, newPassword, oldSalt) {
|
|
185
|
+
try {
|
|
186
|
+
if (encryptedKeystore.type !== KeystoreType.ENCRYPTION) throw new Error("Input is invalid");
|
|
187
|
+
const keys = await openEncryptionKeystore(encryptedKeystore, oldPassword, oldSalt);
|
|
188
|
+
const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(newPassword);
|
|
189
|
+
return {
|
|
190
|
+
newKeystore: await encryptKeystoreContent(secretKey, keys, encryptedKeystore.userEmail, KeystoreType.ENCRYPTION),
|
|
191
|
+
newSalt: salt,
|
|
192
|
+
keys
|
|
193
|
+
};
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw new FailedToChangePasswordForKeyStore(error instanceof Error ? error.message : String(error));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
export { FailedToChangePasswordForKeyStore as a, FailedToOpenRecoveryKeyStore as c, openRecoveryKeystore as i, createEncryptionAndRecoveryKeystores as n, FailedToCreateKeyStores as o, openEncryptionKeystore as r, FailedToOpenEncryptionKeyStore as s, changePasswordForEncryptionKeystore as t };
|
|
201
|
+
//# sourceMappingURL=emailEncryptionKey-D9sk_WKj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emailEncryptionKey-D9sk_WKj.mjs","names":[],"sources":["../src/keystore-crypto/core.ts","../src/keystore-crypto/errors.ts","../src/keystore-crypto/emailEncryptionKey.ts"],"sourcesContent":["import { encryptSymmetrically, decryptSymmetrically } from '../symmetric-crypto';\nimport { base64ToUint8Array, uint8ArrayToBase64, UTF8ToUint8 } from '../utils';\nimport { deriveKeyFromMnemonic, deriveSymmetricKeyFromContext } from '../derive-key';\nimport { CONTEXT_ENC_KEYSTORE, CONTEXT_RECOVERY } from '../constants';\nimport { EncryptedKeystore, HybridKeyPair, KeystoreType } from '../types';\nimport { getKeyFromPasswordAndSalt, getKeyFromPassword } from '../derive-password';\n\n/**\n * Encrypts the user's hybrid key using symmetric encryption to get a keystore\n *\n * @param secretKey - The symmetric key to encrypt the keystore content\n * @param key - The hybrid key pair\n * @param userEmail - The email of the user\n * @param type - The keystore type\n * @returns The encrypted keystore\n */\nexport async function encryptKeystoreContent(\n secretKey: Uint8Array,\n keys: HybridKeyPair,\n userEmail: string,\n type: KeystoreType,\n): Promise<EncryptedKeystore> {\n try {\n const aux = UTF8ToUint8(userEmail + type);\n const publicKey = uint8ArrayToBase64(keys.publicKey);\n const secretKeyEncrypted = await encryptSymmetrically(secretKey, keys.secretKey, aux);\n\n const keystore: EncryptedKeystore = {\n userEmail,\n type,\n publicKey,\n privateKeyEncrypted: uint8ArrayToBase64(secretKeyEncrypted),\n };\n return keystore;\n } catch (error) {\n throw new Error('Failed to encrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Decrypts the keystore content using symmetric encryption\n *\n * @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content\n * @param encryptedKeys - The encrypted keystore content\n * @returns The decrypted hybrid key pair contained in the keystore\n */\nexport async function decryptKeystoreContent(\n kesytoreOpeningKey: Uint8Array,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n const aux = UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);\n const publicKey = base64ToUint8Array(encryptedKeystore.publicKey);\n const ciphertext = base64ToUint8Array(encryptedKeystore.privateKeyEncrypted);\n const secretKey = await decryptSymmetrically(kesytoreOpeningKey, ciphertext, aux);\n return {\n publicKey,\n secretKey,\n };\n } catch (error) {\n throw new Error('Failed to decrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Derives a secret key for protecting the recovery keystore\n *\n * @param recoveryCodes - The recovery codes (machine-generated with secure PRNG)\n * @returns The derived secret key for protecting the recovery keystore\n */\nexport async function deriveRecoveryKey(recoveryCodes: string): Promise<Uint8Array> {\n return deriveKeyFromMnemonic(recoveryCodes, CONTEXT_RECOVERY);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore from user's mnemonic\n *\n * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveEncryptionKeystoreKeyFromMnemonic(mnemonic: string): Promise<Uint8Array> {\n return deriveKeyFromMnemonic(mnemonic, CONTEXT_ENC_KEYSTORE);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore\n *\n * @param password - The user's password\n * @param salt - The keystore salt\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveEncryptionKeystoreKey(password: string, salt: Uint8Array): Promise<Uint8Array> {\n const baseKey = await getKeyFromPasswordAndSalt(password, salt);\n return deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, baseKey);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore\n *\n * @param password - The user's password\n * @param salt - The keystore salt\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveNewEncryptionKeystoreKey(\n password: string,\n): Promise<{ secretKey: Uint8Array; salt: Uint8Array }> {\n const { key, salt } = await getKeyFromPassword(password);\n const secretKey = deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, key);\n return { secretKey, salt };\n}\n","export class FailedToCreateKeyStores extends Error {\n constructor(errorMsg?: string) {\n super('Failed to create encryption and recovery keystores: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToCreateKeyStores.prototype);\n }\n}\n\nexport class FailedToOpenEncryptionKeyStore extends Error {\n constructor(errorMsg?: string) {\n super('Failed to open encryption keystore: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToOpenEncryptionKeyStore.prototype);\n }\n}\n\nexport class FailedToOpenRecoveryKeyStore extends Error {\n constructor(errorMsg?: string) {\n super('Failed to open recovery keystore: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToOpenRecoveryKeyStore.prototype);\n }\n}\n\nexport class FailedToChangePasswordForKeyStore extends Error {\n constructor(errorMsg?: string) {\n super('Error while fetching message: ' + errorMsg);\n\n Object.setPrototypeOf(this, FailedToChangePasswordForKeyStore.prototype);\n }\n}\n","import { EncryptedKeystore, KeystoreType, HybridKeyPair } from '../types';\nimport { genMnemonic } from '../utils';\nimport {\n encryptKeystoreContent,\n decryptKeystoreContent,\n deriveEncryptionKeystoreKey,\n deriveNewEncryptionKeystoreKey,\n deriveRecoveryKey,\n} from './core';\nimport { genHybridKeys } from '../hybrid-crypto';\nimport {\n FailedToOpenEncryptionKeyStore,\n FailedToCreateKeyStores,\n FailedToOpenRecoveryKeyStore,\n FailedToChangePasswordForKeyStore,\n} from './errors';\n\n/**\n * Generates hybrid keys and creates encrypted main and recovery keystores\n * The main keystore encryption key is derived from the user's password\n * The recovery keystore encryption key is derived from the recovery codes\n *\n * @param userEmail - The user's email\n * @param password - The user's password\n * @returns The encryption keys\n *\n * @returns The encryption and recovery keystores, recovery codes and hybrid keys\n */\nexport async function createEncryptionAndRecoveryKeystores(\n userEmail: string,\n password: string,\n): Promise<{\n encryptionKeystore: EncryptedKeystore;\n recoveryKeystore: EncryptedKeystore;\n recoveryCodes: string;\n keys: HybridKeyPair;\n salt: Uint8Array;\n}> {\n try {\n const keys = genHybridKeys();\n\n const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(password);\n const encryptionKeystore = await encryptKeystoreContent(secretKey, keys, userEmail, KeystoreType.ENCRYPTION);\n\n const recoveryCodes = genMnemonic();\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const recoveryKeystore = await encryptKeystoreContent(recoveryKey, keys, userEmail, KeystoreType.RECOVERY);\n\n return { encryptionKeystore, recoveryKeystore, recoveryCodes, keys, salt };\n } catch (error) {\n throw new FailedToCreateKeyStores(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Opens the encryption keystore and returns the email encryption keys\n * The decryption key is derived from the user password\n *\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @param password - The user's password\n * @param salt - The keystore's salt\n * @returns The encryption keys\n */\nexport async function openEncryptionKeystore(\n encryptedKeystore: EncryptedKeystore,\n password: string,\n salt: Uint8Array,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type !== KeystoreType.ENCRYPTION) {\n throw new Error('Input is invalid');\n }\n const secretKey = await deriveEncryptionKeystoreKey(password, salt);\n const keys = await decryptKeystoreContent(secretKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new FailedToOpenEncryptionKeyStore(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Opens the recovery keystore and returns the email encryption keys\n * The decryption key is derived from the recovery codes (machine-generated mnemonic)\n *\n * @param recoveryCodes - The user's recovery codes\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @returns The encryption keys\n */\nexport async function openRecoveryKeystore(\n recoveryCodes: string,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type !== KeystoreType.RECOVERY) {\n throw new Error('Input is invalid');\n }\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const keys = await decryptKeystoreContent(recoveryKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new FailedToOpenRecoveryKeyStore(error instanceof Error ? error.message : String(error));\n }\n}\n\n/**\n * Re-encrypts the encryption keystore with a new password\n * The decryption key is derived from the user password\n *\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @param oldPassword - The user's old password\n * @param newPassword - The user's new password\n * @param oldSalt - The keystore's old salt\n * @returns The keys, re-encrypted keystore, and new salt\n */\nexport async function changePasswordForEncryptionKeystore(\n encryptedKeystore: EncryptedKeystore,\n oldPassword: string,\n newPassword: string,\n oldSalt: Uint8Array,\n): Promise<{ keys: HybridKeyPair; newSalt: Uint8Array; newKeystore: EncryptedKeystore }> {\n try {\n if (encryptedKeystore.type !== KeystoreType.ENCRYPTION) {\n throw new Error('Input is invalid');\n }\n const keys = await openEncryptionKeystore(encryptedKeystore, oldPassword, oldSalt);\n\n const { secretKey, salt } = await deriveNewEncryptionKeystoreKey(newPassword);\n const newKeystore = await encryptKeystoreContent(\n secretKey,\n keys,\n encryptedKeystore.userEmail,\n KeystoreType.ENCRYPTION,\n );\n\n return { newKeystore, newSalt: salt, keys };\n } catch (error) {\n throw new FailedToChangePasswordForKeyStore(error instanceof Error ? error.message : String(error));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,eAAsB,uBACpB,WACA,MACA,WACA,MAC4B;AAC5B,KAAI;EACF,MAAM,MAAM,YAAY,YAAY,KAAK;AAUzC,SANoC;GAClC;GACA;GACA,WANgB,mBAAmB,KAAK,UAAU;GAOlD,qBAAqB,mBANI,MAAM,qBAAqB,WAAW,KAAK,WAAW,IAAI,CAMxB;GAC5D;UAEM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW3E,eAAsB,uBACpB,oBACA,mBACwB;AACxB,KAAI;EACF,MAAM,MAAM,YAAY,kBAAkB,YAAY,kBAAkB,KAAK;AAI7E,SAAO;GACL,WAJgB,mBAAmB,kBAAkB,UA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