internxt-crypto 0.0.13 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +44 -72
  2. package/dist/aes-B8TA-JKq.mjs +49 -0
  3. package/dist/aes-B8TA-JKq.mjs.map +1 -0
  4. package/dist/aes-CuW_SPl-.js +67 -0
  5. package/dist/aes-CuW_SPl-.js.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +8 -31
  7. package/dist/asymmetric-crypto.d.mts.map +1 -1
  8. package/dist/asymmetric-crypto.d.ts +8 -31
  9. package/dist/asymmetric-crypto.d.ts.map +1 -1
  10. package/dist/asymmetric-crypto.js +30 -7
  11. package/dist/asymmetric-crypto.js.map +1 -0
  12. package/dist/asymmetric-crypto.mjs +28 -2
  13. package/dist/asymmetric-crypto.mjs.map +1 -0
  14. package/dist/constants.d.mts +7 -14
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.d.ts +7 -14
  17. package/dist/constants.d.ts.map +1 -1
  18. package/dist/constants.js +11 -25
  19. package/dist/constants.js.map +1 -1
  20. package/dist/constants.mjs +7 -14
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/core-Bj26rNdA.js +227 -0
  23. package/dist/core-Bj26rNdA.js.map +1 -0
  24. package/dist/core-pEGygy6S.mjs +173 -0
  25. package/dist/core-pEGygy6S.mjs.map +1 -0
  26. package/dist/derive-key.d.mts +1 -74
  27. package/dist/derive-key.d.mts.map +1 -1
  28. package/dist/derive-key.d.ts +1 -74
  29. package/dist/derive-key.d.ts.map +1 -1
  30. package/dist/derive-key.js +3 -11
  31. package/dist/derive-key.mjs +2 -2
  32. package/dist/derive-password.d.mts +22 -0
  33. package/dist/derive-password.d.mts.map +1 -0
  34. package/dist/derive-password.d.ts +22 -0
  35. package/dist/derive-password.d.ts.map +1 -0
  36. package/dist/derive-password.js +5 -0
  37. package/dist/derive-password.mjs +3 -0
  38. package/dist/deriveKeysFromKey-C4McqO6_.js +47 -0
  39. package/dist/deriveKeysFromKey-C4McqO6_.js.map +1 -0
  40. package/dist/deriveKeysFromKey-DPU_h7wr.mjs +35 -0
  41. package/dist/deriveKeysFromKey-DPU_h7wr.mjs.map +1 -0
  42. package/dist/{deriveKeysFromPassword-Ko7NxkHM.js → deriveKeysFromPassword-C7xAGGsh.js} +5 -177
  43. package/dist/deriveKeysFromPassword-C7xAGGsh.js.map +1 -0
  44. package/dist/{deriveKeysFromPassword-DJRWZ8Rw.mjs → deriveKeysFromPassword-DXgSvTNC.mjs} +7 -131
  45. package/dist/deriveKeysFromPassword-DXgSvTNC.mjs.map +1 -0
  46. package/dist/email-crypto.d.mts +24 -46
  47. package/dist/email-crypto.d.mts.map +1 -1
  48. package/dist/email-crypto.d.ts +24 -46
  49. package/dist/email-crypto.d.ts.map +1 -1
  50. package/dist/email-crypto.js +121 -12
  51. package/dist/email-crypto.js.map +1 -0
  52. package/dist/email-crypto.mjs +115 -2
  53. package/dist/email-crypto.mjs.map +1 -0
  54. package/dist/email-search.d.mts +18 -18
  55. package/dist/email-search.d.mts.map +1 -1
  56. package/dist/email-search.d.ts +18 -18
  57. package/dist/email-search.d.ts.map +1 -1
  58. package/dist/email-search.js +25 -597
  59. package/dist/email-search.mjs +2 -573
  60. package/dist/{emailEncryptionKey-27mIHh18.mjs → emailEncryptionKey-BtSPYd9M.mjs} +23 -46
  61. package/dist/emailEncryptionKey-BtSPYd9M.mjs.map +1 -0
  62. package/dist/{emailEncryptionKey-DbaDAdoW.js → emailEncryptionKey-C4X1Bwy4.js} +22 -45
  63. package/dist/emailEncryptionKey-C4X1Bwy4.js.map +1 -0
  64. package/dist/{genID-3Er5IowC.mjs → genID-D08K7JPr.mjs} +4 -40
  65. package/dist/genID-D08K7JPr.mjs.map +1 -0
  66. package/dist/{genID-YJSl3YhL.js → genID-cWOPmspk.js} +2 -50
  67. package/dist/genID-cWOPmspk.js.map +1 -0
  68. package/dist/hash.d.mts +24 -36
  69. package/dist/hash.d.mts.map +1 -1
  70. package/dist/hash.d.ts +24 -36
  71. package/dist/hash.d.ts.map +1 -1
  72. package/dist/hash.js +88 -10
  73. package/dist/hash.js.map +1 -0
  74. package/dist/hash.mjs +82 -2
  75. package/dist/hash.mjs.map +1 -0
  76. package/dist/index.d.mts +17 -16
  77. package/dist/index.d.mts.map +1 -1
  78. package/dist/index.d.ts +17 -16
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +60 -83
  81. package/dist/index.mjs +13 -11
  82. package/dist/keystore-crypto.d.mts +6 -6
  83. package/dist/keystore-crypto.d.mts.map +1 -1
  84. package/dist/keystore-crypto.d.ts +6 -6
  85. package/dist/keystore-crypto.d.ts.map +1 -1
  86. package/dist/keystore-crypto.js +1 -1
  87. package/dist/keystore-crypto.mjs +1 -1
  88. package/dist/post-quantum-crypto.d.mts +5 -41
  89. package/dist/post-quantum-crypto.d.mts.map +1 -1
  90. package/dist/post-quantum-crypto.d.ts +5 -41
  91. package/dist/post-quantum-crypto.d.ts.map +1 -1
  92. package/dist/post-quantum-crypto.js +49 -16
  93. package/dist/post-quantum-crypto.js.map +1 -0
  94. package/dist/post-quantum-crypto.mjs +46 -2
  95. package/dist/post-quantum-crypto.mjs.map +1 -0
  96. package/dist/search-B9YM3XAA.mjs +587 -0
  97. package/dist/search-B9YM3XAA.mjs.map +1 -0
  98. package/dist/search-DUTm4-rN.js +731 -0
  99. package/dist/search-DUTm4-rN.js.map +1 -0
  100. package/dist/symmetric-crypto.d.mts +13 -42
  101. package/dist/symmetric-crypto.d.mts.map +1 -1
  102. package/dist/symmetric-crypto.d.ts +13 -42
  103. package/dist/symmetric-crypto.d.ts.map +1 -1
  104. package/dist/symmetric-crypto.js +2 -6
  105. package/dist/symmetric-crypto.mjs +2 -2
  106. package/dist/types.d.mts +16 -39
  107. package/dist/types.d.mts.map +1 -1
  108. package/dist/types.d.ts +16 -39
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/types.js.map +1 -1
  111. package/dist/types.mjs.map +1 -1
  112. package/dist/utils.d.mts +1 -19
  113. package/dist/utils.d.mts.map +1 -1
  114. package/dist/utils.d.ts +1 -19
  115. package/dist/utils.d.ts.map +1 -1
  116. package/dist/utils.js +1 -3
  117. package/dist/utils.mjs +2 -2
  118. package/dist/xwing-CQmQX6hn.mjs +16 -0
  119. package/dist/xwing-CQmQX6hn.mjs.map +1 -0
  120. package/dist/xwing-iRWVRtNE.js +34 -0
  121. package/dist/xwing-iRWVRtNE.js.map +1 -0
  122. package/package.json +4 -2
  123. package/dist/aes-DSDxP8uF.mjs +0 -184
  124. package/dist/aes-DSDxP8uF.mjs.map +0 -1
  125. package/dist/aes-bOrKZuUC.js +0 -226
  126. package/dist/aes-bOrKZuUC.js.map +0 -1
  127. package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs.map +0 -1
  128. package/dist/deriveKeysFromPassword-Ko7NxkHM.js.map +0 -1
  129. package/dist/email-search.js.map +0 -1
  130. package/dist/email-search.mjs.map +0 -1
  131. package/dist/emailEncryptionKey-27mIHh18.mjs.map +0 -1
  132. package/dist/emailEncryptionKey-DbaDAdoW.js.map +0 -1
  133. package/dist/emailKeys-BJGdkLrg.js +0 -593
  134. package/dist/emailKeys-BJGdkLrg.js.map +0 -1
  135. package/dist/emailKeys-Fp9WR3wl.mjs +0 -509
  136. package/dist/emailKeys-Fp9WR3wl.mjs.map +0 -1
  137. package/dist/genID-3Er5IowC.mjs.map +0 -1
  138. package/dist/genID-YJSl3YhL.js.map +0 -1
  139. package/dist/keys-BfcaiAOv.mjs +0 -90
  140. package/dist/keys-BfcaiAOv.mjs.map +0 -1
  141. package/dist/keys-CinT7kEY.js +0 -125
  142. package/dist/keys-CinT7kEY.js.map +0 -1
  143. package/dist/kyber1024-PpwE1rki.mjs +0 -144
  144. package/dist/kyber1024-PpwE1rki.mjs.map +0 -1
  145. package/dist/kyber1024-jeKS8CXf.js +0 -173
  146. package/dist/kyber1024-jeKS8CXf.js.map +0 -1
  147. package/dist/kyber768-DGBB_RS7.d.ts +0 -32
  148. package/dist/kyber768-DGBB_RS7.d.ts.map +0 -1
  149. package/dist/kyber768-DzIcGg1i.d.mts +0 -32
  150. package/dist/kyber768-DzIcGg1i.d.mts.map +0 -1
  151. package/dist/mac-BMb1F0dN.js +0 -170
  152. package/dist/mac-BMb1F0dN.js.map +0 -1
  153. package/dist/mac-ZpRlx8Fs.mjs +0 -116
  154. package/dist/mac-ZpRlx8Fs.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-DUTm4-rN.js","names":["DB_VERSION","DB_LABEL","deriveSymmetricKeyFromContext","CONTEXT_INDEX","encryptEmailBodyWithKey","decryptEmailBody","UTF8ToUint8","MAX_EMAIL_PER_BATCH","MAX_CACHE_SIZE","Index"],"sources":["../src/email-search/indexedDB.ts","../src/email-search/utils.ts","../src/email-search/mailCache.ts","../src/email-search/search.ts"],"sourcesContent":["import { DBSchema, openDB, deleteDB, IDBPDatabase } from 'idb';\nimport { StoredEmail, Email } from '../types';\nimport { decryptEmailBody, encryptEmailBodyWithKey } from '../email-crypto/core';\nimport { deriveSymmetricKeyFromContext } from '../derive-key';\nimport { CONTEXT_INDEX, DB_LABEL, DB_VERSION } from '../constants';\n\nexport type MailDB = IDBPDatabase<EncryptedSearchDB>;\n\nexport interface EncryptedSearchDB extends DBSchema {\n email: {\n key: string;\n value: StoredEmail;\n indexes: { byTime: number[] };\n };\n}\n\n/**\n * Returns IndexedDB database name for the given user\n *\n * @param userID - The user ID\n * @returns The database name\n */\nconst getDatabaseName = (userID: string): string => {\n return `ES:${userID}:DB`;\n};\n\n/**\n * Opens IndexedDB database for the given user\n *\n * @param userID - The user ID\n * @returns The database\n */\nexport const openDatabase = async (userID: string): Promise<MailDB> => {\n try {\n const dbName = getDatabaseName(userID);\n return openDB<EncryptedSearchDB>(dbName, DB_VERSION, {\n upgrade(db) {\n if (!db.objectStoreNames.contains(DB_LABEL)) {\n const store = db.createObjectStore(DB_LABEL, { keyPath: 'id' });\n store.createIndex('byTime', 'params.createdAt');\n }\n },\n });\n } catch (error) {\n throw new Error(`Cannot open a database for the user ${userID}`, { cause: error });\n }\n};\n\n/**\n * Closes the IndexedDB database\n *\n * @param esDB - The database\n */\nexport const closeDatabase = (esDB: MailDB): void => {\n return esDB.close();\n};\n\n/**\n * Deletes IndexedDB database for the given user\n *\n * @param userID - The user ID\n * @returns The database\n */\nexport const deleteDatabase = async (userID: string): Promise<void> => {\n const dbName = getDatabaseName(userID);\n return deleteDB(dbName);\n};\n\n/**\n * Derives database encryption key for the given user\n *\n * @param userID - The user ID\n * @returns The symmetric key for protecting database\n */\nexport const deriveIndexKey = async (baseKey: Uint8Array): Promise<Uint8Array> => {\n return deriveSymmetricKeyFromContext(CONTEXT_INDEX, baseKey);\n};\n\n/**\n * Encrypts the given email and stores it in the IndexedDB database\n *\n * @param newEmailToStore - The email for storing\n * @param indexKey - The symmetric key for protecting database\n * @param esDB - The database\n */\nexport const encryptAndStoreEmail = async (\n newEmailToStore: Email,\n indexKey: Uint8Array,\n esDB: MailDB,\n): Promise<void> => {\n try {\n const enc = await encryptEmailBodyWithKey(newEmailToStore.body, indexKey);\n const encryptedEmail: StoredEmail = { encEmailBody: enc, params: newEmailToStore.params, id: newEmailToStore.id };\n await esDB.put(DB_LABEL, encryptedEmail);\n } catch (error) {\n throw new Error('Cannot encrypt and add the given email to the database', { cause: error });\n }\n};\n\n/**\n * Encrypts the given set of emails and stores it in the IndexedDB database\n *\n * @param newEmailsToStore - The set of emails for storing\n * @param indexKey - The symmetric key key for protecting database\n * @param esDB - The database\n */\nexport const encryptAndStoreManyEmail = async (\n newEmailsToStore: Email[],\n indexKey: Uint8Array,\n esDB: MailDB,\n): Promise<void> => {\n try {\n const encryptedEmails = await Promise.all(\n newEmailsToStore.map(async (email: Email) => {\n const encEmailBody = await encryptEmailBodyWithKey(email.body, indexKey);\n\n return { encEmailBody, params: email.params, id: email.id };\n }),\n );\n\n const tr = esDB.transaction(DB_LABEL, 'readwrite');\n await Promise.all([...encryptedEmails.map((encEmail) => tr.store.put(encEmail)), tr.done]);\n } catch (error) {\n throw new Error('Cannot encrypt and add emails to the database', { cause: error });\n }\n};\n\n/**\n * Decrypts the given email\n *\n * @param indexKey - The symmetric key key for protecting database\n * @param encryptedEmail - The encrypted email\n * @returns The decrypted email\n */\nconst decryptEmail = async (indexKey: Uint8Array, encryptedEmail: StoredEmail): Promise<Email> => {\n try {\n const email = await decryptEmailBody(encryptedEmail.encEmailBody, indexKey);\n return { body: email, params: encryptedEmail.params, id: encryptedEmail.id };\n } catch (error) {\n throw new Error('Cannot decrypt the given email', { cause: error });\n }\n};\n\n/**\n * Fetches the email from the database and decrypts it\n *\n * @param emailID - The email identifier\n * @param indexKey - The symmetric key key for protecting database\n * @param encryptedEmail - The encrypted email\n * @returns The decrypted email\n */\nexport const getAndDecryptEmail = async (emailID: string, indexKey: Uint8Array, esDB: MailDB): Promise<Email> => {\n try {\n const encryptedEmail = await esDB.get(DB_LABEL, emailID);\n if (!encryptedEmail) {\n throw new Error(`DB cannot find email with id ${emailID}`);\n }\n return decryptEmail(indexKey, encryptedEmail);\n } catch (error) {\n throw new Error(`Cannot fetch the email ${emailID} from the database`, { cause: error });\n }\n};\n\n/**\n * Fetches all email from the database and decrypts them\n *\n * @param indexKey - The symmetric key key for protecting database\n * @param esDB - The database\n * @returns The decrypted emails\n */\nexport const getAndDecryptAllEmails = async (indexKey: Uint8Array, esDB: MailDB): Promise<Email[]> => {\n try {\n const encryptedEmails = await esDB.getAll(DB_LABEL);\n\n const decryptedEmails = await Promise.all(\n encryptedEmails.map(async (encEmail) => {\n const body = await decryptEmailBody(encEmail.encEmailBody, indexKey);\n return { body, params: encEmail.params, id: encEmail.id };\n }),\n );\n\n return decryptedEmails.filter((email): email is Email => email !== null);\n } catch (error) {\n throw new Error('Cannot fetch and decrypt all emails from the database', { cause: error });\n }\n};\n\n/**\n * Deletes the email from the database\n *\n * @param emailID - The email identifier\n * @param esDB - The database\n */\nexport const deleteEmail = async (emailID: string, esDB: MailDB): Promise<void> => {\n await esDB.delete(DB_LABEL, emailID);\n};\n\n/**\n * Returns the number of stored email\n *\n * @param esDB - The database\n * @returns The number of stored emails\n */\nexport const getEmailCount = async (esDB: MailDB): Promise<number> => {\n return await esDB.count(DB_LABEL);\n};\n\n/**\n * Removes the given number of oldests emails from the database\n *\n * @param emailsToDelete - The number of emails to delete\n * @param esDB - The database\n */\nexport const deleteOldestEmails = async (emailsToDelete: number, esDB: MailDB): Promise<void> => {\n try {\n const tx = esDB.transaction(DB_LABEL, 'readwrite');\n const index = tx.store.index('byTime');\n\n let cursor = await index.openCursor();\n let deletedCount = 0;\n\n while (cursor && deletedCount < emailsToDelete) {\n await cursor.delete();\n deletedCount++;\n cursor = await cursor.continue();\n }\n\n await tx.done;\n } catch (error) {\n throw new Error(`Cannot delete ${emailsToDelete} oldests emails from the database`, { cause: error });\n }\n};\n\n/**\n * Enforces the maximum email number in the database\n *\n * @param esDB - The database\n * @param max - The maximum allowed number of emails\n */\nexport const enforceMaxEmailNumber = async (esDB: MailDB, max: number): Promise<void> => {\n try {\n const currentCount = await getEmailCount(esDB);\n if (currentCount <= max) {\n return;\n }\n await deleteOldestEmails(currentCount - max, esDB);\n } catch (error) {\n throw new Error(`Cannot enforce the maximum of ${max} emails on the database`, { cause: error });\n }\n};\n\n/**\n * Fetches all emails from the database, decrypts them and sortes the results in the specified order\n *\n * @param esDB - The database\n * @param indexKey - The symmetric key key for protecting database\n * @param direction - The order of sorting. If 'next' - oldest first, if 'prev' - newest first\n * @returns Decryped emails in the specified order\n */\nconst fetchEmails = async (esDB: MailDB, indexKey: Uint8Array, direction: 'next' | 'prev'): Promise<Email[]> => {\n try {\n const tx = esDB.transaction(DB_LABEL, 'readonly');\n const index = tx.store.index('byTime');\n\n const encryptedEmails: StoredEmail[] = [];\n let cursor = await index.openCursor(null, direction);\n\n while (cursor) {\n encryptedEmails.push(cursor.value);\n cursor = await cursor.continue();\n }\n\n const emails = await Promise.all(encryptedEmails.map((encryptedEmail) => decryptEmail(indexKey, encryptedEmail)));\n\n return emails;\n } catch (error) {\n throw new Error('Cannot fetch emails from database', { cause: error });\n }\n};\n\n/**\n * Fetches all emails from the database, decrypts them and sortes the results based on the creation time (newest first)\n *\n * @param esDB - The database\n * @param indexKey - The symmetric Uint8Array key for protecting database\n * @returns The number of stored emails\n */\nexport const getAllEmailsSortedNewestFirst = async (esDB: MailDB, indexKey: Uint8Array): Promise<Email[]> => {\n return fetchEmails(esDB, indexKey, 'prev');\n};\n\n/**\n * Fetches all emails from the database, decrypts them and sortes the results based on the creation time (oldest first)\n *\n * @param esDB - The database\n * @param indexKey - The symmetric key for protecting database\n * @returns The number of stored emails\n */\nexport const getAllEmailsSortedOldestFirst = async (esDB: MailDB, indexKey: Uint8Array): Promise<Email[]> => {\n return fetchEmails(esDB, indexKey, 'next');\n};\n\n/**\n * Fetches a batch of emails from the database, decrypts them and sortes the results based on the creation time (newest first)\n *\n * @param esDB - The database\n * @param indexKey - The symmetric key for protecting database\n * @param batchSize - The size of the batch\n * @param startCursor - The starting point (optional). If not given, starts from the beginning\n * @returns The number of stored emails\n */\nexport const getEmailBatch = async (\n esDB: MailDB,\n indexKey: Uint8Array,\n batchSize: number,\n startCursor?: IDBValidKey,\n): Promise<{ emails: Email[]; nextCursor?: IDBValidKey }> => {\n try {\n const tx = esDB.transaction(DB_LABEL, 'readonly');\n const index = tx.store.index('byTime');\n\n const encryptedEmails: StoredEmail[] = [];\n let cursor;\n\n if (startCursor) {\n const range = IDBKeyRange.upperBound(startCursor, true);\n cursor = await index.openCursor(range, 'prev');\n } else {\n cursor = await index.openCursor(null, 'prev');\n }\n\n let count = 0;\n let nextCursor: IDBValidKey | undefined;\n\n while (cursor && count < batchSize) {\n encryptedEmails.push(cursor.value);\n nextCursor = cursor.key;\n count++;\n cursor = await cursor.continue();\n }\n\n const emails = await Promise.all(encryptedEmails.map((encryptedEmail) => decryptEmail(indexKey, encryptedEmail)));\n\n return {\n emails,\n nextCursor: count === batchSize ? nextCursor : undefined,\n };\n } catch (error) {\n throw new Error(`Cannot fetch email batch of ${batchSize} from the database`, { cause: error });\n }\n};\n","import { UTF8ToUint8 } from '../utils';\nimport { Email } from '../types';\n\n/**\n * Converts an Email type into a Uint8Array array.\n *\n * @param email - The email.\n * @returns The Uint8Array array representation of the Email type.\n */\nexport function emailToBinary(email: Email): Uint8Array {\n try {\n const json = JSON.stringify(email);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert EmailBody to Uint8Array', { cause: error });\n }\n}\n","import { MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH } from '../constants';\nimport { getEmailBatch, getAllEmailsSortedNewestFirst, getEmailCount, MailDB } from './indexedDB';\nimport { Email, MailCache } from '../types';\nimport { emailToBinary } from './utils';\n\n/**\n * Estimates the email size in the memory\n *\n * @param email - The email\n * @returns The estimation of the email size\n */\nfunction sizeOfEmail(email: Email): number {\n return emailToBinary(email).byteLength;\n}\n\n/**\n * Creates an empty cache variable\n *\n * @returns The empty cache\n */\nfunction createEmptyCache(): MailCache<Email> {\n return {\n esCache: new Map(),\n cacheSize: 0,\n isCacheLimited: false,\n isCacheReady: true,\n };\n}\n\n/**\n * Fetches all emails from the database in batches and cahces them\n *\n * @param indexKey - The symmetric key for protecting database\n * @param esCache - The cache to add emails too\n * @param esDB - The database\n */\nexport const createCacheFromDB = async (indexKey: Uint8Array, esDB: MailDB): Promise<MailCache<Email>> => {\n const esCache = createEmptyCache();\n esCache.isCacheReady = false;\n try {\n const count = await getEmailCount(esDB);\n if (!count) {\n esCache.isCacheReady = true;\n return esCache;\n }\n\n if (count <= MAX_EMAIL_PER_BATCH) {\n const emails = await getAllEmailsSortedNewestFirst(esDB, indexKey);\n addEmailsToCache(emails, esCache);\n } else {\n let nextCursor: IDBValidKey | undefined = undefined;\n\n let cacheFull = false;\n while (!cacheFull) {\n const { emails, nextCursor: newCursor }: { emails: Email[]; nextCursor?: IDBValidKey } = await getEmailBatch(\n esDB,\n indexKey,\n MAX_EMAIL_PER_BATCH,\n nextCursor,\n );\n if (!newCursor || !emails.length) break;\n nextCursor = newCursor;\n\n const success = addEmailsToCache(emails, esCache);\n if (!success) cacheFull = true;\n }\n }\n return esCache;\n } catch (error) {\n throw new Error(`Email caching failed: ${error}`, { cause: error });\n }\n};\n\n/**\n * Gets an email from the cache\n *\n * @param emailID - The email identifier\n * @param esCache - The email cache\n * @returns The found email or throws an error\n */\nexport const getEmailFromCache = async (emailID: string, esCache: MailCache<Email>): Promise<Email> => {\n const email = esCache.esCache.get(emailID);\n if (!email) {\n throw new Error(`Email not found in cache for ID: ${emailID}`);\n }\n return email;\n};\n\n/**\n * Removes the email from cache\n *\n * @param emailID - The email identifier\n * @param esCache - The email cache\n */\nexport const deleteEmailFromCache = async (emailID: string, esCache: MailCache<Email>): Promise<void> => {\n try {\n const email = await getEmailFromCache(emailID, esCache);\n const size = sizeOfEmail(email);\n const removed = esCache.esCache.delete(emailID);\n if (removed) esCache.cacheSize -= size;\n } catch (error) {\n throw new Error(`Failed to delete email with ID ${emailID}`, { cause: error });\n }\n};\n\n/**\n * Adds emails to the cache\n *\n * @param emails - The emails to add\n * @param esCache - The email cache\n * @returns TRUE if all emails were added sucessfully, or FALSE and error reason.\n */\nexport function addEmailsToCache(emails: Email[], esCache: MailCache<Email>): { success: boolean; reason?: string } {\n try {\n for (const email of emails) {\n const result = addEmailToCache(email, esCache);\n if (!result.success) return result;\n }\n return { success: true };\n } catch (error) {\n throw new Error('Failed to add emails to the cache', { cause: error });\n }\n}\n\n/**\n * Adds email to the cache\n *\n * @param email - The email to add\n * @param esCache - The email cache\n * @returns TRUE if the email was added sucessfully, or FALSE and error reason.\n */\nexport const addEmailToCache = (email: Email, esCache: MailCache<Email>): { success: boolean; reason?: string } => {\n try {\n if (esCache.esCache.has(email.id)) {\n return { success: false, reason: 'email already exists in cache' };\n }\n\n const emailSize = sizeOfEmail(email);\n\n if (esCache.cacheSize + emailSize > MAX_CACHE_SIZE) {\n esCache.isCacheLimited = true;\n return { success: false, reason: 'hit cache limit' };\n }\n\n esCache.esCache.set(email.id, email);\n esCache.cacheSize += emailSize;\n\n return { success: true };\n } catch (error) {\n throw new Error('Failed to add email to the cache', { cause: error });\n }\n};\n","import { Index, DefaultSearchResults } from 'flexsearch';\nimport type { IndexOptions } from 'flexsearch';\nimport { Email, MailCache, EmailSearchResult } from '../types';\n\ntype ExtendedIndexOptions = IndexOptions & {\n minlength?: number;\n resolution?: number;\n optimize?: boolean;\n fastupdate?: boolean;\n cache?: boolean;\n};\n\nconst SUBJECT_OPTIONS: ExtendedIndexOptions = {\n preset: 'match',\n tokenize: 'forward',\n resolution: 9,\n minlength: 2,\n optimize: true,\n fastupdate: true,\n cache: true,\n};\nconst BODY_OPTIONS: ExtendedIndexOptions = {\n ...SUBJECT_OPTIONS,\n minlength: 3,\n resolution: 6,\n};\n\nconst FROM_OPTIONS: ExtendedIndexOptions = {\n ...SUBJECT_OPTIONS,\n tokenize: 'strict',\n minlength: 1,\n};\n\nconst TO_OPTIONS: ExtendedIndexOptions = {\n ...SUBJECT_OPTIONS,\n tokenize: 'strict',\n minlength: 1,\n};\n\nexport interface EmailSearchIndex {\n subjectIndex: Index;\n bodyIndex: Index;\n fromIndex: Index;\n toIndex: Index;\n isReady: boolean;\n}\n\n/**\n * Creates new email search index\n *\n * @returns The email search index\n */\nconst createSearchIndex = (): EmailSearchIndex => ({\n subjectIndex: new Index(SUBJECT_OPTIONS),\n bodyIndex: new Index(BODY_OPTIONS),\n fromIndex: new Index(FROM_OPTIONS),\n toIndex: new Index(TO_OPTIONS),\n isReady: false,\n});\n\n/**\n * Adds the given email to the email search index\n *\n * @param email - The email to add\n * @param searchIndex - The email search index\n */\nexport const addEmailToSearchIndex = (email: Email, searchIndex: EmailSearchIndex): void => {\n try {\n const emailId = email.id;\n searchIndex.subjectIndex.add(emailId, email.body.subject);\n searchIndex.bodyIndex.add(emailId, email.body.text);\n const senderText = `${email.params.sender.name || ''} ${email.params.sender.email || ''}`.trim();\n searchIndex.fromIndex.add(emailId, senderText);\n\n const recipientsList = email.params.recipients?.length ? email.params.recipients : [email.params.recipient];\n\n const recipientsText = recipientsList\n .map((recipient) => `${recipient.name || ''} ${recipient.email || ''}`.trim())\n .join(' ');\n searchIndex.toIndex.add(emailId, recipientsText);\n } catch (error) {\n throw new Error('Failed to add email to the search index', { cause: error });\n }\n};\n\n/**\n * Removes the email from the email search index\n *\n * @param emailID - The email identifier\n * @param searchIndex - The email search index\n */\nexport const removeEmailFromSearchIndex = (emailID: string, searchIndex: EmailSearchIndex): void => {\n try {\n searchIndex.subjectIndex.remove(emailID);\n searchIndex.bodyIndex.remove(emailID);\n searchIndex.fromIndex.remove(emailID);\n searchIndex.toIndex.remove(emailID);\n } catch (error) {\n throw new Error(`Failed to remove email with ID ${emailID} from the search index`, { cause: error });\n }\n};\n\n/**\n * Buils the email search index from the email cache\n *\n * @param esCache - The email cache\n * @returns The email search index\n */\nexport const buildSearchIndexFromCache = async (esCache: MailCache<Email>): Promise<EmailSearchIndex> => {\n try {\n const searchIndex = createSearchIndex();\n searchIndex.isReady = false;\n\n for (const email of esCache.esCache.values()) {\n addEmailToSearchIndex(email, searchIndex);\n }\n\n searchIndex.isReady = true;\n return searchIndex;\n } catch (error) {\n throw new Error('Failed build an email search index from the cache', { cause: error });\n }\n};\n\nexport interface SearchOptions {\n fields?: ('subject' | 'body' | 'from' | 'to')[];\n limit?: number;\n boost?: {\n subject?: number;\n body?: number;\n from?: number;\n to?: number;\n };\n}\n\n/**\n * Searches in teh\n *\n * @param query - The string to search for\n * @param esCache - The email cache\n * @param searchIndex - The email search index\n * @param opetions - The optional search limitations\n * @returns The result of the email search (emails ans their corresponding result weights)\n */\nexport const searchEmails = async (\n query: string,\n esCache: MailCache<Email>,\n searchIndex: EmailSearchIndex,\n options: SearchOptions = {},\n): Promise<EmailSearchResult[]> => {\n try {\n if (!searchIndex.isReady || !query.trim()) {\n return [];\n }\n\n const {\n fields = ['subject', 'body', 'from', 'to'],\n limit = 50,\n boost = { subject: 3, body: 1, from: 2, to: 2 },\n } = options;\n\n const results = new Map<string, number>();\n\n const searchPromises = fields.map(async (field) => {\n let fieldResults: DefaultSearchResults;\n\n switch (field) {\n case 'subject':\n fieldResults = await searchIndex.subjectIndex.searchAsync(query);\n break;\n case 'body':\n fieldResults = await searchIndex.bodyIndex.searchAsync(query);\n break;\n case 'from':\n fieldResults = await searchIndex.fromIndex.searchAsync(query);\n break;\n case 'to':\n fieldResults = await searchIndex.toIndex.searchAsync(query);\n break;\n default:\n return;\n }\n\n const fieldBoost = boost[field] || 1;\n\n fieldResults.forEach((emailId) => {\n const currentScore = results.get(String(emailId)) || 0;\n results.set(String(emailId), currentScore + fieldBoost);\n });\n });\n\n await Promise.all(searchPromises);\n\n const emailResults: EmailSearchResult[] = [];\n\n for (const [emailId, score] of results) {\n const email = esCache.esCache.get(emailId);\n if (email) {\n emailResults.push({ email, score });\n }\n }\n emailResults.sort((a, b) => (b.score || 0) - (a.score || 0));\n return emailResults.slice(0, limit);\n } catch (error) {\n throw new Error('Email search failed', { cause: error });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,MAAM,mBAAmB,WAA2B;AAClD,QAAO,MAAM,OAAO;;;;;;;;AAStB,MAAa,eAAe,OAAO,WAAoC;AACrE,KAAI;AAEF,yBADe,gBAAgB,OAAO,EACGA,8BAAY,EACnD,QAAQ,IAAI;AACV,OAAI,CAAC,GAAG,iBAAiB,SAASC,2BAAS,CAEzC,CADc,GAAG,kBAAkBA,4BAAU,EAAE,SAAS,MAAM,CAAC,CACzD,YAAY,UAAU,mBAAmB;KAGpD,CAAC;UACK,OAAO;AACd,QAAM,IAAI,MAAM,uCAAuC,UAAU,EAAE,OAAO,OAAO,CAAC;;;;;;;;AAStF,MAAa,iBAAiB,SAAuB;AACnD,QAAO,KAAK,OAAO;;;;;;;;AASrB,MAAa,iBAAiB,OAAO,WAAkC;AAErE,0BADe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IAAO,CAAC;;AAGvC,eAAa,MAAM,GAAG,OAAO,EAAE,SAAS,MAAM,EAAE,SAAS,GAAG;AAC5D,SAAO,aAAa,MAAM,GAAG,MAAM;UAC5B,OAAO;AACd,QAAM,IAAI,MAAM,uBAAuB,EAAE,OAAO,OAAO,CAAC"}
@@ -1,57 +1,28 @@
1
- //#region src/symmetric-crypto/keys.d.ts
2
- /**
3
- * Converts Uint8Array into CryptoKey
4
- *
5
- * @param keyData - The Uint8Array representation of the symmetric key
6
- * @returns The resulting symmetric CryptoKey.
7
- */
8
- declare function importSymmetricCryptoKey(keyData: Uint8Array | ArrayBuffer): Promise<CryptoKey>;
9
- /**
10
- * Converts CryptoKey into Uint8Array
11
- *
12
- * @param key - The symmetric CryptoKey
13
- * @returns The resulting Uint8Array.
14
- */
15
- declare function exportSymmetricCryptoKey(key: CryptoKey): Promise<Uint8Array>;
16
- /**
17
- * Generates symmetric CryptoKey
18
- *
19
- * @returns The generated CryptoKey.
20
- */
21
- declare function genSymmetricCryptoKey(): Promise<CryptoKey>;
22
- /**
23
- * Generates symmetric key as Uint8Array
24
- *
25
- * @returns The generated Uint8Array.
26
- */
27
- declare function genSymmetricKey(): Uint8Array;
28
- /**
29
- * Derives CryptoKey from the given key material
30
- *
31
- * @returns The derived CryptoKey.
32
- */
33
- declare function deriveSymmetricCryptoKey(keyMaterial: Uint8Array): Promise<CryptoKey>;
34
- //#endregion
35
1
  //#region src/symmetric-crypto/aes.d.ts
36
2
  /**
37
3
  * Symmetrically encrypts the message
38
4
  *
39
- * @param encryptionKey - The symmetric CryptoKey used for message encryption
5
+ * @param encryptionKey - The symmetric key used for message encryption
40
6
  * @param message - The message to encrypt
41
- * @param freeField - The context of the message (required for IV generation)
42
- * @param aux - The auxilary string
7
+ * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
43
8
  * @returns The resulting ciphertext.
44
9
  */
45
- declare function encryptSymmetrically(encryptionKey: CryptoKey, message: Uint8Array, aux: Uint8Array, freeField?: Uint8Array): Promise<Uint8Array>;
10
+ declare function encryptSymmetrically(encryptionKey: Uint8Array, message: Uint8Array, aux?: Uint8Array): Promise<Uint8Array>;
46
11
  /**
47
12
  * Decryps symmetrically encrypted message
48
13
  *
49
- * @param encryptionKey - The symmetric CryptoKey used for message encryption
14
+ * @param encryptionKey - The symmetric key used for message encryption
50
15
  * @param encryptedMessage - The ciphertext
51
- * @param aux - The auxilary string
16
+ * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
52
17
  * @returns The resulting ciphertext.
53
18
  */
54
- declare function decryptSymmetrically(encryptionKey: CryptoKey, encryptedMessage: Uint8Array, aux: Uint8Array): Promise<Uint8Array>;
19
+ declare function decryptSymmetrically(encryptionKey: Uint8Array, encryptedMessage: Uint8Array, aux?: Uint8Array): Promise<Uint8Array>;
20
+ /**
21
+ * Generates symmetric key as Uint8Array
22
+ *
23
+ * @returns The generated Uint8Array.
24
+ */
25
+ declare function genSymmetricKey(): Uint8Array;
55
26
  //#endregion
56
- export { decryptSymmetrically, deriveSymmetricCryptoKey, encryptSymmetrically, exportSymmetricCryptoKey, genSymmetricCryptoKey, genSymmetricKey, importSymmetricCryptoKey };
27
+ export { decryptSymmetrically, encryptSymmetrically, genSymmetricKey };
57
28
  //# sourceMappingURL=symmetric-crypto.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"symmetric-crypto.d.mts","names":[],"sources":["../src/symmetric-crypto/keys.ts","../src/symmetric-crypto/aes.ts"],"mappings":";;AASA;;;;;iBAAsB,wBAAA,CAAyB,OAAA,EAAS,UAAA,GAAa,WAAA,GAAc,OAAA,CAAQ,SAAA;;;;;;;iBAmBrE,wBAAA,CAAyB,GAAA,EAAK,SAAA,GAAY,OAAA,CAAQ,UAAA;;;;AAAxE;;iBAcsB,qBAAA,CAAA,GAAyB,OAAA,CAAQ,SAAA;;;;;;iBAgBvC,eAAA,CAAA,GAAmB,UAAA;;;;;;iBAeb,wBAAA,CAAyB,WAAA,EAAa,UAAA,GAAa,OAAA,CAAQ,SAAA;;;;AAhEjF;;;;;;;;iBCIsB,oBAAA,CACpB,aAAA,EAAe,SAAA,EACf,OAAA,EAAS,UAAA,EACT,GAAA,EAAK,UAAA,EACL,SAAA,GAAY,UAAA,GACX,OAAA,CAAQ,UAAA;;;;;;;;ADUX;iBCSsB,oBAAA,CACpB,aAAA,EAAe,SAAA,EACf,gBAAA,EAAkB,UAAA,EAClB,GAAA,EAAK,UAAA,GACJ,OAAA,CAAQ,UAAA"}
1
+ {"version":3,"file":"symmetric-crypto.d.mts","names":[],"sources":["../src/symmetric-crypto/aes.ts"],"mappings":";;AAYA;;;;;;;iBAAsB,oBAAA,CACpB,aAAA,EAAe,UAAA,EACf,OAAA,EAAS,UAAA,EACT,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,UAAA;;;;;;;;;iBAkBW,oBAAA,CACpB,aAAA,EAAe,UAAA,EACf,gBAAA,EAAkB,UAAA,EAClB,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,UAAA;;;;AAJX;;iBAoBgB,eAAA,CAAA,GAAmB,UAAA"}
@@ -1,57 +1,28 @@
1
- //#region src/symmetric-crypto/keys.d.ts
2
- /**
3
- * Converts Uint8Array into CryptoKey
4
- *
5
- * @param keyData - The Uint8Array representation of the symmetric key
6
- * @returns The resulting symmetric CryptoKey.
7
- */
8
- declare function importSymmetricCryptoKey(keyData: Uint8Array | ArrayBuffer): Promise<CryptoKey>;
9
- /**
10
- * Converts CryptoKey into Uint8Array
11
- *
12
- * @param key - The symmetric CryptoKey
13
- * @returns The resulting Uint8Array.
14
- */
15
- declare function exportSymmetricCryptoKey(key: CryptoKey): Promise<Uint8Array>;
16
- /**
17
- * Generates symmetric CryptoKey
18
- *
19
- * @returns The generated CryptoKey.
20
- */
21
- declare function genSymmetricCryptoKey(): Promise<CryptoKey>;
22
- /**
23
- * Generates symmetric key as Uint8Array
24
- *
25
- * @returns The generated Uint8Array.
26
- */
27
- declare function genSymmetricKey(): Uint8Array;
28
- /**
29
- * Derives CryptoKey from the given key material
30
- *
31
- * @returns The derived CryptoKey.
32
- */
33
- declare function deriveSymmetricCryptoKey(keyMaterial: Uint8Array): Promise<CryptoKey>;
34
- //#endregion
35
1
  //#region src/symmetric-crypto/aes.d.ts
36
2
  /**
37
3
  * Symmetrically encrypts the message
38
4
  *
39
- * @param encryptionKey - The symmetric CryptoKey used for message encryption
5
+ * @param encryptionKey - The symmetric key used for message encryption
40
6
  * @param message - The message to encrypt
41
- * @param freeField - The context of the message (required for IV generation)
42
- * @param aux - The auxilary string
7
+ * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
43
8
  * @returns The resulting ciphertext.
44
9
  */
45
- declare function encryptSymmetrically(encryptionKey: CryptoKey, message: Uint8Array, aux: Uint8Array, freeField?: Uint8Array): Promise<Uint8Array>;
10
+ declare function encryptSymmetrically(encryptionKey: Uint8Array, message: Uint8Array, aux?: Uint8Array): Promise<Uint8Array>;
46
11
  /**
47
12
  * Decryps symmetrically encrypted message
48
13
  *
49
- * @param encryptionKey - The symmetric CryptoKey used for message encryption
14
+ * @param encryptionKey - The symmetric key used for message encryption
50
15
  * @param encryptedMessage - The ciphertext
51
- * @param aux - The auxilary string
16
+ * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
52
17
  * @returns The resulting ciphertext.
53
18
  */
54
- declare function decryptSymmetrically(encryptionKey: CryptoKey, encryptedMessage: Uint8Array, aux: Uint8Array): Promise<Uint8Array>;
19
+ declare function decryptSymmetrically(encryptionKey: Uint8Array, encryptedMessage: Uint8Array, aux?: Uint8Array): Promise<Uint8Array>;
20
+ /**
21
+ * Generates symmetric key as Uint8Array
22
+ *
23
+ * @returns The generated Uint8Array.
24
+ */
25
+ declare function genSymmetricKey(): Uint8Array;
55
26
  //#endregion
56
- export { decryptSymmetrically, deriveSymmetricCryptoKey, encryptSymmetrically, exportSymmetricCryptoKey, genSymmetricCryptoKey, genSymmetricKey, importSymmetricCryptoKey };
27
+ export { decryptSymmetrically, encryptSymmetrically, genSymmetricKey };
57
28
  //# sourceMappingURL=symmetric-crypto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"symmetric-crypto.d.ts","names":[],"sources":["../src/symmetric-crypto/keys.ts","../src/symmetric-crypto/aes.ts"],"mappings":";;AASA;;;;;iBAAsB,wBAAA,CAAyB,OAAA,EAAS,UAAA,GAAa,WAAA,GAAc,OAAA,CAAQ,SAAA;;;;;;;iBAmBrE,wBAAA,CAAyB,GAAA,EAAK,SAAA,GAAY,OAAA,CAAQ,UAAA;;;;AAAxE;;iBAcsB,qBAAA,CAAA,GAAyB,OAAA,CAAQ,SAAA;;;;;;iBAgBvC,eAAA,CAAA,GAAmB,UAAA;;;;;;iBAeb,wBAAA,CAAyB,WAAA,EAAa,UAAA,GAAa,OAAA,CAAQ,SAAA;;;;AAhEjF;;;;;;;;iBCIsB,oBAAA,CACpB,aAAA,EAAe,SAAA,EACf,OAAA,EAAS,UAAA,EACT,GAAA,EAAK,UAAA,EACL,SAAA,GAAY,UAAA,GACX,OAAA,CAAQ,UAAA;;;;;;;;ADUX;iBCSsB,oBAAA,CACpB,aAAA,EAAe,SAAA,EACf,gBAAA,EAAkB,UAAA,EAClB,GAAA,EAAK,UAAA,GACJ,OAAA,CAAQ,UAAA"}
1
+ {"version":3,"file":"symmetric-crypto.d.ts","names":[],"sources":["../src/symmetric-crypto/aes.ts"],"mappings":";;AAYA;;;;;;;iBAAsB,oBAAA,CACpB,aAAA,EAAe,UAAA,EACf,OAAA,EAAS,UAAA,EACT,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,UAAA;;;;;;;;;iBAkBW,oBAAA,CACpB,aAAA,EAAe,UAAA,EACf,gBAAA,EAAkB,UAAA,EAClB,GAAA,GAAM,UAAA,GACL,OAAA,CAAQ,UAAA;;;;AAJX;;iBAoBgB,eAAA,CAAA,GAAmB,UAAA"}
@@ -1,10 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_aes = require('./aes-bOrKZuUC.js');
2
+ const require_aes = require('./aes-CuW_SPl-.js');
3
3
 
4
4
  exports.decryptSymmetrically = require_aes.decryptSymmetrically;
5
- exports.deriveSymmetricCryptoKey = require_aes.deriveSymmetricCryptoKey;
6
5
  exports.encryptSymmetrically = require_aes.encryptSymmetrically;
7
- exports.exportSymmetricCryptoKey = require_aes.exportSymmetricCryptoKey;
8
- exports.genSymmetricCryptoKey = require_aes.genSymmetricCryptoKey;
9
- exports.genSymmetricKey = require_aes.genSymmetricKey;
10
- exports.importSymmetricCryptoKey = require_aes.importSymmetricCryptoKey;
6
+ exports.genSymmetricKey = require_aes.genSymmetricKey;
@@ -1,3 +1,3 @@
1
- import { a as genSymmetricCryptoKey, i as exportSymmetricCryptoKey, n as encryptSymmetrically, o as genSymmetricKey, r as deriveSymmetricCryptoKey, s as importSymmetricCryptoKey, t as decryptSymmetrically } from "./aes-DSDxP8uF.mjs";
1
+ import { n as encryptSymmetrically, r as genSymmetricKey, t as decryptSymmetrically } from "./aes-B8TA-JKq.mjs";
2
2
 
3
- export { decryptSymmetrically, deriveSymmetricCryptoKey, encryptSymmetrically, exportSymmetricCryptoKey, genSymmetricCryptoKey, genSymmetricKey, importSymmetricCryptoKey };
3
+ export { decryptSymmetrically, encryptSymmetrically, genSymmetricKey };
package/dist/types.d.mts CHANGED
@@ -2,62 +2,38 @@
2
2
  type EncryptedKeystore = {
3
3
  userEmail: string;
4
4
  type: KeystoreType;
5
- encryptedKeys: EmailKeysEncrypted;
5
+ publicKey: string;
6
+ privateKeyEncrypted: string;
6
7
  };
7
8
  type User = {
8
9
  email: string;
9
10
  name: string;
10
11
  };
11
- type UserWithPublicKeys = User & {
12
- publicKeys: PublicKeys;
13
- };
14
- type PublicKeys = {
15
- eccPublicKey: CryptoKey;
16
- kyberPublicKey: Uint8Array;
17
- };
18
- type PublicKeysBase64 = {
19
- eccPublicKeyBase64: string;
20
- kyberPublicKeyBase64: string;
21
- };
22
- type PrivateKeys = {
23
- eccPrivateKey: CryptoKey;
24
- kyberPrivateKey: Uint8Array;
25
- };
26
- type PrivateKeysEncrypted = {
27
- eccPrivateKeyBase64: string;
28
- kyberPrivateKeyBase64: string;
29
- };
30
- type EmailKeys = {
31
- publicKeys: PublicKeys;
32
- privateKeys: PrivateKeys;
12
+ type RecipientWithPublicKey = {
13
+ email: string;
14
+ publicHybridKey: Uint8Array;
33
15
  };
34
- type EmailKeysEncrypted = {
35
- publicKeys: PublicKeysBase64;
36
- privateKeys: PrivateKeysEncrypted;
16
+ type HybridKeyPair = {
17
+ publicKey: Uint8Array;
18
+ secretKey: Uint8Array;
37
19
  };
38
20
  type HybridEncryptedEmail = {
39
21
  encryptedKey: HybridEncKey;
40
- enc: EmailBodyEncrypted;
41
- recipientEmail: string;
42
- params: EmailPublicParameters;
43
- id: string;
44
- isSubjectEncrypted: boolean;
22
+ encEmailBody: EmailBodyEncrypted;
45
23
  };
46
24
  type PwdProtectedEmail = {
47
25
  encryptedKey: PwdProtectedKey;
48
- enc: EmailBodyEncrypted;
49
- params: EmailPublicParameters;
50
- id: string;
51
- isSubjectEncrypted: boolean;
26
+ encEmailBody: EmailBodyEncrypted;
52
27
  };
53
28
  type StoredEmail = {
54
29
  params: EmailPublicParameters;
55
- enc: EmailBodyEncrypted;
30
+ encEmailBody: EmailBodyEncrypted;
56
31
  id: string;
57
32
  };
58
33
  type HybridEncKey = {
59
- kyberCiphertext: string;
34
+ hybridCiphertext: string;
60
35
  encryptedKey: string;
36
+ encryptedForEmail: string;
61
37
  };
62
38
  type PwdProtectedKey = {
63
39
  encryptedKey: string;
@@ -65,14 +41,15 @@ type PwdProtectedKey = {
65
41
  };
66
42
  type EmailBodyEncrypted = {
67
43
  encText: string;
44
+ encSubject: string;
68
45
  encAttachments?: string[];
69
46
  };
70
47
  type EmailBody = {
71
48
  text: string;
49
+ subject: string;
72
50
  attachments?: string[];
73
51
  };
74
52
  type EmailPublicParameters = {
75
- subject: string;
76
53
  createdAt: string;
77
54
  sender: User;
78
55
  recipient: User;
@@ -100,5 +77,5 @@ declare enum KeystoreType {
100
77
  RECOVERY = "Recovery"
101
78
  }
102
79
  //#endregion
103
- export { Email, EmailBody, EmailBodyEncrypted, EmailKeys, EmailKeysEncrypted, EmailPublicParameters, EmailSearchResult, EncryptedKeystore, HybridEncKey, HybridEncryptedEmail, KeystoreType, MailCache, PrivateKeys, PrivateKeysEncrypted, PublicKeys, PublicKeysBase64, PwdProtectedEmail, PwdProtectedKey, StoredEmail, User, UserWithPublicKeys };
80
+ export { Email, EmailBody, EmailBodyEncrypted, EmailPublicParameters, EmailSearchResult, EncryptedKeystore, HybridEncKey, HybridEncryptedEmail, HybridKeyPair, KeystoreType, MailCache, PwdProtectedEmail, PwdProtectedKey, RecipientWithPublicKey, StoredEmail, User };
104
81
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";KAAY,iBAAA;EACV,SAAA;EACA,IAAA,EAAM,YAAA;EACN,aAAA,EAAe,kBAAA;AAAA;AAAA,KAGL,IAAA;EACV,KAAA;EACA,IAAA;AAAA;AAAA,KAGU,kBAAA,GAAqB,IAAA;EAC/B,UAAA,EAAY,UAAA;AAAA;AAAA,KAGF,UAAA;EACV,YAAA,EAAc,SAAA;EACd,cAAA,EAAgB,UAAA;AAAA;AAAA,KAGN,gBAAA;EACV,kBAAA;EACA,oBAAA;AAAA;AAAA,KAGU,WAAA;EACV,aAAA,EAAe,SAAA;EACf,eAAA,EAAiB,UAAA;AAAA;AAAA,KAGP,oBAAA;EACV,mBAAA;EACA,qBAAA;AAAA;AAAA,KAGU,SAAA;EACV,UAAA,EAAY,UAAA;EACZ,WAAA,EAAa,WAAA;AAAA;AAAA,KAGH,kBAAA;EACV,UAAA,EAAY,gBAAA;EACZ,WAAA,EAAa,oBAAA;AAAA;AAAA,KAGH,oBAAA;EACV,YAAA,EAAc,YAAA;EACd,GAAA,EAAK,kBAAA;EACL,cAAA;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AA;AAAA;AAAA,KAGJ,iBAAA;EACV,YAAA,EAAc,eAAA;EACd,YAAA,EAAc,kBAAA;AAAA;AAAA,KAGJ,WAAA;EACV,MAAA,EAAQ,qBAAA;EACR,YAAA,EAAc,kBAAA;EACd,EAAA;AAAA;AAAA,KAGU,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,KAGU,qBAAA;EACV,SAAA;EACA,MAAA,EAAQ,IAAA;EACR,SAAA,EAAW,IAAA;EACX,UAAA,GAAa,IAAA;EACb,cAAA;EACA,MAAA;AAAA;AAAA,KAGU,KAAA;EACV,EAAA;EACA,IAAA,EAAM,SAAA;EACN,MAAA,EAAQ,qBAAA;AAAA;AAAA,UAGO,SAAA;EACf,OAAA,EAAS,GAAA,SAAY,KAAA;EACrB,SAAA;EACA,cAAA;EACA,YAAA;AAAA;AAAA,UAEe,iBAAA;EACf,KAAA,EAAO,KAAA;EACP,KAAA;AAAA;AAAA,aAGU,YAAA;EACV,UAAA;EACA,QAAA;AAAA"}
package/dist/types.d.ts CHANGED
@@ -2,62 +2,38 @@
2
2
  type EncryptedKeystore = {
3
3
  userEmail: string;
4
4
  type: KeystoreType;
5
- encryptedKeys: EmailKeysEncrypted;
5
+ publicKey: string;
6
+ privateKeyEncrypted: string;
6
7
  };
7
8
  type User = {
8
9
  email: string;
9
10
  name: string;
10
11
  };
11
- type UserWithPublicKeys = User & {
12
- publicKeys: PublicKeys;
13
- };
14
- type PublicKeys = {
15
- eccPublicKey: CryptoKey;
16
- kyberPublicKey: Uint8Array;
17
- };
18
- type PublicKeysBase64 = {
19
- eccPublicKeyBase64: string;
20
- kyberPublicKeyBase64: string;
21
- };
22
- type PrivateKeys = {
23
- eccPrivateKey: CryptoKey;
24
- kyberPrivateKey: Uint8Array;
25
- };
26
- type PrivateKeysEncrypted = {
27
- eccPrivateKeyBase64: string;
28
- kyberPrivateKeyBase64: string;
29
- };
30
- type EmailKeys = {
31
- publicKeys: PublicKeys;
32
- privateKeys: PrivateKeys;
12
+ type RecipientWithPublicKey = {
13
+ email: string;
14
+ publicHybridKey: Uint8Array;
33
15
  };
34
- type EmailKeysEncrypted = {
35
- publicKeys: PublicKeysBase64;
36
- privateKeys: PrivateKeysEncrypted;
16
+ type HybridKeyPair = {
17
+ publicKey: Uint8Array;
18
+ secretKey: Uint8Array;
37
19
  };
38
20
  type HybridEncryptedEmail = {
39
21
  encryptedKey: HybridEncKey;
40
- enc: EmailBodyEncrypted;
41
- recipientEmail: string;
42
- params: EmailPublicParameters;
43
- id: string;
44
- isSubjectEncrypted: boolean;
22
+ encEmailBody: EmailBodyEncrypted;
45
23
  };
46
24
  type PwdProtectedEmail = {
47
25
  encryptedKey: PwdProtectedKey;
48
- enc: EmailBodyEncrypted;
49
- params: EmailPublicParameters;
50
- id: string;
51
- isSubjectEncrypted: boolean;
26
+ encEmailBody: EmailBodyEncrypted;
52
27
  };
53
28
  type StoredEmail = {
54
29
  params: EmailPublicParameters;
55
- enc: EmailBodyEncrypted;
30
+ encEmailBody: EmailBodyEncrypted;
56
31
  id: string;
57
32
  };
58
33
  type HybridEncKey = {
59
- kyberCiphertext: string;
34
+ hybridCiphertext: string;
60
35
  encryptedKey: string;
36
+ encryptedForEmail: string;
61
37
  };
62
38
  type PwdProtectedKey = {
63
39
  encryptedKey: string;
@@ -65,14 +41,15 @@ type PwdProtectedKey = {
65
41
  };
66
42
  type EmailBodyEncrypted = {
67
43
  encText: string;
44
+ encSubject: string;
68
45
  encAttachments?: string[];
69
46
  };
70
47
  type EmailBody = {
71
48
  text: string;
49
+ subject: string;
72
50
  attachments?: string[];
73
51
  };
74
52
  type EmailPublicParameters = {
75
- subject: string;
76
53
  createdAt: string;
77
54
  sender: User;
78
55
  recipient: User;
@@ -100,5 +77,5 @@ declare enum KeystoreType {
100
77
  RECOVERY = "Recovery"
101
78
  }
102
79
  //#endregion
103
- export { Email, EmailBody, EmailBodyEncrypted, EmailKeys, EmailKeysEncrypted, EmailPublicParameters, EmailSearchResult, EncryptedKeystore, HybridEncKey, HybridEncryptedEmail, KeystoreType, MailCache, PrivateKeys, PrivateKeysEncrypted, PublicKeys, PublicKeysBase64, PwdProtectedEmail, PwdProtectedKey, StoredEmail, User, UserWithPublicKeys };
80
+ export { Email, EmailBody, EmailBodyEncrypted, EmailPublicParameters, EmailSearchResult, EncryptedKeystore, HybridEncKey, HybridEncryptedEmail, HybridKeyPair, KeystoreType, MailCache, PwdProtectedEmail, PwdProtectedKey, RecipientWithPublicKey, StoredEmail, User };
104
81
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KAAY,iBAAA;EACV,SAAA;EACA,IAAA,EAAM,YAAA;EACN,aAAA,EAAe,kBAAA;AAAA;AAAA,KAGL,IAAA;EACV,KAAA;EACA,IAAA;AAAA;AAAA,KAGU,kBAAA,GAAqB,IAAA;EAC/B,UAAA,EAAY,UAAA;AAAA;AAAA,KAGF,UAAA;EACV,YAAA,EAAc,SAAA;EACd,cAAA,EAAgB,UAAA;AAAA;AAAA,KAGN,gBAAA;EACV,kBAAA;EACA,oBAAA;AAAA;AAAA,KAGU,WAAA;EACV,aAAA,EAAe,SAAA;EACf,eAAA,EAAiB,UAAA;AAAA;AAAA,KAGP,oBAAA;EACV,mBAAA;EACA,qBAAA;AAAA;AAAA,KAGU,SAAA;EACV,UAAA,EAAY,UAAA;EACZ,WAAA,EAAa,WAAA;AAAA;AAAA,KAGH,kBAAA;EACV,UAAA,EAAY,gBAAA;EACZ,WAAA,EAAa,oBAAA;AAAA;AAAA,KAGH,oBAAA;EACV,YAAA,EAAc,YAAA;EACd,GAAA,EAAK,kBAAA;EACL,cAAA;EACA,MA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A;AAAA,KAGJ,iBAAA;EACV,YAAA,EAAc,eAAA;EACd,YAAA,EAAc,kBAAA;AAAA;AAAA,KAGJ,WAAA;EACV,MAAA,EAAQ,qBAAA;EACR,YAAA,EAAc,kBAAA;EACd,EAAA;AAAA;AAAA,KAGU,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,KAGU,qBAAA;EACV,SAAA;EACA,MAAA,EAAQ,IAAA;EACR,SAAA,EAAW,IAAA;EACX,UAAA,GAAa,IAAA;EACb,cAAA;EACA,MAAA;AAAA;AAAA,KAGU,KAAA;EACV,EAAA;EACA,IAAA,EAAM,SAAA;EACN,MAAA,EAAQ,qBAAA;AAAA;AAAA,UAGO,SAAA;EACf,OAAA,EAAS,GAAA,SAAY,KAAA;EACrB,SAAA;EACA,cAAA;EACA,YAAA;AAAA;AAAA,UAEe,iBAAA;EACf,KAAA,EAAO,KAAA;EACP,KAAA;AAAA;AAAA,aAGU,YAAA;EACV,UAAA;EACA,QAAA;AAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["export type EncryptedKeystore = {\n userEmail: string;\n type: KeystoreType;\n encryptedKeys: EmailKeysEncrypted;\n};\n\nexport type User = {\n email: string;\n name: string;\n};\n\nexport type UserWithPublicKeys = User & {\n publicKeys: PublicKeys;\n};\n\nexport type PublicKeys = {\n eccPublicKey: CryptoKey;\n kyberPublicKey: Uint8Array;\n};\n\nexport type PublicKeysBase64 = {\n eccPublicKeyBase64: string;\n kyberPublicKeyBase64: string;\n};\n\nexport type PrivateKeys = {\n eccPrivateKey: CryptoKey;\n kyberPrivateKey: Uint8Array;\n};\n\nexport type PrivateKeysEncrypted = {\n eccPrivateKeyBase64: string;\n kyberPrivateKeyBase64: string;\n};\n\nexport type EmailKeys = {\n publicKeys: PublicKeys;\n privateKeys: PrivateKeys;\n};\n\nexport type EmailKeysEncrypted = {\n publicKeys: PublicKeysBase64;\n privateKeys: PrivateKeysEncrypted;\n};\n\nexport type HybridEncryptedEmail = {\n encryptedKey: HybridEncKey;\n enc: EmailBodyEncrypted;\n recipientEmail: string;\n params: EmailPublicParameters;\n id: string;\n isSubjectEncrypted: boolean;\n};\n\nexport type PwdProtectedEmail = {\n encryptedKey: PwdProtectedKey;\n enc: EmailBodyEncrypted;\n params: EmailPublicParameters;\n id: string;\n isSubjectEncrypted: boolean;\n};\n\nexport type StoredEmail = {\n params: EmailPublicParameters;\n enc: EmailBodyEncrypted;\n id: string;\n};\n\nexport type HybridEncKey = {\n kyberCiphertext: string;\n encryptedKey: string;\n};\n\nexport type PwdProtectedKey = {\n encryptedKey: string;\n salt: string;\n};\n\nexport type EmailBodyEncrypted = {\n encText: string;\n encAttachments?: string[];\n};\n\nexport type EmailBody = {\n text: string;\n attachments?: string[];\n};\n\nexport type EmailPublicParameters = {\n subject: string;\n createdAt: string;\n sender: User;\n recipient: User;\n recipients?: User[];\n replyToEmailID?: string;\n labels?: string[];\n};\n\nexport type Email = {\n id: string;\n body: EmailBody;\n params: EmailPublicParameters;\n};\n\nexport interface MailCache<Email> {\n esCache: Map<string, Email>;\n cacheSize: number;\n isCacheLimited: boolean;\n isCacheReady: boolean;\n}\nexport interface EmailSearchResult {\n email: Email;\n score?: number;\n}\n\nexport enum KeystoreType {\n ENCRYPTION = 'Encryption',\n RECOVERY = 'Recovery',\n}\n"],"mappings":";;;AAmHA,IAAY,sDAAL;AACL;AACA"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["export type EncryptedKeystore = {\n userEmail: string;\n type: KeystoreType;\n publicKey: string;\n privateKeyEncrypted: string;\n};\n\nexport type User = {\n email: string;\n name: string;\n};\n\nexport type RecipientWithPublicKey = {\n email: string;\n publicHybridKey: Uint8Array;\n};\n\nexport type HybridKeyPair = {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n};\n\nexport type HybridEncryptedEmail = {\n encryptedKey: HybridEncKey;\n encEmailBody: EmailBodyEncrypted;\n};\n\nexport type PwdProtectedEmail = {\n encryptedKey: PwdProtectedKey;\n encEmailBody: EmailBodyEncrypted;\n};\n\nexport type StoredEmail = {\n params: EmailPublicParameters;\n encEmailBody: EmailBodyEncrypted;\n id: string;\n};\n\nexport type HybridEncKey = {\n hybridCiphertext: string;\n encryptedKey: string;\n encryptedForEmail: string;\n};\n\nexport type PwdProtectedKey = {\n encryptedKey: string;\n salt: string;\n};\n\nexport type EmailBodyEncrypted = {\n encText: string;\n encSubject: string;\n encAttachments?: string[];\n};\n\nexport type EmailBody = {\n text: string;\n subject: string;\n attachments?: string[];\n};\n\nexport type EmailPublicParameters = {\n createdAt: string;\n sender: User;\n recipient: User;\n recipients?: User[];\n replyToEmailID?: string;\n labels?: string[];\n};\n\nexport type Email = {\n id: string;\n body: EmailBody;\n params: EmailPublicParameters;\n};\n\nexport interface MailCache<Email> {\n esCache: Map<string, Email>;\n cacheSize: number;\n isCacheLimited: boolean;\n isCacheReady: boolean;\n}\nexport interface EmailSearchResult {\n email: Email;\n score?: number;\n}\n\nexport enum KeystoreType {\n ENCRYPTION = 'Encryption',\n RECOVERY = 'Recovery',\n}\n"],"mappings":";;;AAuFA,IAAY,sDAAL;AACL;AACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["export type EncryptedKeystore = {\n userEmail: string;\n type: KeystoreType;\n encryptedKeys: EmailKeysEncrypted;\n};\n\nexport type User = {\n email: string;\n name: string;\n};\n\nexport type UserWithPublicKeys = User & {\n publicKeys: PublicKeys;\n};\n\nexport type PublicKeys = {\n eccPublicKey: CryptoKey;\n kyberPublicKey: Uint8Array;\n};\n\nexport type PublicKeysBase64 = {\n eccPublicKeyBase64: string;\n kyberPublicKeyBase64: string;\n};\n\nexport type PrivateKeys = {\n eccPrivateKey: CryptoKey;\n kyberPrivateKey: Uint8Array;\n};\n\nexport type PrivateKeysEncrypted = {\n eccPrivateKeyBase64: string;\n kyberPrivateKeyBase64: string;\n};\n\nexport type EmailKeys = {\n publicKeys: PublicKeys;\n privateKeys: PrivateKeys;\n};\n\nexport type EmailKeysEncrypted = {\n publicKeys: PublicKeysBase64;\n privateKeys: PrivateKeysEncrypted;\n};\n\nexport type HybridEncryptedEmail = {\n encryptedKey: HybridEncKey;\n enc: EmailBodyEncrypted;\n recipientEmail: string;\n params: EmailPublicParameters;\n id: string;\n isSubjectEncrypted: boolean;\n};\n\nexport type PwdProtectedEmail = {\n encryptedKey: PwdProtectedKey;\n enc: EmailBodyEncrypted;\n params: EmailPublicParameters;\n id: string;\n isSubjectEncrypted: boolean;\n};\n\nexport type StoredEmail = {\n params: EmailPublicParameters;\n enc: EmailBodyEncrypted;\n id: string;\n};\n\nexport type HybridEncKey = {\n kyberCiphertext: string;\n encryptedKey: string;\n};\n\nexport type PwdProtectedKey = {\n encryptedKey: string;\n salt: string;\n};\n\nexport type EmailBodyEncrypted = {\n encText: string;\n encAttachments?: string[];\n};\n\nexport type EmailBody = {\n text: string;\n attachments?: string[];\n};\n\nexport type EmailPublicParameters = {\n subject: string;\n createdAt: string;\n sender: User;\n recipient: User;\n recipients?: User[];\n replyToEmailID?: string;\n labels?: string[];\n};\n\nexport type Email = {\n id: string;\n body: EmailBody;\n params: EmailPublicParameters;\n};\n\nexport interface MailCache<Email> {\n esCache: Map<string, Email>;\n cacheSize: number;\n isCacheLimited: boolean;\n isCacheReady: boolean;\n}\nexport interface EmailSearchResult {\n email: Email;\n score?: number;\n}\n\nexport enum KeystoreType {\n ENCRYPTION = 'Encryption',\n RECOVERY = 'Recovery',\n}\n"],"mappings":";AAmHA,IAAY,sDAAL;AACL;AACA"}
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["export type EncryptedKeystore = {\n userEmail: string;\n type: KeystoreType;\n publicKey: string;\n privateKeyEncrypted: string;\n};\n\nexport type User = {\n email: string;\n name: string;\n};\n\nexport type RecipientWithPublicKey = {\n email: string;\n publicHybridKey: Uint8Array;\n};\n\nexport type HybridKeyPair = {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n};\n\nexport type HybridEncryptedEmail = {\n encryptedKey: HybridEncKey;\n encEmailBody: EmailBodyEncrypted;\n};\n\nexport type PwdProtectedEmail = {\n encryptedKey: PwdProtectedKey;\n encEmailBody: EmailBodyEncrypted;\n};\n\nexport type StoredEmail = {\n params: EmailPublicParameters;\n encEmailBody: EmailBodyEncrypted;\n id: string;\n};\n\nexport type HybridEncKey = {\n hybridCiphertext: string;\n encryptedKey: string;\n encryptedForEmail: string;\n};\n\nexport type PwdProtectedKey = {\n encryptedKey: string;\n salt: string;\n};\n\nexport type EmailBodyEncrypted = {\n encText: string;\n encSubject: string;\n encAttachments?: string[];\n};\n\nexport type EmailBody = {\n text: string;\n subject: string;\n attachments?: string[];\n};\n\nexport type EmailPublicParameters = {\n createdAt: string;\n sender: User;\n recipient: User;\n recipients?: User[];\n replyToEmailID?: string;\n labels?: string[];\n};\n\nexport type Email = {\n id: string;\n body: EmailBody;\n params: EmailPublicParameters;\n};\n\nexport interface MailCache<Email> {\n esCache: Map<string, Email>;\n cacheSize: number;\n isCacheLimited: boolean;\n isCacheReady: boolean;\n}\nexport interface EmailSearchResult {\n email: Email;\n score?: number;\n}\n\nexport enum KeystoreType {\n ENCRYPTION = 'Encryption',\n RECOVERY = 'Recovery',\n}\n"],"mappings":";AAuFA,IAAY,sDAAL;AACL;AACA"}
package/dist/utils.d.mts CHANGED
@@ -1,5 +1,3 @@
1
- import { PublicKeys, PublicKeysBase64 } from "./types.mjs";
2
-
3
1
  //#region src/utils/converters.d.ts
4
2
  /**
5
3
  * Converts a Uint8Array into a hexadecimal string.
@@ -44,22 +42,6 @@ declare function uint8ArrayToBase64(buffer: Uint8Array): string;
44
42
  */
45
43
  declare function base64ToUint8Array(str: string): Uint8Array;
46
44
  //#endregion
47
- //#region src/utils/keyConverters.d.ts
48
- /**
49
- * Converts a base64 string into PublicKeys type.
50
- *
51
- * @param base64 - The base64 representation of the public key.
52
- * @returns The resulting PublicKeys.
53
- */
54
- declare function base64ToPublicKey(base64: PublicKeysBase64): Promise<PublicKeys>;
55
- /**
56
- * Converts a PublicKeys type into PublicKeysBase64.
57
- *
58
- * @param key - The PublicKeys key.
59
- * @returns The resulting PublicKeysBase64.
60
- */
61
- declare function publicKeyToBase64(key: PublicKeys): Promise<PublicKeysBase64>;
62
- //#endregion
63
45
  //#region src/utils/genMnemonic.d.ts
64
46
  /**
65
47
  * Generates a mnemonic
@@ -92,5 +74,5 @@ declare function generateUuid(): string;
92
74
  declare function uuidToBytes(uuid: string): Uint8Array;
93
75
  declare function bytesToUuid(bytes: Uint8Array): string;
94
76
  //#endregion
95
- export { UTF8ToUint8, base64ToPublicKey, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, publicKeyToBase64, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
77
+ export { UTF8ToUint8, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
96
78
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils/converters.ts","../src/utils/keyConverters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"mappings":";;;;;;AAQA;;;iBAAgB,eAAA,CAAgB,KAAA,EAAO,UAAA;;AAUvC;;;;;iBAAgB,WAAA,CAAY,GAAA,WAAc,UAAA;;;;;AAoB1C;;iBAVgB,WAAA,CAAY,KAAA,EAAO,UAAA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,YAAA,CAAA;AAAA,iBAIA,WAAA,CAAY,IAAA,WAAe,UAAA;AAAA,iBAI3B,WAAA,CAAY,KAAA,EAAO,UAAA"}
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { PublicKeys, PublicKeysBase64 } from "./types.js";
2
-
3
1
  //#region src/utils/converters.d.ts
4
2
  /**
5
3
  * Converts a Uint8Array into a hexadecimal string.
@@ -44,22 +42,6 @@ declare function uint8ArrayToBase64(buffer: Uint8Array): string;
44
42
  */
45
43
  declare function base64ToUint8Array(str: string): Uint8Array;
46
44
  //#endregion
47
- //#region src/utils/keyConverters.d.ts
48
- /**
49
- * Converts a base64 string into PublicKeys type.
50
- *
51
- * @param base64 - The base64 representation of the public key.
52
- * @returns The resulting PublicKeys.
53
- */
54
- declare function base64ToPublicKey(base64: PublicKeysBase64): Promise<PublicKeys>;
55
- /**
56
- * Converts a PublicKeys type into PublicKeysBase64.
57
- *
58
- * @param key - The PublicKeys key.
59
- * @returns The resulting PublicKeysBase64.
60
- */
61
- declare function publicKeyToBase64(key: PublicKeys): Promise<PublicKeysBase64>;
62
- //#endregion
63
45
  //#region src/utils/genMnemonic.d.ts
64
46
  /**
65
47
  * Generates a mnemonic
@@ -92,5 +74,5 @@ declare function generateUuid(): string;
92
74
  declare function uuidToBytes(uuid: string): Uint8Array;
93
75
  declare function bytesToUuid(bytes: Uint8Array): string;
94
76
  //#endregion
95
- export { UTF8ToUint8, base64ToPublicKey, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, publicKeyToBase64, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
77
+ export { UTF8ToUint8, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
96
78
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","names":[],"sources":["../src/utils/converters.ts","../src/utils/keyConverters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"mappings":";;;;;;AAQA;;;iBAAgB,eAAA,CAAgB,KAAA,EAAO,UAAA;;AAUvC;;;;;iBAAgB,WAAA,CAAY,GAAA,WAAc,UAAA;;;;;AAoB1C;;iBAVgB,WAAA,CAAY,KAAA,EAAO,UAAA;;;AAoBnC;;;;iBAVgB,eAAA,CAAgB,GAAA,WAAc,UAAA;AAsB9C;;;;;;AAAA,iBAZgB,kBAAA,CAAmB,MAAA,EAAQ,UAAA;;ACtC3C;;;;;iBDkDgB,kBAAA,CAAmB,GAAA,WAAc,UAAA;;;;;AApDjD;;;;iBCEsB,iBAAA,CAAkB,MAAA,EAAQ,gBAAA,GAAmB,OAAA,CAAQ,UAAA;ADQ3E;;;;;AAUA;AAVA,iBCYsB,iBAAA,CAAkB,GAAA,EAAK,UAAA,GAAa,OAAA,CAAQ,gBAAA;;;;;;ADtBlE;;iBEAgB,WAAA,CAAA;;;AFUhB;;;;iBEAgB,eAAA,CAAgB,QAAA,WAAmB,UAAA;AFUnD;;;;;AAUA;AAVA,iBEAgB,eAAA,CAAgB,KAAA,EAAO,UAAA;;;;;;AFpBvC;;iBGFgB,YAAA,CAAA;AAAA,iBAIA,WAAA,CAAY,IAAA,WAAe,UAAA;AAAA,iBAI3B,WAAA,CAAY,KAAA,EAAO,UAAA"}
1
+ {"version":3,"file":"utils.d.ts","names":[],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"mappings":";;AAQA;;;;;iBAAgB,eAAA,CAAgB,KAAA,EAAO,UAAA;;;;;AAoBvC;;iBAVgB,WAAA,CAAY,GAAA,WAAc,UAAA;;;AAoB1C;;;;iBAVgB,WAAA,CAAY,KAAA,EAAO,UAAA;AAoBnC;;;;;AAYA;AAZA,iBAVgB,eAAA,CAAgB,GAAA,WAAc,UAAA;;;;;;;iBAU9B,kBAAA,CAAmB,MAAA,EAAQ,UAAA;;;;;AC9B3C;;iBD0CgB,kBAAA,CAAmB,GAAA,WAAc,UAAA;;;;AApDjD;;;;iBCAgB,WAAA,CAAA;ADUhB;;;;;AAUA;AAVA,iBCAgB,eAAA,CAAgB,QAAA,WAAmB,UAAA;;;;ADoBnD;;;iBCVgB,eAAA,CAAgB,KAAA,EAAO,UAAA;;;;ADpBvC;;;;iBEFgB,YAAA,CAAA;AAAA,iBAIA,WAAA,CAAY,IAAA,WAAe,UAAA;AAAA,iBAI3B,WAAA,CAAY,KAAA,EAAO,UAAA"}
package/dist/utils.js CHANGED
@@ -1,8 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_genID = require('./genID-YJSl3YhL.js');
2
+ const require_genID = require('./genID-cWOPmspk.js');
3
3
 
4
4
  exports.UTF8ToUint8 = require_genID.UTF8ToUint8;
5
- exports.base64ToPublicKey = require_genID.base64ToPublicKey;
6
5
  exports.base64ToUint8Array = require_genID.base64ToUint8Array;
7
6
  exports.bytesToMnemonic = require_genID.bytesToMnemonic;
8
7
  exports.bytesToUuid = require_genID.bytesToUuid;
@@ -10,7 +9,6 @@ exports.genMnemonic = require_genID.genMnemonic;
10
9
  exports.generateUuid = require_genID.generateUuid;
11
10
  exports.hexToUint8Array = require_genID.hexToUint8Array;
12
11
  exports.mnemonicToBytes = require_genID.mnemonicToBytes;
13
- exports.publicKeyToBase64 = require_genID.publicKeyToBase64;
14
12
  exports.uint8ArrayToBase64 = require_genID.uint8ArrayToBase64;
15
13
  exports.uint8ArrayToHex = require_genID.uint8ArrayToHex;
16
14
  exports.uint8ToUTF8 = require_genID.uint8ToUTF8;
package/dist/utils.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as genMnemonic, c as publicKeyToBase64, d as hexToUint8Array, f as uint8ArrayToBase64, i as bytesToMnemonic, l as UTF8ToUint8, m as uint8ToUTF8, n as generateUuid, o as mnemonicToBytes, p as uint8ArrayToHex, r as uuidToBytes, s as base64ToPublicKey, t as bytesToUuid, u as base64ToUint8Array } from "./genID-3Er5IowC.mjs";
1
+ import { a as genMnemonic, c as base64ToUint8Array, d as uint8ArrayToHex, f as uint8ToUTF8, i as bytesToMnemonic, l as hexToUint8Array, n as generateUuid, o as mnemonicToBytes, r as uuidToBytes, s as UTF8ToUint8, t as bytesToUuid, u as uint8ArrayToBase64 } from "./genID-D08K7JPr.mjs";
2
2
 
3
- export { UTF8ToUint8, base64ToPublicKey, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, publicKeyToBase64, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
3
+ export { UTF8ToUint8, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
@@ -0,0 +1,16 @@
1
+ import { ml_kem768_x25519 } from "@noble/post-quantum/hybrid.js";
2
+
3
+ //#region src/hybrid-crypto/xwing.ts
4
+ function genHybridKeys(seed) {
5
+ return ml_kem768_x25519.keygen(seed);
6
+ }
7
+ function encapsulateHybrid(publicKey) {
8
+ return ml_kem768_x25519.encapsulate(publicKey);
9
+ }
10
+ function decapsulateHybrid(cipherText, secretKey) {
11
+ return ml_kem768_x25519.decapsulate(cipherText, secretKey);
12
+ }
13
+
14
+ //#endregion
15
+ export { encapsulateHybrid as n, genHybridKeys as r, decapsulateHybrid as t };
16
+ //# sourceMappingURL=xwing-CQmQX6hn.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xwing-CQmQX6hn.mjs","names":["hybridCipher"],"sources":["../src/hybrid-crypto/xwing.ts"],"sourcesContent":["import { ml_kem768_x25519 as hybridCipher } from '@noble/post-quantum/hybrid.js';\nimport { HybridKeyPair } from '../types';\n\nexport function genHybridKeys(seed?: Uint8Array): HybridKeyPair {\n return hybridCipher.keygen(seed);\n}\n\nexport function encapsulateHybrid(publicKey: Uint8Array): { cipherText: Uint8Array; sharedSecret: Uint8Array } {\n return hybridCipher.encapsulate(publicKey);\n}\n\nexport function decapsulateHybrid(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n return hybridCipher.decapsulate(cipherText, secretKey);\n}\n"],"mappings":";;;AAGA,SAAgB,cAAc,MAAkC;AAC9D,QAAOA,iBAAa,OAAO,KAAK;;AAGlC,SAAgB,kBAAkB,WAA6E;AAC7G,QAAOA,iBAAa,YAAY,UAAU;;AAG5C,SAAgB,kBAAkB,YAAwB,WAAmC;AAC3F,QAAOA,iBAAa,YAAY,YAAY,UAAU"}