internxt-crypto 1.3.1 → 1.4.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 +15 -73
- package/dist/email-crypto-Di814Pbk.js +739 -0
- package/dist/email-crypto-Di814Pbk.js.map +1 -0
- package/dist/email-crypto-DpjfXDes.mjs +535 -0
- package/dist/email-crypto-DpjfXDes.mjs.map +1 -0
- package/dist/email-crypto.d.mts +138 -29
- package/dist/email-crypto.d.mts.map +1 -1
- package/dist/email-crypto.d.ts +138 -29
- package/dist/email-crypto.d.ts.map +1 -1
- package/dist/email-crypto.js +21 -4
- 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 +21 -4
- package/dist/index.mjs +2 -2
- package/dist/keystore-crypto.d.mts +1 -1
- package/dist/keystore-crypto.d.ts +1 -1
- package/dist/{types-4P0WII1D.d.ts → types-CrAiKyb0.d.ts} +20 -8
- package/dist/types-CrAiKyb0.d.ts.map +1 -0
- package/dist/{types-DAPJQG8U.d.mts → types-D6hsUfma.d.mts} +20 -8
- package/dist/types-D6hsUfma.d.mts.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/package.json +1 -1
- package/dist/email-crypto-Cr7znO1a.js +0 -401
- package/dist/email-crypto-Cr7znO1a.js.map +0 -1
- package/dist/email-crypto-cHDsjSb5.mjs +0 -299
- package/dist/email-crypto-cHDsjSb5.mjs.map +0 -1
- package/dist/types-4P0WII1D.d.ts.map +0 -1
- package/dist/types-DAPJQG8U.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -107,9 +107,9 @@ const password = 'your password';
|
|
|
107
107
|
const { key, salt } = await getKeyFromPassword(password);
|
|
108
108
|
|
|
109
109
|
// Hybrid email encryption
|
|
110
|
-
const email:
|
|
110
|
+
const email: Email = {
|
|
111
111
|
text: 'email text',
|
|
112
|
-
|
|
112
|
+
attachments: ['email attachements'],
|
|
113
113
|
};
|
|
114
114
|
const { secretKey: bobPrivateKeys, publicKey: bobPublicKeys } = await generateEmailKeys();
|
|
115
115
|
const bobWithPublicKeys = {
|
|
@@ -119,8 +119,19 @@ const bobWithPublicKeys = {
|
|
|
119
119
|
const encryptedEmail = await encryptEmailHybrid(email, bobWithPublicKeys);
|
|
120
120
|
const decryptedEmail = await decryptEmailHybrid(encryptedEmail, bobPrivateKeys);
|
|
121
121
|
|
|
122
|
-
expect(
|
|
123
|
-
|
|
122
|
+
expect(decryptedEmail).toStrictEqual(email);
|
|
123
|
+
|
|
124
|
+
// Hybrid email and subject encryption
|
|
125
|
+
const emailAndSubject: EmailAndSubject = {
|
|
126
|
+
text: 'email text',
|
|
127
|
+
subject: 'email subject'
|
|
128
|
+
attachments: ['email attachements'],
|
|
129
|
+
};
|
|
130
|
+
const encryptedEmailAndSubject = await encryptEmailAndSubjectHybrid(emailAndSubject, bobWithPublicKeys);
|
|
131
|
+
const decryptedEmailAndSubject = await decryptEmailAndSubjectHybrid(encryptedEmailAndSubject, bobPrivateKeys);
|
|
132
|
+
|
|
133
|
+
expect(encryptedEmailAndSubject.encEmail.encSubject).not.toBe(emailAndSubject.subject);
|
|
134
|
+
expect(decryptedEmailAndSubject).toStrictEqual(emailAndSubject);
|
|
124
135
|
|
|
125
136
|
|
|
126
137
|
// password-protected email
|
|
@@ -141,73 +152,4 @@ const resultRec = await openRecoveryKeystore(recoveryCodes, recoveryKeystore);
|
|
|
141
152
|
|
|
142
153
|
expect(resultEnc).toStrictEqual(resultRec);
|
|
143
154
|
|
|
144
|
-
// Email storage and search
|
|
145
|
-
|
|
146
|
-
// Between sessions emails are stored encrypted in IndexedDB. The encryption key is derived from user's mnemonic
|
|
147
|
-
// During the session, all emails are decrypted and stored in the cache (up to 600 MB, if excides - we delete oldests emails)
|
|
148
|
-
// For search, we build a search index from cache, then use Flexsearch for the search.
|
|
149
|
-
// The search is doen separately for email content, subject, sender and recivers.
|
|
150
|
-
|
|
151
|
-
// Open IndexedDB database
|
|
152
|
-
const userID = 'user ID';
|
|
153
|
-
const db = await openDatabase(userID);
|
|
154
|
-
const mnemonic = genMnemonic();
|
|
155
|
-
|
|
156
|
-
// Derive key for encrypting emails before storing them in a local database
|
|
157
|
-
const key = await deriveDatabaseKey(mnemonic);
|
|
158
|
-
|
|
159
|
-
// Derive key for encrypting email draft
|
|
160
|
-
const key = await deriveDatabaseKey(mnemonic);
|
|
161
|
-
|
|
162
|
-
// Encrypt and store one or several emails
|
|
163
|
-
await encryptAndStoreEmail(email, key, db);
|
|
164
|
-
await encryptAndStoreManyEmail(emails, key, db);
|
|
165
|
-
|
|
166
|
-
// Delete given email by its ID
|
|
167
|
-
await deleteEmail(emailID, db);
|
|
168
|
-
|
|
169
|
-
// Delete oldests emails
|
|
170
|
-
const number = 5;
|
|
171
|
-
await deleteOldestEmails(number, db);
|
|
172
|
-
|
|
173
|
-
// Get all emails with or without sorting
|
|
174
|
-
const allEmails = await getAndDecryptAllEmails(key, db);
|
|
175
|
-
const newestFirst = await getAllEmailsSortedNewestFirst(db, key);
|
|
176
|
-
const oldestFirst = await getAllEmailsSortedOldestFirst(db, key);
|
|
177
|
-
|
|
178
|
-
// Get the number of stored emails
|
|
179
|
-
const count = await getEmailCount(db);
|
|
180
|
-
|
|
181
|
-
// Close IndexedDB database
|
|
182
|
-
closeDatabase(db);
|
|
183
|
-
|
|
184
|
-
// Delete IndexedDB database
|
|
185
|
-
await deleteDatabase(userID);
|
|
186
|
-
|
|
187
|
-
// Create email cache
|
|
188
|
-
const esCache = await createCacheFromDB(key, db);
|
|
189
|
-
|
|
190
|
-
// Add one or multiple emails to cache
|
|
191
|
-
const result = addEmailToCache(email, esCache);
|
|
192
|
-
expect(result.success).toBe(true);
|
|
193
|
-
|
|
194
|
-
const result = addEmailsToCache(emails, esCache);
|
|
195
|
-
expect(result.success).toBe(true);
|
|
196
|
-
|
|
197
|
-
// Get email from cache by its ID
|
|
198
|
-
const email = await getEmailFromCache(emailID, esCache);
|
|
199
|
-
|
|
200
|
-
// Delete email from cache by its ID
|
|
201
|
-
await deleteEmailFromCache(emailID, esCache);
|
|
202
|
-
|
|
203
|
-
// Create search index and search by query
|
|
204
|
-
const searchIndex = await buildSearchIndexFromCache(esCache);
|
|
205
|
-
const query = 'keywords to search';
|
|
206
|
-
const options = {
|
|
207
|
-
fields: ['subject'], // in which fields to search, all by deafult (subject, body, from, to)
|
|
208
|
-
limit: 5, // result limit, 50 by default
|
|
209
|
-
boost: { subject: 3, body: 1, from: 2, to: 2 }, // custom waights for matches in different email parts
|
|
210
|
-
};
|
|
211
|
-
const result: EmailSearchResult = await searchEmails(query, esCache, searchIndex);
|
|
212
|
-
|
|
213
155
|
```
|