internxt-crypto 1.3.0 → 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.
Files changed (101) hide show
  1. package/README.md +15 -73
  2. package/dist/asymmetric-crypto.js +3 -4
  3. package/dist/asymmetric-crypto.js.map +1 -1
  4. package/dist/asymmetric-crypto.mjs +1 -2
  5. package/dist/asymmetric-crypto.mjs.map +1 -1
  6. package/dist/chunk-C13QxCFV.js +50 -0
  7. package/dist/chunk-CfYAbeIz.mjs +13 -0
  8. package/dist/constants.js +2 -3
  9. package/dist/constants.js.map +1 -1
  10. package/dist/constants.mjs +1 -1
  11. package/dist/derive-key.js +50 -5
  12. package/dist/derive-key.js.map +1 -0
  13. package/dist/derive-key.mjs +46 -2
  14. package/dist/derive-key.mjs.map +1 -0
  15. package/dist/{deriveKeysFromPassword-iMHv-tIA.js → derive-password-CbYRDq7V.js} +25 -30
  16. package/dist/derive-password-CbYRDq7V.js.map +1 -0
  17. package/dist/{deriveKeysFromPassword-DFzo2OII.mjs → derive-password-PED-YfwE.mjs} +27 -34
  18. package/dist/derive-password-PED-YfwE.mjs.map +1 -0
  19. package/dist/derive-password.js +5 -6
  20. package/dist/derive-password.mjs +2 -3
  21. package/dist/email-crypto-Di814Pbk.js +739 -0
  22. package/dist/email-crypto-Di814Pbk.js.map +1 -0
  23. package/dist/email-crypto-DpjfXDes.mjs +535 -0
  24. package/dist/email-crypto-DpjfXDes.mjs.map +1 -0
  25. package/dist/email-crypto.d.mts +138 -29
  26. package/dist/email-crypto.d.mts.map +1 -1
  27. package/dist/email-crypto.d.ts +138 -29
  28. package/dist/email-crypto.d.ts.map +1 -1
  29. package/dist/email-crypto.js +34 -18
  30. package/dist/email-crypto.mjs +2 -3
  31. package/dist/hash.js +3 -4
  32. package/dist/hash.js.map +1 -1
  33. package/dist/hash.mjs +1 -2
  34. package/dist/hash.mjs.map +1 -1
  35. package/dist/index.d.mts +3 -3
  36. package/dist/index.d.ts +3 -3
  37. package/dist/index.js +72 -56
  38. package/dist/index.mjs +7 -8
  39. package/dist/{emailEncryptionKey-CYvr26FG.mjs → keystore-crypto-C6F-NQdX.mjs} +12 -15
  40. package/dist/keystore-crypto-C6F-NQdX.mjs.map +1 -0
  41. package/dist/{emailEncryptionKey-Ba95VuFO.js → keystore-crypto-CFiiGohl.js} +67 -70
  42. package/dist/keystore-crypto-CFiiGohl.js.map +1 -0
  43. package/dist/keystore-crypto.d.mts +1 -1
  44. package/dist/keystore-crypto.d.ts +1 -1
  45. package/dist/keystore-crypto.js +11 -12
  46. package/dist/keystore-crypto.mjs +2 -3
  47. package/dist/post-quantum-crypto.js +3 -4
  48. package/dist/post-quantum-crypto.js.map +1 -1
  49. package/dist/post-quantum-crypto.mjs +1 -2
  50. package/dist/post-quantum-crypto.mjs.map +1 -1
  51. package/dist/storage-service.js +13 -15
  52. package/dist/storage-service.js.map +1 -1
  53. package/dist/storage-service.mjs +2 -4
  54. package/dist/storage-service.mjs.map +1 -1
  55. package/dist/symmetric-crypto.js +51 -5
  56. package/dist/symmetric-crypto.js.map +1 -0
  57. package/dist/symmetric-crypto.mjs +47 -2
  58. package/dist/symmetric-crypto.mjs.map +1 -0
  59. package/dist/types-CrAiKyb0.d.ts +61 -0
  60. package/dist/types-CrAiKyb0.d.ts.map +1 -0
  61. package/dist/types-D6hsUfma.d.mts +61 -0
  62. package/dist/types-D6hsUfma.d.mts.map +1 -0
  63. package/dist/types.d.mts +2 -49
  64. package/dist/types.d.ts +2 -49
  65. package/dist/types.js +2 -3
  66. package/dist/types.js.map +1 -1
  67. package/dist/types.mjs +1 -1
  68. package/dist/types.mjs.map +1 -1
  69. package/dist/utils.js +127 -14
  70. package/dist/utils.js.map +1 -0
  71. package/dist/utils.mjs +113 -2
  72. package/dist/utils.mjs.map +1 -0
  73. package/dist/{xwing-iRWVRtNE.js → xwing-7fEqAT7W.js} +18 -19
  74. package/dist/{xwing-iRWVRtNE.js.map → xwing-7fEqAT7W.js.map} +1 -1
  75. package/dist/{xwing-CQmQX6hn.mjs → xwing-B34h5e3Z.mjs} +2 -3
  76. package/dist/{xwing-CQmQX6hn.mjs.map → xwing-B34h5e3Z.mjs.map} +1 -1
  77. package/package.json +22 -22
  78. package/dist/aes-B8TA-JKq.mjs +0 -49
  79. package/dist/aes-B8TA-JKq.mjs.map +0 -1
  80. package/dist/aes-CuW_SPl-.js +0 -67
  81. package/dist/aes-CuW_SPl-.js.map +0 -1
  82. package/dist/chunk-DQk6qfdC.mjs +0 -18
  83. package/dist/chunk-EbLFQX5m.js +0 -60
  84. package/dist/deriveKeysFromMnemonic-DB0UHE-y.mjs +0 -49
  85. package/dist/deriveKeysFromMnemonic-DB0UHE-y.mjs.map +0 -1
  86. package/dist/deriveKeysFromMnemonic-Dbx7VSBQ.js +0 -67
  87. package/dist/deriveKeysFromMnemonic-Dbx7VSBQ.js.map +0 -1
  88. package/dist/deriveKeysFromPassword-DFzo2OII.mjs.map +0 -1
  89. package/dist/deriveKeysFromPassword-iMHv-tIA.js.map +0 -1
  90. package/dist/emailEncryptionKey-Ba95VuFO.js.map +0 -1
  91. package/dist/emailEncryptionKey-CYvr26FG.mjs.map +0 -1
  92. package/dist/emailKeys-BFI-paQq.js +0 -406
  93. package/dist/emailKeys-BFI-paQq.js.map +0 -1
  94. package/dist/emailKeys-BjIeINfC.mjs +0 -304
  95. package/dist/emailKeys-BjIeINfC.mjs.map +0 -1
  96. package/dist/genID-D08K7JPr.mjs +0 -117
  97. package/dist/genID-D08K7JPr.mjs.map +0 -1
  98. package/dist/genID-cWOPmspk.js +0 -190
  99. package/dist/genID-cWOPmspk.js.map +0 -1
  100. package/dist/types.d.mts.map +0 -1
  101. package/dist/types.d.ts.map +0 -1
@@ -1,304 +0,0 @@
1
- import { CONTEXT_DATABASE, CONTEXT_DRAFT } from "./constants.mjs";
2
- import { c as base64ToUint8Array, f as uint8ToUTF8, s as UTF8ToUint8, u as uint8ArrayToBase64 } from "./genID-D08K7JPr.mjs";
3
- import { 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, r as genSymmetricKey, t as decryptSymmetrically } from "./aes-B8TA-JKq.mjs";
6
- import { n as encapsulateHybrid, r as genHybridKeys, t as decapsulateHybrid } from "./xwing-CQmQX6hn.mjs";
7
- import { aeskw } from "@noble/ciphers/aes.js";
8
-
9
- //#region src/key-wrapper/aesWrapper.ts
10
- /**
11
- * Unwraps the given wrapped key
12
- *
13
- * @param encryptedKey - The wrapped key
14
- * @param wrappingKey - The secret key used for unwrapping
15
- * @returns The resulting key
16
- */
17
- async function unwrapKey(encryptedKey, wrappingKey) {
18
- return aeskw(wrappingKey).decrypt(encryptedKey);
19
- }
20
- /**
21
- * Wraps the given key
22
- *
23
- * @param key - The key to be wrapped
24
- * @param wrappingKey - The secret key used for wrapping
25
- * @returns The resulting ciphertext
26
- */
27
- async function wrapKey(key, wrappingKey) {
28
- return aeskw(wrappingKey).encrypt(key);
29
- }
30
-
31
- //#endregion
32
- //#region src/email-crypto/core.ts
33
- /**
34
- * Symmetrically encrypts email body.
35
- *
36
- * @param body - The email body to encrypt.
37
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
38
- * @returns The resulting encrypted email body and symmetric key used for encryption
39
- */
40
- async function encryptEmailBody(body, aux) {
41
- try {
42
- if (!body.text || !body.subject) throw new Error("Invalid input");
43
- const encryptionKey = genSymmetricKey();
44
- return {
45
- encEmailBody: await encryptEmailBodyWithKey(body, encryptionKey, aux),
46
- encryptionKey
47
- };
48
- } catch (error) {
49
- throw new Error("Failed to symmetrically encrypt email body", { cause: error });
50
- }
51
- }
52
- /**
53
- * Symmetrically encrypts email body with the given key.
54
- *
55
- * @param body - The email body to encrypt.
56
- * @param encryptionKey - The symmetric key to encrypt the email.
57
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
58
- * @returns The resulting encrypted email body and symmetric key used for encryption
59
- */
60
- async function encryptEmailBodyWithKey(body, encryptionKey, aux) {
61
- try {
62
- const text = UTF8ToUint8(body.text);
63
- const subjectEnc = await encryptSymmetrically(encryptionKey, UTF8ToUint8(body.subject), aux);
64
- const enc = {
65
- encText: uint8ArrayToBase64(await encryptSymmetrically(encryptionKey, text, aux)),
66
- encSubject: uint8ArrayToBase64(subjectEnc)
67
- };
68
- if (body.attachments) {
69
- const promises = body.attachments.map((attachment) => {
70
- return encryptSymmetrically(encryptionKey, UTF8ToUint8(attachment), aux);
71
- });
72
- enc.encAttachments = (await Promise.all(promises))?.map(uint8ArrayToBase64);
73
- }
74
- return enc;
75
- } catch (error) {
76
- throw new Error("Failed to encrypt email body", { cause: error });
77
- }
78
- }
79
- /**
80
- * Decrypts symmetrically encrypted email body.
81
- *
82
- * @param encEmailBody - The email body to decrypt.
83
- * @param encryptionKey - The symmetric key to decrypt the email.
84
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
85
- * @returns The resulting decrypted email body
86
- */
87
- async function decryptEmailBody(encEmailBody, encryptionKey, aux) {
88
- try {
89
- const subject = uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailBody.encSubject), aux));
90
- const body = {
91
- text: uint8ToUTF8(await decryptSymmetrically(encryptionKey, base64ToUint8Array(encEmailBody.encText), aux)),
92
- subject
93
- };
94
- if (encEmailBody.encAttachments) {
95
- const promises = (encEmailBody.encAttachments?.map(base64ToUint8Array))?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));
96
- body.attachments = (await Promise.all(promises))?.map((att) => uint8ToUTF8(att));
97
- }
98
- return body;
99
- } catch (error) {
100
- throw new Error("Failed to symmetrically decrypt email body", { cause: error });
101
- }
102
- }
103
- /**
104
- * Encrypts the email symmetric key using hybrid encryption.
105
- *
106
- * @param emailEncryptionKey - The symmetric key used for email encryption.
107
- * @param recipient - The recipient with a public hybrid key.
108
- * @returns The encrypted email symmetric key
109
- */
110
- async function encryptKeysHybrid(emailEncryptionKey, recipient) {
111
- try {
112
- const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);
113
- return {
114
- encryptedKey: uint8ArrayToBase64(await wrapKey(emailEncryptionKey, sharedSecret)),
115
- hybridCiphertext: uint8ArrayToBase64(cipherText),
116
- encryptedForEmail: recipient.email
117
- };
118
- } catch (error) {
119
- throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
120
- }
121
- }
122
- /**
123
- * Decrypts the email symmetric key encrypted via hybrid encryption.
124
- *
125
- * @param encryptedKey - The encrypted email key.
126
- * @param recipientPrivateKey - The private key of the recipient.
127
- * @returns The email encryption key
128
- */
129
- async function decryptKeysHybrid(encryptedKey, recipientPrivateKey) {
130
- try {
131
- const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);
132
- return await unwrapKey(base64ToUint8Array(encryptedKey.encryptedKey), decapsulateHybrid(kyberCiphertext, recipientPrivateKey));
133
- } catch (error) {
134
- throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
135
- }
136
- }
137
- /**
138
- * Password-protects the email symmetric key.
139
- *
140
- * @param emailEncryptionKey - The symmetric key used for email encryption.
141
- * @param password - The secret password for key protection.
142
- * @returns The password-protected email symmetric key
143
- */
144
- async function passwordProtectKey(emailEncryptionKey, password) {
145
- try {
146
- const { key, salt } = await getKeyFromPassword(password);
147
- const encryptedKey = await wrapKey(emailEncryptionKey, key);
148
- const saltStr = uint8ArrayToBase64(salt);
149
- return {
150
- encryptedKey: uint8ArrayToBase64(encryptedKey),
151
- salt: saltStr
152
- };
153
- } catch (error) {
154
- throw new Error("Failed to password-protect email key", { cause: error });
155
- }
156
- }
157
- /**
158
- * Removes passoword-protection and exposes the email symmetric key.
159
- *
160
- * @param emailEncryptionKey - The password-protected email key.
161
- * @param password - The secret password for key protection.
162
- * @returns The email encryption key
163
- */
164
- async function removePasswordProtection(emailEncryptionKey, password) {
165
- try {
166
- const salt = base64ToUint8Array(emailEncryptionKey.salt);
167
- return await unwrapKey(base64ToUint8Array(emailEncryptionKey.encryptedKey), await getKeyFromPasswordAndSalt(password, salt));
168
- } catch (error) {
169
- throw new Error("Failed to remove password-protection from email key", { cause: error });
170
- }
171
- }
172
-
173
- //#endregion
174
- //#region src/email-crypto/hybridEncyptedEmail.ts
175
- /**
176
- * Encrypts the email body using hybrid encryption.
177
- *
178
- * @param body - The email body to encrypt.
179
- * @param recipientPublicKeys - The public keys of the recipient.
180
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
181
- * @returns The encrypted email body
182
- */
183
- async function encryptEmailHybrid(body, recipient, aux) {
184
- try {
185
- const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);
186
- return {
187
- encEmailBody,
188
- encryptedKey: await encryptKeysHybrid(encryptionKey, recipient)
189
- };
190
- } catch (error) {
191
- throw new Error("Failed to encrypt email body with hybrid encryption", { cause: error });
192
- }
193
- }
194
- /**
195
- * Encrypts the email body using hybrid encryption for multiple recipients.
196
- *
197
- * @param body - The email body to encrypt for multiple recipients.
198
- * @param recipients - The recipients with corresponding public keys.
199
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
200
- * @returns The set of encrypted email bodies
201
- */
202
- async function encryptEmailHybridForMultipleRecipients(body, recipients, aux) {
203
- try {
204
- const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);
205
- const encryptedEmails = [];
206
- for (const recipient of recipients) {
207
- const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);
208
- encryptedEmails.push({
209
- encEmailBody,
210
- encryptedKey
211
- });
212
- }
213
- return encryptedEmails;
214
- } catch (error) {
215
- throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
216
- }
217
- }
218
- /**
219
- * Decrypts the email using hybrid encryption.
220
- *
221
- * @param encEmailBody - The encrypted email.
222
- * @param recipientPrivateHybridKeys - The private key of the recipient.
223
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
224
- * @returns The decrypted email body
225
- */
226
- async function decryptEmailHybrid(encEmailBody, recipientPrivateHybridKeys, aux) {
227
- try {
228
- const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);
229
- return await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);
230
- } catch (error) {
231
- throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
232
- }
233
- }
234
-
235
- //#endregion
236
- //#region src/email-crypto/pwdProtectedEmail.ts
237
- /**
238
- * Creates a password-protected email.
239
- *
240
- * @param email - The email to password-protect
241
- * @param password - The secret password shared among recipients
242
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
243
- * @returns The password-protected email
244
- */
245
- async function createPwdProtectedEmail(emailBody, password, aux) {
246
- try {
247
- const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);
248
- return {
249
- encEmailBody,
250
- encryptedKey: await passwordProtectKey(encryptionKey, password)
251
- };
252
- } catch (error) {
253
- throw new Error("Failed to password-protect email", { cause: error });
254
- }
255
- }
256
- /**
257
- * Opens a password-protected email.
258
- *
259
- * @param encryptedEmail - The encrypted email
260
- * @param password - The secret password shared among recipients.
261
- * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).
262
- * @returns The decrypted email body
263
- */
264
- async function decryptPwdProtectedEmail(encryptedEmail, password, aux) {
265
- try {
266
- const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);
267
- return await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);
268
- } catch (error) {
269
- throw new Error("Failed to decrypt password-protect email", { cause: error });
270
- }
271
- }
272
-
273
- //#endregion
274
- //#region src/email-crypto/emailKeys.ts
275
- /**
276
- * Generates public and private keys for email encryption.
277
- *
278
- * @returns The user's private and public keys
279
- */
280
- async function generateEmailKeys() {
281
- return genHybridKeys();
282
- }
283
- /**
284
- * Derives database encryption key for the given user
285
- *
286
- * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)
287
- * @returns The symmetric key for protecting database
288
- */
289
- const deriveDatabaseKey = async (mnemonic) => {
290
- return deriveKeyFromMnemonic(mnemonic, CONTEXT_DATABASE);
291
- };
292
- /**
293
- * Derives email draft encryption key for the given user
294
- *
295
- * @param mnemonic - The user's mnemonic (machine-generated with secure PRNG)
296
- * @returns The symmetric key for protecting email drafts
297
- */
298
- const deriveEmailDraftKey = async (mnemonic) => {
299
- return deriveKeyFromMnemonic(mnemonic, CONTEXT_DRAFT);
300
- };
301
-
302
- //#endregion
303
- export { wrapKey as _, decryptPwdProtectedEmail as a, encryptEmailHybridForMultipleRecipients as c, encryptEmailBody as d, encryptEmailBodyWithKey as f, unwrapKey as g, removePasswordProtection as h, createPwdProtectedEmail as i, decryptEmailBody as l, passwordProtectKey as m, deriveEmailDraftKey as n, decryptEmailHybrid as o, encryptKeysHybrid as p, generateEmailKeys as r, encryptEmailHybrid as s, deriveDatabaseKey as t, decryptKeysHybrid as u };
304
- //# sourceMappingURL=emailKeys-BjIeINfC.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emailKeys-BjIeINfC.mjs","names":[],"sources":["../src/key-wrapper/aesWrapper.ts","../src/email-crypto/core.ts","../src/email-crypto/hybridEncyptedEmail.ts","../src/email-crypto/pwdProtectedEmail.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","import { HybridEncKey, PwdProtectedKey, EmailBody, EmailBodyEncrypted, RecipientWithPublicKey } from '../types';\nimport { encryptSymmetrically, decryptSymmetrically, genSymmetricKey } from '../symmetric-crypto';\nimport { encapsulateHybrid, decapsulateHybrid } from '../hybrid-crypto';\nimport { wrapKey, unwrapKey } from '../key-wrapper';\nimport { getKeyFromPassword, getKeyFromPasswordAndSalt } from '../derive-password';\nimport { UTF8ToUint8, base64ToUint8Array, uint8ArrayToBase64, uint8ToUTF8 } from '../utils';\n\n/**\n * Symmetrically encrypts email body.\n *\n * @param body - The email body to encrypt.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBody(\n body: EmailBody,\n aux?: Uint8Array,\n): Promise<{\n encEmailBody: EmailBodyEncrypted;\n encryptionKey: Uint8Array;\n}> {\n try {\n if (!body.text || !body.subject) {\n throw new Error('Invalid input');\n }\n const encryptionKey = genSymmetricKey();\n const encEmailBody = await encryptEmailBodyWithKey(body, encryptionKey, aux);\n\n return { encEmailBody, encryptionKey };\n } catch (error) {\n throw new Error('Failed to symmetrically encrypt email body', { cause: error });\n }\n}\n\n/**\n * Symmetrically encrypts email body with the given key.\n *\n * @param body - The email body to encrypt.\n * @param encryptionKey - The symmetric key to encrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting encrypted email body and symmetric key used for encryption\n */\nexport async function encryptEmailBodyWithKey(\n body: EmailBody,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBodyEncrypted> {\n try {\n const text = UTF8ToUint8(body.text);\n const subject = UTF8ToUint8(body.subject);\n const subjectEnc = await encryptSymmetrically(encryptionKey, subject, aux);\n const encryptedText = await encryptSymmetrically(encryptionKey, text, aux);\n const encText = uint8ArrayToBase64(encryptedText);\n const encSubject = uint8ArrayToBase64(subjectEnc);\n const enc: EmailBodyEncrypted = { encText, encSubject };\n\n if (body.attachments) {\n const promises = body.attachments.map((attachment) => {\n const binaryAttachment = UTF8ToUint8(attachment);\n return encryptSymmetrically(encryptionKey, binaryAttachment, aux);\n });\n const encryptedAttachments = await Promise.all(promises);\n enc.encAttachments = encryptedAttachments?.map(uint8ArrayToBase64);\n }\n\n return enc;\n } catch (error) {\n throw new Error('Failed to encrypt email body', { cause: error });\n }\n}\n\n/**\n * Decrypts symmetrically encrypted email body.\n *\n * @param encEmailBody - The email body to decrypt.\n * @param encryptionKey - The symmetric key to decrypt the email.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The resulting decrypted email body\n */\nexport async function decryptEmailBody(\n encEmailBody: EmailBodyEncrypted,\n encryptionKey: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encSubject = base64ToUint8Array(encEmailBody.encSubject);\n const subjectArray = await decryptSymmetrically(encryptionKey, encSubject, aux);\n const subject = uint8ToUTF8(subjectArray);\n const encText = base64ToUint8Array(encEmailBody.encText);\n const textArray = await decryptSymmetrically(encryptionKey, encText, aux);\n const text = uint8ToUTF8(textArray);\n const body: EmailBody = { text, subject };\n\n if (encEmailBody.encAttachments) {\n const encAttachments = encEmailBody.encAttachments?.map(base64ToUint8Array);\n const promises = encAttachments?.map((encAtt) => decryptSymmetrically(encryptionKey, encAtt, aux));\n const decryptedAttachments = await Promise.all(promises);\n body.attachments = decryptedAttachments?.map((att) => uint8ToUTF8(att));\n }\n\n return body;\n } catch (error) {\n throw new Error('Failed to symmetrically decrypt email body', { cause: error });\n }\n}\n\n/**\n * Encrypts the email symmetric key using hybrid encryption.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param recipient - The recipient with a public hybrid key.\n * @returns The encrypted email symmetric key\n */\nexport async function encryptKeysHybrid(\n emailEncryptionKey: Uint8Array,\n recipient: RecipientWithPublicKey,\n): Promise<HybridEncKey> {\n try {\n const { cipherText, sharedSecret } = encapsulateHybrid(recipient.publicHybridKey);\n const encryptedKey = await wrapKey(emailEncryptionKey, sharedSecret);\n const encryptedKeyBase64 = uint8ArrayToBase64(encryptedKey);\n const kyberCiphertextBase64 = uint8ArrayToBase64(cipherText);\n\n return {\n encryptedKey: encryptedKeyBase64,\n hybridCiphertext: kyberCiphertextBase64,\n encryptedForEmail: recipient.email,\n };\n } catch (error) {\n throw new Error('Failed to encrypt email key using hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email symmetric key encrypted via hybrid encryption.\n *\n * @param encryptedKey - The encrypted email key.\n * @param recipientPrivateKey - The private key of the recipient.\n * @returns The email encryption key\n */\nexport async function decryptKeysHybrid(\n encryptedKey: HybridEncKey,\n recipientPrivateKey: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const kyberCiphertext = base64ToUint8Array(encryptedKey.hybridCiphertext);\n const encKey = base64ToUint8Array(encryptedKey.encryptedKey);\n const sharedSecret = decapsulateHybrid(kyberCiphertext, recipientPrivateKey);\n const encryptionKey = await unwrapKey(encKey, sharedSecret);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to decrypt email key encrypted via hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Password-protects the email symmetric key.\n *\n * @param emailEncryptionKey - The symmetric key used for email encryption.\n * @param password - The secret password for key protection.\n * @returns The password-protected email symmetric key\n */\nexport async function passwordProtectKey(emailEncryptionKey: Uint8Array, password: string): Promise<PwdProtectedKey> {\n try {\n const { key, salt } = await getKeyFromPassword(password);\n const encryptedKey = await wrapKey(emailEncryptionKey, key);\n const saltStr = uint8ArrayToBase64(salt);\n const encryptedKeyStr = uint8ArrayToBase64(encryptedKey);\n return { encryptedKey: encryptedKeyStr, salt: saltStr };\n } catch (error) {\n throw new Error('Failed to password-protect email key', { cause: error });\n }\n}\n\n/**\n * Removes passoword-protection and exposes the email symmetric key.\n *\n * @param emailEncryptionKey - The password-protected email key.\n * @param password - The secret password for key protection.\n * @returns The email encryption key\n */\nexport async function removePasswordProtection(\n emailEncryptionKey: PwdProtectedKey,\n password: string,\n): Promise<Uint8Array> {\n try {\n const salt = base64ToUint8Array(emailEncryptionKey.salt);\n const encryptedKey = base64ToUint8Array(emailEncryptionKey.encryptedKey);\n const key = await getKeyFromPasswordAndSalt(password, salt);\n const encryptionKey = await unwrapKey(encryptedKey, key);\n return encryptionKey;\n } catch (error) {\n throw new Error('Failed to remove password-protection from email key', { cause: error });\n }\n}\n","import { HybridEncryptedEmail, EmailBody, RecipientWithPublicKey } from '../types';\nimport { decryptEmailBody, encryptKeysHybrid, decryptKeysHybrid, encryptEmailBody } from './core';\n\n/**\n * Encrypts the email body using hybrid encryption.\n *\n * @param body - The email body to encrypt.\n * @param recipientPublicKeys - The public keys of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The encrypted email body\n */\nexport async function encryptEmailHybrid(\n body: EmailBody,\n recipient: RecipientWithPublicKey,\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to encrypt email body with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Encrypts the email body using hybrid encryption for multiple recipients.\n *\n * @param body - The email body to encrypt for multiple recipients.\n * @param recipients - The recipients with corresponding public keys.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The set of encrypted email bodies\n */\nexport async function encryptEmailHybridForMultipleRecipients(\n body: EmailBody,\n recipients: RecipientWithPublicKey[],\n aux?: Uint8Array,\n): Promise<HybridEncryptedEmail[]> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(body, aux);\n\n const encryptedEmails: HybridEncryptedEmail[] = [];\n for (const recipient of recipients) {\n const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient);\n encryptedEmails.push({\n encEmailBody: encEmailBody,\n encryptedKey,\n });\n }\n return encryptedEmails;\n } catch (error) {\n throw new Error('Failed to encrypt email to multiple recipients with hybrid encryption', { cause: error });\n }\n}\n\n/**\n * Decrypts the email using hybrid encryption.\n *\n * @param encEmailBody - The encrypted email.\n * @param recipientPrivateHybridKeys - The private key of the recipient.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptEmailHybrid(\n encEmailBody: HybridEncryptedEmail,\n recipientPrivateHybridKeys: Uint8Array,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await decryptKeysHybrid(encEmailBody.encryptedKey, recipientPrivateHybridKeys);\n const body = await decryptEmailBody(encEmailBody.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt email with hybrid encryption', { cause: error });\n }\n}\n","import { PwdProtectedEmail, EmailBody } from '../types';\nimport { decryptEmailBody, passwordProtectKey, removePasswordProtection, encryptEmailBody } from './core';\n\n/**\n * Creates a password-protected email.\n *\n * @param email - The email to password-protect\n * @param password - The secret password shared among recipients\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The password-protected email\n */\nexport async function createPwdProtectedEmail(\n emailBody: EmailBody,\n password: string,\n aux?: Uint8Array,\n): Promise<PwdProtectedEmail> {\n try {\n const { encryptionKey, encEmailBody } = await encryptEmailBody(emailBody, aux);\n const encryptedKey = await passwordProtectKey(encryptionKey, password);\n\n return { encEmailBody, encryptedKey };\n } catch (error) {\n throw new Error('Failed to password-protect email', { cause: error });\n }\n}\n\n/**\n * Opens a password-protected email.\n *\n * @param encryptedEmail - The encrypted email\n * @param password - The secret password shared among recipients.\n * @param aux - An optional auxilary sting for AEAD (e.g., email ID or timestamp).\n * @returns The decrypted email body\n */\nexport async function decryptPwdProtectedEmail(\n encryptedEmail: PwdProtectedEmail,\n password: string,\n aux?: Uint8Array,\n): Promise<EmailBody> {\n try {\n const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);\n const body = await decryptEmailBody(encryptedEmail.encEmailBody, encryptionKey, aux);\n return body;\n } catch (error) {\n throw new Error('Failed to decrypt password-protect email', { cause: error });\n }\n}\n","import { genHybridKeys } from '../hybrid-crypto';\nimport { HybridKeyPair } from '../types';\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;;;;;;;;;;;;ACPxC,eAAsB,iBACpB,MACA,KAIC;AACD,KAAI;AACF,MAAI,CAAC,KAAK,QAAQ,CAAC,KAAK,QACtB,OAAM,IAAI,MAAM,gBAAgB;EAElC,MAAM,gBAAgB,iBAAiB;AAGvC,SAAO;GAAE,cAFY,MAAM,wBAAwB,MAAM,eAAe,IAAI;GAErD;GAAe;UAC/B,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;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AClF,QAAO,sBAAsB,UAAU,cAAc"}
@@ -1,117 +0,0 @@
1
- import { AES_KEY_BYTE_LENGTH } from "./constants.mjs";
2
- import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
3
- import * as bip39 from "@scure/bip39";
4
- import { wordlist } from "@scure/bip39/wordlists/english.js";
5
- import { parse, stringify, v4 } from "uuid";
6
-
7
- //#region src/utils/converters.ts
8
- /**
9
- * Converts a Uint8Array into a hexadecimal string.
10
- *
11
- * @param array - The Uint8Array to convert.
12
- * @returns The hexadecimal string representation of the array.
13
- */
14
- function uint8ArrayToHex(array) {
15
- return bytesToHex(array);
16
- }
17
- /**
18
- * Converts a UTF-8 string into a Uint8Array.
19
- *
20
- * @param str - The UTF-8 string to convert.
21
- * @returns A Uint8Array created from the UTF-8 string.
22
- */
23
- function UTF8ToUint8(str) {
24
- return new TextEncoder().encode(str);
25
- }
26
- /**
27
- * Converts an Uint8Array into a UTF-8 string.
28
- *
29
- * @param array - The Uint8Array to convert.
30
- * @returns The UTF-8 string representation of the array.
31
- */
32
- function uint8ToUTF8(array) {
33
- return new TextDecoder().decode(array);
34
- }
35
- /**
36
- * Converts a hexadecimal string into a Uint8Array.
37
- *
38
- * @param hex - The hexadecimal string to convert.
39
- * @returns A Uint8Array created from the hex string.
40
- */
41
- function hexToUint8Array(hex) {
42
- return hexToBytes(hex);
43
- }
44
- /**
45
- * Converts a Uint8Array into a base64 string.
46
- *
47
- * @param array - The Uint8Array to convert.
48
- * @returns The base64 string representation of the array.
49
- */
50
- function uint8ArrayToBase64(buffer) {
51
- const array = Uint16Array.from(buffer);
52
- const binaryString = new TextDecoder("UTF-16").decode(array);
53
- return btoa(binaryString);
54
- }
55
- /**
56
- * Converts a base64 string into a Uint8Array.
57
- *
58
- * @param str - The base64 string to convert.
59
- * @returns A Uint8Array created from the base64 string.
60
- */
61
- function base64ToUint8Array(str) {
62
- const binaryString = atob(str);
63
- const len = binaryString.length;
64
- const array = new Uint8Array(len);
65
- for (let i = 0; i < len; i++) array[i] = binaryString.codePointAt(i);
66
- return new Uint8Array(array.buffer);
67
- }
68
-
69
- //#endregion
70
- //#region src/utils/genMnemonic.ts
71
- /**
72
- * Generates a mnemonic
73
- *
74
- * @returns The generated mnemonic.
75
- */
76
- function genMnemonic() {
77
- return bip39.generateMnemonic(wordlist, AES_KEY_BYTE_LENGTH * 8);
78
- }
79
- /**
80
- * Converts a mnemonic to Uint8Array
81
- *
82
- * @param mnemonic - The mnemonic to convert
83
- * @returns The mnemonic as Uint8Array
84
- */
85
- function mnemonicToBytes(mnemonic) {
86
- return bip39.mnemonicToEntropy(mnemonic, wordlist);
87
- }
88
- /**
89
- * Converts a Uint8Array to a mnemonic
90
- *
91
- * @param bytes - The bytes to convert
92
- * @returns The mnemonic string
93
- */
94
- function bytesToMnemonic(bytes) {
95
- return bip39.entropyToMnemonic(bytes, wordlist);
96
- }
97
-
98
- //#endregion
99
- //#region src/utils/genID.ts
100
- /**
101
- * Creates a random identifier.
102
- *
103
- * @returns The resulting auxilary string
104
- */
105
- function generateUuid() {
106
- return v4();
107
- }
108
- function uuidToBytes(uuid) {
109
- return parse(uuid);
110
- }
111
- function bytesToUuid(bytes) {
112
- return stringify(bytes);
113
- }
114
-
115
- //#endregion
116
- export { genMnemonic as a, base64ToUint8Array as c, uint8ArrayToHex as d, uint8ToUTF8 as f, bytesToMnemonic as i, hexToUint8Array as l, generateUuid as n, mnemonicToBytes as o, uuidToBytes as r, UTF8ToUint8 as s, bytesToUuid as t, uint8ArrayToBase64 as u };
117
- //# sourceMappingURL=genID-D08K7JPr.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"genID-D08K7JPr.mjs","names":["uuidv4"],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.codePointAt(i)!;\n }\n return new Uint8Array(array.buffer);\n}\n","import * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BYTE_LENGTH } from '../constants';\n/**\n * Generates a mnemonic\n *\n * @returns The generated mnemonic.\n */\nexport function genMnemonic(): string {\n return bip39.generateMnemonic(wordlist, AES_KEY_BYTE_LENGTH * 8);\n}\n\n/**\n * Converts a mnemonic to Uint8Array\n *\n * @param mnemonic - The mnemonic to convert\n * @returns The mnemonic as Uint8Array\n */\nexport function mnemonicToBytes(mnemonic: string): Uint8Array {\n return bip39.mnemonicToEntropy(mnemonic, wordlist);\n}\n\n/**\n * Converts a Uint8Array to a mnemonic\n *\n * @param bytes - The bytes to convert\n * @returns The mnemonic string\n */\nexport function bytesToMnemonic(bytes: Uint8Array): string {\n return bip39.entropyToMnemonic(bytes, wordlist);\n}\n","import { v4 as uuidv4, parse, stringify } from 'uuid';\n/**\n * Creates a random identifier.\n *\n * @returns The resulting auxilary string\n */\nexport function generateUuid(): string {\n return uuidv4();\n}\n\nexport function uuidToBytes(uuid: string): Uint8Array {\n return parse(uuid);\n}\n\nexport function bytesToUuid(bytes: Uint8Array): string {\n return stringify(bytes);\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,QAAO,WAAW,MAAM;;;;;;;;AAS1B,SAAgB,YAAY,KAAyB;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;;AAStC,SAAgB,YAAY,OAA2B;AACrD,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;;;;;;;;AASxC,SAAgB,gBAAgB,KAAyB;AACvD,QAAO,WAAW,IAAI;;;;;;;;AASxB,SAAgB,mBAAmB,QAA4B;CAC7D,MAAM,QAAQ,YAAY,KAAK,OAAO;CACtC,MAAM,eAAe,IAAI,YAAY,SAAS,CAAC,OAAO,MAAM;AAC5D,QAAO,KAAK,aAAa;;;;;;;;AAS3B,SAAgB,mBAAmB,KAAyB;CAC1D,MAAM,eAAe,KAAK,IAAI;CAC9B,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,OAAM,KAAK,aAAa,YAAY,EAAE;AAExC,QAAO,IAAI,WAAW,MAAM,OAAO;;;;;;;;;;AC3DrC,SAAgB,cAAsB;AACpC,QAAO,MAAM,iBAAiB,UAAU,sBAAsB,EAAE;;;;;;;;AASlE,SAAgB,gBAAgB,UAA8B;AAC5D,QAAO,MAAM,kBAAkB,UAAU,SAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAO,MAAM,kBAAkB,OAAO,SAAS;;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,QAAOA,IAAQ;;AAGjB,SAAgB,YAAY,MAA0B;AACpD,QAAO,MAAM,KAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,QAAO,UAAU,MAAM"}
@@ -1,190 +0,0 @@
1
- const require_chunk = require('./chunk-EbLFQX5m.js');
2
- const require_constants = require('./constants.js');
3
- let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
4
- let _scure_bip39 = require("@scure/bip39");
5
- _scure_bip39 = require_chunk.__toESM(_scure_bip39);
6
- let _scure_bip39_wordlists_english_js = require("@scure/bip39/wordlists/english.js");
7
- let uuid = require("uuid");
8
-
9
- //#region src/utils/converters.ts
10
- /**
11
- * Converts a Uint8Array into a hexadecimal string.
12
- *
13
- * @param array - The Uint8Array to convert.
14
- * @returns The hexadecimal string representation of the array.
15
- */
16
- function uint8ArrayToHex(array) {
17
- return (0, _noble_hashes_utils_js.bytesToHex)(array);
18
- }
19
- /**
20
- * Converts a UTF-8 string into a Uint8Array.
21
- *
22
- * @param str - The UTF-8 string to convert.
23
- * @returns A Uint8Array created from the UTF-8 string.
24
- */
25
- function UTF8ToUint8(str) {
26
- return new TextEncoder().encode(str);
27
- }
28
- /**
29
- * Converts an Uint8Array into a UTF-8 string.
30
- *
31
- * @param array - The Uint8Array to convert.
32
- * @returns The UTF-8 string representation of the array.
33
- */
34
- function uint8ToUTF8(array) {
35
- return new TextDecoder().decode(array);
36
- }
37
- /**
38
- * Converts a hexadecimal string into a Uint8Array.
39
- *
40
- * @param hex - The hexadecimal string to convert.
41
- * @returns A Uint8Array created from the hex string.
42
- */
43
- function hexToUint8Array(hex) {
44
- return (0, _noble_hashes_utils_js.hexToBytes)(hex);
45
- }
46
- /**
47
- * Converts a Uint8Array into a base64 string.
48
- *
49
- * @param array - The Uint8Array to convert.
50
- * @returns The base64 string representation of the array.
51
- */
52
- function uint8ArrayToBase64(buffer) {
53
- const array = Uint16Array.from(buffer);
54
- const binaryString = new TextDecoder("UTF-16").decode(array);
55
- return btoa(binaryString);
56
- }
57
- /**
58
- * Converts a base64 string into a Uint8Array.
59
- *
60
- * @param str - The base64 string to convert.
61
- * @returns A Uint8Array created from the base64 string.
62
- */
63
- function base64ToUint8Array(str) {
64
- const binaryString = atob(str);
65
- const len = binaryString.length;
66
- const array = new Uint8Array(len);
67
- for (let i = 0; i < len; i++) array[i] = binaryString.codePointAt(i);
68
- return new Uint8Array(array.buffer);
69
- }
70
-
71
- //#endregion
72
- //#region src/utils/genMnemonic.ts
73
- /**
74
- * Generates a mnemonic
75
- *
76
- * @returns The generated mnemonic.
77
- */
78
- function genMnemonic() {
79
- return _scure_bip39.generateMnemonic(_scure_bip39_wordlists_english_js.wordlist, require_constants.AES_KEY_BYTE_LENGTH * 8);
80
- }
81
- /**
82
- * Converts a mnemonic to Uint8Array
83
- *
84
- * @param mnemonic - The mnemonic to convert
85
- * @returns The mnemonic as Uint8Array
86
- */
87
- function mnemonicToBytes(mnemonic) {
88
- return _scure_bip39.mnemonicToEntropy(mnemonic, _scure_bip39_wordlists_english_js.wordlist);
89
- }
90
- /**
91
- * Converts a Uint8Array to a mnemonic
92
- *
93
- * @param bytes - The bytes to convert
94
- * @returns The mnemonic string
95
- */
96
- function bytesToMnemonic(bytes) {
97
- return _scure_bip39.entropyToMnemonic(bytes, _scure_bip39_wordlists_english_js.wordlist);
98
- }
99
-
100
- //#endregion
101
- //#region src/utils/genID.ts
102
- /**
103
- * Creates a random identifier.
104
- *
105
- * @returns The resulting auxilary string
106
- */
107
- function generateUuid() {
108
- return (0, uuid.v4)();
109
- }
110
- function uuidToBytes(uuid$1) {
111
- return (0, uuid.parse)(uuid$1);
112
- }
113
- function bytesToUuid(bytes) {
114
- return (0, uuid.stringify)(bytes);
115
- }
116
-
117
- //#endregion
118
- Object.defineProperty(exports, 'UTF8ToUint8', {
119
- enumerable: true,
120
- get: function () {
121
- return UTF8ToUint8;
122
- }
123
- });
124
- Object.defineProperty(exports, 'base64ToUint8Array', {
125
- enumerable: true,
126
- get: function () {
127
- return base64ToUint8Array;
128
- }
129
- });
130
- Object.defineProperty(exports, 'bytesToMnemonic', {
131
- enumerable: true,
132
- get: function () {
133
- return bytesToMnemonic;
134
- }
135
- });
136
- Object.defineProperty(exports, 'bytesToUuid', {
137
- enumerable: true,
138
- get: function () {
139
- return bytesToUuid;
140
- }
141
- });
142
- Object.defineProperty(exports, 'genMnemonic', {
143
- enumerable: true,
144
- get: function () {
145
- return genMnemonic;
146
- }
147
- });
148
- Object.defineProperty(exports, 'generateUuid', {
149
- enumerable: true,
150
- get: function () {
151
- return generateUuid;
152
- }
153
- });
154
- Object.defineProperty(exports, 'hexToUint8Array', {
155
- enumerable: true,
156
- get: function () {
157
- return hexToUint8Array;
158
- }
159
- });
160
- Object.defineProperty(exports, 'mnemonicToBytes', {
161
- enumerable: true,
162
- get: function () {
163
- return mnemonicToBytes;
164
- }
165
- });
166
- Object.defineProperty(exports, 'uint8ArrayToBase64', {
167
- enumerable: true,
168
- get: function () {
169
- return uint8ArrayToBase64;
170
- }
171
- });
172
- Object.defineProperty(exports, 'uint8ArrayToHex', {
173
- enumerable: true,
174
- get: function () {
175
- return uint8ArrayToHex;
176
- }
177
- });
178
- Object.defineProperty(exports, 'uint8ToUTF8', {
179
- enumerable: true,
180
- get: function () {
181
- return uint8ToUTF8;
182
- }
183
- });
184
- Object.defineProperty(exports, 'uuidToBytes', {
185
- enumerable: true,
186
- get: function () {
187
- return uuidToBytes;
188
- }
189
- });
190
- //# sourceMappingURL=genID-cWOPmspk.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"genID-cWOPmspk.js","names":["bip39","wordlist","AES_KEY_BYTE_LENGTH","uuid"],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.codePointAt(i)!;\n }\n return new Uint8Array(array.buffer);\n}\n","import * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BYTE_LENGTH } from '../constants';\n/**\n * Generates a mnemonic\n *\n * @returns The generated mnemonic.\n */\nexport function genMnemonic(): string {\n return bip39.generateMnemonic(wordlist, AES_KEY_BYTE_LENGTH * 8);\n}\n\n/**\n * Converts a mnemonic to Uint8Array\n *\n * @param mnemonic - The mnemonic to convert\n * @returns The mnemonic as Uint8Array\n */\nexport function mnemonicToBytes(mnemonic: string): Uint8Array {\n return bip39.mnemonicToEntropy(mnemonic, wordlist);\n}\n\n/**\n * Converts a Uint8Array to a mnemonic\n *\n * @param bytes - The bytes to convert\n * @returns The mnemonic string\n */\nexport function bytesToMnemonic(bytes: Uint8Array): string {\n return bip39.entropyToMnemonic(bytes, wordlist);\n}\n","import { v4 as uuidv4, parse, stringify } from 'uuid';\n/**\n * Creates a random identifier.\n *\n * @returns The resulting auxilary string\n */\nexport function generateUuid(): string {\n return uuidv4();\n}\n\nexport function uuidToBytes(uuid: string): Uint8Array {\n return parse(uuid);\n}\n\nexport function bytesToUuid(bytes: Uint8Array): string {\n return stringify(bytes);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,+CAAkB,MAAM;;;;;;;;AAS1B,SAAgB,YAAY,KAAyB;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;;AAStC,SAAgB,YAAY,OAA2B;AACrD,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;;;;;;;;AASxC,SAAgB,gBAAgB,KAAyB;AACvD,+CAAkB,IAAI;;;;;;;;AASxB,SAAgB,mBAAmB,QAA4B;CAC7D,MAAM,QAAQ,YAAY,KAAK,OAAO;CACtC,MAAM,eAAe,IAAI,YAAY,SAAS,CAAC,OAAO,MAAM;AAC5D,QAAO,KAAK,aAAa;;;;;;;;AAS3B,SAAgB,mBAAmB,KAAyB;CAC1D,MAAM,eAAe,KAAK,IAAI;CAC9B,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,OAAM,KAAK,aAAa,YAAY,EAAE;AAExC,QAAO,IAAI,WAAW,MAAM,OAAO;;;;;;;;;;AC3DrC,SAAgB,cAAsB;AACpC,QAAOA,aAAM,iBAAiBC,4CAAUC,wCAAsB,EAAE;;;;;;;;AASlE,SAAgB,gBAAgB,UAA8B;AAC5D,QAAOF,aAAM,kBAAkB,UAAUC,2CAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAOD,aAAM,kBAAkB,OAAOC,2CAAS;;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,sBAAe;;AAGjB,SAAgB,YAAY,QAA0B;AACpD,wBAAaE,OAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,4BAAiB,MAAM"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";KAAY,iBAAA;EACV,SAAA;EACA,IAAA,EAAM,YAAA;EACN,SAAA;EACA,mBAAA;AAAA;AAAA,KAGU,sBAAA;EACV,KAAA;EACA,eAAA,EAAiB,UAAA;AAAA;AAAA,KAGP,aAAA;EACV,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;AAAA,KAGD,oBAAA;EACV,YAAA,EAAc,YAAA;EACd,YAAA,EAAc,kBAAA;AAAA;AAAA,KAGJ,iBAAA;EACV,YAAA,EAAc,eAAA;EACd,YAAA,EAAc,kBAAA;AAAA;AAAA,KAGJ,YAAA;EACV,gBAAA;EACA,YAAA;EACA,iBAAA;AAAA;AAAA,KAGU,eAAA;EACV,YAAA;EACA,IAAA;AAAA;AAAA,KAGU,kBAAA;EACV,OAAA;EACA,UAAA;EACA,cAAA;AAAA;AAAA,KAGU,SAAA;EACV,IAAA;EACA,OAAA;EACA,WAAA;AAAA;AAAA,aAGU,YAAA;EACV,UAAA;EACA,QAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KAAY,iBAAA;EACV,SAAA;EACA,IAAA,EAAM,YAAA;EACN,SAAA;EACA,mBAAA;AAAA;AAAA,KAGU,sBAAA;EACV,KAAA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