cipher-kit 2.1.1 → 2.1.2

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 (39) hide show
  1. package/dist/{chunk-LTVOIZP5.cjs → chunk-66WIL32E.cjs} +145 -150
  2. package/dist/chunk-66WIL32E.cjs.map +1 -0
  3. package/dist/{chunk-X4CS7UXE.cjs → chunk-HTRGOBZF.cjs} +10 -2
  4. package/dist/chunk-HTRGOBZF.cjs.map +1 -0
  5. package/dist/{chunk-FSEA3UXJ.js → chunk-JLFVTZY4.js} +4 -8
  6. package/dist/chunk-JLFVTZY4.js.map +1 -0
  7. package/dist/{chunk-6C4NIWQ4.js → chunk-LU7QOSQH.js} +9 -3
  8. package/dist/chunk-LU7QOSQH.js.map +1 -0
  9. package/dist/{chunk-PWTFVMW6.js → chunk-S6SNCTU6.js} +4 -8
  10. package/dist/chunk-S6SNCTU6.js.map +1 -0
  11. package/dist/{chunk-56PVVFVM.cjs → chunk-ZNM5M6RD.cjs} +140 -145
  12. package/dist/chunk-ZNM5M6RD.cjs.map +1 -0
  13. package/dist/{export-DUgIcobC.d.ts → export-BaM_OTFk.d.ts} +13 -31
  14. package/dist/{export-C4DbO5zM.d.ts → export-CCTGAosO.d.ts} +13 -31
  15. package/dist/{export-CpZ7s25O.d.cts → export-FYHgb-8E.d.cts} +13 -31
  16. package/dist/{export-DO9n7Np-.d.cts → export-KFT0YyMg.d.cts} +13 -31
  17. package/dist/index.cjs +19 -11
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +3 -3
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +3 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/node.cjs +35 -35
  24. package/dist/node.d.cts +2 -2
  25. package/dist/node.d.ts +2 -2
  26. package/dist/node.js +2 -2
  27. package/dist/{validate-cJEdGlj1.d.cts → validate-lkJAHCeJ.d.cts} +39 -11
  28. package/dist/{validate-cJEdGlj1.d.ts → validate-lkJAHCeJ.d.ts} +39 -11
  29. package/dist/web-api.cjs +35 -35
  30. package/dist/web-api.d.cts +2 -2
  31. package/dist/web-api.d.ts +2 -2
  32. package/dist/web-api.js +2 -2
  33. package/package.json +1 -1
  34. package/dist/chunk-56PVVFVM.cjs.map +0 -1
  35. package/dist/chunk-6C4NIWQ4.js.map +0 -1
  36. package/dist/chunk-FSEA3UXJ.js.map +0 -1
  37. package/dist/chunk-LTVOIZP5.cjs.map +0 -1
  38. package/dist/chunk-PWTFVMW6.js.map +0 -1
  39. package/dist/chunk-X4CS7UXE.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/web/kit.ts","../src/web/web-encode.ts","../src/web/web-encrypt.ts"],"names":["__export","$isStr","$err","ENCODING","$ok","$fmtError","title","$isPlainObj","ENCRYPTION_ALGORITHMS","DIGEST_ALGORITHMS","CIPHER_ENCODING","$isSecretKey","$fmtResultErr","error","matchEncryptedPattern","$stringifyObj","$parseToObj"],"mappings":";;;;;AAAA,IAAA,WAAA,GAAA;AAAAA,0BAAA,CAAA,WAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,eAAA,EAAA,MAAA,eAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,eAAA,EAAA,MAAA,eAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,IAAA,EAAA,MAAA,IAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,oBAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,oBAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBA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B,MAAM,cAAc,CAAA;AAChD;AAqBO,SAAS,iBAAA,CAAkB,IAAA,EAAgC,cAAA,GAA2B,MAAA,EAAgB;AAC3G,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAM,GAAI,kBAAA,CAAmB,MAAM,cAAc,CAAA;AACjE,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAMA,+BAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT;AAuBO,SAAS,kBAAA,CAAmB,IAAA,EAAc,IAAA,EAAgB,EAAA,EAA8B;AAC7F,EAAA,OAAO,gBAAA,CAAiB,IAAA,EAAM,IAAA,EAAM,EAAE,CAAA;AACxC;AAqBO,SAAS,eAAA,CAAgB,IAAA,EAAc,IAAA,EAAgB,EAAA,EAAsB;AAClF,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,KAAU,gBAAA,CAAiB,IAAA,EAAM,MAAM,EAAE,CAAA;AACzD,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAMA,+BAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT","file":"chunk-66WIL32E.cjs","sourcesContent":["import { $fmtResultErr, type Result } from \"~/helpers/error\";\r\nimport type {\r\n CreateSecretKeyOptions,\r\n DecryptOptions,\r\n Encoding,\r\n EncryptOptions,\r\n HashOptions,\r\n HashPasswordOptions,\r\n VerifyPasswordOptions,\r\n WebSecretKey,\r\n} from \"~/helpers/types\";\r\nimport { $isSecretKey } from \"~/helpers/validate\";\r\nimport { $convertBytesToStr, $convertEncoding, $convertStrToBytes } from \"./web-encode\";\r\nimport {\r\n $createSecretKey,\r\n $decrypt,\r\n $decryptObj,\r\n $encrypt,\r\n $encryptObj,\r\n $generateUuid,\r\n $hash,\r\n $hashPassword,\r\n $verifyPassword,\r\n} from \"./web-encrypt\";\r\n\r\n/**\r\n * Safely generates a UUID (v4) (non-throwing).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It's like giving your pet a name tag with a super random name made of numbers and letters.\r\n * The chance of two pets getting the same name tag is practically zero, and it's very hard to guess!\r\n *\r\n * @returns A `Result` containing the UUID string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryGenerateUuid();\r\n *\r\n * if (success) console.log(result); // \"...\" (a UUID string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryGenerateUuid(): Result<string> {\r\n return $generateUuid();\r\n}\r\n\r\n/**\r\n * Generates a UUID (v4) (throwing).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It's like giving your pet a name tag with a super random name made of numbers and letters.\r\n * The chance of two pets getting the same name tag is practically zero, and it's very hard to guess!\r\n *\r\n * @returns A UUID string.\r\n * @throws {Error} If UUID generation fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const uuid = generateUuid(); // \"...\" (a UUID string)\r\n * ```\r\n */\r\nexport function generateUuid(): string {\r\n const { result, error } = $generateUuid();\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely derives a `SecretKey` from the provided string for encryption/decryption (non-throwing).\r\n *\r\n * Uses HKDF to derive a key from the input string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you want to create a special key for future use to lock your treasure box (data).\r\n * So, you stir in some secret ingredients (like salt and info) to make sure your key is one-of-a-kind.\r\n *\r\n * @param secret - The input string to derive the `SecretKey` from, must be at least 8 characters.\r\n * @param options.algorithm - The encryption algorithm to use (default: `'aes256gcm'`).\r\n * @param options.digest - The hash algorithm for HKDF (default: `'sha256'`).\r\n * @param options.salt - A salt string (default: `'cipher-kit-salt'`, must be ≥ 8 chars).\r\n * @param options.info - An info string (default: `'cipher-kit'`).\r\n * @returns A `Result` promise containing the derived `SecretKey` or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = await tryCreateSecretKey(\"my-secret\");\r\n *\r\n * if (success) console.log(result); // SecretKey object\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryCreateSecretKey(\r\n secret: string,\r\n options: CreateSecretKeyOptions = {},\r\n): Promise<Result<{ result: WebSecretKey }>> {\r\n return await $createSecretKey(secret, options);\r\n}\r\n\r\n/**\r\n * Derives a `SecretKey` from the provided string for encryption/decryption (throwing).\r\n *\r\n * Uses HKDF to derive a key from the input string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you want to create a special key for future use to lock your treasure box (data).\r\n * So, you stir in some secret ingredients (like salt and info) to make sure your key is one-of-a-kind.\r\n *\r\n * @param secret - The input string to derive the `SecretKey` from, must be at least 8 characters.\r\n * @param options.algorithm - The encryption algorithm to use (default: `'aes256gcm'`).\r\n * @param options.digest - The hash algorithm for HKDF (default: `'sha256'`).\r\n * @param options.salt - A salt string (default: `'cipher-kit-salt'`, must be ≥ 8 chars).\r\n * @param options.info - An info string (default: `'cipher-kit'`).\r\n * @returns A promise of the derived `SecretKey`.\r\n * @throws {Error} If key derivation fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\"); // SecretKey object\r\n * ```\r\n */\r\nexport async function createSecretKey(secret: string, options: CreateSecretKeyOptions = {}): Promise<WebSecretKey> {\r\n const { result, error } = await $createSecretKey(secret, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely encrypts a UTF-8 string using the provided `SecretKey` (non-throwing).\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You scramble a secret message with your special key,\r\n * creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @param data - A UTF-8 string to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A `Result` promise containing the encrypted string in the specified format or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const {result, error, success} = await tryEncrypt(\"Hello, World!\", secretKey);\r\n *\r\n * if (success) console.log(result); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryEncrypt(\r\n data: string,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions = {},\r\n): Promise<Result<string>> {\r\n return await $encrypt(data, secretKey, options);\r\n}\r\n\r\n/**\r\n * Encrypts a UTF-8 string using the provided `SecretKey` (throwing).\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You scramble a secret message with your special key,\r\n * creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @param data - A UTF-8 string to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A promise with the encrypted string in the specified format.\r\n * @throws {Error} If the input data or key is invalid, or if encryption fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encrypt(\"Hello, World!\", secretKey); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * ```\r\n */\r\nexport async function encrypt(data: string, secretKey: WebSecretKey, options: EncryptOptions = {}): Promise<string> {\r\n const { result, error } = await $encrypt(data, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely decrypts the input string using the provided `SecretKey` (non-throwing).\r\n *\r\n * Expects input in the format \"iv.cipherWithTag.\" and returns the decrypted UTF-8 string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You take a scrambled secret message and use your special key to unscramble it,\r\n * revealing the original message inside.\r\n *\r\n * @param encrypted - The input string to decrypt, in the format \"iv.cipherWithTag.\".\r\n * @param secretKey - The `SecretKey` object used for decryption.\r\n * @param options.inputEncoding - The encoding format for the input ciphertext (default: `'base64url'`).\r\n * @returns A `Result` promise containing the decrypted UTF-8 string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encrypt(\"Hello, World!\", secretKey);\r\n * const {result, error, success} = await tryDecrypt(encrypted, secretKey);\r\n *\r\n * if (success) console.log(result); // \"Hello, World!\"\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryDecrypt(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<Result<string>> {\r\n return await $decrypt(encrypted, secretKey, options);\r\n}\r\n\r\n/**\r\n * Decrypts the input string using the provided `SecretKey` (throwing).\r\n *\r\n * Expects input in the format \"iv.cipherWithTag.\" and returns the decrypted UTF-8 string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You take a scrambled secret message and use your special key to unscramble it,\r\n * revealing the original message inside.\r\n *\r\n * @param encrypted - The input string to decrypt, in the format \"iv.cipherWithTag.\".\r\n * @param secretKey - The `SecretKey` object used for decryption.\r\n * @param options.inputEncoding - The encoding format for the input ciphertext (default: `'base64url'`).\r\n * @returns A promise with the decrypted UTF-8 string.\r\n * @throws {Error} If the input data or key is invalid, or if decryption fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encrypt(\"Hello, World!\", secretKey);\r\n * const decrypted = await decrypt(encrypted, secretKey); // \"Hello, World!\"\r\n * ```\r\n */\r\nexport async function decrypt(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<string> {\r\n const { result, error } = await $decrypt(encrypted, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely encrypts a plain object using the provided `SecretKey` (non-throwing).\r\n *\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you have a toy box (an object) that you want to keep secret.\r\n * So, you take a picture of your toy box (convert it to JSON), and scramble that with\r\n * your special key, creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @template T - The type of the plain object to encrypt.\r\n * @param obj - A plain object to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A `Result` promise containing the encrypted string in the specified format or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const {result, error, success} = await tryEncryptObj({ a: 1 }, secretKey);\r\n *\r\n * if (success) console.log(result); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryEncryptObj<T extends object = Record<string, unknown>>(\r\n obj: T,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions = {},\r\n): Promise<Result<string>> {\r\n return await $encryptObj(obj, secretKey, options);\r\n}\r\n\r\n/**\r\n * Encrypts a plain object using the provided `SecretKey` (throwing).\r\n *\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you have a toy box (an object) that you want to keep secret.\r\n * So, you take a picture of your toy box (convert it to JSON), and scramble that with\r\n * your special key, creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @template T - The type of the plain object to encrypt.\r\n * @param obj - A plain object to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A promise with the encrypted string in the specified format.\r\n * @throws {Error} If the input data or key is invalid, or if encryption fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encryptObj({ a: 1 }, secretKey); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * ```\r\n */\r\nexport async function encryptObj<T extends object = Record<string, unknown>>(\r\n obj: T,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions = {},\r\n): Promise<string> {\r\n const { result, error } = await $encryptObj(obj, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely decrypts an encrypted JSON string into a plain object (non-throwing).\r\n *\r\n * Expects input in the format `\"iv.cipherWithTag.\"` and returns a plain object.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) by unscrambling the jumbled code (encrypted text),\r\n * using your special key to open it.\r\n *\r\n * @template T - The expected shape of the decrypted object.\r\n * @param encrypted - The encrypted string (format: `\"iv.cipherWithTag.\"`).\r\n * @param secretKey - The `SecretKey` used for decryption.\r\n * @param options.inputEncoding - Input ciphertext encoding (default: `'base64url'`).\r\n * @returns A `Result` promise with the decrypted object on success, or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encryptObj({ a: 1 }, secretKey);\r\n * const {result, error, success} = await tryDecryptObj<{ a: number }>(encrypted, secretKey);\r\n *\r\n * if (success) console.log(result); // { a: 1 }\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryDecryptObj<T extends object = Record<string, unknown>>(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<Result<{ result: T }>> {\r\n return await $decryptObj<T>(encrypted, secretKey, options);\r\n}\r\n\r\n/**\r\n * Decrypts an encrypted JSON string into a plain object (throwing).\r\n *\r\n * Expects input in the format `\"iv.cipherWithTag.\"` and returns a plain object.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) by unscrambling the jumbled code (encrypted text),\r\n * using your special key to open it.\r\n *\r\n * @template T - The expected shape of the decrypted object.\r\n * @param encrypted - The encrypted string (format: `\"iv.cipherWithTag.\"`).\r\n * @param secretKey - The `SecretKey` used for decryption.\r\n * @param options.inputEncoding - Input ciphertext encoding (default: `'base64url'`).\r\n * @returns A promise with the decrypted object.\r\n * @throws {Error} If decryption or JSON parsing fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encryptObj({ a: 1 }, secretKey);\r\n * const obj = await decryptObj<{ a: number }>(encrypted, secretKey); // obj.a === 1\r\n * ```\r\n */\r\nexport async function decryptObj<T extends object = Record<string, unknown>>(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<T> {\r\n const { result, error } = await $decryptObj<T>(encrypted, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely hashes a UTF-8 string (non-throwing).\r\n *\r\n * Uses the selected digest (default: `'sha256'`) and returns the hash\r\n * in the chosen encoding (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Like putting something in a blender and getting a smoothie, you can’t get the original ingredients back,\r\n * but the smoothie is always the same if you use the same ingredients.\r\n *\r\n * @param data - The input string to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`, default: `'sha256'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`, default: `'base64url'`).\r\n * @returns A `Result` promise with the hash string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = await tryHash(\"my data\");\r\n *\r\n * if (success) console.log(result); // \"...\" (Hashed string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryHash(data: string, options: HashOptions = {}): Promise<Result<string>> {\r\n return await $hash(data, options);\r\n}\r\n\r\n/**\r\n * Hashes a UTF-8 string (throwing).\r\n *\r\n * Uses the selected digest (default: `'sha256'`) and returns the hash\r\n * in the chosen encoding (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Like putting something in a blender and getting a smoothie, you can’t get the original ingredients back,\r\n * but the smoothie is always the same if you use the same ingredients.\r\n *\r\n * @param data - The input string to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`, default: `'sha256'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`, default: `'base64url'`).\r\n * @returns A promise of the hashed string.\r\n * @throws {Error} If input is invalid or hashing fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const hashed = await hash(\"my data\"); // \"...\" (Hashed string)\r\n * ```\r\n */\r\nexport async function hash(data: string, options: HashOptions = {}): Promise<string> {\r\n const { result, error } = await $hash(data, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely hashes a password using PBKDF2 (non-throwing).\r\n *\r\n * Uses strong defaults (`sha512`, 320k iterations, 64-byte key, 16-byte salt) and\r\n * returns `{ hash, salt }` encoded (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * We take your password, mix in some random salt, and stir many times.\r\n * The result is a super-secret soup that’s hard to copy.\r\n *\r\n * @param password - The password to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).\r\n * @param options.saltLength - Length of the random salt in bytes (default: `16` bytes, min: `8` bytes).\r\n * @param options.iterations - Number of iterations (default: `320000`, min: `1000`).\r\n * @param options.keyLength - Length of the derived key in bytes (default: `64` bytes, min: `16` bytes).\r\n * @returns A `Result` promise with `{ result, salt }` or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = await tryHashPassword(\"my-password\");\r\n *\r\n * if (success) console.log(result, salt); // \"...\" (hashed password), \"...\" (salt)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryHashPassword(\r\n password: string,\r\n options: HashPasswordOptions = {},\r\n): Promise<Result<{ result: string; salt: string }>> {\r\n return await $hashPassword(password, options);\r\n}\r\n\r\n/**\r\n * Hashes a password using PBKDF2 (throwing).\r\n *\r\n * Uses strong defaults (`sha512`, 320k iterations, 64-byte key, 16-byte salt) and\r\n * returns `{ hash, salt }` encoded (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * We take your password, mix in some random salt, and stir many times.\r\n * The result is a super-secret soup that’s hard to copy.\r\n *\r\n * @param password - The password to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).\r\n * @param options.saltLength - Length of the random salt in bytes (default: `16` bytes, min: `8` bytes).\r\n * @param options.iterations - Number of iterations (default: `320000`, min: `1000`).\r\n * @param options.keyLength - Length of the derived key in bytes (default: `64` bytes, min: `16` bytes).\r\n * @returns A promise with `{ result, salt }` for storage.\r\n * @throws {Error} If inputs are invalid or hashing fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, salt} = await hashPassword(\"my-password\"); // \"...\" (hashed password), \"...\" (salt)\r\n * ```\r\n */\r\nexport async function hashPassword(\r\n password: string,\r\n options: HashPasswordOptions = {},\r\n): Promise<{ result: string; salt: string }> {\r\n const { result, salt, error } = await $hashPassword(password, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return { result, salt };\r\n}\r\n\r\n/**\r\n * Verifies a password against a stored PBKDF2 hash (non-throwing).\r\n *\r\n * Re-derives the key using the same parameters and compares in constant time, to prevent timing attacks.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * We follow the same recipe as when we made the secret.\r\n * If the new soup tastes exactly the same, the password is correct.\r\n *\r\n * @param password - The plain password to verify.\r\n * @param hashedPassword - The stored hash (encoded).\r\n * @param salt - The stored salt (encoded).\r\n * @param options.digest - Hash algorithm used during hashing (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).\r\n * @param options.inputEncoding - Encoding of the stored hash and salt (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).\r\n * @param options.iterations - Number of iterations used during hashing (default: `320000`).\r\n * @param options.keyLength - Length of the derived key in bytes used during hashing (default: `64` bytes).\r\n * @returns A promise of boolean, `true` if the password matches, otherwise `false`.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, salt} = await hashPassword(\"my-password\");\r\n *\r\n * await verifyPassword(\"my-password\", result, salt); // true\r\n * await verifyPassword(\"wrong-password\", result, salt); // false\r\n * ```\r\n */\r\nexport async function verifyPassword(\r\n password: string,\r\n hashedPassword: string,\r\n salt: string,\r\n options: VerifyPasswordOptions = {},\r\n): Promise<boolean> {\r\n return await $verifyPassword(password, hashedPassword, salt, options);\r\n}\r\n\r\n/**\r\n * Safely converts a string to a `Uint8Array` using the specified encoding (non-throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns your words into tiny computer building blocks (bytes) so computers can work with them.\r\n *\r\n * @param data - The input string to convert.\r\n * @param inputEncoding - The encoding of the input string (default: `'utf8'`).\r\n * @returns A `Result` with `{ result: Uint8Array }` or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryConvertStrToBytes(\"Hello\", \"utf8\");\r\n *\r\n * if (success) console.log(result); // Uint8Array([...])\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryConvertStrToBytes(\r\n data: string,\r\n inputEncoding: Encoding = \"utf8\",\r\n): Result<{ result: Uint8Array<ArrayBuffer> }> {\r\n return $convertStrToBytes(data, inputEncoding);\r\n}\r\n\r\n/**\r\n * Converts a string to a `Uint8Array` using the specified encoding (throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns your words into tiny computer building blocks (bytes) so computers can work with them.\r\n *\r\n * @param data - The input string to convert.\r\n * @param inputEncoding - The encoding of the input string (default: `'utf8'`).\r\n * @returns A `Uint8Array` containing the bytes.\r\n * @throws {Error} If input is invalid or conversion fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const bytes = convertStrToBytes(\"Hello\", \"utf8\"); // Uint8Array([...])\r\n * ```\r\n */\r\nexport function convertStrToBytes(data: string, inputEncoding: Encoding = \"utf8\"): Uint8Array<ArrayBuffer> {\r\n const { result, error } = $convertStrToBytes(data, inputEncoding);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely converts a `Uint8Array` or `ArrayBuffer` to a string using the specified encoding (non-throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns the tiny computer building blocks (bytes) back into a readable sentence.\r\n *\r\n * @param data - The `Uint8Array` or `ArrayBuffer` to convert.\r\n * @param outputEncoding - The output encoding (default: `'utf8'`).\r\n * @returns A `Result` with the string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const bytes = convertStrToBytes(\"Hello\", \"utf8\"); // Uint8Array([...])\r\n * const {result, error, success} = tryConvertBytesToStr(bytes, \"utf8\");\r\n *\r\n * if (success) console.log(result); // \"Hello\"\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryConvertBytesToStr(\r\n data: Uint8Array | ArrayBuffer,\r\n outputEncoding: Encoding = \"utf8\",\r\n): Result<string> {\r\n return $convertBytesToStr(data, outputEncoding);\r\n}\r\n\r\n/**\r\n * Converts a `Uint8Array` or `ArrayBuffer` to a string using the specified encoding (throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns the tiny computer building blocks (bytes) back into a readable sentence.\r\n *\r\n * @param data - The `Uint8Array` or `ArrayBuffer` to convert.\r\n * @param outputEncoding - The output encoding (default: `'utf8'`).\r\n * @returns The encoded string.\r\n * @throws {Error} If input is invalid or conversion fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const bytes = convertStrToBytes(\"Hello\", \"utf8\"); // Uint8Array([...])\r\n * const str = convertBytesToStr(bytes, \"utf8\"); // \"Hello\"\r\n * ```\r\n */\r\nexport function convertBytesToStr(data: Uint8Array | ArrayBuffer, outputEncoding: Encoding = \"utf8\"): string {\r\n const { result, error } = $convertBytesToStr(data, outputEncoding);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely converts text between encodings (non-throwing).\r\n *\r\n * Example: convert `'utf8'` text to `'base64url'`, or `'hex'` to `'utf8'`.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It’s like translating your sentence from one alphabet to another.\r\n *\r\n * @param data - The input string to convert.\r\n * @param from - The current encoding of `data`.\r\n * @param to - The target encoding for `data`.\r\n * @returns A `Result` with a string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryConvertEncoding(\"Hello\", \"utf8\", \"base64url\");\r\n *\r\n * if (success) console.log(result); // \"...\" (Base64url encoded string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryConvertEncoding(data: string, from: Encoding, to: Encoding): Result<string> {\r\n return $convertEncoding(data, from, to);\r\n}\r\n\r\n/**\r\n * Converts text between encodings (throwing).\r\n *\r\n * Example: convert `'utf8'` text to `'base64url'`, or `'hex'` to `'utf8'`.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It’s like translating your sentence from one alphabet to another.\r\n *\r\n * @param data - The input string to convert.\r\n * @param from - The current encoding of `data`.\r\n * @param to - The target encoding for `data`.\r\n * @returns The converted string.\r\n * @throws {Error} If encodings are invalid or conversion fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const base64url = convertEncoding(\"Hello\", \"utf8\", \"base64url\"); // \"...\" (Base64url encoded string)\r\n * ```\r\n */\r\nexport function convertEncoding(data: string, from: Encoding, to: Encoding): string {\r\n const { result, error } = $convertEncoding(data, from, to);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n","import { ENCODING } from \"~/helpers/consts\";\r\nimport { $err, $fmtError, $ok, type Result } from \"~/helpers/error\";\r\nimport type { Encoding } from \"~/helpers/types\";\r\nimport { $isStr } from \"~/helpers/validate\";\r\n\r\nexport const textEncoder = new TextEncoder();\r\nexport const textDecoder = new TextDecoder();\r\n\r\nexport function $convertStrToBytes(\r\n data: string,\r\n inputEncoding: Encoding = \"utf8\",\r\n): Result<{ result: Uint8Array<ArrayBuffer> }> {\r\n if (!$isStr(data)) {\r\n return $err({\r\n msg: \"Crypto Web API - String to Bytes: Empty data\",\r\n desc: \"Data must be a non-empty string\",\r\n });\r\n }\r\n if (!ENCODING.includes(inputEncoding)) {\r\n return $err({\r\n msg: `Crypto Web API - String to Bytes: Unsupported encoding: ${inputEncoding}`,\r\n desc: \"Use base64, base64url, hex, utf8, or latin1\",\r\n });\r\n }\r\n\r\n try {\r\n const bytes = strToBytes[inputEncoding](data);\r\n return $ok({ result: bytes });\r\n } catch (error) {\r\n return $err({ msg: \"Crypto Web API - String to Bytes: Failed to convert data\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport function $convertBytesToStr(data: Uint8Array | ArrayBuffer, outputEncoding: Encoding = \"utf8\"): Result<string> {\r\n if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) {\r\n return $err({\r\n msg: \"Crypto Web API - Bytes to String: Invalid data type\",\r\n desc: \"Data must be an ArrayBuffer or Uint8Array\",\r\n });\r\n }\r\n if (!ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `Crypto Web API - Bytes to String: Unsupported encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, hex, utf8, or latin1\",\r\n });\r\n }\r\n try {\r\n const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);\r\n const str = bytesToStr[outputEncoding](bytes);\r\n return $ok(str);\r\n } catch (error) {\r\n return $err({ msg: \"Crypto Web API - Bytes to String: Failed to convert data\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport function $convertEncoding(data: string, from: Encoding, to: Encoding): Result<string> {\r\n if (!$isStr(data)) {\r\n return $err({\r\n msg: \"Crypto Web API - Convert Format: Empty data\",\r\n desc: \"Data must be a non-empty string\",\r\n });\r\n }\r\n if (!ENCODING.includes(from) || !ENCODING.includes(to)) {\r\n return $err({\r\n msg: `Crypto Web API - Convert Format: Unsupported encoding: from ${from} to ${to}`,\r\n desc: \"Use base64, base64url, hex, utf8, or latin1\",\r\n });\r\n }\r\n\r\n const bytes = $convertStrToBytes(data, from);\r\n if (bytes.error) return $err({ msg: bytes.error.message, desc: bytes.error.description });\r\n\r\n const str = $convertBytesToStr(bytes.result, to);\r\n if (str.error) return $err({ msg: str.error.message, desc: str.error.description });\r\n\r\n return $ok({ result: str.result });\r\n}\r\n\r\nconst strToBytes = {\r\n base64: $fromBase64,\r\n base64url: $fromBase64Url,\r\n hex: $fromHex,\r\n latin1: $fromLatin1,\r\n utf8: (data: string) => textEncoder.encode(data),\r\n} as const satisfies Record<Encoding, (data: string) => Uint8Array<ArrayBuffer>>;\r\n\r\nconst bytesToStr = {\r\n base64: $toBase64,\r\n base64url: $toBase64Url,\r\n hex: $toHex,\r\n latin1: $toLatin1,\r\n utf8: (data: Uint8Array) => textDecoder.decode(data),\r\n} as const satisfies Record<Encoding, (data: Uint8Array) => string>;\r\n\r\nfunction $toLatin1(bytes: Uint8Array): string {\r\n let out = \"\";\r\n const chunk = 1 << 15; // 32KiB per chunk\r\n for (let i = 0; i < bytes.length; i += chunk) {\r\n out += String.fromCharCode(...bytes.subarray(i, i + chunk));\r\n }\r\n return out;\r\n}\r\n\r\nfunction $fromLatin1(data: string): Uint8Array<ArrayBuffer> {\r\n const out = new Uint8Array(data.length);\r\n for (let i = 0; i < data.length; i++) {\r\n const charCode = data.charCodeAt(i);\r\n if (charCode > 255) throw new Error(\"Invalid latin1 string\");\r\n out[i] = charCode;\r\n }\r\n return out;\r\n}\r\n\r\nfunction $toBase64(bytes: Uint8Array): string {\r\n return btoa($toLatin1(bytes));\r\n}\r\n\r\nfunction $fromBase64(data: string): Uint8Array<ArrayBuffer> {\r\n return $fromLatin1(atob(data));\r\n}\r\n\r\nfunction $toBase64Url(bytes: Uint8Array): string {\r\n return $toBase64(bytes).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\r\n}\r\n\r\nfunction $fromBase64Url(data: string): Uint8Array<ArrayBuffer> {\r\n let base64 = data.replace(/-/g, \"+\").replace(/_/g, \"/\");\r\n const padLen = (4 - (base64.length % 4)) % 4;\r\n base64 += \"=\".repeat(padLen);\r\n return $fromBase64(base64);\r\n}\r\n\r\nfunction $toHex(bytes: Uint8Array): string {\r\n return Array.from(bytes)\r\n .map((b) => b.toString(16).padStart(2, \"0\"))\r\n .join(\"\");\r\n}\r\n\r\nfunction $fromHex(data: string): Uint8Array<ArrayBuffer> {\r\n const clean = data.startsWith(\"0x\") ? data.slice(2) : data;\r\n if (clean.length % 2 !== 0) throw new Error(\"Invalid hex string\");\r\n const out = new Uint8Array(clean.length / 2);\r\n for (let i = 0; i < out.length; i++) {\r\n const byte = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);\r\n if (Number.isNaN(byte)) throw new Error(\"Invalid hex string\");\r\n out[i] = byte;\r\n }\r\n return out;\r\n}\r\n","import { CIPHER_ENCODING, DIGEST_ALGORITHMS, ENCRYPTION_ALGORITHMS } from \"~/helpers/consts\";\r\nimport { $err, $fmtError, $fmtResultErr, $ok, type Result, title } from \"~/helpers/error\";\r\nimport { $parseToObj, $stringifyObj } from \"~/helpers/object\";\r\nimport type {\r\n CreateSecretKeyOptions,\r\n DecryptOptions,\r\n EncryptOptions,\r\n HashOptions,\r\n HashPasswordOptions,\r\n VerifyPasswordOptions,\r\n WebSecretKey,\r\n} from \"~/helpers/types\";\r\nimport { $isPlainObj, $isSecretKey, $isStr, matchEncryptedPattern } from \"~/helpers/validate\";\r\nimport { $convertBytesToStr, $convertStrToBytes, textEncoder } from \"./web-encode\";\r\n\r\nexport function $generateUuid(): Result<string> {\r\n try {\r\n return $ok(crypto.randomUUID());\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"UUID Generation\")}: Failed to generate UUID`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $createSecretKey(\r\n secret: string,\r\n options: CreateSecretKeyOptions,\r\n): Promise<Result<{ result: WebSecretKey }>> {\r\n if (!$isStr(secret, 8)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Empty Secret`,\r\n desc: \"Secret must be a non-empty string with at least 8 characters\",\r\n });\r\n }\r\n\r\n if (!$isPlainObj<CreateSecretKeyOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const algorithm = options.algorithm ?? \"aes256gcm\";\r\n if (!(algorithm in ENCRYPTION_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Unsupported algorithm: ${algorithm}`,\r\n desc: `Supported algorithms are: ${Object.keys(ENCRYPTION_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n\r\n const digest = options.digest ?? \"sha256\";\r\n if (!(digest in DIGEST_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Unsupported digest: ${digest}`,\r\n desc: `Supported digests are: ${Object.keys(DIGEST_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n\r\n const salt = options.salt ?? \"cipher-kit-salt\";\r\n if (!$isStr(salt, 8)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Weak salt`,\r\n desc: \"Salt must be a non-empty string with at least 8 characters\",\r\n });\r\n }\r\n\r\n const info = options.info ?? \"cipher-kit\";\r\n if (!$isStr(info)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Invalid info`,\r\n desc: \"Info must be a non-empty string\",\r\n });\r\n }\r\n\r\n const encryptAlgo = ENCRYPTION_ALGORITHMS[algorithm];\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n try {\r\n const ikm = await crypto.subtle.importKey(\"raw\", textEncoder.encode(secret.normalize(\"NFKC\")), \"HKDF\", false, [\r\n \"deriveKey\",\r\n ]);\r\n const key = await crypto.subtle.deriveKey(\r\n {\r\n name: \"HKDF\",\r\n hash: digestAlgo.web,\r\n salt: textEncoder.encode(salt.normalize(\"NFKC\")),\r\n info: textEncoder.encode(info.normalize(\"NFKC\")),\r\n },\r\n ikm,\r\n { name: encryptAlgo.web, length: encryptAlgo.keyBytes * 8 },\r\n true,\r\n [\"encrypt\", \"decrypt\"],\r\n );\r\n const secretKey = Object.freeze({\r\n platform: \"web\",\r\n digest: digest,\r\n algorithm: algorithm,\r\n key: key,\r\n }) as WebSecretKey;\r\n\r\n return $ok({ result: secretKey });\r\n } catch (error) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Failed to create secret key`,\r\n desc: $fmtError(error),\r\n });\r\n }\r\n}\r\n\r\nexport async function $encrypt(\r\n data: string,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions,\r\n): Promise<Result<string>> {\r\n if (!$isStr(data)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Empty data for encryption`,\r\n desc: \"Data must be a non-empty string\",\r\n });\r\n }\r\n\r\n if (!$isPlainObj<EncryptOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const outputEncoding = options.outputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Unsupported output encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const injectedKey = $isSecretKey(secretKey, \"web\");\r\n if (!injectedKey) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Invalid Secret Key`,\r\n desc: \"Expected a Web SecretKey\",\r\n });\r\n }\r\n\r\n const { result, error } = $convertStrToBytes(data, \"utf8\");\r\n if (error) return $err(error);\r\n\r\n try {\r\n const iv = crypto.getRandomValues(new Uint8Array(injectedKey.injected.ivLength));\r\n const cipherWithTag = await crypto.subtle.encrypt(\r\n { name: injectedKey.injected.web, iv: iv },\r\n injectedKey.key,\r\n result,\r\n );\r\n\r\n const ivStr = $convertBytesToStr(iv, outputEncoding);\r\n const cipherStr = $convertBytesToStr(cipherWithTag, outputEncoding);\r\n\r\n if (ivStr.error || cipherStr.error) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Failed to convert IV or encrypted data`,\r\n desc: `Conversion error: ${$fmtResultErr(ivStr.error || cipherStr.error)}`,\r\n });\r\n }\r\n\r\n return $ok(`${ivStr.result}.${cipherStr.result}.`);\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Encryption\")}: Failed to encrypt data`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $decrypt(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions,\r\n): Promise<Result<string>> {\r\n if (!matchEncryptedPattern(encrypted, \"web\")) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid encrypted data format`,\r\n desc: 'Encrypted data must be in the format \"iv.cipherWithTag.\"',\r\n });\r\n }\r\n\r\n if (!$isPlainObj<DecryptOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const inputEncoding = options.inputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(inputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Unsupported input encoding: ${inputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const [iv, encryptedWithTag] = encrypted.split(\".\", 3);\r\n if (!$isStr(iv) || !$isStr(encryptedWithTag)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid encrypted data`,\r\n desc: \"Encrypted data must contain valid IV, encrypted and tag components\",\r\n });\r\n }\r\n\r\n const injectedKey = $isSecretKey(secretKey, \"web\");\r\n if (!injectedKey) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid Secret Key`,\r\n desc: \"Expected a Web SecretKey\",\r\n });\r\n }\r\n\r\n const ivBytes = $convertStrToBytes(iv, inputEncoding);\r\n const cipherWithTagBytes = $convertStrToBytes(encryptedWithTag, inputEncoding);\r\n\r\n if (ivBytes.error || cipherWithTagBytes.error) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Failed to convert IV or encrypted data`,\r\n desc: `Conversion error: ${$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`,\r\n });\r\n }\r\n\r\n try {\r\n const decrypted = await crypto.subtle.decrypt(\r\n { name: injectedKey.injected.web, iv: ivBytes.result },\r\n injectedKey.key,\r\n cipherWithTagBytes.result,\r\n );\r\n\r\n return $convertBytesToStr(decrypted, \"utf8\");\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Decryption\")}: Failed to decrypt data`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $encryptObj<T extends object = Record<string, unknown>>(\r\n data: T,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions,\r\n): Promise<Result<string>> {\r\n const { result, error } = $stringifyObj(data);\r\n if (error) return $err(error);\r\n return await $encrypt(result, secretKey, options);\r\n}\r\n\r\nexport async function $decryptObj<T extends object = Record<string, unknown>>(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions,\r\n): Promise<Result<{ result: T }>> {\r\n const { result, error } = await $decrypt(encrypted, secretKey, options);\r\n if (error) return $err(error);\r\n return $parseToObj<T>(result);\r\n}\r\n\r\nexport async function $hash(data: string, options: HashOptions): Promise<Result<string>> {\r\n if (!$isStr(data)) {\r\n return $err({ msg: `${title(\"web\", \"Hashing\")}: Empty data for hashing`, desc: \"Data must be a non-empty string\" });\r\n }\r\n\r\n if (!$isPlainObj<HashOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Hashing\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const outputEncoding = options.outputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Hashing\")}: Unsupported output encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const digest = options.digest ?? \"sha256\";\r\n if (!(digest in DIGEST_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Hashing\")}: Unsupported digest: ${digest}`,\r\n desc: `Supported digests are: ${Object.keys(DIGEST_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n const { result, error } = $convertStrToBytes(data, \"utf8\");\r\n if (error) return $err(error);\r\n\r\n try {\r\n const hashed = await crypto.subtle.digest(digestAlgo.web, result);\r\n return $convertBytesToStr(hashed, outputEncoding);\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Hashing\")}: Failed to hash data`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $hashPassword(\r\n password: string,\r\n options: HashPasswordOptions,\r\n): Promise<Result<{ result: string; salt: string }>> {\r\n if (!$isStr(password)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Empty password`,\r\n desc: \"Password must be a non-empty string\",\r\n });\r\n }\r\n\r\n if (!$isPlainObj<HashPasswordOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const digest = options.digest ?? \"sha512\";\r\n if (!(digest in DIGEST_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Unsupported digest: ${digest}`,\r\n desc: `Supported digests are: ${Object.keys(DIGEST_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n const outputEncoding = options.outputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Unsupported output encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const saltLength = options.saltLength ?? 16;\r\n if (typeof saltLength !== \"number\" || saltLength < 8) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Weak salt length`,\r\n desc: \"Salt length must be a number and at least 8 bytes (recommended 16)\",\r\n });\r\n }\r\n\r\n const iterations = options.iterations ?? 320_000;\r\n if (typeof iterations !== \"number\" || iterations < 1000) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Weak iteration count`,\r\n desc: \"Iterations must be a number and at least 1000 (recommended 320,000 or more)\",\r\n });\r\n }\r\n\r\n const keyLength = options.keyLength ?? 64;\r\n if (typeof keyLength !== \"number\" || keyLength < 16) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Weak key length`,\r\n desc: \"Key length must be a number and at least 16 bytes (recommended 64)\",\r\n });\r\n }\r\n\r\n try {\r\n const salt = crypto.getRandomValues(new Uint8Array(saltLength));\r\n const baseKey = await crypto.subtle.importKey(\r\n \"raw\",\r\n textEncoder.encode(password.normalize(\"NFKC\")),\r\n \"PBKDF2\",\r\n false,\r\n [\"deriveBits\"],\r\n );\r\n const bits = await crypto.subtle.deriveBits(\r\n { name: \"PBKDF2\", salt, iterations: iterations, hash: digestAlgo.web },\r\n baseKey,\r\n keyLength * 8,\r\n );\r\n\r\n const saltStr = $convertBytesToStr(salt, outputEncoding);\r\n if (saltStr.error) return $err(saltStr.error);\r\n\r\n const hashedPasswordStr = $convertBytesToStr(bits, outputEncoding);\r\n if (hashedPasswordStr.error) return $err(hashedPasswordStr.error);\r\n\r\n return $ok({ result: hashedPasswordStr.result, salt: saltStr.result });\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Password Hashing\")}: Failed to hash password`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $verifyPassword(\r\n password: string,\r\n hashedPassword: string,\r\n salt: string,\r\n options: VerifyPasswordOptions,\r\n): Promise<boolean> {\r\n if (!$isStr(password) || !$isStr(hashedPassword) || !$isStr(salt) || !$isPlainObj<VerifyPasswordOptions>(options)) {\r\n return false;\r\n }\r\n\r\n const digest = options.digest ?? \"sha512\";\r\n if (!(digest in DIGEST_ALGORITHMS)) return false;\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n const inputEncoding = options.inputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(inputEncoding)) return false;\r\n\r\n const iterations = options.iterations ?? 320_000;\r\n if (typeof iterations !== \"number\" || iterations < 1000) return false;\r\n\r\n const keyLength = options.keyLength ?? 64;\r\n if (typeof keyLength !== \"number\" || keyLength < 16) return false;\r\n\r\n const saltBytes = $convertStrToBytes(salt, inputEncoding);\r\n if (saltBytes.error) return false;\r\n\r\n const hashedPasswordBytes = $convertStrToBytes(hashedPassword, inputEncoding);\r\n if (hashedPasswordBytes.error) return false;\r\n\r\n try {\r\n const baseKey = await crypto.subtle.importKey(\r\n \"raw\",\r\n textEncoder.encode(password.normalize(\"NFKC\")),\r\n \"PBKDF2\",\r\n false,\r\n [\"deriveBits\"],\r\n );\r\n\r\n const bits = new Uint8Array(\r\n await crypto.subtle.deriveBits(\r\n {\r\n name: \"PBKDF2\",\r\n salt: saltBytes.result,\r\n iterations: iterations,\r\n hash: digestAlgo.web,\r\n },\r\n baseKey,\r\n keyLength * 8,\r\n ),\r\n );\r\n\r\n if (bits === undefined || hashedPasswordBytes.result === undefined) return false;\r\n if (bits.length !== hashedPasswordBytes.result.length) return false;\r\n\r\n let diff = 0;\r\n for (let i = 0; i < bits.length; i++) {\r\n diff |= (bits[i] as number) ^ (hashedPasswordBytes.result[i] as number);\r\n }\r\n return diff === 0;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n"]}
@@ -60,6 +60,12 @@ function $isSecretKey(x, platform) {
60
60
  }
61
61
  return Object.freeze({ ...x, injected: algorithm });
62
62
  }
63
+ function isNodeSecretKey(x) {
64
+ return $isSecretKey(x, "node") !== null;
65
+ }
66
+ function isWebSecretKey(x) {
67
+ return $isSecretKey(x, "web") !== null;
68
+ }
63
69
  var ENCRYPTED_REGEX = Object.freeze({
64
70
  node: /^([^.]+)\.([^.]+)\.([^.]+)\.$/,
65
71
  web: /^([^.]+)\.([^.]+)\.$/,
@@ -151,11 +157,13 @@ exports.ENCODING = ENCODING;
151
157
  exports.ENCRYPTED_REGEX = ENCRYPTED_REGEX;
152
158
  exports.ENCRYPTION_ALGORITHMS = ENCRYPTION_ALGORITHMS;
153
159
  exports.__export = __export;
160
+ exports.isNodeSecretKey = isNodeSecretKey;
161
+ exports.isWebSecretKey = isWebSecretKey;
154
162
  exports.matchEncryptedPattern = matchEncryptedPattern;
155
163
  exports.parseToObj = parseToObj;
156
164
  exports.stringifyObj = stringifyObj;
157
165
  exports.title = title;
158
166
  exports.tryParseToObj = tryParseToObj;
159
167
  exports.tryStringifyObj = tryStringifyObj;
160
- //# sourceMappingURL=chunk-X4CS7UXE.cjs.map
161
- //# sourceMappingURL=chunk-X4CS7UXE.cjs.map
168
+ //# sourceMappingURL=chunk-HTRGOBZF.cjs.map
169
+ //# sourceMappingURL=chunk-HTRGOBZF.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/consts.ts","../src/helpers/validate.ts","../src/helpers/error.ts","../src/helpers/object.ts"],"names":["nodeCrypto","title"],"mappings":";;;;;;;;;;;;;;;AAAO,IAAM,QAAA,GAAW,OAAO,MAAA,CAAO,CAAC,UAAU,WAAA,EAAa,KAAA,EAAO,MAAA,EAAQ,QAAQ,CAAU;AAExF,IAAM,kBAAkB,MAAA,CAAO,MAAA,CAAO,CAAC,QAAA,EAAU,WAAA,EAAa,KAAK,CAAU;AAE7E,IAAM,iBAAA,GAAoB,OAAO,MAAA,CAAO;AAAA,EAC7C,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,SAAA,EAAU;AAAA,EACzC,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,SAAA,EAAU;AAAA,EACzC,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,SAAA;AACjC,CAAU;AAEH,IAAM,qBAAA,GAAwB,OAAO,MAAA,CAAO;AAAA,EACjD,SAAA,EAAW,EAAE,QAAA,EAAU,EAAA,EAAI,UAAU,EAAA,EAAI,IAAA,EAAM,aAAA,EAAe,GAAA,EAAK,SAAA,EAAU;AAAA,EAC7E,SAAA,EAAW,EAAE,QAAA,EAAU,EAAA,EAAI,UAAU,EAAA,EAAI,IAAA,EAAM,aAAA,EAAe,GAAA,EAAK,SAAA,EAAU;AAAA,EAC7E,SAAA,EAAW,EAAE,QAAA,EAAU,EAAA,EAAI,UAAU,EAAA,EAAI,IAAA,EAAM,aAAA,EAAe,GAAA,EAAK,SAAA;AACrE,CAAU;;;ACVH,SAAS,MAAA,CAAO,CAAA,EAAY,GAAA,GAAM,CAAA,EAAgB;AACvD,EAAA,OAAO,CAAA,KAAM,IAAA,IAAQ,CAAA,KAAM,MAAA,IAAa,OAAO,MAAM,QAAA,IAAY,CAAA,CAAE,I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AAY,GAAG,CAAA,EAAG;AACrB,MAAA,OAAO,KAAK,EAAE,GAAA,EAAK,6BAAA,EAA+B,IAAA,EAAM,qCAAqC,CAAA;AAAA,IAC/F;AAEA,IAAA,OAAO,GAAA,CAAI,EAAE,MAAA,EAAQ,GAAA,EAAU,CAAA;AAAA,EACjC,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,IAAA,CAAK,EAAE,GAAA,EAAK,sBAAA,EAAwB,MAAM,SAAA,CAAU,KAAK,GAAG,CAAA;AAAA,EACrE;AACF;AAwBO,SAAS,gBAA4D,GAAA,EAAwB;AAClG,EAAA,OAAO,cAAc,GAAG,CAAA;AAC1B;AAsBO,SAAS,aAAyD,GAAA,EAAgB;AACvF,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAM,GAAI,cAAc,GAAG,CAAA;AAC3C,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAM,aAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT;AAsBO,SAAS,cAA0D,GAAA,EAAoC;AAC5G,EAAA,OAAO,YAAe,GAAG,CAAA;AAC3B;AAoBO,SAAS,WAAuD,GAAA,EAAgB;AACrF,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAM,GAAI,YAAe,GAAG,CAAA;AAC5C,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAM,aAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT","file":"chunk-HTRGOBZF.cjs","sourcesContent":["export const ENCODING = Object.freeze([\"base64\", \"base64url\", \"hex\", \"utf8\", \"latin1\"] as const);\r\n\r\nexport const CIPHER_ENCODING = Object.freeze([\"base64\", \"base64url\", \"hex\"] as const);\r\n\r\nexport const DIGEST_ALGORITHMS = Object.freeze({\r\n sha256: { node: \"sha256\", web: \"SHA-256\" },\r\n sha384: { node: \"sha384\", web: \"SHA-384\" },\r\n sha512: { node: \"sha512\", web: \"SHA-512\" },\r\n} as const);\r\n\r\nexport const ENCRYPTION_ALGORITHMS = Object.freeze({\r\n aes256gcm: { keyBytes: 32, ivLength: 12, node: \"aes-256-gcm\", web: \"AES-GCM\" },\r\n aes192gcm: { keyBytes: 24, ivLength: 12, node: \"aes-192-gcm\", web: \"AES-GCM\" },\r\n aes128gcm: { keyBytes: 16, ivLength: 12, node: \"aes-128-gcm\", web: \"AES-GCM\" },\r\n} as const);\r\n","import nodeCrypto from \"node:crypto\";\r\nimport type { NodeSecretKey, WebSecretKey } from \"~/helpers/types\";\r\nimport { DIGEST_ALGORITHMS, ENCRYPTION_ALGORITHMS } from \"./consts\";\r\n\r\nexport function $isStr(x: unknown, min = 1): x is string {\r\n return x !== null && x !== undefined && typeof x === \"string\" && x.trim().length >= min;\r\n}\r\n\r\nexport function $isPlainObj<T extends object = Record<string, unknown>>(x: unknown): x is T {\r\n if (typeof x !== \"object\" || x === null || x === undefined) return false;\r\n const proto = Object.getPrototypeOf(x);\r\n return proto === Object.prototype || proto === null;\r\n}\r\n\r\nexport function $isObj(x: unknown): x is Record<string, unknown> {\r\n return typeof x === \"object\" && x !== null && x !== undefined;\r\n}\r\n\r\ntype InjectedSecretKey<Platform extends \"web\" | \"node\"> = (Platform extends \"web\" ? WebSecretKey : NodeSecretKey) & {\r\n readonly injected: (typeof ENCRYPTION_ALGORITHMS)[keyof typeof ENCRYPTION_ALGORITHMS];\r\n};\r\n\r\nconst expectedKeys = new Set([\"platform\", \"digest\", \"algorithm\", \"key\"]);\r\n\r\nexport function $isSecretKey<Platform extends \"node\" | \"web\">(\r\n x: unknown,\r\n platform: Platform,\r\n): InjectedSecretKey<Platform> | null {\r\n if (!$isObj(x) || (platform !== \"node\" && platform !== \"web\") || x.platform !== platform) return null;\r\n\r\n const keys = Object.keys(x);\r\n if (keys.length !== expectedKeys.size) return null;\r\n for (const key of keys) if (!expectedKeys.has(key)) return null;\r\n for (const key of expectedKeys) if (!Object.hasOwn(x, key)) return null;\r\n\r\n if (\r\n typeof x.digest !== \"string\" ||\r\n !(x.digest in DIGEST_ALGORITHMS) ||\r\n typeof x.algorithm !== \"string\" ||\r\n !(x.algorithm in ENCRYPTION_ALGORITHMS) ||\r\n !$isObj(x.key) ||\r\n x.key.type !== \"secret\"\r\n ) {\r\n return null;\r\n }\r\n\r\n const algorithm = ENCRYPTION_ALGORITHMS[x.algorithm as keyof typeof ENCRYPTION_ALGORITHMS];\r\n\r\n if (platform === \"node\") {\r\n if (\r\n !(x.key instanceof nodeCrypto.KeyObject) ||\r\n (typeof x.key.symmetricKeySize === \"number\" && x.key.symmetricKeySize !== algorithm.keyBytes)\r\n ) {\r\n return null;\r\n }\r\n return Object.freeze({ ...x, injected: algorithm }) as InjectedSecretKey<Platform>;\r\n }\r\n\r\n if (\r\n !$isObj(x.key.algorithm) ||\r\n x.key.algorithm.name !== algorithm.web ||\r\n (typeof x.key.algorithm.length === \"number\" && x.key.algorithm.length !== algorithm.keyBytes * 8) ||\r\n typeof x.key.extractable !== \"boolean\" ||\r\n !Array.isArray(x.key.usages) ||\r\n x.key.usages.length !== 2 ||\r\n !(x.key.usages.includes(\"encrypt\") && x.key.usages.includes(\"decrypt\"))\r\n ) {\r\n return null;\r\n }\r\n return Object.freeze({ ...x, injected: algorithm }) as InjectedSecretKey<Platform>;\r\n}\r\n\r\n/**\r\n * Type guard to check if the provided value is a SecretKey object for Node.js environment.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Checking if the key in your hand is the right kind of key for the lock.\r\n *\r\n * @param x - The value to check.\r\n * @returns True if the value is a SecretKey object for Node.js, false otherwise.\r\n *\r\n * @example\r\n * ```ts\r\n * isNodeSecretKey(nodeKey); // true\r\n * isNodeSecretKey(webKey); // false\r\n * isNodeSecretKey({}); // false\r\n * ```\r\n */\r\nexport function isNodeSecretKey(x: unknown): x is NodeSecretKey {\r\n return $isSecretKey(x, \"node\") !== null;\r\n}\r\n\r\n/**\r\n * Type guard to check if the provided value is a SecretKey object for Web (Deno, Bun, Cloudflare included) environment.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Checking if the key in your hand is the right kind of key for the lock.\r\n *\r\n * @param x - The value to check.\r\n * @returns True if the value is a SecretKey object for Web, false otherwise.\r\n *\r\n * @example\r\n * ```ts\r\n * isWebSecretKey(webKey); // true\r\n * isWebSecretKey(nodeKey); // false\r\n * isWebSecretKey({}); // false\r\n * ```\r\n */\r\nexport function isWebSecretKey(x: unknown): x is WebSecretKey {\r\n return $isSecretKey(x, \"web\") !== null;\r\n}\r\n\r\n/**\r\n * Regular expressions for encrypted data patterns.\r\n *\r\n * - **node**: `\"iv.cipher.tag.\"` (three dot-separated parts plus a trailing dot)\r\n * - **web**: `\"iv.cipherWithTag.\"` (two parts plus a trailing dot)\r\n * - **general**: accepts both shapes (2 or 3 parts) with a trailing dot\r\n *\r\n * Each part is any non-empty string without dots.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a secret code you want to check. Before you check it,\r\n * you make sure it looks how a secret code should look.\r\n */\r\nexport const ENCRYPTED_REGEX = Object.freeze({\r\n node: /^([^.]+)\\.([^.]+)\\.([^.]+)\\.$/,\r\n web: /^([^.]+)\\.([^.]+)\\.$/,\r\n general: /^([^.]+)\\.([^.]+)(?:\\.([^.]+))?\\.$/,\r\n});\r\n\r\n/**\r\n * Checks if a string matches an expected encrypted payload shape.\r\n *\r\n * - **node**: `\"iv.cipher.tag.\"` (three dot-separated parts plus a trailing dot)\r\n * - **web**: `\"iv.cipherWithTag.\"` (two parts plus a trailing dot)\r\n * - **general**: accepts both shapes (2 or 3 parts) with a trailing dot\r\n *\r\n * Each part is any non-empty string without dots.\r\n *\r\n * This validates only the **shape**, not whether content is valid base64/hex, etc.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a secret code you want to check. Before you check it,\r\n * you make sure it looks how a secret code should look.\r\n *\r\n * @param data - The string to test.\r\n * @param format - Which layout to check: `'node'`, `'web'`, or `'general'`.\r\n * @returns `true` if the string matches the pattern; otherwise `false`.\r\n * @throws {Error} If an unknown `format` is provided.\r\n *\r\n * @example\r\n * ```ts\r\n * matchEncryptedPattern(\"abc.def.ghi.\", \"node\"); // true\r\n * matchEncryptedPattern(\"abc.def.\", \"web\"); // true\r\n * matchEncryptedPattern(\"abc.def.\", \"node\"); // false\r\n * matchEncryptedPattern(\"abc.def.ghi.\", \"general\"); // true\r\n * ```\r\n */\r\nexport function matchEncryptedPattern(data: string, format: \"node\" | \"web\" | \"general\"): boolean {\r\n if (typeof data !== \"string\") return false;\r\n if (!(format in ENCRYPTED_REGEX)) throw new Error(`Unknown format: ${format}`);\r\n return ENCRYPTED_REGEX[format].test(data);\r\n}\r\n","import { $isPlainObj } from \"./validate\";\r\n\r\n/**\r\n * Standardized error object for the `Result` type.\r\n * Always has a brief `message` and a more detailed `description`.\r\n */\r\nexport interface ErrorStruct {\r\n readonly message: string;\r\n readonly description: string;\r\n}\r\n\r\ntype ReservedWords<Obj extends object> = \"success\" extends keyof Obj ? never : \"error\" extends keyof Obj ? never : Obj;\r\n\r\ntype OkType<T> = {\r\n readonly success: true;\r\n readonly error?: undefined;\r\n} & (T extends object ? ReservedWords<{ readonly [K in keyof T]: T[K] }> : { readonly result: T });\r\n\r\ntype ErrType<T> = {\r\n readonly success: false;\r\n readonly error: ErrorStruct;\r\n} & (T extends object ? ReservedWords<{ readonly [K in keyof T]?: undefined }> : { readonly result?: undefined });\r\n\r\n/**\r\n * Discriminated union for functions that can succeed or fail.\r\n *\r\n * - On **success**:\r\n * - If `T` is an object - properties of `T` are **spread** into the result\r\n * along with `success: true`.\r\n * - Otherwise - `{ success: true, result: T }`.\r\n * - On **failure**: `{ success: false, error: E }`.\r\n *\r\n * @example\r\n * ```ts\r\n * // Primitive result\r\n * function getNum(): Result<number> {\r\n * return $ok(42);\r\n * }\r\n * const r1 = getNum();\r\n * if (r1.success) console.log(r1.result); // 42\r\n *\r\n * // Object result (spread)\r\n * function getObject(): Result<{ name: string; age: number }> {\r\n * return $ok({ name: 'Alice', age: 30 });\r\n * }\r\n * const r2 = getObject();\r\n * if (r2.success) console.log(r2.name, r2.age); // 'Alice' 30\r\n * ```\r\n */\r\nexport type Result<T> = OkType<T> | ErrType<T>;\r\n\r\nexport function $ok<T>(result: T): Result<T> {\r\n if ($isPlainObj(result)) return { success: true, ...(result as T & object) } as Result<T>;\r\n return { success: true, result } as Result<T>;\r\n}\r\n\r\ninterface ShortErrorStruct {\r\n readonly msg: string;\r\n readonly desc: string;\r\n}\r\n\r\nexport function $err(err: ShortErrorStruct | ErrorStruct): Result<never> {\r\n return {\r\n success: false,\r\n error: {\r\n message: \"msg\" in err ? err.msg : err.message,\r\n description: \"desc\" in err ? err.desc : err.description,\r\n },\r\n } as Result<never>;\r\n}\r\n\r\nexport function $fmtError(error: unknown): string {\r\n if (typeof error === \"string\") return error;\r\n if (error instanceof Error) return error.message;\r\n return String(error);\r\n}\r\n\r\nexport function $fmtResultErr(err: ErrorStruct | undefined): string {\r\n if (!err) return \"Unknown error\";\r\n return `${err.message} - ${err.description}`;\r\n}\r\n\r\nexport function title(platform: \"web\" | \"node\", title: string): string {\r\n return `${platform === \"web\" ? \"Crypto Web API\" : \"Crypto NodeJS API\"} - ${title}`;\r\n}\r\n","import { $err, $fmtError, $fmtResultErr, $ok, type Result } from \"./error\";\r\nimport { $isPlainObj, $isStr } from \"./validate\";\r\n\r\nexport function $stringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string> {\r\n try {\r\n if (!$isPlainObj(obj)) return $err({ msg: \"JSON: Invalid object\", desc: \"Input is not a plain object\" });\r\n return $ok(JSON.stringify(obj));\r\n } catch (error) {\r\n return $err({ msg: \"JSON: Stringify error\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport function $parseToObj<T extends object = Record<string, unknown>>(str: string): Result<{ result: T }> {\r\n try {\r\n if (!$isStr(str)) return $err({ msg: \"JSON: Invalid input\", desc: \"Input is not a valid string\" });\r\n const obj = JSON.parse(str);\r\n\r\n if (!$isPlainObj(obj)) {\r\n return $err({ msg: \"JSON: Invalid object format\", desc: \"Parsed data is not a plain object\" });\r\n }\r\n\r\n return $ok({ result: obj as T });\r\n } catch (error) {\r\n return $err({ msg: \"JSON: Invalid format\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\n/**\r\n * Safely serializes a plain object to JSON without throwing.\r\n *\r\n * Wraps `JSON.stringify` and returns a `Result` containing the JSON string or an error.\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a box of toys (your object) and take a photo of it (a JSON string)\r\n * so you can send it to a friend.\r\n *\r\n * @template T - Plain object type to serialize.\r\n * @param obj - The object to stringify (must be a plain object).\r\n * @returns A `Result` with the JSON string on success, or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const { result, error, success } = tryStringifyObj({ a: 1 });\r\n *\r\n * if (success) console.log(result); // \"{\\\"a\\\":1}\"\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string> {\r\n return $stringifyObj(obj);\r\n}\r\n\r\n/**\r\n * Serializes a plain object to JSON (throwing).\r\n *\r\n * Wraps `JSON.stringify` and returns the result or throws an error.\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a box of toys (your object) and take a photo of it (a JSON string)\r\n * so you can send it to a friend.\r\n *\r\n * @template T - Plain object type to serialize.\r\n * @param obj - The object to stringify (must be a plain object).\r\n * @returns JSON string representation of the object.\r\n * @throws {Error} If `obj` is not a plain object or serialization fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const json = stringifyObj({ a: 1 }); // \"{\\\"a\\\":1}\"\r\n * ```\r\n */\r\nexport function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string {\r\n const { result, error } = $stringifyObj(obj);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely parses a JSON string to a plain object (non-throwing).\r\n *\r\n * Wraps `JSON.parse` and returns a `Result` containing the parsed object, or an error.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) from a photo you took (a JSON string).\r\n *\r\n * @template T - The expected object type.\r\n * @param str - The JSON string to parse.\r\n * @returns A `Result` with the parsed object on success, or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryParseToObj<{ a: number }>('{\"a\":1}');\r\n *\r\n * if (success) console.log(result); // { a: 1 }\r\n * else console.error(error) // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{ result: T }> {\r\n return $parseToObj<T>(str);\r\n}\r\n\r\n/**\r\n * Parses a JSON string to a plain object (throwing).\r\n *\r\n * Wraps `JSON.parse` and returns the parsed object, or throws on failure.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) from a photo you took (a JSON string).\r\n *\r\n * @template T - The expected object type.\r\n * @param str - The JSON string to parse.\r\n * @returns The parsed plain object.\r\n * @throws {Error} If the string can’t be parsed or doesn’t represent a plain object.\r\n *\r\n * @example\r\n * ```ts\r\n * const obj = parseToObj<{ a: number }>('{\"a\":1}'); // obj.a === 1\r\n * ```\r\n */\r\nexport function parseToObj<T extends object = Record<string, unknown>>(str: string): T {\r\n const { result, error } = $parseToObj<T>(str);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n"]}
@@ -1,4 +1,4 @@
1
- import { __export, $isSecretKey, $fmtResultErr, $ok, $err, $fmtError, title, $isStr, $isPlainObj, ENCRYPTION_ALGORITHMS, DIGEST_ALGORITHMS, CIPHER_ENCODING, matchEncryptedPattern, $stringifyObj, $parseToObj, ENCODING } from './chunk-6C4NIWQ4.js';
1
+ import { __export, $fmtResultErr, $ok, $err, $fmtError, title, $isStr, $isPlainObj, ENCRYPTION_ALGORITHMS, DIGEST_ALGORITHMS, CIPHER_ENCODING, $isSecretKey, matchEncryptedPattern, $stringifyObj, $parseToObj, ENCODING } from './chunk-LU7QOSQH.js';
2
2
 
3
3
  // src/web/kit.ts
4
4
  var kit_exports = {};
@@ -14,7 +14,6 @@ __export(kit_exports, {
14
14
  generateUuid: () => generateUuid,
15
15
  hash: () => hash,
16
16
  hashPassword: () => hashPassword,
17
- isWebSecretKey: () => isWebSecretKey,
18
17
  tryConvertBytesToStr: () => tryConvertBytesToStr,
19
18
  tryConvertEncoding: () => tryConvertEncoding,
20
19
  tryConvertStrToBytes: () => tryConvertStrToBytes,
@@ -502,9 +501,6 @@ async function $verifyPassword(password, hashedPassword, salt, options) {
502
501
  }
503
502
 
504
503
  // src/web/kit.ts
505
- function isWebSecretKey(x) {
506
- return $isSecretKey(x, "web") !== null;
507
- }
508
504
  function tryGenerateUuid() {
509
505
  return $generateUuid();
510
506
  }
@@ -597,6 +593,6 @@ function convertEncoding(data, from, to) {
597
593
  return result;
598
594
  }
599
595
 
600
- export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, isWebSecretKey, kit_exports, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword };
601
- //# sourceMappingURL=chunk-FSEA3UXJ.js.map
602
- //# sourceMappingURL=chunk-FSEA3UXJ.js.map
596
+ export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, kit_exports, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword };
597
+ //# sourceMappingURL=chunk-JLFVTZY4.js.map
598
+ //#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,OAAO,kBAAA,CAAmB,MAAM,aAAa,CAAA;AAC/C;AAoBO,SAAS,iBAAA,CAAkB,IAAA,EAAc,aAAA,GAA0B,MAAA,EAAiC;AACzG,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAM,GAAI,kBAAA,CAAmB,MAAM,aAAa,CAAA;AAChE,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAM,aAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT;AAuBO,SAAS,oBAAA,CACd,IAAA,EACA,cAAA,GAA2B,MAAA,EACX;AAChB,EAAA,OAAO,kBAAA,CAAmB,MAAM,cAAc,CAAA;AAChD;AAqBO,SAAS,iBAAA,CAAkB,IAAA,EAAgC,cAAA,GAA2B,MAAA,EAAgB;AAC3G,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAM,GAAI,kBAAA,CAAmB,MAAM,cAAc,CAAA;AACjE,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAM,aAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT;AAuBO,SAAS,kBAAA,CAAmB,IAAA,EAAc,IAAA,EAAgB,EAAA,EAA8B;AAC7F,EAAA,OAAO,gBAAA,CAAiB,IAAA,EAAM,IAAA,EAAM,EAAE,CAAA;AACxC;AAqBO,SAAS,eAAA,CAAgB,IAAA,EAAc,IAAA,EAAgB,EAAA,EAAsB;AAClF,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,KAAU,gBAAA,CAAiB,IAAA,EAAM,MAAM,EAAE,CAAA;AACzD,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAM,aAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT","file":"chunk-JLFVTZY4.js","sourcesContent":["import { $fmtResultErr, type Result } from \"~/helpers/error\";\r\nimport type {\r\n CreateSecretKeyOptions,\r\n DecryptOptions,\r\n Encoding,\r\n EncryptOptions,\r\n HashOptions,\r\n HashPasswordOptions,\r\n VerifyPasswordOptions,\r\n WebSecretKey,\r\n} from \"~/helpers/types\";\r\nimport { $isSecretKey } from \"~/helpers/validate\";\r\nimport { $convertBytesToStr, $convertEncoding, $convertStrToBytes } from \"./web-encode\";\r\nimport {\r\n $createSecretKey,\r\n $decrypt,\r\n $decryptObj,\r\n $encrypt,\r\n $encryptObj,\r\n $generateUuid,\r\n $hash,\r\n $hashPassword,\r\n $verifyPassword,\r\n} from \"./web-encrypt\";\r\n\r\n/**\r\n * Safely generates a UUID (v4) (non-throwing).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It's like giving your pet a name tag with a super random name made of numbers and letters.\r\n * The chance of two pets getting the same name tag is practically zero, and it's very hard to guess!\r\n *\r\n * @returns A `Result` containing the UUID string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryGenerateUuid();\r\n *\r\n * if (success) console.log(result); // \"...\" (a UUID string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryGenerateUuid(): Result<string> {\r\n return $generateUuid();\r\n}\r\n\r\n/**\r\n * Generates a UUID (v4) (throwing).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It's like giving your pet a name tag with a super random name made of numbers and letters.\r\n * The chance of two pets getting the same name tag is practically zero, and it's very hard to guess!\r\n *\r\n * @returns A UUID string.\r\n * @throws {Error} If UUID generation fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const uuid = generateUuid(); // \"...\" (a UUID string)\r\n * ```\r\n */\r\nexport function generateUuid(): string {\r\n const { result, error } = $generateUuid();\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely derives a `SecretKey` from the provided string for encryption/decryption (non-throwing).\r\n *\r\n * Uses HKDF to derive a key from the input string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you want to create a special key for future use to lock your treasure box (data).\r\n * So, you stir in some secret ingredients (like salt and info) to make sure your key is one-of-a-kind.\r\n *\r\n * @param secret - The input string to derive the `SecretKey` from, must be at least 8 characters.\r\n * @param options.algorithm - The encryption algorithm to use (default: `'aes256gcm'`).\r\n * @param options.digest - The hash algorithm for HKDF (default: `'sha256'`).\r\n * @param options.salt - A salt string (default: `'cipher-kit-salt'`, must be ≥ 8 chars).\r\n * @param options.info - An info string (default: `'cipher-kit'`).\r\n * @returns A `Result` promise containing the derived `SecretKey` or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = await tryCreateSecretKey(\"my-secret\");\r\n *\r\n * if (success) console.log(result); // SecretKey object\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryCreateSecretKey(\r\n secret: string,\r\n options: CreateSecretKeyOptions = {},\r\n): Promise<Result<{ result: WebSecretKey }>> {\r\n return await $createSecretKey(secret, options);\r\n}\r\n\r\n/**\r\n * Derives a `SecretKey` from the provided string for encryption/decryption (throwing).\r\n *\r\n * Uses HKDF to derive a key from the input string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you want to create a special key for future use to lock your treasure box (data).\r\n * So, you stir in some secret ingredients (like salt and info) to make sure your key is one-of-a-kind.\r\n *\r\n * @param secret - The input string to derive the `SecretKey` from, must be at least 8 characters.\r\n * @param options.algorithm - The encryption algorithm to use (default: `'aes256gcm'`).\r\n * @param options.digest - The hash algorithm for HKDF (default: `'sha256'`).\r\n * @param options.salt - A salt string (default: `'cipher-kit-salt'`, must be ≥ 8 chars).\r\n * @param options.info - An info string (default: `'cipher-kit'`).\r\n * @returns A promise of the derived `SecretKey`.\r\n * @throws {Error} If key derivation fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\"); // SecretKey object\r\n * ```\r\n */\r\nexport async function createSecretKey(secret: string, options: CreateSecretKeyOptions = {}): Promise<WebSecretKey> {\r\n const { result, error } = await $createSecretKey(secret, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely encrypts a UTF-8 string using the provided `SecretKey` (non-throwing).\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You scramble a secret message with your special key,\r\n * creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @param data - A UTF-8 string to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A `Result` promise containing the encrypted string in the specified format or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const {result, error, success} = await tryEncrypt(\"Hello, World!\", secretKey);\r\n *\r\n * if (success) console.log(result); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryEncrypt(\r\n data: string,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions = {},\r\n): Promise<Result<string>> {\r\n return await $encrypt(data, secretKey, options);\r\n}\r\n\r\n/**\r\n * Encrypts a UTF-8 string using the provided `SecretKey` (throwing).\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You scramble a secret message with your special key,\r\n * creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @param data - A UTF-8 string to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A promise with the encrypted string in the specified format.\r\n * @throws {Error} If the input data or key is invalid, or if encryption fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encrypt(\"Hello, World!\", secretKey); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * ```\r\n */\r\nexport async function encrypt(data: string, secretKey: WebSecretKey, options: EncryptOptions = {}): Promise<string> {\r\n const { result, error } = await $encrypt(data, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely decrypts the input string using the provided `SecretKey` (non-throwing).\r\n *\r\n * Expects input in the format \"iv.cipherWithTag.\" and returns the decrypted UTF-8 string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You take a scrambled secret message and use your special key to unscramble it,\r\n * revealing the original message inside.\r\n *\r\n * @param encrypted - The input string to decrypt, in the format \"iv.cipherWithTag.\".\r\n * @param secretKey - The `SecretKey` object used for decryption.\r\n * @param options.inputEncoding - The encoding format for the input ciphertext (default: `'base64url'`).\r\n * @returns A `Result` promise containing the decrypted UTF-8 string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encrypt(\"Hello, World!\", secretKey);\r\n * const {result, error, success} = await tryDecrypt(encrypted, secretKey);\r\n *\r\n * if (success) console.log(result); // \"Hello, World!\"\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryDecrypt(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<Result<string>> {\r\n return await $decrypt(encrypted, secretKey, options);\r\n}\r\n\r\n/**\r\n * Decrypts the input string using the provided `SecretKey` (throwing).\r\n *\r\n * Expects input in the format \"iv.cipherWithTag.\" and returns the decrypted UTF-8 string.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You take a scrambled secret message and use your special key to unscramble it,\r\n * revealing the original message inside.\r\n *\r\n * @param encrypted - The input string to decrypt, in the format \"iv.cipherWithTag.\".\r\n * @param secretKey - The `SecretKey` object used for decryption.\r\n * @param options.inputEncoding - The encoding format for the input ciphertext (default: `'base64url'`).\r\n * @returns A promise with the decrypted UTF-8 string.\r\n * @throws {Error} If the input data or key is invalid, or if decryption fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encrypt(\"Hello, World!\", secretKey);\r\n * const decrypted = await decrypt(encrypted, secretKey); // \"Hello, World!\"\r\n * ```\r\n */\r\nexport async function decrypt(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<string> {\r\n const { result, error } = await $decrypt(encrypted, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely encrypts a plain object using the provided `SecretKey` (non-throwing).\r\n *\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you have a toy box (an object) that you want to keep secret.\r\n * So, you take a picture of your toy box (convert it to JSON), and scramble that with\r\n * your special key, creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @template T - The type of the plain object to encrypt.\r\n * @param obj - A plain object to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A `Result` promise containing the encrypted string in the specified format or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const {result, error, success} = await tryEncryptObj({ a: 1 }, secretKey);\r\n *\r\n * if (success) console.log(result); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryEncryptObj<T extends object = Record<string, unknown>>(\r\n obj: T,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions = {},\r\n): Promise<Result<string>> {\r\n return await $encryptObj(obj, secretKey, options);\r\n}\r\n\r\n/**\r\n * Encrypts a plain object using the provided `SecretKey` (throwing).\r\n *\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * Output format: \"iv.cipherWithTag.\"\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Imagine you have a toy box (an object) that you want to keep secret.\r\n * So, you take a picture of your toy box (convert it to JSON), and scramble that with\r\n * your special key, creating a jumbled code that only someone with the right key can read.\r\n *\r\n * @template T - The type of the plain object to encrypt.\r\n * @param obj - A plain object to encrypt.\r\n * @param secretKey - The `SecretKey` object used for encryption.\r\n * @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).\r\n * @returns A promise with the encrypted string in the specified format.\r\n * @throws {Error} If the input data or key is invalid, or if encryption fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encryptObj({ a: 1 }, secretKey); // \"iv.cipherWithTag.\" (Encrypted string)\r\n * ```\r\n */\r\nexport async function encryptObj<T extends object = Record<string, unknown>>(\r\n obj: T,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions = {},\r\n): Promise<string> {\r\n const { result, error } = await $encryptObj(obj, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely decrypts an encrypted JSON string into a plain object (non-throwing).\r\n *\r\n * Expects input in the format `\"iv.cipherWithTag.\"` and returns a plain object.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) by unscrambling the jumbled code (encrypted text),\r\n * using your special key to open it.\r\n *\r\n * @template T - The expected shape of the decrypted object.\r\n * @param encrypted - The encrypted string (format: `\"iv.cipherWithTag.\"`).\r\n * @param secretKey - The `SecretKey` used for decryption.\r\n * @param options.inputEncoding - Input ciphertext encoding (default: `'base64url'`).\r\n * @returns A `Result` promise with the decrypted object on success, or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encryptObj({ a: 1 }, secretKey);\r\n * const {result, error, success} = await tryDecryptObj<{ a: number }>(encrypted, secretKey);\r\n *\r\n * if (success) console.log(result); // { a: 1 }\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryDecryptObj<T extends object = Record<string, unknown>>(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<Result<{ result: T }>> {\r\n return await $decryptObj<T>(encrypted, secretKey, options);\r\n}\r\n\r\n/**\r\n * Decrypts an encrypted JSON string into a plain object (throwing).\r\n *\r\n * Expects input in the format `\"iv.cipherWithTag.\"` and returns a plain object.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) by unscrambling the jumbled code (encrypted text),\r\n * using your special key to open it.\r\n *\r\n * @template T - The expected shape of the decrypted object.\r\n * @param encrypted - The encrypted string (format: `\"iv.cipherWithTag.\"`).\r\n * @param secretKey - The `SecretKey` used for decryption.\r\n * @param options.inputEncoding - Input ciphertext encoding (default: `'base64url'`).\r\n * @returns A promise with the decrypted object.\r\n * @throws {Error} If decryption or JSON parsing fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const secretKey = await createSecretKey(\"my-secret\");\r\n * const encrypted = await encryptObj({ a: 1 }, secretKey);\r\n * const obj = await decryptObj<{ a: number }>(encrypted, secretKey); // obj.a === 1\r\n * ```\r\n */\r\nexport async function decryptObj<T extends object = Record<string, unknown>>(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions = {},\r\n): Promise<T> {\r\n const { result, error } = await $decryptObj<T>(encrypted, secretKey, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely hashes a UTF-8 string (non-throwing).\r\n *\r\n * Uses the selected digest (default: `'sha256'`) and returns the hash\r\n * in the chosen encoding (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Like putting something in a blender and getting a smoothie, you can’t get the original ingredients back,\r\n * but the smoothie is always the same if you use the same ingredients.\r\n *\r\n * @param data - The input string to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`, default: `'sha256'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`, default: `'base64url'`).\r\n * @returns A `Result` promise with the hash string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = await tryHash(\"my data\");\r\n *\r\n * if (success) console.log(result); // \"...\" (Hashed string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryHash(data: string, options: HashOptions = {}): Promise<Result<string>> {\r\n return await $hash(data, options);\r\n}\r\n\r\n/**\r\n * Hashes a UTF-8 string (throwing).\r\n *\r\n * Uses the selected digest (default: `'sha256'`) and returns the hash\r\n * in the chosen encoding (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Like putting something in a blender and getting a smoothie, you can’t get the original ingredients back,\r\n * but the smoothie is always the same if you use the same ingredients.\r\n *\r\n * @param data - The input string to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`, default: `'sha256'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`, default: `'base64url'`).\r\n * @returns A promise of the hashed string.\r\n * @throws {Error} If input is invalid or hashing fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const hashed = await hash(\"my data\"); // \"...\" (Hashed string)\r\n * ```\r\n */\r\nexport async function hash(data: string, options: HashOptions = {}): Promise<string> {\r\n const { result, error } = await $hash(data, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely hashes a password using PBKDF2 (non-throwing).\r\n *\r\n * Uses strong defaults (`sha512`, 320k iterations, 64-byte key, 16-byte salt) and\r\n * returns `{ hash, salt }` encoded (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * We take your password, mix in some random salt, and stir many times.\r\n * The result is a super-secret soup that’s hard to copy.\r\n *\r\n * @param password - The password to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).\r\n * @param options.saltLength - Length of the random salt in bytes (default: `16` bytes, min: `8` bytes).\r\n * @param options.iterations - Number of iterations (default: `320000`, min: `1000`).\r\n * @param options.keyLength - Length of the derived key in bytes (default: `64` bytes, min: `16` bytes).\r\n * @returns A `Result` promise with `{ result, salt }` or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = await tryHashPassword(\"my-password\");\r\n *\r\n * if (success) console.log(result, salt); // \"...\" (hashed password), \"...\" (salt)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport async function tryHashPassword(\r\n password: string,\r\n options: HashPasswordOptions = {},\r\n): Promise<Result<{ result: string; salt: string }>> {\r\n return await $hashPassword(password, options);\r\n}\r\n\r\n/**\r\n * Hashes a password using PBKDF2 (throwing).\r\n *\r\n * Uses strong defaults (`sha512`, 320k iterations, 64-byte key, 16-byte salt) and\r\n * returns `{ hash, salt }` encoded (default: `'base64url'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * We take your password, mix in some random salt, and stir many times.\r\n * The result is a super-secret soup that’s hard to copy.\r\n *\r\n * @param password - The password to hash.\r\n * @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).\r\n * @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).\r\n * @param options.saltLength - Length of the random salt in bytes (default: `16` bytes, min: `8` bytes).\r\n * @param options.iterations - Number of iterations (default: `320000`, min: `1000`).\r\n * @param options.keyLength - Length of the derived key in bytes (default: `64` bytes, min: `16` bytes).\r\n * @returns A promise with `{ result, salt }` for storage.\r\n * @throws {Error} If inputs are invalid or hashing fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, salt} = await hashPassword(\"my-password\"); // \"...\" (hashed password), \"...\" (salt)\r\n * ```\r\n */\r\nexport async function hashPassword(\r\n password: string,\r\n options: HashPasswordOptions = {},\r\n): Promise<{ result: string; salt: string }> {\r\n const { result, salt, error } = await $hashPassword(password, options);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return { result, salt };\r\n}\r\n\r\n/**\r\n * Verifies a password against a stored PBKDF2 hash (non-throwing).\r\n *\r\n * Re-derives the key using the same parameters and compares in constant time, to prevent timing attacks.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * We follow the same recipe as when we made the secret.\r\n * If the new soup tastes exactly the same, the password is correct.\r\n *\r\n * @param password - The plain password to verify.\r\n * @param hashedPassword - The stored hash (encoded).\r\n * @param salt - The stored salt (encoded).\r\n * @param options.digest - Hash algorithm used during hashing (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).\r\n * @param options.inputEncoding - Encoding of the stored hash and salt (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).\r\n * @param options.iterations - Number of iterations used during hashing (default: `320000`).\r\n * @param options.keyLength - Length of the derived key in bytes used during hashing (default: `64` bytes).\r\n * @returns A promise of boolean, `true` if the password matches, otherwise `false`.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, salt} = await hashPassword(\"my-password\");\r\n *\r\n * await verifyPassword(\"my-password\", result, salt); // true\r\n * await verifyPassword(\"wrong-password\", result, salt); // false\r\n * ```\r\n */\r\nexport async function verifyPassword(\r\n password: string,\r\n hashedPassword: string,\r\n salt: string,\r\n options: VerifyPasswordOptions = {},\r\n): Promise<boolean> {\r\n return await $verifyPassword(password, hashedPassword, salt, options);\r\n}\r\n\r\n/**\r\n * Safely converts a string to a `Uint8Array` using the specified encoding (non-throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns your words into tiny computer building blocks (bytes) so computers can work with them.\r\n *\r\n * @param data - The input string to convert.\r\n * @param inputEncoding - The encoding of the input string (default: `'utf8'`).\r\n * @returns A `Result` with `{ result: Uint8Array }` or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryConvertStrToBytes(\"Hello\", \"utf8\");\r\n *\r\n * if (success) console.log(result); // Uint8Array([...])\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryConvertStrToBytes(\r\n data: string,\r\n inputEncoding: Encoding = \"utf8\",\r\n): Result<{ result: Uint8Array<ArrayBuffer> }> {\r\n return $convertStrToBytes(data, inputEncoding);\r\n}\r\n\r\n/**\r\n * Converts a string to a `Uint8Array` using the specified encoding (throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns your words into tiny computer building blocks (bytes) so computers can work with them.\r\n *\r\n * @param data - The input string to convert.\r\n * @param inputEncoding - The encoding of the input string (default: `'utf8'`).\r\n * @returns A `Uint8Array` containing the bytes.\r\n * @throws {Error} If input is invalid or conversion fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const bytes = convertStrToBytes(\"Hello\", \"utf8\"); // Uint8Array([...])\r\n * ```\r\n */\r\nexport function convertStrToBytes(data: string, inputEncoding: Encoding = \"utf8\"): Uint8Array<ArrayBuffer> {\r\n const { result, error } = $convertStrToBytes(data, inputEncoding);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely converts a `Uint8Array` or `ArrayBuffer` to a string using the specified encoding (non-throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns the tiny computer building blocks (bytes) back into a readable sentence.\r\n *\r\n * @param data - The `Uint8Array` or `ArrayBuffer` to convert.\r\n * @param outputEncoding - The output encoding (default: `'utf8'`).\r\n * @returns A `Result` with the string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const bytes = convertStrToBytes(\"Hello\", \"utf8\"); // Uint8Array([...])\r\n * const {result, error, success} = tryConvertBytesToStr(bytes, \"utf8\");\r\n *\r\n * if (success) console.log(result); // \"Hello\"\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryConvertBytesToStr(\r\n data: Uint8Array | ArrayBuffer,\r\n outputEncoding: Encoding = \"utf8\",\r\n): Result<string> {\r\n return $convertBytesToStr(data, outputEncoding);\r\n}\r\n\r\n/**\r\n * Converts a `Uint8Array` or `ArrayBuffer` to a string using the specified encoding (throwing).\r\n *\r\n * Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * This turns the tiny computer building blocks (bytes) back into a readable sentence.\r\n *\r\n * @param data - The `Uint8Array` or `ArrayBuffer` to convert.\r\n * @param outputEncoding - The output encoding (default: `'utf8'`).\r\n * @returns The encoded string.\r\n * @throws {Error} If input is invalid or conversion fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const bytes = convertStrToBytes(\"Hello\", \"utf8\"); // Uint8Array([...])\r\n * const str = convertBytesToStr(bytes, \"utf8\"); // \"Hello\"\r\n * ```\r\n */\r\nexport function convertBytesToStr(data: Uint8Array | ArrayBuffer, outputEncoding: Encoding = \"utf8\"): string {\r\n const { result, error } = $convertBytesToStr(data, outputEncoding);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely converts text between encodings (non-throwing).\r\n *\r\n * Example: convert `'utf8'` text to `'base64url'`, or `'hex'` to `'utf8'`.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It’s like translating your sentence from one alphabet to another.\r\n *\r\n * @param data - The input string to convert.\r\n * @param from - The current encoding of `data`.\r\n * @param to - The target encoding for `data`.\r\n * @returns A `Result` with a string or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryConvertEncoding(\"Hello\", \"utf8\", \"base64url\");\r\n *\r\n * if (success) console.log(result); // \"...\" (Base64url encoded string)\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryConvertEncoding(data: string, from: Encoding, to: Encoding): Result<string> {\r\n return $convertEncoding(data, from, to);\r\n}\r\n\r\n/**\r\n * Converts text between encodings (throwing).\r\n *\r\n * Example: convert `'utf8'` text to `'base64url'`, or `'hex'` to `'utf8'`.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * It’s like translating your sentence from one alphabet to another.\r\n *\r\n * @param data - The input string to convert.\r\n * @param from - The current encoding of `data`.\r\n * @param to - The target encoding for `data`.\r\n * @returns The converted string.\r\n * @throws {Error} If encodings are invalid or conversion fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const base64url = convertEncoding(\"Hello\", \"utf8\", \"base64url\"); // \"...\" (Base64url encoded string)\r\n * ```\r\n */\r\nexport function convertEncoding(data: string, from: Encoding, to: Encoding): string {\r\n const { result, error } = $convertEncoding(data, from, to);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n","import { ENCODING } from \"~/helpers/consts\";\r\nimport { $err, $fmtError, $ok, type Result } from \"~/helpers/error\";\r\nimport type { Encoding } from \"~/helpers/types\";\r\nimport { $isStr } from \"~/helpers/validate\";\r\n\r\nexport const textEncoder = new TextEncoder();\r\nexport const textDecoder = new TextDecoder();\r\n\r\nexport function $convertStrToBytes(\r\n data: string,\r\n inputEncoding: Encoding = \"utf8\",\r\n): Result<{ result: Uint8Array<ArrayBuffer> }> {\r\n if (!$isStr(data)) {\r\n return $err({\r\n msg: \"Crypto Web API - String to Bytes: Empty data\",\r\n desc: \"Data must be a non-empty string\",\r\n });\r\n }\r\n if (!ENCODING.includes(inputEncoding)) {\r\n return $err({\r\n msg: `Crypto Web API - String to Bytes: Unsupported encoding: ${inputEncoding}`,\r\n desc: \"Use base64, base64url, hex, utf8, or latin1\",\r\n });\r\n }\r\n\r\n try {\r\n const bytes = strToBytes[inputEncoding](data);\r\n return $ok({ result: bytes });\r\n } catch (error) {\r\n return $err({ msg: \"Crypto Web API - String to Bytes: Failed to convert data\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport function $convertBytesToStr(data: Uint8Array | ArrayBuffer, outputEncoding: Encoding = \"utf8\"): Result<string> {\r\n if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) {\r\n return $err({\r\n msg: \"Crypto Web API - Bytes to String: Invalid data type\",\r\n desc: \"Data must be an ArrayBuffer or Uint8Array\",\r\n });\r\n }\r\n if (!ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `Crypto Web API - Bytes to String: Unsupported encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, hex, utf8, or latin1\",\r\n });\r\n }\r\n try {\r\n const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);\r\n const str = bytesToStr[outputEncoding](bytes);\r\n return $ok(str);\r\n } catch (error) {\r\n return $err({ msg: \"Crypto Web API - Bytes to String: Failed to convert data\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport function $convertEncoding(data: string, from: Encoding, to: Encoding): Result<string> {\r\n if (!$isStr(data)) {\r\n return $err({\r\n msg: \"Crypto Web API - Convert Format: Empty data\",\r\n desc: \"Data must be a non-empty string\",\r\n });\r\n }\r\n if (!ENCODING.includes(from) || !ENCODING.includes(to)) {\r\n return $err({\r\n msg: `Crypto Web API - Convert Format: Unsupported encoding: from ${from} to ${to}`,\r\n desc: \"Use base64, base64url, hex, utf8, or latin1\",\r\n });\r\n }\r\n\r\n const bytes = $convertStrToBytes(data, from);\r\n if (bytes.error) return $err({ msg: bytes.error.message, desc: bytes.error.description });\r\n\r\n const str = $convertBytesToStr(bytes.result, to);\r\n if (str.error) return $err({ msg: str.error.message, desc: str.error.description });\r\n\r\n return $ok({ result: str.result });\r\n}\r\n\r\nconst strToBytes = {\r\n base64: $fromBase64,\r\n base64url: $fromBase64Url,\r\n hex: $fromHex,\r\n latin1: $fromLatin1,\r\n utf8: (data: string) => textEncoder.encode(data),\r\n} as const satisfies Record<Encoding, (data: string) => Uint8Array<ArrayBuffer>>;\r\n\r\nconst bytesToStr = {\r\n base64: $toBase64,\r\n base64url: $toBase64Url,\r\n hex: $toHex,\r\n latin1: $toLatin1,\r\n utf8: (data: Uint8Array) => textDecoder.decode(data),\r\n} as const satisfies Record<Encoding, (data: Uint8Array) => string>;\r\n\r\nfunction $toLatin1(bytes: Uint8Array): string {\r\n let out = \"\";\r\n const chunk = 1 << 15; // 32KiB per chunk\r\n for (let i = 0; i < bytes.length; i += chunk) {\r\n out += String.fromCharCode(...bytes.subarray(i, i + chunk));\r\n }\r\n return out;\r\n}\r\n\r\nfunction $fromLatin1(data: string): Uint8Array<ArrayBuffer> {\r\n const out = new Uint8Array(data.length);\r\n for (let i = 0; i < data.length; i++) {\r\n const charCode = data.charCodeAt(i);\r\n if (charCode > 255) throw new Error(\"Invalid latin1 string\");\r\n out[i] = charCode;\r\n }\r\n return out;\r\n}\r\n\r\nfunction $toBase64(bytes: Uint8Array): string {\r\n return btoa($toLatin1(bytes));\r\n}\r\n\r\nfunction $fromBase64(data: string): Uint8Array<ArrayBuffer> {\r\n return $fromLatin1(atob(data));\r\n}\r\n\r\nfunction $toBase64Url(bytes: Uint8Array): string {\r\n return $toBase64(bytes).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\r\n}\r\n\r\nfunction $fromBase64Url(data: string): Uint8Array<ArrayBuffer> {\r\n let base64 = data.replace(/-/g, \"+\").replace(/_/g, \"/\");\r\n const padLen = (4 - (base64.length % 4)) % 4;\r\n base64 += \"=\".repeat(padLen);\r\n return $fromBase64(base64);\r\n}\r\n\r\nfunction $toHex(bytes: Uint8Array): string {\r\n return Array.from(bytes)\r\n .map((b) => b.toString(16).padStart(2, \"0\"))\r\n .join(\"\");\r\n}\r\n\r\nfunction $fromHex(data: string): Uint8Array<ArrayBuffer> {\r\n const clean = data.startsWith(\"0x\") ? data.slice(2) : data;\r\n if (clean.length % 2 !== 0) throw new Error(\"Invalid hex string\");\r\n const out = new Uint8Array(clean.length / 2);\r\n for (let i = 0; i < out.length; i++) {\r\n const byte = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);\r\n if (Number.isNaN(byte)) throw new Error(\"Invalid hex string\");\r\n out[i] = byte;\r\n }\r\n return out;\r\n}\r\n","import { CIPHER_ENCODING, DIGEST_ALGORITHMS, ENCRYPTION_ALGORITHMS } from \"~/helpers/consts\";\r\nimport { $err, $fmtError, $fmtResultErr, $ok, type Result, title } from \"~/helpers/error\";\r\nimport { $parseToObj, $stringifyObj } from \"~/helpers/object\";\r\nimport type {\r\n CreateSecretKeyOptions,\r\n DecryptOptions,\r\n EncryptOptions,\r\n HashOptions,\r\n HashPasswordOptions,\r\n VerifyPasswordOptions,\r\n WebSecretKey,\r\n} from \"~/helpers/types\";\r\nimport { $isPlainObj, $isSecretKey, $isStr, matchEncryptedPattern } from \"~/helpers/validate\";\r\nimport { $convertBytesToStr, $convertStrToBytes, textEncoder } from \"./web-encode\";\r\n\r\nexport function $generateUuid(): Result<string> {\r\n try {\r\n return $ok(crypto.randomUUID());\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"UUID Generation\")}: Failed to generate UUID`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $createSecretKey(\r\n secret: string,\r\n options: CreateSecretKeyOptions,\r\n): Promise<Result<{ result: WebSecretKey }>> {\r\n if (!$isStr(secret, 8)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Empty Secret`,\r\n desc: \"Secret must be a non-empty string with at least 8 characters\",\r\n });\r\n }\r\n\r\n if (!$isPlainObj<CreateSecretKeyOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const algorithm = options.algorithm ?? \"aes256gcm\";\r\n if (!(algorithm in ENCRYPTION_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Unsupported algorithm: ${algorithm}`,\r\n desc: `Supported algorithms are: ${Object.keys(ENCRYPTION_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n\r\n const digest = options.digest ?? \"sha256\";\r\n if (!(digest in DIGEST_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Unsupported digest: ${digest}`,\r\n desc: `Supported digests are: ${Object.keys(DIGEST_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n\r\n const salt = options.salt ?? \"cipher-kit-salt\";\r\n if (!$isStr(salt, 8)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Weak salt`,\r\n desc: \"Salt must be a non-empty string with at least 8 characters\",\r\n });\r\n }\r\n\r\n const info = options.info ?? \"cipher-kit\";\r\n if (!$isStr(info)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Invalid info`,\r\n desc: \"Info must be a non-empty string\",\r\n });\r\n }\r\n\r\n const encryptAlgo = ENCRYPTION_ALGORITHMS[algorithm];\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n try {\r\n const ikm = await crypto.subtle.importKey(\"raw\", textEncoder.encode(secret.normalize(\"NFKC\")), \"HKDF\", false, [\r\n \"deriveKey\",\r\n ]);\r\n const key = await crypto.subtle.deriveKey(\r\n {\r\n name: \"HKDF\",\r\n hash: digestAlgo.web,\r\n salt: textEncoder.encode(salt.normalize(\"NFKC\")),\r\n info: textEncoder.encode(info.normalize(\"NFKC\")),\r\n },\r\n ikm,\r\n { name: encryptAlgo.web, length: encryptAlgo.keyBytes * 8 },\r\n true,\r\n [\"encrypt\", \"decrypt\"],\r\n );\r\n const secretKey = Object.freeze({\r\n platform: \"web\",\r\n digest: digest,\r\n algorithm: algorithm,\r\n key: key,\r\n }) as WebSecretKey;\r\n\r\n return $ok({ result: secretKey });\r\n } catch (error) {\r\n return $err({\r\n msg: `${title(\"web\", \"Key Generation\")}: Failed to create secret key`,\r\n desc: $fmtError(error),\r\n });\r\n }\r\n}\r\n\r\nexport async function $encrypt(\r\n data: string,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions,\r\n): Promise<Result<string>> {\r\n if (!$isStr(data)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Empty data for encryption`,\r\n desc: \"Data must be a non-empty string\",\r\n });\r\n }\r\n\r\n if (!$isPlainObj<EncryptOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const outputEncoding = options.outputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Unsupported output encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const injectedKey = $isSecretKey(secretKey, \"web\");\r\n if (!injectedKey) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Invalid Secret Key`,\r\n desc: \"Expected a Web SecretKey\",\r\n });\r\n }\r\n\r\n const { result, error } = $convertStrToBytes(data, \"utf8\");\r\n if (error) return $err(error);\r\n\r\n try {\r\n const iv = crypto.getRandomValues(new Uint8Array(injectedKey.injected.ivLength));\r\n const cipherWithTag = await crypto.subtle.encrypt(\r\n { name: injectedKey.injected.web, iv: iv },\r\n injectedKey.key,\r\n result,\r\n );\r\n\r\n const ivStr = $convertBytesToStr(iv, outputEncoding);\r\n const cipherStr = $convertBytesToStr(cipherWithTag, outputEncoding);\r\n\r\n if (ivStr.error || cipherStr.error) {\r\n return $err({\r\n msg: `${title(\"web\", \"Encryption\")}: Failed to convert IV or encrypted data`,\r\n desc: `Conversion error: ${$fmtResultErr(ivStr.error || cipherStr.error)}`,\r\n });\r\n }\r\n\r\n return $ok(`${ivStr.result}.${cipherStr.result}.`);\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Encryption\")}: Failed to encrypt data`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $decrypt(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions,\r\n): Promise<Result<string>> {\r\n if (!matchEncryptedPattern(encrypted, \"web\")) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid encrypted data format`,\r\n desc: 'Encrypted data must be in the format \"iv.cipherWithTag.\"',\r\n });\r\n }\r\n\r\n if (!$isPlainObj<DecryptOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const inputEncoding = options.inputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(inputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Unsupported input encoding: ${inputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const [iv, encryptedWithTag] = encrypted.split(\".\", 3);\r\n if (!$isStr(iv) || !$isStr(encryptedWithTag)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid encrypted data`,\r\n desc: \"Encrypted data must contain valid IV, encrypted and tag components\",\r\n });\r\n }\r\n\r\n const injectedKey = $isSecretKey(secretKey, \"web\");\r\n if (!injectedKey) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Invalid Secret Key`,\r\n desc: \"Expected a Web SecretKey\",\r\n });\r\n }\r\n\r\n const ivBytes = $convertStrToBytes(iv, inputEncoding);\r\n const cipherWithTagBytes = $convertStrToBytes(encryptedWithTag, inputEncoding);\r\n\r\n if (ivBytes.error || cipherWithTagBytes.error) {\r\n return $err({\r\n msg: `${title(\"web\", \"Decryption\")}: Failed to convert IV or encrypted data`,\r\n desc: `Conversion error: ${$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`,\r\n });\r\n }\r\n\r\n try {\r\n const decrypted = await crypto.subtle.decrypt(\r\n { name: injectedKey.injected.web, iv: ivBytes.result },\r\n injectedKey.key,\r\n cipherWithTagBytes.result,\r\n );\r\n\r\n return $convertBytesToStr(decrypted, \"utf8\");\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Decryption\")}: Failed to decrypt data`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $encryptObj<T extends object = Record<string, unknown>>(\r\n data: T,\r\n secretKey: WebSecretKey,\r\n options: EncryptOptions,\r\n): Promise<Result<string>> {\r\n const { result, error } = $stringifyObj(data);\r\n if (error) return $err(error);\r\n return await $encrypt(result, secretKey, options);\r\n}\r\n\r\nexport async function $decryptObj<T extends object = Record<string, unknown>>(\r\n encrypted: string,\r\n secretKey: WebSecretKey,\r\n options: DecryptOptions,\r\n): Promise<Result<{ result: T }>> {\r\n const { result, error } = await $decrypt(encrypted, secretKey, options);\r\n if (error) return $err(error);\r\n return $parseToObj<T>(result);\r\n}\r\n\r\nexport async function $hash(data: string, options: HashOptions): Promise<Result<string>> {\r\n if (!$isStr(data)) {\r\n return $err({ msg: `${title(\"web\", \"Hashing\")}: Empty data for hashing`, desc: \"Data must be a non-empty string\" });\r\n }\r\n\r\n if (!$isPlainObj<HashOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Hashing\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const outputEncoding = options.outputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Hashing\")}: Unsupported output encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const digest = options.digest ?? \"sha256\";\r\n if (!(digest in DIGEST_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Hashing\")}: Unsupported digest: ${digest}`,\r\n desc: `Supported digests are: ${Object.keys(DIGEST_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n const { result, error } = $convertStrToBytes(data, \"utf8\");\r\n if (error) return $err(error);\r\n\r\n try {\r\n const hashed = await crypto.subtle.digest(digestAlgo.web, result);\r\n return $convertBytesToStr(hashed, outputEncoding);\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Hashing\")}: Failed to hash data`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $hashPassword(\r\n password: string,\r\n options: HashPasswordOptions,\r\n): Promise<Result<{ result: string; salt: string }>> {\r\n if (!$isStr(password)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Empty password`,\r\n desc: \"Password must be a non-empty string\",\r\n });\r\n }\r\n\r\n if (!$isPlainObj<HashPasswordOptions>(options)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Invalid options`,\r\n desc: \"Options must be an object\",\r\n });\r\n }\r\n\r\n const digest = options.digest ?? \"sha512\";\r\n if (!(digest in DIGEST_ALGORITHMS)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Unsupported digest: ${digest}`,\r\n desc: `Supported digests are: ${Object.keys(DIGEST_ALGORITHMS).join(\", \")}`,\r\n });\r\n }\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n const outputEncoding = options.outputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(outputEncoding)) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Unsupported output encoding: ${outputEncoding}`,\r\n desc: \"Use base64, base64url, or hex\",\r\n });\r\n }\r\n\r\n const saltLength = options.saltLength ?? 16;\r\n if (typeof saltLength !== \"number\" || saltLength < 8) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Weak salt length`,\r\n desc: \"Salt length must be a number and at least 8 bytes (recommended 16)\",\r\n });\r\n }\r\n\r\n const iterations = options.iterations ?? 320_000;\r\n if (typeof iterations !== \"number\" || iterations < 1000) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Weak iteration count`,\r\n desc: \"Iterations must be a number and at least 1000 (recommended 320,000 or more)\",\r\n });\r\n }\r\n\r\n const keyLength = options.keyLength ?? 64;\r\n if (typeof keyLength !== \"number\" || keyLength < 16) {\r\n return $err({\r\n msg: `${title(\"web\", \"Password Hashing\")}: Weak key length`,\r\n desc: \"Key length must be a number and at least 16 bytes (recommended 64)\",\r\n });\r\n }\r\n\r\n try {\r\n const salt = crypto.getRandomValues(new Uint8Array(saltLength));\r\n const baseKey = await crypto.subtle.importKey(\r\n \"raw\",\r\n textEncoder.encode(password.normalize(\"NFKC\")),\r\n \"PBKDF2\",\r\n false,\r\n [\"deriveBits\"],\r\n );\r\n const bits = await crypto.subtle.deriveBits(\r\n { name: \"PBKDF2\", salt, iterations: iterations, hash: digestAlgo.web },\r\n baseKey,\r\n keyLength * 8,\r\n );\r\n\r\n const saltStr = $convertBytesToStr(salt, outputEncoding);\r\n if (saltStr.error) return $err(saltStr.error);\r\n\r\n const hashedPasswordStr = $convertBytesToStr(bits, outputEncoding);\r\n if (hashedPasswordStr.error) return $err(hashedPasswordStr.error);\r\n\r\n return $ok({ result: hashedPasswordStr.result, salt: saltStr.result });\r\n } catch (error) {\r\n return $err({ msg: `${title(\"web\", \"Password Hashing\")}: Failed to hash password`, desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport async function $verifyPassword(\r\n password: string,\r\n hashedPassword: string,\r\n salt: string,\r\n options: VerifyPasswordOptions,\r\n): Promise<boolean> {\r\n if (!$isStr(password) || !$isStr(hashedPassword) || !$isStr(salt) || !$isPlainObj<VerifyPasswordOptions>(options)) {\r\n return false;\r\n }\r\n\r\n const digest = options.digest ?? \"sha512\";\r\n if (!(digest in DIGEST_ALGORITHMS)) return false;\r\n const digestAlgo = DIGEST_ALGORITHMS[digest];\r\n\r\n const inputEncoding = options.inputEncoding ?? \"base64url\";\r\n if (!CIPHER_ENCODING.includes(inputEncoding)) return false;\r\n\r\n const iterations = options.iterations ?? 320_000;\r\n if (typeof iterations !== \"number\" || iterations < 1000) return false;\r\n\r\n const keyLength = options.keyLength ?? 64;\r\n if (typeof keyLength !== \"number\" || keyLength < 16) return false;\r\n\r\n const saltBytes = $convertStrToBytes(salt, inputEncoding);\r\n if (saltBytes.error) return false;\r\n\r\n const hashedPasswordBytes = $convertStrToBytes(hashedPassword, inputEncoding);\r\n if (hashedPasswordBytes.error) return false;\r\n\r\n try {\r\n const baseKey = await crypto.subtle.importKey(\r\n \"raw\",\r\n textEncoder.encode(password.normalize(\"NFKC\")),\r\n \"PBKDF2\",\r\n false,\r\n [\"deriveBits\"],\r\n );\r\n\r\n const bits = new Uint8Array(\r\n await crypto.subtle.deriveBits(\r\n {\r\n name: \"PBKDF2\",\r\n salt: saltBytes.result,\r\n iterations: iterations,\r\n hash: digestAlgo.web,\r\n },\r\n baseKey,\r\n keyLength * 8,\r\n ),\r\n );\r\n\r\n if (bits === undefined || hashedPasswordBytes.result === undefined) return false;\r\n if (bits.length !== hashedPasswordBytes.result.length) return false;\r\n\r\n let diff = 0;\r\n for (let i = 0; i < bits.length; i++) {\r\n diff |= (bits[i] as number) ^ (hashedPasswordBytes.result[i] as number);\r\n }\r\n return diff === 0;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n"]}
@@ -54,6 +54,12 @@ function $isSecretKey(x, platform) {
54
54
  }
55
55
  return Object.freeze({ ...x, injected: algorithm });
56
56
  }
57
+ function isNodeSecretKey(x) {
58
+ return $isSecretKey(x, "node") !== null;
59
+ }
60
+ function isWebSecretKey(x) {
61
+ return $isSecretKey(x, "web") !== null;
62
+ }
57
63
  var ENCRYPTED_REGEX = Object.freeze({
58
64
  node: /^([^.]+)\.([^.]+)\.([^.]+)\.$/,
59
65
  web: /^([^.]+)\.([^.]+)\.$/,
@@ -130,6 +136,6 @@ function parseToObj(str) {
130
136
  return result;
131
137
  }
132
138
 
133
- export { $err, $fmtError, $fmtResultErr, $isPlainObj, $isSecretKey, $isStr, $ok, $parseToObj, $stringifyObj, CIPHER_ENCODING, DIGEST_ALGORITHMS, ENCODING, ENCRYPTED_REGEX, ENCRYPTION_ALGORITHMS, __export, matchEncryptedPattern, parseToObj, stringifyObj, title, tryParseToObj, tryStringifyObj };
134
- //# sourceMappingURL=chunk-6C4NIWQ4.js.map
135
- //# sourceMappingURL=chunk-6C4NIWQ4.js.map
139
+ export { $err, $fmtError, $fmtResultErr, $isPlainObj, $isSecretKey, $isStr, $ok, $parseToObj, $stringifyObj, CIPHER_ENCODING, DIGEST_ALGORITHMS, ENCODING, ENCRYPTED_REGEX, ENCRYPTION_ALGORITHMS, __export, isNodeSecretKey, isWebSecretKey, matchEncryptedPattern, parseToObj, stringifyObj, title, tryParseToObj, tryStringifyObj };
140
+ //# sourceMappingURL=chunk-LU7QOSQH.js.map
141
+ //# sourceMappingURL=chunk-LU7QOSQH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/consts.ts","../src/helpers/validate.ts","../src/helpers/error.ts","../src/helpers/object.ts"],"names":["title"],"mappings":";;;;;;;;;AAAO,IAAM,QAAA,GAAW,OAAO,MAAA,CAAO,CAAC,UAAU,WAAA,EAAa,KAAA,EAAO,MAAA,EAAQ,QAAQ,CAAU;AAExF,IAAM,kBAAkB,MAAA,CAAO,MAAA,CAAO,CAAC,QAAA,EAAU,WAAA,EAAa,KAAK,CAAU;AAE7E,IAAM,iBAAA,GAAoB,OAAO,MAAA,CAAO;AAAA,EAC7C,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,SAAA,EAAU;AAAA,EACzC,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,SAAA,EAAU;AAAA,EACzC,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAU,KAAK,SAAA;AACjC,CAAU;AAEH,IAAM,qBAAA,GAAwB,OAAO,MAAA,CAAO;AAAA,EACjD,SAAA,EAAW,EAAE,QAAA,EAAU,EAAA,EAA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,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAM,GAAI,YAAe,GAAG,CAAA;AAC5C,EAAA,IAAI,OAAO,MAAM,IAAI,KAAA,CAAM,aAAA,CAAc,KAAK,CAAC,CAAA;AAC/C,EAAA,OAAO,MAAA;AACT","file":"chunk-LU7QOSQH.js","sourcesContent":["export const ENCODING = Object.freeze([\"base64\", \"base64url\", \"hex\", \"utf8\", \"latin1\"] as const);\r\n\r\nexport const CIPHER_ENCODING = Object.freeze([\"base64\", \"base64url\", \"hex\"] as const);\r\n\r\nexport const DIGEST_ALGORITHMS = Object.freeze({\r\n sha256: { node: \"sha256\", web: \"SHA-256\" },\r\n sha384: { node: \"sha384\", web: \"SHA-384\" },\r\n sha512: { node: \"sha512\", web: \"SHA-512\" },\r\n} as const);\r\n\r\nexport const ENCRYPTION_ALGORITHMS = Object.freeze({\r\n aes256gcm: { keyBytes: 32, ivLength: 12, node: \"aes-256-gcm\", web: \"AES-GCM\" },\r\n aes192gcm: { keyBytes: 24, ivLength: 12, node: \"aes-192-gcm\", web: \"AES-GCM\" },\r\n aes128gcm: { keyBytes: 16, ivLength: 12, node: \"aes-128-gcm\", web: \"AES-GCM\" },\r\n} as const);\r\n","import nodeCrypto from \"node:crypto\";\r\nimport type { NodeSecretKey, WebSecretKey } from \"~/helpers/types\";\r\nimport { DIGEST_ALGORITHMS, ENCRYPTION_ALGORITHMS } from \"./consts\";\r\n\r\nexport function $isStr(x: unknown, min = 1): x is string {\r\n return x !== null && x !== undefined && typeof x === \"string\" && x.trim().length >= min;\r\n}\r\n\r\nexport function $isPlainObj<T extends object = Record<string, unknown>>(x: unknown): x is T {\r\n if (typeof x !== \"object\" || x === null || x === undefined) return false;\r\n const proto = Object.getPrototypeOf(x);\r\n return proto === Object.prototype || proto === null;\r\n}\r\n\r\nexport function $isObj(x: unknown): x is Record<string, unknown> {\r\n return typeof x === \"object\" && x !== null && x !== undefined;\r\n}\r\n\r\ntype InjectedSecretKey<Platform extends \"web\" | \"node\"> = (Platform extends \"web\" ? WebSecretKey : NodeSecretKey) & {\r\n readonly injected: (typeof ENCRYPTION_ALGORITHMS)[keyof typeof ENCRYPTION_ALGORITHMS];\r\n};\r\n\r\nconst expectedKeys = new Set([\"platform\", \"digest\", \"algorithm\", \"key\"]);\r\n\r\nexport function $isSecretKey<Platform extends \"node\" | \"web\">(\r\n x: unknown,\r\n platform: Platform,\r\n): InjectedSecretKey<Platform> | null {\r\n if (!$isObj(x) || (platform !== \"node\" && platform !== \"web\") || x.platform !== platform) return null;\r\n\r\n const keys = Object.keys(x);\r\n if (keys.length !== expectedKeys.size) return null;\r\n for (const key of keys) if (!expectedKeys.has(key)) return null;\r\n for (const key of expectedKeys) if (!Object.hasOwn(x, key)) return null;\r\n\r\n if (\r\n typeof x.digest !== \"string\" ||\r\n !(x.digest in DIGEST_ALGORITHMS) ||\r\n typeof x.algorithm !== \"string\" ||\r\n !(x.algorithm in ENCRYPTION_ALGORITHMS) ||\r\n !$isObj(x.key) ||\r\n x.key.type !== \"secret\"\r\n ) {\r\n return null;\r\n }\r\n\r\n const algorithm = ENCRYPTION_ALGORITHMS[x.algorithm as keyof typeof ENCRYPTION_ALGORITHMS];\r\n\r\n if (platform === \"node\") {\r\n if (\r\n !(x.key instanceof nodeCrypto.KeyObject) ||\r\n (typeof x.key.symmetricKeySize === \"number\" && x.key.symmetricKeySize !== algorithm.keyBytes)\r\n ) {\r\n return null;\r\n }\r\n return Object.freeze({ ...x, injected: algorithm }) as InjectedSecretKey<Platform>;\r\n }\r\n\r\n if (\r\n !$isObj(x.key.algorithm) ||\r\n x.key.algorithm.name !== algorithm.web ||\r\n (typeof x.key.algorithm.length === \"number\" && x.key.algorithm.length !== algorithm.keyBytes * 8) ||\r\n typeof x.key.extractable !== \"boolean\" ||\r\n !Array.isArray(x.key.usages) ||\r\n x.key.usages.length !== 2 ||\r\n !(x.key.usages.includes(\"encrypt\") && x.key.usages.includes(\"decrypt\"))\r\n ) {\r\n return null;\r\n }\r\n return Object.freeze({ ...x, injected: algorithm }) as InjectedSecretKey<Platform>;\r\n}\r\n\r\n/**\r\n * Type guard to check if the provided value is a SecretKey object for Node.js environment.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Checking if the key in your hand is the right kind of key for the lock.\r\n *\r\n * @param x - The value to check.\r\n * @returns True if the value is a SecretKey object for Node.js, false otherwise.\r\n *\r\n * @example\r\n * ```ts\r\n * isNodeSecretKey(nodeKey); // true\r\n * isNodeSecretKey(webKey); // false\r\n * isNodeSecretKey({}); // false\r\n * ```\r\n */\r\nexport function isNodeSecretKey(x: unknown): x is NodeSecretKey {\r\n return $isSecretKey(x, \"node\") !== null;\r\n}\r\n\r\n/**\r\n * Type guard to check if the provided value is a SecretKey object for Web (Deno, Bun, Cloudflare included) environment.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * Checking if the key in your hand is the right kind of key for the lock.\r\n *\r\n * @param x - The value to check.\r\n * @returns True if the value is a SecretKey object for Web, false otherwise.\r\n *\r\n * @example\r\n * ```ts\r\n * isWebSecretKey(webKey); // true\r\n * isWebSecretKey(nodeKey); // false\r\n * isWebSecretKey({}); // false\r\n * ```\r\n */\r\nexport function isWebSecretKey(x: unknown): x is WebSecretKey {\r\n return $isSecretKey(x, \"web\") !== null;\r\n}\r\n\r\n/**\r\n * Regular expressions for encrypted data patterns.\r\n *\r\n * - **node**: `\"iv.cipher.tag.\"` (three dot-separated parts plus a trailing dot)\r\n * - **web**: `\"iv.cipherWithTag.\"` (two parts plus a trailing dot)\r\n * - **general**: accepts both shapes (2 or 3 parts) with a trailing dot\r\n *\r\n * Each part is any non-empty string without dots.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a secret code you want to check. Before you check it,\r\n * you make sure it looks how a secret code should look.\r\n */\r\nexport const ENCRYPTED_REGEX = Object.freeze({\r\n node: /^([^.]+)\\.([^.]+)\\.([^.]+)\\.$/,\r\n web: /^([^.]+)\\.([^.]+)\\.$/,\r\n general: /^([^.]+)\\.([^.]+)(?:\\.([^.]+))?\\.$/,\r\n});\r\n\r\n/**\r\n * Checks if a string matches an expected encrypted payload shape.\r\n *\r\n * - **node**: `\"iv.cipher.tag.\"` (three dot-separated parts plus a trailing dot)\r\n * - **web**: `\"iv.cipherWithTag.\"` (two parts plus a trailing dot)\r\n * - **general**: accepts both shapes (2 or 3 parts) with a trailing dot\r\n *\r\n * Each part is any non-empty string without dots.\r\n *\r\n * This validates only the **shape**, not whether content is valid base64/hex, etc.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a secret code you want to check. Before you check it,\r\n * you make sure it looks how a secret code should look.\r\n *\r\n * @param data - The string to test.\r\n * @param format - Which layout to check: `'node'`, `'web'`, or `'general'`.\r\n * @returns `true` if the string matches the pattern; otherwise `false`.\r\n * @throws {Error} If an unknown `format` is provided.\r\n *\r\n * @example\r\n * ```ts\r\n * matchEncryptedPattern(\"abc.def.ghi.\", \"node\"); // true\r\n * matchEncryptedPattern(\"abc.def.\", \"web\"); // true\r\n * matchEncryptedPattern(\"abc.def.\", \"node\"); // false\r\n * matchEncryptedPattern(\"abc.def.ghi.\", \"general\"); // true\r\n * ```\r\n */\r\nexport function matchEncryptedPattern(data: string, format: \"node\" | \"web\" | \"general\"): boolean {\r\n if (typeof data !== \"string\") return false;\r\n if (!(format in ENCRYPTED_REGEX)) throw new Error(`Unknown format: ${format}`);\r\n return ENCRYPTED_REGEX[format].test(data);\r\n}\r\n","import { $isPlainObj } from \"./validate\";\r\n\r\n/**\r\n * Standardized error object for the `Result` type.\r\n * Always has a brief `message` and a more detailed `description`.\r\n */\r\nexport interface ErrorStruct {\r\n readonly message: string;\r\n readonly description: string;\r\n}\r\n\r\ntype ReservedWords<Obj extends object> = \"success\" extends keyof Obj ? never : \"error\" extends keyof Obj ? never : Obj;\r\n\r\ntype OkType<T> = {\r\n readonly success: true;\r\n readonly error?: undefined;\r\n} & (T extends object ? ReservedWords<{ readonly [K in keyof T]: T[K] }> : { readonly result: T });\r\n\r\ntype ErrType<T> = {\r\n readonly success: false;\r\n readonly error: ErrorStruct;\r\n} & (T extends object ? ReservedWords<{ readonly [K in keyof T]?: undefined }> : { readonly result?: undefined });\r\n\r\n/**\r\n * Discriminated union for functions that can succeed or fail.\r\n *\r\n * - On **success**:\r\n * - If `T` is an object - properties of `T` are **spread** into the result\r\n * along with `success: true`.\r\n * - Otherwise - `{ success: true, result: T }`.\r\n * - On **failure**: `{ success: false, error: E }`.\r\n *\r\n * @example\r\n * ```ts\r\n * // Primitive result\r\n * function getNum(): Result<number> {\r\n * return $ok(42);\r\n * }\r\n * const r1 = getNum();\r\n * if (r1.success) console.log(r1.result); // 42\r\n *\r\n * // Object result (spread)\r\n * function getObject(): Result<{ name: string; age: number }> {\r\n * return $ok({ name: 'Alice', age: 30 });\r\n * }\r\n * const r2 = getObject();\r\n * if (r2.success) console.log(r2.name, r2.age); // 'Alice' 30\r\n * ```\r\n */\r\nexport type Result<T> = OkType<T> | ErrType<T>;\r\n\r\nexport function $ok<T>(result: T): Result<T> {\r\n if ($isPlainObj(result)) return { success: true, ...(result as T & object) } as Result<T>;\r\n return { success: true, result } as Result<T>;\r\n}\r\n\r\ninterface ShortErrorStruct {\r\n readonly msg: string;\r\n readonly desc: string;\r\n}\r\n\r\nexport function $err(err: ShortErrorStruct | ErrorStruct): Result<never> {\r\n return {\r\n success: false,\r\n error: {\r\n message: \"msg\" in err ? err.msg : err.message,\r\n description: \"desc\" in err ? err.desc : err.description,\r\n },\r\n } as Result<never>;\r\n}\r\n\r\nexport function $fmtError(error: unknown): string {\r\n if (typeof error === \"string\") return error;\r\n if (error instanceof Error) return error.message;\r\n return String(error);\r\n}\r\n\r\nexport function $fmtResultErr(err: ErrorStruct | undefined): string {\r\n if (!err) return \"Unknown error\";\r\n return `${err.message} - ${err.description}`;\r\n}\r\n\r\nexport function title(platform: \"web\" | \"node\", title: string): string {\r\n return `${platform === \"web\" ? \"Crypto Web API\" : \"Crypto NodeJS API\"} - ${title}`;\r\n}\r\n","import { $err, $fmtError, $fmtResultErr, $ok, type Result } from \"./error\";\r\nimport { $isPlainObj, $isStr } from \"./validate\";\r\n\r\nexport function $stringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string> {\r\n try {\r\n if (!$isPlainObj(obj)) return $err({ msg: \"JSON: Invalid object\", desc: \"Input is not a plain object\" });\r\n return $ok(JSON.stringify(obj));\r\n } catch (error) {\r\n return $err({ msg: \"JSON: Stringify error\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\nexport function $parseToObj<T extends object = Record<string, unknown>>(str: string): Result<{ result: T }> {\r\n try {\r\n if (!$isStr(str)) return $err({ msg: \"JSON: Invalid input\", desc: \"Input is not a valid string\" });\r\n const obj = JSON.parse(str);\r\n\r\n if (!$isPlainObj(obj)) {\r\n return $err({ msg: \"JSON: Invalid object format\", desc: \"Parsed data is not a plain object\" });\r\n }\r\n\r\n return $ok({ result: obj as T });\r\n } catch (error) {\r\n return $err({ msg: \"JSON: Invalid format\", desc: $fmtError(error) });\r\n }\r\n}\r\n\r\n/**\r\n * Safely serializes a plain object to JSON without throwing.\r\n *\r\n * Wraps `JSON.stringify` and returns a `Result` containing the JSON string or an error.\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a box of toys (your object) and take a photo of it (a JSON string)\r\n * so you can send it to a friend.\r\n *\r\n * @template T - Plain object type to serialize.\r\n * @param obj - The object to stringify (must be a plain object).\r\n * @returns A `Result` with the JSON string on success, or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const { result, error, success } = tryStringifyObj({ a: 1 });\r\n *\r\n * if (success) console.log(result); // \"{\\\"a\\\":1}\"\r\n * else console.error(error); // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string> {\r\n return $stringifyObj(obj);\r\n}\r\n\r\n/**\r\n * Serializes a plain object to JSON (throwing).\r\n *\r\n * Wraps `JSON.stringify` and returns the result or throws an error.\r\n * Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You have a box of toys (your object) and take a photo of it (a JSON string)\r\n * so you can send it to a friend.\r\n *\r\n * @template T - Plain object type to serialize.\r\n * @param obj - The object to stringify (must be a plain object).\r\n * @returns JSON string representation of the object.\r\n * @throws {Error} If `obj` is not a plain object or serialization fails.\r\n *\r\n * @example\r\n * ```ts\r\n * const json = stringifyObj({ a: 1 }); // \"{\\\"a\\\":1}\"\r\n * ```\r\n */\r\nexport function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string {\r\n const { result, error } = $stringifyObj(obj);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n\r\n/**\r\n * Safely parses a JSON string to a plain object (non-throwing).\r\n *\r\n * Wraps `JSON.parse` and returns a `Result` containing the parsed object, or an error.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) from a photo you took (a JSON string).\r\n *\r\n * @template T - The expected object type.\r\n * @param str - The JSON string to parse.\r\n * @returns A `Result` with the parsed object on success, or an error.\r\n *\r\n * @example\r\n * ```ts\r\n * const {result, error, success} = tryParseToObj<{ a: number }>('{\"a\":1}');\r\n *\r\n * if (success) console.log(result); // { a: 1 }\r\n * else console.error(error) // { message: \"...\", description: \"...\" }\r\n * ```\r\n */\r\nexport function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{ result: T }> {\r\n return $parseToObj<T>(str);\r\n}\r\n\r\n/**\r\n * Parses a JSON string to a plain object (throwing).\r\n *\r\n * Wraps `JSON.parse` and returns the parsed object, or throws on failure.\r\n *\r\n * ### 🍼 Explain Like I'm Five\r\n * You rebuild your toy box (an object) from a photo you took (a JSON string).\r\n *\r\n * @template T - The expected object type.\r\n * @param str - The JSON string to parse.\r\n * @returns The parsed plain object.\r\n * @throws {Error} If the string can’t be parsed or doesn’t represent a plain object.\r\n *\r\n * @example\r\n * ```ts\r\n * const obj = parseToObj<{ a: number }>('{\"a\":1}'); // obj.a === 1\r\n * ```\r\n */\r\nexport function parseToObj<T extends object = Record<string, unknown>>(str: string): T {\r\n const { result, error } = $parseToObj<T>(str);\r\n if (error) throw new Error($fmtResultErr(error));\r\n return result;\r\n}\r\n"]}
@@ -1,4 +1,4 @@
1
- import { __export, $isSecretKey, $fmtResultErr, $ok, $err, $fmtError, title, $isStr, $isPlainObj, ENCRYPTION_ALGORITHMS, DIGEST_ALGORITHMS, CIPHER_ENCODING, matchEncryptedPattern, $stringifyObj, $parseToObj, ENCODING } from './chunk-6C4NIWQ4.js';
1
+ import { __export, $fmtResultErr, $ok, $err, $fmtError, title, $isStr, $isPlainObj, ENCRYPTION_ALGORITHMS, DIGEST_ALGORITHMS, CIPHER_ENCODING, $isSecretKey, matchEncryptedPattern, $stringifyObj, $parseToObj, ENCODING } from './chunk-LU7QOSQH.js';
2
2
  import { Buffer } from 'buffer';
3
3
  import nodeCrypto from 'crypto';
4
4
 
@@ -16,7 +16,6 @@ __export(kit_exports, {
16
16
  generateUuid: () => generateUuid,
17
17
  hash: () => hash,
18
18
  hashPassword: () => hashPassword,
19
- isNodeSecretKey: () => isNodeSecretKey,
20
19
  tryConvertBytesToStr: () => tryConvertBytesToStr,
21
20
  tryConvertEncoding: () => tryConvertEncoding,
22
21
  tryConvertStrToBytes: () => tryConvertStrToBytes,
@@ -389,9 +388,6 @@ function $verifyPassword(password, hashedPassword, salt, options) {
389
388
  }
390
389
 
391
390
  // src/node/kit.ts
392
- function isNodeSecretKey(x) {
393
- return $isSecretKey(x, "node") !== null;
394
- }
395
391
  function tryGenerateUuid() {
396
392
  return $generateUuid();
397
393
  }
@@ -484,6 +480,6 @@ function convertEncoding(data, from, to) {
484
480
  return result;
485
481
  }
486
482
 
487
- export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, isNodeSecretKey, kit_exports, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword };
488
- //# sourceMappingURL=chunk-PWTFVMW6.js.map
489
- //# sourceMappingURL=chunk-PWTFVMW6.js.map
483
+ export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, kit_exports, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword };
484
+ //# sourceMappingURL=chunk-S6SNCTU6.js.map
485
+ //# sourceMappingURL=chunk-S6SNCTU6.js.map