cipher-kit 2.1.1 → 2.1.3

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-BMX42IZM.cjs} +145 -150
  2. package/dist/chunk-BMX42IZM.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-6C4NIWQ4.js → chunk-LU7QOSQH.js} +9 -3
  6. package/dist/chunk-LU7QOSQH.js.map +1 -0
  7. package/dist/{chunk-PWTFVMW6.js → chunk-S6SNCTU6.js} +4 -8
  8. package/dist/chunk-S6SNCTU6.js.map +1 -0
  9. package/dist/{chunk-FSEA3UXJ.js → chunk-T36BEDPY.js} +4 -8
  10. package/dist/chunk-T36BEDPY.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
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkX4CS7UXE_cjs = require('./chunk-X4CS7UXE.cjs');
3
+ var chunkHTRGOBZF_cjs = require('./chunk-HTRGOBZF.cjs');
4
4
 
5
5
  // src/web/kit.ts
6
6
  var kit_exports = {};
7
- chunkX4CS7UXE_cjs.__export(kit_exports, {
7
+ chunkHTRGOBZF_cjs.__export(kit_exports, {
8
8
  convertBytesToStr: () => convertBytesToStr,
9
9
  convertEncoding: () => convertEncoding,
10
10
  convertStrToBytes: () => convertStrToBytes,
@@ -16,7 +16,6 @@ chunkX4CS7UXE_cjs.__export(kit_exports, {
16
16
  generateUuid: () => generateUuid,
17
17
  hash: () => hash,
18
18
  hashPassword: () => hashPassword,
19
- isWebSecretKey: () => isWebSecretKey,
20
19
  tryConvertBytesToStr: () => tryConvertBytesToStr,
21
20
  tryConvertEncoding: () => tryConvertEncoding,
22
21
  tryConvertStrToBytes: () => tryConvertStrToBytes,
@@ -35,34 +34,34 @@ chunkX4CS7UXE_cjs.__export(kit_exports, {
35
34
  var textEncoder = new TextEncoder();
36
35
  var textDecoder = new TextDecoder();
37
36
  function $convertStrToBytes(data, inputEncoding = "utf8") {
38
- if (!chunkX4CS7UXE_cjs.$isStr(data)) {
39
- return chunkX4CS7UXE_cjs.$err({
37
+ if (!chunkHTRGOBZF_cjs.$isStr(data)) {
38
+ return chunkHTRGOBZF_cjs.$err({
40
39
  msg: "Crypto Web API - String to Bytes: Empty data",
41
40
  desc: "Data must be a non-empty string"
42
41
  });
43
42
  }
44
- if (!chunkX4CS7UXE_cjs.ENCODING.includes(inputEncoding)) {
45
- return chunkX4CS7UXE_cjs.$err({
43
+ if (!chunkHTRGOBZF_cjs.ENCODING.includes(inputEncoding)) {
44
+ return chunkHTRGOBZF_cjs.$err({
46
45
  msg: `Crypto Web API - String to Bytes: Unsupported encoding: ${inputEncoding}`,
47
46
  desc: "Use base64, base64url, hex, utf8, or latin1"
48
47
  });
49
48
  }
50
49
  try {
51
50
  const bytes = strToBytes[inputEncoding](data);
52
- return chunkX4CS7UXE_cjs.$ok({ result: bytes });
51
+ return chunkHTRGOBZF_cjs.$ok({ result: bytes });
53
52
  } catch (error) {
54
- return chunkX4CS7UXE_cjs.$err({ msg: "Crypto Web API - String to Bytes: Failed to convert data", desc: chunkX4CS7UXE_cjs.$fmtError(error) });
53
+ return chunkHTRGOBZF_cjs.$err({ msg: "Crypto Web API - String to Bytes: Failed to convert data", desc: chunkHTRGOBZF_cjs.$fmtError(error) });
55
54
  }
56
55
  }
57
56
  function $convertBytesToStr(data, outputEncoding = "utf8") {
58
57
  if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) {
59
- return chunkX4CS7UXE_cjs.$err({
58
+ return chunkHTRGOBZF_cjs.$err({
60
59
  msg: "Crypto Web API - Bytes to String: Invalid data type",
61
60
  desc: "Data must be an ArrayBuffer or Uint8Array"
62
61
  });
63
62
  }
64
- if (!chunkX4CS7UXE_cjs.ENCODING.includes(outputEncoding)) {
65
- return chunkX4CS7UXE_cjs.$err({
63
+ if (!chunkHTRGOBZF_cjs.ENCODING.includes(outputEncoding)) {
64
+ return chunkHTRGOBZF_cjs.$err({
66
65
  msg: `Crypto Web API - Bytes to String: Unsupported encoding: ${outputEncoding}`,
67
66
  desc: "Use base64, base64url, hex, utf8, or latin1"
68
67
  });
@@ -70,29 +69,29 @@ function $convertBytesToStr(data, outputEncoding = "utf8") {
70
69
  try {
71
70
  const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
72
71
  const str = bytesToStr[outputEncoding](bytes);
73
- return chunkX4CS7UXE_cjs.$ok(str);
72
+ return chunkHTRGOBZF_cjs.$ok(str);
74
73
  } catch (error) {
75
- return chunkX4CS7UXE_cjs.$err({ msg: "Crypto Web API - Bytes to String: Failed to convert data", desc: chunkX4CS7UXE_cjs.$fmtError(error) });
74
+ return chunkHTRGOBZF_cjs.$err({ msg: "Crypto Web API - Bytes to String: Failed to convert data", desc: chunkHTRGOBZF_cjs.$fmtError(error) });
76
75
  }
77
76
  }
78
77
  function $convertEncoding(data, from, to) {
79
- if (!chunkX4CS7UXE_cjs.$isStr(data)) {
80
- return chunkX4CS7UXE_cjs.$err({
78
+ if (!chunkHTRGOBZF_cjs.$isStr(data)) {
79
+ return chunkHTRGOBZF_cjs.$err({
81
80
  msg: "Crypto Web API - Convert Format: Empty data",
82
81
  desc: "Data must be a non-empty string"
83
82
  });
84
83
  }
85
- if (!chunkX4CS7UXE_cjs.ENCODING.includes(from) || !chunkX4CS7UXE_cjs.ENCODING.includes(to)) {
86
- return chunkX4CS7UXE_cjs.$err({
84
+ if (!chunkHTRGOBZF_cjs.ENCODING.includes(from) || !chunkHTRGOBZF_cjs.ENCODING.includes(to)) {
85
+ return chunkHTRGOBZF_cjs.$err({
87
86
  msg: `Crypto Web API - Convert Format: Unsupported encoding: from ${from} to ${to}`,
88
87
  desc: "Use base64, base64url, hex, utf8, or latin1"
89
88
  });
90
89
  }
91
90
  const bytes = $convertStrToBytes(data, from);
92
- if (bytes.error) return chunkX4CS7UXE_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
91
+ if (bytes.error) return chunkHTRGOBZF_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
93
92
  const str = $convertBytesToStr(bytes.result, to);
94
- if (str.error) return chunkX4CS7UXE_cjs.$err({ msg: str.error.message, desc: str.error.description });
95
- return chunkX4CS7UXE_cjs.$ok({ result: str.result });
93
+ if (str.error) return chunkHTRGOBZF_cjs.$err({ msg: str.error.message, desc: str.error.description });
94
+ return chunkHTRGOBZF_cjs.$ok({ result: str.result });
96
95
  }
97
96
  var strToBytes = {
98
97
  base64: $fromBase64,
@@ -158,54 +157,54 @@ function $fromHex(data) {
158
157
  // src/web/web-encrypt.ts
159
158
  function $generateUuid() {
160
159
  try {
161
- return chunkX4CS7UXE_cjs.$ok(crypto.randomUUID());
160
+ return chunkHTRGOBZF_cjs.$ok(crypto.randomUUID());
162
161
  } catch (error) {
163
- return chunkX4CS7UXE_cjs.$err({ msg: `${chunkX4CS7UXE_cjs.title("web", "UUID Generation")}: Failed to generate UUID`, desc: chunkX4CS7UXE_cjs.$fmtError(error) });
162
+ return chunkHTRGOBZF_cjs.$err({ msg: `${chunkHTRGOBZF_cjs.title("web", "UUID Generation")}: Failed to generate UUID`, desc: chunkHTRGOBZF_cjs.$fmtError(error) });
164
163
  }
165
164
  }
166
165
  async function $createSecretKey(secret, options) {
167
- if (!chunkX4CS7UXE_cjs.$isStr(secret, 8)) {
168
- return chunkX4CS7UXE_cjs.$err({
169
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Empty Secret`,
166
+ if (!chunkHTRGOBZF_cjs.$isStr(secret, 8)) {
167
+ return chunkHTRGOBZF_cjs.$err({
168
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Empty Secret`,
170
169
  desc: "Secret must be a non-empty string with at least 8 characters"
171
170
  });
172
171
  }
173
- if (!chunkX4CS7UXE_cjs.$isPlainObj(options)) {
174
- return chunkX4CS7UXE_cjs.$err({
175
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Invalid options`,
172
+ if (!chunkHTRGOBZF_cjs.$isPlainObj(options)) {
173
+ return chunkHTRGOBZF_cjs.$err({
174
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Invalid options`,
176
175
  desc: "Options must be an object"
177
176
  });
178
177
  }
179
178
  const algorithm = options.algorithm ?? "aes256gcm";
180
- if (!(algorithm in chunkX4CS7UXE_cjs.ENCRYPTION_ALGORITHMS)) {
181
- return chunkX4CS7UXE_cjs.$err({
182
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
183
- desc: `Supported algorithms are: ${Object.keys(chunkX4CS7UXE_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
179
+ if (!(algorithm in chunkHTRGOBZF_cjs.ENCRYPTION_ALGORITHMS)) {
180
+ return chunkHTRGOBZF_cjs.$err({
181
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
182
+ desc: `Supported algorithms are: ${Object.keys(chunkHTRGOBZF_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
184
183
  });
185
184
  }
186
185
  const digest = options.digest ?? "sha256";
187
- if (!(digest in chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS)) {
188
- return chunkX4CS7UXE_cjs.$err({
189
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Unsupported digest: ${digest}`,
190
- desc: `Supported digests are: ${Object.keys(chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS).join(", ")}`
186
+ if (!(digest in chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS)) {
187
+ return chunkHTRGOBZF_cjs.$err({
188
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Unsupported digest: ${digest}`,
189
+ desc: `Supported digests are: ${Object.keys(chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS).join(", ")}`
191
190
  });
192
191
  }
193
192
  const salt = options.salt ?? "cipher-kit-salt";
194
- if (!chunkX4CS7UXE_cjs.$isStr(salt, 8)) {
195
- return chunkX4CS7UXE_cjs.$err({
196
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Weak salt`,
193
+ if (!chunkHTRGOBZF_cjs.$isStr(salt, 8)) {
194
+ return chunkHTRGOBZF_cjs.$err({
195
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Weak salt`,
197
196
  desc: "Salt must be a non-empty string with at least 8 characters"
198
197
  });
199
198
  }
200
199
  const info = options.info ?? "cipher-kit";
201
- if (!chunkX4CS7UXE_cjs.$isStr(info)) {
202
- return chunkX4CS7UXE_cjs.$err({
203
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Invalid info`,
200
+ if (!chunkHTRGOBZF_cjs.$isStr(info)) {
201
+ return chunkHTRGOBZF_cjs.$err({
202
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Invalid info`,
204
203
  desc: "Info must be a non-empty string"
205
204
  });
206
205
  }
207
- const encryptAlgo = chunkX4CS7UXE_cjs.ENCRYPTION_ALGORITHMS[algorithm];
208
- const digestAlgo = chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS[digest];
206
+ const encryptAlgo = chunkHTRGOBZF_cjs.ENCRYPTION_ALGORITHMS[algorithm];
207
+ const digestAlgo = chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS[digest];
209
208
  try {
210
209
  const ikm = await crypto.subtle.importKey("raw", textEncoder.encode(secret.normalize("NFKC")), "HKDF", false, [
211
210
  "deriveKey"
@@ -228,43 +227,43 @@ async function $createSecretKey(secret, options) {
228
227
  algorithm,
229
228
  key
230
229
  });
231
- return chunkX4CS7UXE_cjs.$ok({ result: secretKey });
230
+ return chunkHTRGOBZF_cjs.$ok({ result: secretKey });
232
231
  } catch (error) {
233
- return chunkX4CS7UXE_cjs.$err({
234
- msg: `${chunkX4CS7UXE_cjs.title("web", "Key Generation")}: Failed to create secret key`,
235
- desc: chunkX4CS7UXE_cjs.$fmtError(error)
232
+ return chunkHTRGOBZF_cjs.$err({
233
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Key Generation")}: Failed to create secret key`,
234
+ desc: chunkHTRGOBZF_cjs.$fmtError(error)
236
235
  });
237
236
  }
238
237
  }
239
238
  async function $encrypt(data, secretKey, options) {
240
- if (!chunkX4CS7UXE_cjs.$isStr(data)) {
241
- return chunkX4CS7UXE_cjs.$err({
242
- msg: `${chunkX4CS7UXE_cjs.title("web", "Encryption")}: Empty data for encryption`,
239
+ if (!chunkHTRGOBZF_cjs.$isStr(data)) {
240
+ return chunkHTRGOBZF_cjs.$err({
241
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Encryption")}: Empty data for encryption`,
243
242
  desc: "Data must be a non-empty string"
244
243
  });
245
244
  }
246
- if (!chunkX4CS7UXE_cjs.$isPlainObj(options)) {
247
- return chunkX4CS7UXE_cjs.$err({
248
- msg: `${chunkX4CS7UXE_cjs.title("web", "Encryption")}: Invalid options`,
245
+ if (!chunkHTRGOBZF_cjs.$isPlainObj(options)) {
246
+ return chunkHTRGOBZF_cjs.$err({
247
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Encryption")}: Invalid options`,
249
248
  desc: "Options must be an object"
250
249
  });
251
250
  }
252
251
  const outputEncoding = options.outputEncoding ?? "base64url";
253
- if (!chunkX4CS7UXE_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
254
- return chunkX4CS7UXE_cjs.$err({
255
- msg: `${chunkX4CS7UXE_cjs.title("web", "Encryption")}: Unsupported output encoding: ${outputEncoding}`,
252
+ if (!chunkHTRGOBZF_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
253
+ return chunkHTRGOBZF_cjs.$err({
254
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Encryption")}: Unsupported output encoding: ${outputEncoding}`,
256
255
  desc: "Use base64, base64url, or hex"
257
256
  });
258
257
  }
259
- const injectedKey = chunkX4CS7UXE_cjs.$isSecretKey(secretKey, "web");
258
+ const injectedKey = chunkHTRGOBZF_cjs.$isSecretKey(secretKey, "web");
260
259
  if (!injectedKey) {
261
- return chunkX4CS7UXE_cjs.$err({
262
- msg: `${chunkX4CS7UXE_cjs.title("web", "Encryption")}: Invalid Secret Key`,
260
+ return chunkHTRGOBZF_cjs.$err({
261
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Encryption")}: Invalid Secret Key`,
263
262
  desc: "Expected a Web SecretKey"
264
263
  });
265
264
  }
266
265
  const { result, error } = $convertStrToBytes(data, "utf8");
267
- if (error) return chunkX4CS7UXE_cjs.$err(error);
266
+ if (error) return chunkHTRGOBZF_cjs.$err(error);
268
267
  try {
269
268
  const iv = crypto.getRandomValues(new Uint8Array(injectedKey.injected.ivLength));
270
269
  const cipherWithTag = await crypto.subtle.encrypt(
@@ -275,56 +274,56 @@ async function $encrypt(data, secretKey, options) {
275
274
  const ivStr = $convertBytesToStr(iv, outputEncoding);
276
275
  const cipherStr = $convertBytesToStr(cipherWithTag, outputEncoding);
277
276
  if (ivStr.error || cipherStr.error) {
278
- return chunkX4CS7UXE_cjs.$err({
279
- msg: `${chunkX4CS7UXE_cjs.title("web", "Encryption")}: Failed to convert IV or encrypted data`,
280
- desc: `Conversion error: ${chunkX4CS7UXE_cjs.$fmtResultErr(ivStr.error || cipherStr.error)}`
277
+ return chunkHTRGOBZF_cjs.$err({
278
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Encryption")}: Failed to convert IV or encrypted data`,
279
+ desc: `Conversion error: ${chunkHTRGOBZF_cjs.$fmtResultErr(ivStr.error || cipherStr.error)}`
281
280
  });
282
281
  }
283
- return chunkX4CS7UXE_cjs.$ok(`${ivStr.result}.${cipherStr.result}.`);
282
+ return chunkHTRGOBZF_cjs.$ok(`${ivStr.result}.${cipherStr.result}.`);
284
283
  } catch (error2) {
285
- return chunkX4CS7UXE_cjs.$err({ msg: `${chunkX4CS7UXE_cjs.title("web", "Encryption")}: Failed to encrypt data`, desc: chunkX4CS7UXE_cjs.$fmtError(error2) });
284
+ return chunkHTRGOBZF_cjs.$err({ msg: `${chunkHTRGOBZF_cjs.title("web", "Encryption")}: Failed to encrypt data`, desc: chunkHTRGOBZF_cjs.$fmtError(error2) });
286
285
  }
287
286
  }
288
287
  async function $decrypt(encrypted, secretKey, options) {
289
- if (!chunkX4CS7UXE_cjs.matchEncryptedPattern(encrypted, "web")) {
290
- return chunkX4CS7UXE_cjs.$err({
291
- msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Invalid encrypted data format`,
288
+ if (!chunkHTRGOBZF_cjs.matchEncryptedPattern(encrypted, "web")) {
289
+ return chunkHTRGOBZF_cjs.$err({
290
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Invalid encrypted data format`,
292
291
  desc: 'Encrypted data must be in the format "iv.cipherWithTag."'
293
292
  });
294
293
  }
295
- if (!chunkX4CS7UXE_cjs.$isPlainObj(options)) {
296
- return chunkX4CS7UXE_cjs.$err({
297
- msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Invalid options`,
294
+ if (!chunkHTRGOBZF_cjs.$isPlainObj(options)) {
295
+ return chunkHTRGOBZF_cjs.$err({
296
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Invalid options`,
298
297
  desc: "Options must be an object"
299
298
  });
300
299
  }
301
300
  const inputEncoding = options.inputEncoding ?? "base64url";
302
- if (!chunkX4CS7UXE_cjs.CIPHER_ENCODING.includes(inputEncoding)) {
303
- return chunkX4CS7UXE_cjs.$err({
304
- msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Unsupported input encoding: ${inputEncoding}`,
301
+ if (!chunkHTRGOBZF_cjs.CIPHER_ENCODING.includes(inputEncoding)) {
302
+ return chunkHTRGOBZF_cjs.$err({
303
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Unsupported input encoding: ${inputEncoding}`,
305
304
  desc: "Use base64, base64url, or hex"
306
305
  });
307
306
  }
308
307
  const [iv, encryptedWithTag] = encrypted.split(".", 3);
309
- if (!chunkX4CS7UXE_cjs.$isStr(iv) || !chunkX4CS7UXE_cjs.$isStr(encryptedWithTag)) {
310
- return chunkX4CS7UXE_cjs.$err({
311
- msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Invalid encrypted data`,
308
+ if (!chunkHTRGOBZF_cjs.$isStr(iv) || !chunkHTRGOBZF_cjs.$isStr(encryptedWithTag)) {
309
+ return chunkHTRGOBZF_cjs.$err({
310
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Invalid encrypted data`,
312
311
  desc: "Encrypted data must contain valid IV, encrypted and tag components"
313
312
  });
314
313
  }
315
- const injectedKey = chunkX4CS7UXE_cjs.$isSecretKey(secretKey, "web");
314
+ const injectedKey = chunkHTRGOBZF_cjs.$isSecretKey(secretKey, "web");
316
315
  if (!injectedKey) {
317
- return chunkX4CS7UXE_cjs.$err({
318
- msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Invalid Secret Key`,
316
+ return chunkHTRGOBZF_cjs.$err({
317
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Invalid Secret Key`,
319
318
  desc: "Expected a Web SecretKey"
320
319
  });
321
320
  }
322
321
  const ivBytes = $convertStrToBytes(iv, inputEncoding);
323
322
  const cipherWithTagBytes = $convertStrToBytes(encryptedWithTag, inputEncoding);
324
323
  if (ivBytes.error || cipherWithTagBytes.error) {
325
- return chunkX4CS7UXE_cjs.$err({
326
- msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Failed to convert IV or encrypted data`,
327
- desc: `Conversion error: ${chunkX4CS7UXE_cjs.$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`
324
+ return chunkHTRGOBZF_cjs.$err({
325
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Failed to convert IV or encrypted data`,
326
+ desc: `Conversion error: ${chunkHTRGOBZF_cjs.$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`
328
327
  });
329
328
  }
330
329
  try {
@@ -335,99 +334,99 @@ async function $decrypt(encrypted, secretKey, options) {
335
334
  );
336
335
  return $convertBytesToStr(decrypted, "utf8");
337
336
  } catch (error) {
338
- return chunkX4CS7UXE_cjs.$err({ msg: `${chunkX4CS7UXE_cjs.title("web", "Decryption")}: Failed to decrypt data`, desc: chunkX4CS7UXE_cjs.$fmtError(error) });
337
+ return chunkHTRGOBZF_cjs.$err({ msg: `${chunkHTRGOBZF_cjs.title("web", "Decryption")}: Failed to decrypt data`, desc: chunkHTRGOBZF_cjs.$fmtError(error) });
339
338
  }
340
339
  }
341
340
  async function $encryptObj(data, secretKey, options) {
342
- const { result, error } = chunkX4CS7UXE_cjs.$stringifyObj(data);
343
- if (error) return chunkX4CS7UXE_cjs.$err(error);
341
+ const { result, error } = chunkHTRGOBZF_cjs.$stringifyObj(data);
342
+ if (error) return chunkHTRGOBZF_cjs.$err(error);
344
343
  return await $encrypt(result, secretKey, options);
345
344
  }
346
345
  async function $decryptObj(encrypted, secretKey, options) {
347
346
  const { result, error } = await $decrypt(encrypted, secretKey, options);
348
- if (error) return chunkX4CS7UXE_cjs.$err(error);
349
- return chunkX4CS7UXE_cjs.$parseToObj(result);
347
+ if (error) return chunkHTRGOBZF_cjs.$err(error);
348
+ return chunkHTRGOBZF_cjs.$parseToObj(result);
350
349
  }
351
350
  async function $hash(data, options) {
352
- if (!chunkX4CS7UXE_cjs.$isStr(data)) {
353
- return chunkX4CS7UXE_cjs.$err({ msg: `${chunkX4CS7UXE_cjs.title("web", "Hashing")}: Empty data for hashing`, desc: "Data must be a non-empty string" });
351
+ if (!chunkHTRGOBZF_cjs.$isStr(data)) {
352
+ return chunkHTRGOBZF_cjs.$err({ msg: `${chunkHTRGOBZF_cjs.title("web", "Hashing")}: Empty data for hashing`, desc: "Data must be a non-empty string" });
354
353
  }
355
- if (!chunkX4CS7UXE_cjs.$isPlainObj(options)) {
356
- return chunkX4CS7UXE_cjs.$err({
357
- msg: `${chunkX4CS7UXE_cjs.title("web", "Hashing")}: Invalid options`,
354
+ if (!chunkHTRGOBZF_cjs.$isPlainObj(options)) {
355
+ return chunkHTRGOBZF_cjs.$err({
356
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Hashing")}: Invalid options`,
358
357
  desc: "Options must be an object"
359
358
  });
360
359
  }
361
360
  const outputEncoding = options.outputEncoding ?? "base64url";
362
- if (!chunkX4CS7UXE_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
363
- return chunkX4CS7UXE_cjs.$err({
364
- msg: `${chunkX4CS7UXE_cjs.title("web", "Hashing")}: Unsupported output encoding: ${outputEncoding}`,
361
+ if (!chunkHTRGOBZF_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
362
+ return chunkHTRGOBZF_cjs.$err({
363
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Hashing")}: Unsupported output encoding: ${outputEncoding}`,
365
364
  desc: "Use base64, base64url, or hex"
366
365
  });
367
366
  }
368
367
  const digest = options.digest ?? "sha256";
369
- if (!(digest in chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS)) {
370
- return chunkX4CS7UXE_cjs.$err({
371
- msg: `${chunkX4CS7UXE_cjs.title("web", "Hashing")}: Unsupported digest: ${digest}`,
372
- desc: `Supported digests are: ${Object.keys(chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS).join(", ")}`
368
+ if (!(digest in chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS)) {
369
+ return chunkHTRGOBZF_cjs.$err({
370
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Hashing")}: Unsupported digest: ${digest}`,
371
+ desc: `Supported digests are: ${Object.keys(chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS).join(", ")}`
373
372
  });
374
373
  }
375
- const digestAlgo = chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS[digest];
374
+ const digestAlgo = chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS[digest];
376
375
  const { result, error } = $convertStrToBytes(data, "utf8");
377
- if (error) return chunkX4CS7UXE_cjs.$err(error);
376
+ if (error) return chunkHTRGOBZF_cjs.$err(error);
378
377
  try {
379
378
  const hashed = await crypto.subtle.digest(digestAlgo.web, result);
380
379
  return $convertBytesToStr(hashed, outputEncoding);
381
380
  } catch (error2) {
382
- return chunkX4CS7UXE_cjs.$err({ msg: `${chunkX4CS7UXE_cjs.title("web", "Hashing")}: Failed to hash data`, desc: chunkX4CS7UXE_cjs.$fmtError(error2) });
381
+ return chunkHTRGOBZF_cjs.$err({ msg: `${chunkHTRGOBZF_cjs.title("web", "Hashing")}: Failed to hash data`, desc: chunkHTRGOBZF_cjs.$fmtError(error2) });
383
382
  }
384
383
  }
385
384
  async function $hashPassword(password, options) {
386
- if (!chunkX4CS7UXE_cjs.$isStr(password)) {
387
- return chunkX4CS7UXE_cjs.$err({
388
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Empty password`,
385
+ if (!chunkHTRGOBZF_cjs.$isStr(password)) {
386
+ return chunkHTRGOBZF_cjs.$err({
387
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Empty password`,
389
388
  desc: "Password must be a non-empty string"
390
389
  });
391
390
  }
392
- if (!chunkX4CS7UXE_cjs.$isPlainObj(options)) {
393
- return chunkX4CS7UXE_cjs.$err({
394
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Invalid options`,
391
+ if (!chunkHTRGOBZF_cjs.$isPlainObj(options)) {
392
+ return chunkHTRGOBZF_cjs.$err({
393
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Invalid options`,
395
394
  desc: "Options must be an object"
396
395
  });
397
396
  }
398
397
  const digest = options.digest ?? "sha512";
399
- if (!(digest in chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS)) {
400
- return chunkX4CS7UXE_cjs.$err({
401
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Unsupported digest: ${digest}`,
402
- desc: `Supported digests are: ${Object.keys(chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS).join(", ")}`
398
+ if (!(digest in chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS)) {
399
+ return chunkHTRGOBZF_cjs.$err({
400
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Unsupported digest: ${digest}`,
401
+ desc: `Supported digests are: ${Object.keys(chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS).join(", ")}`
403
402
  });
404
403
  }
405
- const digestAlgo = chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS[digest];
404
+ const digestAlgo = chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS[digest];
406
405
  const outputEncoding = options.outputEncoding ?? "base64url";
407
- if (!chunkX4CS7UXE_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
408
- return chunkX4CS7UXE_cjs.$err({
409
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Unsupported output encoding: ${outputEncoding}`,
406
+ if (!chunkHTRGOBZF_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
407
+ return chunkHTRGOBZF_cjs.$err({
408
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Unsupported output encoding: ${outputEncoding}`,
410
409
  desc: "Use base64, base64url, or hex"
411
410
  });
412
411
  }
413
412
  const saltLength = options.saltLength ?? 16;
414
413
  if (typeof saltLength !== "number" || saltLength < 8) {
415
- return chunkX4CS7UXE_cjs.$err({
416
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Weak salt length`,
414
+ return chunkHTRGOBZF_cjs.$err({
415
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Weak salt length`,
417
416
  desc: "Salt length must be a number and at least 8 bytes (recommended 16)"
418
417
  });
419
418
  }
420
419
  const iterations = options.iterations ?? 32e4;
421
420
  if (typeof iterations !== "number" || iterations < 1e3) {
422
- return chunkX4CS7UXE_cjs.$err({
423
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Weak iteration count`,
421
+ return chunkHTRGOBZF_cjs.$err({
422
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Weak iteration count`,
424
423
  desc: "Iterations must be a number and at least 1000 (recommended 320,000 or more)"
425
424
  });
426
425
  }
427
426
  const keyLength = options.keyLength ?? 64;
428
427
  if (typeof keyLength !== "number" || keyLength < 16) {
429
- return chunkX4CS7UXE_cjs.$err({
430
- msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Weak key length`,
428
+ return chunkHTRGOBZF_cjs.$err({
429
+ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Weak key length`,
431
430
  desc: "Key length must be a number and at least 16 bytes (recommended 64)"
432
431
  });
433
432
  }
@@ -446,23 +445,23 @@ async function $hashPassword(password, options) {
446
445
  keyLength * 8
447
446
  );
448
447
  const saltStr = $convertBytesToStr(salt, outputEncoding);
449
- if (saltStr.error) return chunkX4CS7UXE_cjs.$err(saltStr.error);
448
+ if (saltStr.error) return chunkHTRGOBZF_cjs.$err(saltStr.error);
450
449
  const hashedPasswordStr = $convertBytesToStr(bits, outputEncoding);
451
- if (hashedPasswordStr.error) return chunkX4CS7UXE_cjs.$err(hashedPasswordStr.error);
452
- return chunkX4CS7UXE_cjs.$ok({ result: hashedPasswordStr.result, salt: saltStr.result });
450
+ if (hashedPasswordStr.error) return chunkHTRGOBZF_cjs.$err(hashedPasswordStr.error);
451
+ return chunkHTRGOBZF_cjs.$ok({ result: hashedPasswordStr.result, salt: saltStr.result });
453
452
  } catch (error) {
454
- return chunkX4CS7UXE_cjs.$err({ msg: `${chunkX4CS7UXE_cjs.title("web", "Password Hashing")}: Failed to hash password`, desc: chunkX4CS7UXE_cjs.$fmtError(error) });
453
+ return chunkHTRGOBZF_cjs.$err({ msg: `${chunkHTRGOBZF_cjs.title("web", "Password Hashing")}: Failed to hash password`, desc: chunkHTRGOBZF_cjs.$fmtError(error) });
455
454
  }
456
455
  }
457
456
  async function $verifyPassword(password, hashedPassword, salt, options) {
458
- if (!chunkX4CS7UXE_cjs.$isStr(password) || !chunkX4CS7UXE_cjs.$isStr(hashedPassword) || !chunkX4CS7UXE_cjs.$isStr(salt) || !chunkX4CS7UXE_cjs.$isPlainObj(options)) {
457
+ if (!chunkHTRGOBZF_cjs.$isStr(password) || !chunkHTRGOBZF_cjs.$isStr(hashedPassword) || !chunkHTRGOBZF_cjs.$isStr(salt) || !chunkHTRGOBZF_cjs.$isPlainObj(options)) {
459
458
  return false;
460
459
  }
461
460
  const digest = options.digest ?? "sha512";
462
- if (!(digest in chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS)) return false;
463
- const digestAlgo = chunkX4CS7UXE_cjs.DIGEST_ALGORITHMS[digest];
461
+ if (!(digest in chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS)) return false;
462
+ const digestAlgo = chunkHTRGOBZF_cjs.DIGEST_ALGORITHMS[digest];
464
463
  const inputEncoding = options.inputEncoding ?? "base64url";
465
- if (!chunkX4CS7UXE_cjs.CIPHER_ENCODING.includes(inputEncoding)) return false;
464
+ if (!chunkHTRGOBZF_cjs.CIPHER_ENCODING.includes(inputEncoding)) return false;
466
465
  const iterations = options.iterations ?? 32e4;
467
466
  if (typeof iterations !== "number" || iterations < 1e3) return false;
468
467
  const keyLength = options.keyLength ?? 64;
@@ -504,15 +503,12 @@ async function $verifyPassword(password, hashedPassword, salt, options) {
504
503
  }
505
504
 
506
505
  // src/web/kit.ts
507
- function isWebSecretKey(x) {
508
- return chunkX4CS7UXE_cjs.$isSecretKey(x, "web") !== null;
509
- }
510
506
  function tryGenerateUuid() {
511
507
  return $generateUuid();
512
508
  }
513
509
  function generateUuid() {
514
510
  const { result, error } = $generateUuid();
515
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
511
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
516
512
  return result;
517
513
  }
518
514
  async function tryCreateSecretKey(secret, options = {}) {
@@ -520,7 +516,7 @@ async function tryCreateSecretKey(secret, options = {}) {
520
516
  }
521
517
  async function createSecretKey(secret, options = {}) {
522
518
  const { result, error } = await $createSecretKey(secret, options);
523
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
519
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
524
520
  return result;
525
521
  }
526
522
  async function tryEncrypt(data, secretKey, options = {}) {
@@ -528,7 +524,7 @@ async function tryEncrypt(data, secretKey, options = {}) {
528
524
  }
529
525
  async function encrypt(data, secretKey, options = {}) {
530
526
  const { result, error } = await $encrypt(data, secretKey, options);
531
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
527
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
532
528
  return result;
533
529
  }
534
530
  async function tryDecrypt(encrypted, secretKey, options = {}) {
@@ -536,7 +532,7 @@ async function tryDecrypt(encrypted, secretKey, options = {}) {
536
532
  }
537
533
  async function decrypt(encrypted, secretKey, options = {}) {
538
534
  const { result, error } = await $decrypt(encrypted, secretKey, options);
539
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
535
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
540
536
  return result;
541
537
  }
542
538
  async function tryEncryptObj(obj, secretKey, options = {}) {
@@ -544,7 +540,7 @@ async function tryEncryptObj(obj, secretKey, options = {}) {
544
540
  }
545
541
  async function encryptObj(obj, secretKey, options = {}) {
546
542
  const { result, error } = await $encryptObj(obj, secretKey, options);
547
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
543
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
548
544
  return result;
549
545
  }
550
546
  async function tryDecryptObj(encrypted, secretKey, options = {}) {
@@ -552,7 +548,7 @@ async function tryDecryptObj(encrypted, secretKey, options = {}) {
552
548
  }
553
549
  async function decryptObj(encrypted, secretKey, options = {}) {
554
550
  const { result, error } = await $decryptObj(encrypted, secretKey, options);
555
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
551
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
556
552
  return result;
557
553
  }
558
554
  async function tryHash(data, options = {}) {
@@ -560,7 +556,7 @@ async function tryHash(data, options = {}) {
560
556
  }
561
557
  async function hash(data, options = {}) {
562
558
  const { result, error } = await $hash(data, options);
563
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
559
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
564
560
  return result;
565
561
  }
566
562
  async function tryHashPassword(password, options = {}) {
@@ -568,7 +564,7 @@ async function tryHashPassword(password, options = {}) {
568
564
  }
569
565
  async function hashPassword(password, options = {}) {
570
566
  const { result, salt, error } = await $hashPassword(password, options);
571
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
567
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
572
568
  return { result, salt };
573
569
  }
574
570
  async function verifyPassword(password, hashedPassword, salt, options = {}) {
@@ -579,7 +575,7 @@ function tryConvertStrToBytes(data, inputEncoding = "utf8") {
579
575
  }
580
576
  function convertStrToBytes(data, inputEncoding = "utf8") {
581
577
  const { result, error } = $convertStrToBytes(data, inputEncoding);
582
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
578
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
583
579
  return result;
584
580
  }
585
581
  function tryConvertBytesToStr(data, outputEncoding = "utf8") {
@@ -587,7 +583,7 @@ function tryConvertBytesToStr(data, outputEncoding = "utf8") {
587
583
  }
588
584
  function convertBytesToStr(data, outputEncoding = "utf8") {
589
585
  const { result, error } = $convertBytesToStr(data, outputEncoding);
590
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
586
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
591
587
  return result;
592
588
  }
593
589
  function tryConvertEncoding(data, from, to) {
@@ -595,7 +591,7 @@ function tryConvertEncoding(data, from, to) {
595
591
  }
596
592
  function convertEncoding(data, from, to) {
597
593
  const { result, error } = $convertEncoding(data, from, to);
598
- if (error) throw new Error(chunkX4CS7UXE_cjs.$fmtResultErr(error));
594
+ if (error) throw new Error(chunkHTRGOBZF_cjs.$fmtResultErr(error));
599
595
  return result;
600
596
  }
601
597
 
@@ -610,7 +606,6 @@ exports.encryptObj = encryptObj;
610
606
  exports.generateUuid = generateUuid;
611
607
  exports.hash = hash;
612
608
  exports.hashPassword = hashPassword;
613
- exports.isWebSecretKey = isWebSecretKey;
614
609
  exports.kit_exports = kit_exports;
615
610
  exports.tryConvertBytesToStr = tryConvertBytesToStr;
616
611
  exports.tryConvertEncoding = tryConvertEncoding;
@@ -624,5 +619,5 @@ exports.tryGenerateUuid = tryGenerateUuid;
624
619
  exports.tryHash = tryHash;
625
620
  exports.tryHashPassword = tryHashPassword;
626
621
  exports.verifyPassword = verifyPassword;
627
- //# sourceMappingURL=chunk-LTVOIZP5.cjs.map
628
- //# sourceMappingURL=chunk-LTVOIZP5.cjs.map
622
+ //# sourceMappingURL=chunk-BMX42IZM.cjs.map
623
+ //# sourceMappingURL=chunk-BMX42IZM.cjs.map