internxt-crypto 0.0.9-alpha → 0.0.11

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 (120) hide show
  1. package/README.md +3 -4
  2. package/dist/asymmetric-crypto-BORmLhnx.js +143 -0
  3. package/dist/asymmetric-crypto-BORmLhnx.js.map +1 -0
  4. package/dist/asymmetric-crypto-CyXsV4XT.mjs +102 -0
  5. package/dist/asymmetric-crypto-CyXsV4XT.mjs.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +47 -0
  7. package/dist/asymmetric-crypto.d.ts +47 -0
  8. package/dist/asymmetric-crypto.js +8 -0
  9. package/dist/asymmetric-crypto.mjs +3 -0
  10. package/dist/chunk-DWirmd9C.mjs +18 -0
  11. package/dist/chunk-Dt-PWiN7.js +60 -0
  12. package/dist/constants-Ccp21E03.js +208 -0
  13. package/dist/constants-Ccp21E03.js.map +1 -0
  14. package/dist/constants-kTeX-2T0.mjs +34 -0
  15. package/dist/constants-kTeX-2T0.mjs.map +1 -0
  16. package/dist/constants.d.mts +33 -0
  17. package/dist/constants.d.ts +33 -0
  18. package/dist/constants.js +31 -0
  19. package/dist/constants.mjs +3 -0
  20. package/dist/derive-key-Be7hS-cN.mjs +751 -0
  21. package/dist/derive-key-Be7hS-cN.mjs.map +1 -0
  22. package/dist/derive-key-CBf2WxJd.js +2513 -0
  23. package/dist/derive-key-CBf2WxJd.js.map +1 -0
  24. package/dist/derive-key.d.mts +97 -0
  25. package/dist/derive-key.d.ts +97 -0
  26. package/dist/derive-key.js +15 -0
  27. package/dist/derive-key.mjs +6 -0
  28. package/dist/email-crypto-BrT98taw.js +617 -0
  29. package/dist/email-crypto-BrT98taw.js.map +1 -0
  30. package/dist/email-crypto-DJUEjTxA.mjs +534 -0
  31. package/dist/email-crypto-DJUEjTxA.mjs.map +1 -0
  32. package/dist/email-crypto.d.mts +86 -0
  33. package/dist/email-crypto.d.ts +86 -0
  34. package/dist/email-crypto.js +17 -0
  35. package/dist/email-crypto.mjs +8 -0
  36. package/dist/email-search.d.mts +235 -0
  37. package/dist/email-search.d.ts +235 -0
  38. package/dist/email-search.js +637 -0
  39. package/dist/email-search.js.map +1 -0
  40. package/dist/email-search.mjs +608 -0
  41. package/dist/email-search.mjs.map +1 -0
  42. package/dist/hash-BoqwNkcd.js +190 -0
  43. package/dist/hash-BoqwNkcd.js.map +1 -0
  44. package/dist/hash-CXeGAwai.mjs +131 -0
  45. package/dist/hash-CXeGAwai.mjs.map +1 -0
  46. package/dist/hash.d.mts +65 -0
  47. package/dist/hash.d.ts +65 -0
  48. package/dist/hash.js +11 -0
  49. package/dist/hash.mjs +3 -0
  50. package/dist/index-CQqgKsbX.d.ts +50 -0
  51. package/dist/index-CintVUbp.d.ts +97 -0
  52. package/dist/index-D5pBU_A5.d.mts +50 -0
  53. package/dist/index-MaOov-ag.d.mts +97 -0
  54. package/dist/index.d.mts +52 -0
  55. package/dist/index.d.ts +52 -0
  56. package/dist/index.js +116 -2055
  57. package/dist/index.mjs +15 -8712
  58. package/dist/keystore-crypto-B4yCVo9l.js +182 -0
  59. package/dist/keystore-crypto-B4yCVo9l.js.map +1 -0
  60. package/dist/keystore-crypto-Bjgriq9h.mjs +159 -0
  61. package/dist/keystore-crypto-Bjgriq9h.mjs.map +1 -0
  62. package/dist/keystore-crypto.d.mts +40 -0
  63. package/dist/keystore-crypto.d.ts +40 -0
  64. package/dist/keystore-crypto.js +11 -0
  65. package/dist/keystore-crypto.mjs +9 -0
  66. package/dist/keystore-service.d.mts +48 -0
  67. package/dist/keystore-service.d.ts +48 -0
  68. package/dist/keystore-service.js +122 -0
  69. package/dist/keystore-service.js.map +1 -0
  70. package/dist/keystore-service.mjs +114 -0
  71. package/dist/keystore-service.mjs.map +1 -0
  72. package/dist/post-quantum-crypto-CAi-cEkV.js +189 -0
  73. package/dist/post-quantum-crypto-CAi-cEkV.js.map +1 -0
  74. package/dist/post-quantum-crypto-Vv34t6gX.mjs +154 -0
  75. package/dist/post-quantum-crypto-Vv34t6gX.mjs.map +1 -0
  76. package/dist/post-quantum-crypto.d.mts +2 -0
  77. package/dist/post-quantum-crypto.d.ts +2 -0
  78. package/dist/post-quantum-crypto.js +17 -0
  79. package/dist/post-quantum-crypto.mjs +3 -0
  80. package/dist/storage-service-BgIK2aYZ.js +82 -0
  81. package/dist/storage-service-BgIK2aYZ.js.map +1 -0
  82. package/dist/storage-service-CubCbhY2.mjs +65 -0
  83. package/dist/storage-service-CubCbhY2.mjs.map +1 -0
  84. package/dist/storage-service.d.mts +2 -0
  85. package/dist/storage-service.d.ts +2 -0
  86. package/dist/storage-service.js +14 -0
  87. package/dist/storage-service.mjs +3 -0
  88. package/dist/symmetric-crypto-CrdS1Che.mjs +197 -0
  89. package/dist/symmetric-crypto-CrdS1Che.mjs.map +1 -0
  90. package/dist/symmetric-crypto-D65zB396.js +244 -0
  91. package/dist/symmetric-crypto-D65zB396.js.map +1 -0
  92. package/dist/symmetric-crypto.d.mts +60 -0
  93. package/dist/symmetric-crypto.d.ts +60 -0
  94. package/dist/symmetric-crypto.js +10 -0
  95. package/dist/symmetric-crypto.mjs +4 -0
  96. package/dist/types-52g887Zi.js +16 -0
  97. package/dist/types-52g887Zi.js.map +1 -0
  98. package/dist/types-BiEoleqw.mjs +10 -0
  99. package/dist/types-BiEoleqw.mjs.map +1 -0
  100. package/dist/types-Ds3ivE9W.d.ts +104 -0
  101. package/dist/types-DwQJtrTx.d.mts +104 -0
  102. package/dist/types.d.mts +2 -0
  103. package/dist/types.d.ts +2 -0
  104. package/dist/types.js +3 -0
  105. package/dist/types.mjs +3 -0
  106. package/dist/utils-CNs3cyDj.js +263 -0
  107. package/dist/utils-CNs3cyDj.js.map +1 -0
  108. package/dist/utils-DS04iUcX.mjs +173 -0
  109. package/dist/utils-DS04iUcX.mjs.map +1 -0
  110. package/dist/utils.d.mts +99 -0
  111. package/dist/utils.d.ts +99 -0
  112. package/dist/utils.js +16 -0
  113. package/dist/utils.mjs +3 -0
  114. package/package.json +12 -11
  115. package/dist/__vite-browser-external-Dyvby5gX.js +0 -2
  116. package/dist/__vite-browser-external-Dyvby5gX.js.map +0 -1
  117. package/dist/__vite-browser-external-l0sNRNKZ.mjs +0 -2
  118. package/dist/__vite-browser-external-l0sNRNKZ.mjs.map +0 -1
  119. package/dist/index.js.map +0 -1
  120. package/dist/index.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-search.mjs","names":[],"sources":["../src/email-search/indexedDB.ts","../src/email-search/mailCache.ts","../src/email-search/search.ts","../src/email-search/index.ts"],"sourcesContent":["import { DBSchema, openDB, deleteDB, IDBPDatabase } from 'idb';\nimport { StoredEmail, Email } from '../types';\nimport { decryptEmailSymmetrically, encryptEmailContentSymmetricallyWithKey } from '../email-crypto/core';\nimport { deriveSymmetricCryptoKeyFromContext } from '../derive-key';\nimport { CONTEXT_INDEX, DB_LABEL, DB_VERSION } from '../constants';\nimport { getAux } from '../email-crypto';\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 CryptoKey for protecting database\n */\nexport const deriveIndexKey = async (baseKey: Uint8Array): Promise<CryptoKey> => {\n return deriveSymmetricCryptoKeyFromContext(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 CryptoKey key for protecting database\n * @param esDB - The database\n */\nexport const encryptAndStoreEmail = async (\n newEmailToStore: Email,\n indexKey: CryptoKey,\n esDB: MailDB,\n): Promise<void> => {\n try {\n const aux = getAux(newEmailToStore.params, false);\n const enc = await encryptEmailContentSymmetricallyWithKey(newEmailToStore.body, indexKey, aux, newEmailToStore.id);\n const encryptedEmail: StoredEmail = { 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 CryptoKey key for protecting database\n * @param esDB - The database\n */\nexport const encryptAndStoreManyEmail = async (\n newEmailsToStore: Email[],\n indexKey: CryptoKey,\n esDB: MailDB,\n): Promise<void> => {\n try {\n const encryptedEmails = await Promise.all(\n newEmailsToStore.map(async (email: Email) => {\n const aux = getAux(email.params, false);\n const enc = await encryptEmailContentSymmetricallyWithKey(email.body, indexKey, aux, email.id);\n\n return { enc, 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 CryptoKey key for protecting database\n * @param encryptedEmail - The encrypted email\n * @returns The decrypted email\n */\nconst decryptEmail = async (indexKey: CryptoKey, encryptedEmail: StoredEmail): Promise<Email> => {\n try {\n const aux = getAux(encryptedEmail.params, false);\n const email = await decryptEmailSymmetrically(indexKey, aux, encryptedEmail.enc);\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 CryptoKey key for protecting database\n * @param encryptedEmail - The encrypted email\n * @returns The decrypted email\n */\nexport const getAndDecryptEmail = async (emailID: string, indexKey: CryptoKey, 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 CryptoKey key for protecting database\n * @param esDB - The database\n * @returns The decrypted emails\n */\nexport const getAndDecryptAllEmails = async (indexKey: CryptoKey, 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 aux = getAux(encEmail.params, false);\n const body = await decryptEmailSymmetrically(indexKey, aux, encEmail.enc);\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 CryptoKey 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: CryptoKey, 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 CryptoKey key for protecting database\n * @returns The number of stored emails\n */\nexport const getAllEmailsSortedNewestFirst = async (esDB: MailDB, indexKey: CryptoKey): 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 CryptoKey key for protecting database\n * @returns The number of stored emails\n */\nexport const getAllEmailsSortedOldestFirst = async (esDB: MailDB, indexKey: CryptoKey): 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 CryptoKey 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: CryptoKey,\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 { MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH } from '../constants';\nimport { getEmailBatch, getAllEmailsSortedNewestFirst, getEmailCount, MailDB } from './indexedDB';\nimport { Email, MailCache } from '../types';\nimport { emailToBinary } from '../email-crypto';\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 CryptoKey key for protecting database\n * @param esCache - The cache to add emails too\n * @param esDB - The database\n */\nexport const createCacheFromDB = async (indexKey: CryptoKey, 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}`);\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\n if (email.params.subject) {\n searchIndex.subjectIndex.add(emailId, email.params.subject);\n }\n\n if (email.body?.text) {\n searchIndex.bodyIndex.add(emailId, email.body.text);\n }\n\n if (email.params.sender) {\n const senderText = `${email.params.sender.name || ''} ${email.params.sender.email || ''}`.trim();\n searchIndex.fromIndex.add(emailId, senderText);\n }\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","export * from './indexedDB';\nexport * from './mailCache';\nexport * from './search';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAM,mBAAmB,WAA2B;AAClD,QAAO,MAAM,OAAO;;;;;;;;AAStB,MAAa,eAAe,OAAO,WAAoC;AACrE,KAAI;AAEF,SAAO,OADQ,gBAAgB,OAAO,EACG,YAAY,EACnD,QAAQ,IAAI;AACV,OAAI,CAAC,GAAG,iBAAiB,SAAS,SAAS,CAEzC,CADc,GAAG,kBAAkB,UAAU,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,QAAO,SADQ,gBAAgB,OAAO,CACf;;;;;;;;AASzB,MAAa,iBAAiB,OAAO,YAA4C;AAC/E,QAAO,oCAAoC,eAAe,QAAQ;;;;;;;;;A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EAAE,SAAS,GAAG;AAC5D,SAAO,aAAa,MAAM,GAAG,MAAM;UAC5B,OAAO;AACd,QAAM,IAAI,MAAM,uBAAuB,EAAE,OAAO,OAAO,CAAC"}
@@ -0,0 +1,190 @@
1
+ const require_chunk = require('./chunk-Dt-PWiN7.js');
2
+ const require_constants = require('./constants-Ccp21E03.js');
3
+ let _noble_hashes_blake3_js = require("@noble/hashes/blake3.js");
4
+ let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
5
+
6
+ //#region src/hash/blake3.ts
7
+ /**
8
+ * Hashes the given array of data
9
+ *
10
+ * @param data - The data to hash
11
+ * @returns The resulting hash array
12
+ */
13
+ function hashDataArray(data) {
14
+ try {
15
+ const hasher = _noble_hashes_blake3_js.blake3.create();
16
+ for (const d of data) hasher.update(d);
17
+ return hasher.digest();
18
+ } catch (error) {
19
+ throw new Error("Failed to compute hash", { cause: error });
20
+ }
21
+ }
22
+ /**
23
+ * Hashes the given array of data
24
+ *
25
+ * @param data - The data to hash
26
+ * @returns The resulting hash hex string
27
+ */
28
+ function hashDataArrayHex(data) {
29
+ return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArray(data));
30
+ }
31
+ function hashDataArrayWithKeyHex(hashKey, data) {
32
+ try {
33
+ return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArrayWithKey(hashKey, data));
34
+ } catch (error) {
35
+ throw new Error("Failed to compute hash hex", { cause: error });
36
+ }
37
+ }
38
+ function hashDataArrayWithKey(hashKey, data) {
39
+ try {
40
+ const hasher = _noble_hashes_blake3_js.blake3.create({ key: hashKey });
41
+ for (const d of data) hasher.update(d);
42
+ return hasher.digest();
43
+ } catch (error) {
44
+ throw new Error("Failed to compute hash", { cause: error });
45
+ }
46
+ }
47
+ /**
48
+ * Hashes the given array of data using blake3 algorithm
49
+ *
50
+ * @param bytes - The desired output byte-length
51
+ * @param data - The data to hash
52
+ * @returns The resulting hash value
53
+ */
54
+ function getBytesFromDataArray(bytes, data) {
55
+ try {
56
+ const hasher = _noble_hashes_blake3_js.blake3.create({ dkLen: bytes });
57
+ for (const chunk of data) hasher.update(chunk);
58
+ return hasher.digest();
59
+ } catch (error) {
60
+ throw new Error("Failed to get bytes from data", { cause: error });
61
+ }
62
+ }
63
+ /**
64
+ * Hashes the given array of data using blake3 algorithm
65
+ *
66
+ * @param bytes - The desired output byte-length
67
+ * @param data - The data to hash
68
+ * @returns The resulting hash value
69
+ */
70
+ function getBytesFromDataArrayHex(bytes, data) {
71
+ try {
72
+ return (0, _noble_hashes_utils_js.bytesToHex)(getBytesFromDataArray(bytes, data));
73
+ } catch (error) {
74
+ throw new Error("Failed to get bytes from data", { cause: error });
75
+ }
76
+ }
77
+ /**
78
+ * Hashes the given string using blake3 algorithm
79
+ *
80
+ * @param bytes - The desired output byte-length
81
+ * @param data - The data to hash
82
+ * @returns The resulting hash value
83
+ */
84
+ function getBytesFromData(bytes, data) {
85
+ return (0, _noble_hashes_blake3_js.blake3)(data, { dkLen: bytes });
86
+ }
87
+ /**
88
+ * Hashes the given data using blake3 algorithm
89
+ *
90
+ * @param bytes - The desired output byte-length
91
+ * @param data - The data to hash
92
+ * @returns The resulting hash value
93
+ */
94
+ function getBytesFromDataHex(bytes, data) {
95
+ return (0, _noble_hashes_utils_js.bytesToHex)(getBytesFromData(bytes, data));
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/hash/mac.ts
100
+ /**
101
+ * Computes mac for the given key material and data
102
+ *
103
+ * @param keyMaterial - The key material
104
+ * @param data - The data to hash
105
+ * @returns The resulting hash hex string
106
+ */
107
+ function computeMac(keyMaterial, data) {
108
+ try {
109
+ return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArrayWithKey(getBytesFromData(require_constants.AES_KEY_BIT_LENGTH / 8, keyMaterial), data));
110
+ } catch (error) {
111
+ throw new Error("Failed to compute mac", { cause: error });
112
+ }
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/hash/index.ts
117
+ var hash_exports = /* @__PURE__ */ require_chunk.__exportAll({
118
+ computeMac: () => computeMac,
119
+ getBytesFromData: () => getBytesFromData,
120
+ getBytesFromDataArray: () => getBytesFromDataArray,
121
+ getBytesFromDataArrayHex: () => getBytesFromDataArrayHex,
122
+ getBytesFromDataHex: () => getBytesFromDataHex,
123
+ hashDataArray: () => hashDataArray,
124
+ hashDataArrayHex: () => hashDataArrayHex,
125
+ hashDataArrayWithKey: () => hashDataArrayWithKey,
126
+ hashDataArrayWithKeyHex: () => hashDataArrayWithKeyHex
127
+ });
128
+
129
+ //#endregion
130
+ Object.defineProperty(exports, 'computeMac', {
131
+ enumerable: true,
132
+ get: function () {
133
+ return computeMac;
134
+ }
135
+ });
136
+ Object.defineProperty(exports, 'getBytesFromData', {
137
+ enumerable: true,
138
+ get: function () {
139
+ return getBytesFromData;
140
+ }
141
+ });
142
+ Object.defineProperty(exports, 'getBytesFromDataArray', {
143
+ enumerable: true,
144
+ get: function () {
145
+ return getBytesFromDataArray;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, 'getBytesFromDataArrayHex', {
149
+ enumerable: true,
150
+ get: function () {
151
+ return getBytesFromDataArrayHex;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, 'getBytesFromDataHex', {
155
+ enumerable: true,
156
+ get: function () {
157
+ return getBytesFromDataHex;
158
+ }
159
+ });
160
+ Object.defineProperty(exports, 'hashDataArray', {
161
+ enumerable: true,
162
+ get: function () {
163
+ return hashDataArray;
164
+ }
165
+ });
166
+ Object.defineProperty(exports, 'hashDataArrayHex', {
167
+ enumerable: true,
168
+ get: function () {
169
+ return hashDataArrayHex;
170
+ }
171
+ });
172
+ Object.defineProperty(exports, 'hashDataArrayWithKey', {
173
+ enumerable: true,
174
+ get: function () {
175
+ return hashDataArrayWithKey;
176
+ }
177
+ });
178
+ Object.defineProperty(exports, 'hashDataArrayWithKeyHex', {
179
+ enumerable: true,
180
+ get: function () {
181
+ return hashDataArrayWithKeyHex;
182
+ }
183
+ });
184
+ Object.defineProperty(exports, 'hash_exports', {
185
+ enumerable: true,
186
+ get: function () {
187
+ return hash_exports;
188
+ }
189
+ });
190
+ //# sourceMappingURL=hash-BoqwNkcd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-BoqwNkcd.js","names":["blake3","AES_KEY_BIT_LENGTH"],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts","../src/hash/index.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash array\n */\nexport function hashDataArray(data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create();\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function hashDataArrayHex(data: Uint8Array[]): string {\n return bytesToHex(hashDataArray(data));\n}\n\nexport function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = hashDataArrayWithKey(hashKey, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute hash hex', { cause: error });\n }\n}\n\nexport function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ key: hashKey });\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ dkLen: bytes });\n for (const chunk of data) {\n hasher.update(chunk);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromDataArray(bytes, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given string using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n\n/**\n * Hashes the given data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataHex(bytes: number, data: Uint8Array): string {\n return bytesToHex(getBytesFromData(bytes, data));\n}\n","import { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromData, hashDataArrayWithKey } from './blake3';\n\n/**\n * Computes mac for the given key material and data\n *\n * @param keyMaterial - The key material\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string {\n try {\n const key = getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = hashDataArrayWithKey(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n","export * from './blake3';\nexport * from './mac';\n"],"mappings":";;;;;;;;;;;;AASA,SAAgB,cAAc,MAAgC;AAC5D,KAAI;EACF,MAAM,SAASA,+BAAO,QAAQ;AAC9B,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/D,SAAgB,iBAAiB,MAA4B;AAC3D,+CAAkB,cAAc,KAAK,CAAC;;AA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from "./chunk-DWirmd9C.mjs";
2
+ import { n as AES_KEY_BIT_LENGTH } from "./constants-kTeX-2T0.mjs";
3
+ import { blake3 } from "@noble/hashes/blake3.js";
4
+ import { bytesToHex } from "@noble/hashes/utils.js";
5
+
6
+ //#region src/hash/blake3.ts
7
+ /**
8
+ * Hashes the given array of data
9
+ *
10
+ * @param data - The data to hash
11
+ * @returns The resulting hash array
12
+ */
13
+ function hashDataArray(data) {
14
+ try {
15
+ const hasher = blake3.create();
16
+ for (const d of data) hasher.update(d);
17
+ return hasher.digest();
18
+ } catch (error) {
19
+ throw new Error("Failed to compute hash", { cause: error });
20
+ }
21
+ }
22
+ /**
23
+ * Hashes the given array of data
24
+ *
25
+ * @param data - The data to hash
26
+ * @returns The resulting hash hex string
27
+ */
28
+ function hashDataArrayHex(data) {
29
+ return bytesToHex(hashDataArray(data));
30
+ }
31
+ function hashDataArrayWithKeyHex(hashKey, data) {
32
+ try {
33
+ return bytesToHex(hashDataArrayWithKey(hashKey, data));
34
+ } catch (error) {
35
+ throw new Error("Failed to compute hash hex", { cause: error });
36
+ }
37
+ }
38
+ function hashDataArrayWithKey(hashKey, data) {
39
+ try {
40
+ const hasher = blake3.create({ key: hashKey });
41
+ for (const d of data) hasher.update(d);
42
+ return hasher.digest();
43
+ } catch (error) {
44
+ throw new Error("Failed to compute hash", { cause: error });
45
+ }
46
+ }
47
+ /**
48
+ * Hashes the given array of data using blake3 algorithm
49
+ *
50
+ * @param bytes - The desired output byte-length
51
+ * @param data - The data to hash
52
+ * @returns The resulting hash value
53
+ */
54
+ function getBytesFromDataArray(bytes, data) {
55
+ try {
56
+ const hasher = blake3.create({ dkLen: bytes });
57
+ for (const chunk of data) hasher.update(chunk);
58
+ return hasher.digest();
59
+ } catch (error) {
60
+ throw new Error("Failed to get bytes from data", { cause: error });
61
+ }
62
+ }
63
+ /**
64
+ * Hashes the given array of data using blake3 algorithm
65
+ *
66
+ * @param bytes - The desired output byte-length
67
+ * @param data - The data to hash
68
+ * @returns The resulting hash value
69
+ */
70
+ function getBytesFromDataArrayHex(bytes, data) {
71
+ try {
72
+ return bytesToHex(getBytesFromDataArray(bytes, data));
73
+ } catch (error) {
74
+ throw new Error("Failed to get bytes from data", { cause: error });
75
+ }
76
+ }
77
+ /**
78
+ * Hashes the given string using blake3 algorithm
79
+ *
80
+ * @param bytes - The desired output byte-length
81
+ * @param data - The data to hash
82
+ * @returns The resulting hash value
83
+ */
84
+ function getBytesFromData(bytes, data) {
85
+ return blake3(data, { dkLen: bytes });
86
+ }
87
+ /**
88
+ * Hashes the given data using blake3 algorithm
89
+ *
90
+ * @param bytes - The desired output byte-length
91
+ * @param data - The data to hash
92
+ * @returns The resulting hash value
93
+ */
94
+ function getBytesFromDataHex(bytes, data) {
95
+ return bytesToHex(getBytesFromData(bytes, data));
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/hash/mac.ts
100
+ /**
101
+ * Computes mac for the given key material and data
102
+ *
103
+ * @param keyMaterial - The key material
104
+ * @param data - The data to hash
105
+ * @returns The resulting hash hex string
106
+ */
107
+ function computeMac(keyMaterial, data) {
108
+ try {
109
+ return bytesToHex(hashDataArrayWithKey(getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial), data));
110
+ } catch (error) {
111
+ throw new Error("Failed to compute mac", { cause: error });
112
+ }
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/hash/index.ts
117
+ var hash_exports = /* @__PURE__ */ __exportAll({
118
+ computeMac: () => computeMac,
119
+ getBytesFromData: () => getBytesFromData,
120
+ getBytesFromDataArray: () => getBytesFromDataArray,
121
+ getBytesFromDataArrayHex: () => getBytesFromDataArrayHex,
122
+ getBytesFromDataHex: () => getBytesFromDataHex,
123
+ hashDataArray: () => hashDataArray,
124
+ hashDataArrayHex: () => hashDataArrayHex,
125
+ hashDataArrayWithKey: () => hashDataArrayWithKey,
126
+ hashDataArrayWithKeyHex: () => hashDataArrayWithKeyHex
127
+ });
128
+
129
+ //#endregion
130
+ export { getBytesFromDataArrayHex as a, hashDataArrayHex as c, getBytesFromDataArray as i, hashDataArrayWithKey as l, computeMac as n, getBytesFromDataHex as o, getBytesFromData as r, hashDataArray as s, hash_exports as t, hashDataArrayWithKeyHex as u };
131
+ //# sourceMappingURL=hash-CXeGAwai.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-CXeGAwai.mjs","names":[],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts","../src/hash/index.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash array\n */\nexport function hashDataArray(data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create();\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function hashDataArrayHex(data: Uint8Array[]): string {\n return bytesToHex(hashDataArray(data));\n}\n\nexport function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = hashDataArrayWithKey(hashKey, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute hash hex', { cause: error });\n }\n}\n\nexport function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ key: hashKey });\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ dkLen: bytes });\n for (const chunk of data) {\n hasher.update(chunk);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromDataArray(bytes, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given string using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n\n/**\n * Hashes the given data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataHex(bytes: number, data: Uint8Array): string {\n return bytesToHex(getBytesFromData(bytes, data));\n}\n","import { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromData, hashDataArrayWithKey } from './blake3';\n\n/**\n * Computes mac for the given key material and data\n *\n * @param keyMaterial - The key material\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string {\n try {\n const key = getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = hashDataArrayWithKey(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n","export * from './blake3';\nexport * from './mac';\n"],"mappings":";;;;;;;;;;;;AASA,SAAgB,cAAc,MAAgC;AAC5D,KAAI;EACF,MAAM,SAAS,OAAO,QAAQ;AAC9B,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/D,S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AAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
@@ -0,0 +1,65 @@
1
+ //#region src/hash/blake3.d.ts
2
+ /**
3
+ * Hashes the given array of data
4
+ *
5
+ * @param data - The data to hash
6
+ * @returns The resulting hash array
7
+ */
8
+ declare function hashDataArray(data: Uint8Array[]): Uint8Array;
9
+ /**
10
+ * Hashes the given array of data
11
+ *
12
+ * @param data - The data to hash
13
+ * @returns The resulting hash hex string
14
+ */
15
+ declare function hashDataArrayHex(data: Uint8Array[]): string;
16
+ declare function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string;
17
+ declare function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array;
18
+ /**
19
+ * Hashes the given array of data using blake3 algorithm
20
+ *
21
+ * @param bytes - The desired output byte-length
22
+ * @param data - The data to hash
23
+ * @returns The resulting hash value
24
+ */
25
+ declare function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array;
26
+ /**
27
+ * Hashes the given array of data using blake3 algorithm
28
+ *
29
+ * @param bytes - The desired output byte-length
30
+ * @param data - The data to hash
31
+ * @returns The resulting hash value
32
+ */
33
+ declare function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string;
34
+ /**
35
+ * Hashes the given string using blake3 algorithm
36
+ *
37
+ * @param bytes - The desired output byte-length
38
+ * @param data - The data to hash
39
+ * @returns The resulting hash value
40
+ */
41
+ declare function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array;
42
+ /**
43
+ * Hashes the given data using blake3 algorithm
44
+ *
45
+ * @param bytes - The desired output byte-length
46
+ * @param data - The data to hash
47
+ * @returns The resulting hash value
48
+ */
49
+ declare function getBytesFromDataHex(bytes: number, data: Uint8Array): string;
50
+ //#endregion
51
+ //#region src/hash/mac.d.ts
52
+ /**
53
+ * Computes mac for the given key material and data
54
+ *
55
+ * @param keyMaterial - The key material
56
+ * @param data - The data to hash
57
+ * @returns The resulting hash hex string
58
+ */
59
+ declare function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string;
60
+ declare namespace index_d_exports {
61
+ export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex };
62
+ }
63
+ //#endregion
64
+ export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex, index_d_exports as t };
65
+ //# sourceMappingURL=hash.d.mts.map
package/dist/hash.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ //#region src/hash/blake3.d.ts
2
+ /**
3
+ * Hashes the given array of data
4
+ *
5
+ * @param data - The data to hash
6
+ * @returns The resulting hash array
7
+ */
8
+ declare function hashDataArray(data: Uint8Array[]): Uint8Array;
9
+ /**
10
+ * Hashes the given array of data
11
+ *
12
+ * @param data - The data to hash
13
+ * @returns The resulting hash hex string
14
+ */
15
+ declare function hashDataArrayHex(data: Uint8Array[]): string;
16
+ declare function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string;
17
+ declare function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array;
18
+ /**
19
+ * Hashes the given array of data using blake3 algorithm
20
+ *
21
+ * @param bytes - The desired output byte-length
22
+ * @param data - The data to hash
23
+ * @returns The resulting hash value
24
+ */
25
+ declare function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array;
26
+ /**
27
+ * Hashes the given array of data using blake3 algorithm
28
+ *
29
+ * @param bytes - The desired output byte-length
30
+ * @param data - The data to hash
31
+ * @returns The resulting hash value
32
+ */
33
+ declare function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string;
34
+ /**
35
+ * Hashes the given string using blake3 algorithm
36
+ *
37
+ * @param bytes - The desired output byte-length
38
+ * @param data - The data to hash
39
+ * @returns The resulting hash value
40
+ */
41
+ declare function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array;
42
+ /**
43
+ * Hashes the given data using blake3 algorithm
44
+ *
45
+ * @param bytes - The desired output byte-length
46
+ * @param data - The data to hash
47
+ * @returns The resulting hash value
48
+ */
49
+ declare function getBytesFromDataHex(bytes: number, data: Uint8Array): string;
50
+ //#endregion
51
+ //#region src/hash/mac.d.ts
52
+ /**
53
+ * Computes mac for the given key material and data
54
+ *
55
+ * @param keyMaterial - The key material
56
+ * @param data - The data to hash
57
+ * @returns The resulting hash hex string
58
+ */
59
+ declare function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string;
60
+ declare namespace index_d_exports {
61
+ export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex };
62
+ }
63
+ //#endregion
64
+ export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex, index_d_exports as t };
65
+ //# sourceMappingURL=hash.d.ts.map
package/dist/hash.js ADDED
@@ -0,0 +1,11 @@
1
+ const require_hash = require('./hash-BoqwNkcd.js');
2
+
3
+ exports.computeMac = require_hash.computeMac;
4
+ exports.getBytesFromData = require_hash.getBytesFromData;
5
+ exports.getBytesFromDataArray = require_hash.getBytesFromDataArray;
6
+ exports.getBytesFromDataArrayHex = require_hash.getBytesFromDataArrayHex;
7
+ exports.getBytesFromDataHex = require_hash.getBytesFromDataHex;
8
+ exports.hashDataArray = require_hash.hashDataArray;
9
+ exports.hashDataArrayHex = require_hash.hashDataArrayHex;
10
+ exports.hashDataArrayWithKey = require_hash.hashDataArrayWithKey;
11
+ exports.hashDataArrayWithKeyHex = require_hash.hashDataArrayWithKeyHex;
package/dist/hash.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { a as getBytesFromDataArrayHex, c as hashDataArrayHex, i as getBytesFromDataArray, l as hashDataArrayWithKey, n as computeMac, o as getBytesFromDataHex, r as getBytesFromData, s as hashDataArray, u as hashDataArrayWithKeyHex } from "./hash-CXeGAwai.mjs";
2
+
3
+ export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex };
@@ -0,0 +1,50 @@
1
+ declare namespace localStorageService_d_exports {
2
+ export { LocalStorageService, localStorageService as default };
3
+ }
4
+ declare function get$1(key: string): string | null;
5
+ declare function set$1(key: string, value: string): void;
6
+ declare function removeItem$1(key: string): void;
7
+ declare function exists$1(key: string): boolean;
8
+ declare function clear$1(): void;
9
+ declare const localStorageService: {
10
+ set: typeof set$1;
11
+ get: typeof get$1;
12
+ removeItem: typeof removeItem$1;
13
+ exists: typeof exists$1;
14
+ clear: typeof clear$1;
15
+ };
16
+ interface LocalStorageService {
17
+ set: (key: string, value: string) => void;
18
+ get: (key: string) => string | null;
19
+ removeItem: (key: string) => void;
20
+ exists: (key: string) => boolean;
21
+ clear: () => void;
22
+ }
23
+ declare namespace sessionStorageService_d_exports {
24
+ export { SessionStorageService, sessionStorageService as default };
25
+ }
26
+ declare function get(key: string): string | null;
27
+ declare function set(key: string, value: string): void;
28
+ declare function removeItem(key: string): void;
29
+ declare function exists(key: string): boolean;
30
+ declare function clear(): void;
31
+ declare const sessionStorageService: {
32
+ set: typeof set;
33
+ get: typeof get;
34
+ removeItem: typeof removeItem;
35
+ exists: typeof exists;
36
+ clear: typeof clear;
37
+ };
38
+ interface SessionStorageService {
39
+ set: (key: string, value: string) => void;
40
+ get: (key: string) => string | null;
41
+ removeItem: (key: string) => void;
42
+ exists: (key: string) => boolean;
43
+ clear: () => void;
44
+ }
45
+ declare namespace index_d_exports {
46
+ export { localStorageService_d_exports as localStorageService, sessionStorageService_d_exports as sessionStorageService };
47
+ }
48
+ //#endregion
49
+ export { sessionStorageService_d_exports as n, localStorageService_d_exports as r, index_d_exports as t };
50
+ //# sourceMappingURL=index-CQqgKsbX.d.ts.map