cipher-kit 2.0.0-beta.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +241 -66
  2. package/dist/{chunk-3FJZA77A.cjs → chunk-3UX5MZ2P.cjs} +2 -2
  3. package/dist/chunk-3UX5MZ2P.cjs.map +1 -0
  4. package/dist/{chunk-7WPZVN7G.js → chunk-4MFF6V3R.js} +3 -3
  5. package/dist/chunk-4MFF6V3R.js.map +1 -0
  6. package/dist/{chunk-BWE6JWHY.js → chunk-ACFPMIXO.js} +3 -3
  7. package/dist/chunk-ACFPMIXO.js.map +1 -0
  8. package/dist/{chunk-CEXY7GOU.cjs → chunk-CVCDAHDW.cjs} +130 -130
  9. package/dist/chunk-CVCDAHDW.cjs.map +1 -0
  10. package/dist/{chunk-YAZRJN6X.js → chunk-FKSYSPJR.js} +2 -2
  11. package/dist/chunk-FKSYSPJR.js.map +1 -0
  12. package/dist/{chunk-WLLCFK4U.cjs → chunk-N2EW2FDZ.cjs} +125 -125
  13. package/dist/chunk-N2EW2FDZ.cjs.map +1 -0
  14. package/dist/{export-DX7bFv-3.d.cts → export-55tHE0Bw.d.cts} +12 -12
  15. package/dist/{export-DPAoLdh1.d.ts → export-BMvZq46v.d.ts} +12 -12
  16. package/dist/{export-Du70yDea.d.cts → export-CQNsJFh_.d.cts} +12 -12
  17. package/dist/{export-DjUgZ7dz.d.ts → export-llM6c7Do.d.ts} +12 -12
  18. package/dist/index.cjs +11 -11
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +3 -3
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +3 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/node.cjs +32 -32
  25. package/dist/node.d.cts +2 -2
  26. package/dist/node.d.ts +2 -2
  27. package/dist/node.js +2 -2
  28. package/dist/{validate-DrBddQyu.d.cts → validate-EHuJC5QQ.d.cts} +3 -3
  29. package/dist/{validate-DrBddQyu.d.ts → validate-EHuJC5QQ.d.ts} +3 -3
  30. package/dist/web-api.cjs +32 -32
  31. package/dist/web-api.d.cts +2 -2
  32. package/dist/web-api.d.ts +2 -2
  33. package/dist/web-api.js +2 -2
  34. package/package.json +4 -3
  35. package/dist/chunk-3FJZA77A.cjs.map +0 -1
  36. package/dist/chunk-7WPZVN7G.js.map +0 -1
  37. package/dist/chunk-BWE6JWHY.js.map +0 -1
  38. package/dist/chunk-CEXY7GOU.cjs.map +0 -1
  39. package/dist/chunk-WLLCFK4U.cjs.map +0 -1
  40. package/dist/chunk-YAZRJN6X.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunk3FJZA77A_cjs = require('./chunk-3FJZA77A.cjs');
3
+ var chunk3UX5MZ2P_cjs = require('./chunk-3UX5MZ2P.cjs');
4
4
 
5
5
  // src/web/kit.ts
6
6
  var kit_exports = {};
7
- chunk3FJZA77A_cjs.__export(kit_exports, {
7
+ chunk3UX5MZ2P_cjs.__export(kit_exports, {
8
8
  convertBytesToStr: () => convertBytesToStr,
9
9
  convertEncoding: () => convertEncoding,
10
10
  convertStrToBytes: () => convertStrToBytes,
@@ -35,34 +35,34 @@ chunk3FJZA77A_cjs.__export(kit_exports, {
35
35
  var textEncoder = new TextEncoder();
36
36
  var textDecoder = new TextDecoder();
37
37
  function $convertStrToBytes(data, inputEncoding = "utf8") {
38
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
39
- return chunk3FJZA77A_cjs.$err({
38
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
39
+ return chunk3UX5MZ2P_cjs.$err({
40
40
  msg: "Crypto Web API - String to Bytes: Empty data",
41
41
  desc: "Data must be a non-empty string"
42
42
  });
43
43
  }
44
- if (!chunk3FJZA77A_cjs.ENCODING.includes(inputEncoding)) {
45
- return chunk3FJZA77A_cjs.$err({
44
+ if (!chunk3UX5MZ2P_cjs.ENCODING.includes(inputEncoding)) {
45
+ return chunk3UX5MZ2P_cjs.$err({
46
46
  msg: `Crypto Web API - String to Bytes: Unsupported encoding: ${inputEncoding}`,
47
47
  desc: "Use base64, base64url, hex, utf8, or latin1"
48
48
  });
49
49
  }
50
50
  try {
51
51
  const bytes = strToBytes[inputEncoding](data);
52
- return chunk3FJZA77A_cjs.$ok({ result: bytes });
52
+ return chunk3UX5MZ2P_cjs.$ok({ result: bytes });
53
53
  } catch (error) {
54
- return chunk3FJZA77A_cjs.$err({ msg: "Crypto Web API - String to Bytes: Failed to convert data", desc: chunk3FJZA77A_cjs.$fmtError(error) });
54
+ return chunk3UX5MZ2P_cjs.$err({ msg: "Crypto Web API - String to Bytes: Failed to convert data", desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
55
55
  }
56
56
  }
57
57
  function $convertBytesToStr(data, outputEncoding = "utf8") {
58
58
  if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) {
59
- return chunk3FJZA77A_cjs.$err({
59
+ return chunk3UX5MZ2P_cjs.$err({
60
60
  msg: "Crypto Web API - Bytes to String: Invalid data type",
61
61
  desc: "Data must be an ArrayBuffer or Uint8Array"
62
62
  });
63
63
  }
64
- if (!chunk3FJZA77A_cjs.ENCODING.includes(outputEncoding)) {
65
- return chunk3FJZA77A_cjs.$err({
64
+ if (!chunk3UX5MZ2P_cjs.ENCODING.includes(outputEncoding)) {
65
+ return chunk3UX5MZ2P_cjs.$err({
66
66
  msg: `Crypto Web API - Bytes to String: Unsupported encoding: ${outputEncoding}`,
67
67
  desc: "Use base64, base64url, hex, utf8, or latin1"
68
68
  });
@@ -70,29 +70,29 @@ function $convertBytesToStr(data, outputEncoding = "utf8") {
70
70
  try {
71
71
  const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
72
72
  const str = bytesToStr[outputEncoding](bytes);
73
- return chunk3FJZA77A_cjs.$ok(str);
73
+ return chunk3UX5MZ2P_cjs.$ok(str);
74
74
  } catch (error) {
75
- return chunk3FJZA77A_cjs.$err({ msg: "Crypto Web API - Bytes to String: Failed to convert data", desc: chunk3FJZA77A_cjs.$fmtError(error) });
75
+ return chunk3UX5MZ2P_cjs.$err({ msg: "Crypto Web API - Bytes to String: Failed to convert data", desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
76
76
  }
77
77
  }
78
78
  function $convertEncoding(data, from, to) {
79
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
80
- return chunk3FJZA77A_cjs.$err({
79
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
80
+ return chunk3UX5MZ2P_cjs.$err({
81
81
  msg: "Crypto Web API - Convert Format: Empty data",
82
82
  desc: "Data must be a non-empty string"
83
83
  });
84
84
  }
85
- if (!chunk3FJZA77A_cjs.ENCODING.includes(from) || !chunk3FJZA77A_cjs.ENCODING.includes(to)) {
86
- return chunk3FJZA77A_cjs.$err({
85
+ if (!chunk3UX5MZ2P_cjs.ENCODING.includes(from) || !chunk3UX5MZ2P_cjs.ENCODING.includes(to)) {
86
+ return chunk3UX5MZ2P_cjs.$err({
87
87
  msg: `Crypto Web API - Convert Format: Unsupported encoding: from ${from} to ${to}`,
88
88
  desc: "Use base64, base64url, hex, utf8, or latin1"
89
89
  });
90
90
  }
91
91
  const bytes = $convertStrToBytes(data, from);
92
- if (bytes.error) return chunk3FJZA77A_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
92
+ if (bytes.error) return chunk3UX5MZ2P_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
93
93
  const str = $convertBytesToStr(bytes.result, to);
94
- if (str.error) return chunk3FJZA77A_cjs.$err({ msg: str.error.message, desc: str.error.description });
95
- return chunk3FJZA77A_cjs.$ok({ result: str.result });
94
+ if (str.error) return chunk3UX5MZ2P_cjs.$err({ msg: str.error.message, desc: str.error.description });
95
+ return chunk3UX5MZ2P_cjs.$ok({ result: str.result });
96
96
  }
97
97
  var strToBytes = {
98
98
  base64: $fromBase64,
@@ -158,45 +158,45 @@ function $fromHex(data) {
158
158
  // src/web/web-encrypt.ts
159
159
  function $generateUuid() {
160
160
  try {
161
- return chunk3FJZA77A_cjs.$ok(crypto.randomUUID());
161
+ return chunk3UX5MZ2P_cjs.$ok(crypto.randomUUID());
162
162
  } catch (error) {
163
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "UUID Generation")}: Failed to generate UUID`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
163
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "UUID Generation")}: Failed to generate UUID`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
164
164
  }
165
165
  }
166
166
  async function $createSecretKey(secret, options = {}) {
167
- if (!chunk3FJZA77A_cjs.$isStr(secret)) {
168
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "Key Generation")}: Empty Secret`, desc: "Secret must be a non-empty string" });
167
+ if (!chunk3UX5MZ2P_cjs.$isStr(secret)) {
168
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "Key Generation")}: Empty Secret`, desc: "Secret must be a non-empty string" });
169
169
  }
170
170
  const algorithm = options.algorithm ?? "aes256gcm";
171
- if (!(algorithm in chunk3FJZA77A_cjs.ENCRYPTION_ALGORITHMS)) {
172
- return chunk3FJZA77A_cjs.$err({
173
- msg: `${chunk3FJZA77A_cjs.title("web", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
174
- desc: `Supported algorithms are: ${Object.keys(chunk3FJZA77A_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
171
+ if (!(algorithm in chunk3UX5MZ2P_cjs.ENCRYPTION_ALGORITHMS)) {
172
+ return chunk3UX5MZ2P_cjs.$err({
173
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
174
+ desc: `Supported algorithms are: ${Object.keys(chunk3UX5MZ2P_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
175
175
  });
176
176
  }
177
177
  const digest = options.digest ?? "sha256";
178
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) {
179
- return chunk3FJZA77A_cjs.$err({
180
- msg: `${chunk3FJZA77A_cjs.title("web", "Key Generation")}: Unsupported digest: ${digest}`,
181
- desc: `Supported digests are: ${Object.keys(chunk3FJZA77A_cjs.DIGEST_ALGORITHMS).join(", ")}`
178
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) {
179
+ return chunk3UX5MZ2P_cjs.$err({
180
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Key Generation")}: Unsupported digest: ${digest}`,
181
+ desc: `Supported digests are: ${Object.keys(chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS).join(", ")}`
182
182
  });
183
183
  }
184
184
  const salt = options.salt ?? "cipher-kit-salt";
185
- if (!chunk3FJZA77A_cjs.$isStr(salt, 8)) {
186
- return chunk3FJZA77A_cjs.$err({
187
- msg: `${chunk3FJZA77A_cjs.title("web", "Key Generation")}: Weak salt`,
185
+ if (!chunk3UX5MZ2P_cjs.$isStr(salt, 8)) {
186
+ return chunk3UX5MZ2P_cjs.$err({
187
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Key Generation")}: Weak salt`,
188
188
  desc: "Salt must be a non-empty string with at least 8 characters"
189
189
  });
190
190
  }
191
191
  const info = options.info ?? "cipher-kit";
192
- if (!chunk3FJZA77A_cjs.$isStr(info)) {
193
- return chunk3FJZA77A_cjs.$err({
194
- msg: `${chunk3FJZA77A_cjs.title("web", "Key Generation")}: Invalid info`,
192
+ if (!chunk3UX5MZ2P_cjs.$isStr(info)) {
193
+ return chunk3UX5MZ2P_cjs.$err({
194
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Key Generation")}: Invalid info`,
195
195
  desc: "Info must be a non-empty string"
196
196
  });
197
197
  }
198
- const encryptAlgo = chunk3FJZA77A_cjs.ENCRYPTION_ALGORITHMS[algorithm];
199
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
198
+ const encryptAlgo = chunk3UX5MZ2P_cjs.ENCRYPTION_ALGORITHMS[algorithm];
199
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
200
200
  try {
201
201
  const ikm = await crypto.subtle.importKey("raw", textEncoder.encode(secret.normalize("NFKC")), "HKDF", false, [
202
202
  "deriveKey"
@@ -219,37 +219,37 @@ async function $createSecretKey(secret, options = {}) {
219
219
  algorithm,
220
220
  key
221
221
  });
222
- return chunk3FJZA77A_cjs.$ok({ result: secretKey });
222
+ return chunk3UX5MZ2P_cjs.$ok({ result: secretKey });
223
223
  } catch (error) {
224
- return chunk3FJZA77A_cjs.$err({
225
- msg: `${chunk3FJZA77A_cjs.title("web", "Key Generation")}: Failed to create secret key`,
226
- desc: chunk3FJZA77A_cjs.$fmtError(error)
224
+ return chunk3UX5MZ2P_cjs.$err({
225
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Key Generation")}: Failed to create secret key`,
226
+ desc: chunk3UX5MZ2P_cjs.$fmtError(error)
227
227
  });
228
228
  }
229
229
  }
230
230
  async function $encrypt(data, secretKey, options = {}) {
231
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
232
- return chunk3FJZA77A_cjs.$err({
233
- msg: `${chunk3FJZA77A_cjs.title("web", "Encryption")}: Empty data for encryption`,
231
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
232
+ return chunk3UX5MZ2P_cjs.$err({
233
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Encryption")}: Empty data for encryption`,
234
234
  desc: "Data must be a non-empty string"
235
235
  });
236
236
  }
237
237
  const encoding = options.encoding ?? "base64url";
238
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
239
- return chunk3FJZA77A_cjs.$err({
240
- msg: `${chunk3FJZA77A_cjs.title("web", "Encryption")}: Unsupported output encoding: ${encoding}`,
238
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
239
+ return chunk3UX5MZ2P_cjs.$err({
240
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Encryption")}: Unsupported output encoding: ${encoding}`,
241
241
  desc: "Use base64, base64url, or hex"
242
242
  });
243
243
  }
244
- const injectedKey = chunk3FJZA77A_cjs.$isSecretKey(secretKey, "web");
244
+ const injectedKey = chunk3UX5MZ2P_cjs.$isSecretKey(secretKey, "web");
245
245
  if (!injectedKey) {
246
- return chunk3FJZA77A_cjs.$err({
247
- msg: `${chunk3FJZA77A_cjs.title("web", "Encryption")}: Invalid Secret Key`,
246
+ return chunk3UX5MZ2P_cjs.$err({
247
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Encryption")}: Invalid Secret Key`,
248
248
  desc: "Expected a Web SecretKey"
249
249
  });
250
250
  }
251
251
  const { result, error } = $convertStrToBytes(data, "utf8");
252
- if (error) return chunk3FJZA77A_cjs.$err(error);
252
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
253
253
  try {
254
254
  const iv = crypto.getRandomValues(new Uint8Array(injectedKey.injected.ivLength));
255
255
  const cipherWithTag = await crypto.subtle.encrypt(
@@ -260,50 +260,50 @@ async function $encrypt(data, secretKey, options = {}) {
260
260
  const ivStr = $convertBytesToStr(iv, encoding);
261
261
  const cipherStr = $convertBytesToStr(cipherWithTag, encoding);
262
262
  if (ivStr.error || cipherStr.error) {
263
- return chunk3FJZA77A_cjs.$err({
264
- msg: `${chunk3FJZA77A_cjs.title("web", "Encryption")}: Failed to convert IV or encrypted data`,
265
- desc: `Conversion error: ${chunk3FJZA77A_cjs.$fmtResultErr(ivStr.error || cipherStr.error)}`
263
+ return chunk3UX5MZ2P_cjs.$err({
264
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Encryption")}: Failed to convert IV or encrypted data`,
265
+ desc: `Conversion error: ${chunk3UX5MZ2P_cjs.$fmtResultErr(ivStr.error || cipherStr.error)}`
266
266
  });
267
267
  }
268
- return chunk3FJZA77A_cjs.$ok(`${ivStr.result}.${cipherStr.result}.`);
268
+ return chunk3UX5MZ2P_cjs.$ok(`${ivStr.result}.${cipherStr.result}.`);
269
269
  } catch (error2) {
270
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "Encryption")}: Failed to encrypt data`, desc: chunk3FJZA77A_cjs.$fmtError(error2) });
270
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "Encryption")}: Failed to encrypt data`, desc: chunk3UX5MZ2P_cjs.$fmtError(error2) });
271
271
  }
272
272
  }
273
273
  async function $decrypt(encrypted, secretKey, options = {}) {
274
- if (chunk3FJZA77A_cjs.matchPattern(encrypted, "web") === false) {
275
- return chunk3FJZA77A_cjs.$err({
276
- msg: `${chunk3FJZA77A_cjs.title("web", "Decryption")}: Invalid encrypted data format`,
274
+ if (chunk3UX5MZ2P_cjs.matchPattern(encrypted, "web") === false) {
275
+ return chunk3UX5MZ2P_cjs.$err({
276
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Decryption")}: Invalid encrypted data format`,
277
277
  desc: 'Encrypted data must be in the format "iv.cipherWithTag."'
278
278
  });
279
279
  }
280
280
  const encoding = options.encoding ?? "base64url";
281
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
282
- return chunk3FJZA77A_cjs.$err({
283
- msg: `${chunk3FJZA77A_cjs.title("web", "Decryption")}: Unsupported input encoding: ${encoding}`,
281
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
282
+ return chunk3UX5MZ2P_cjs.$err({
283
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Decryption")}: Unsupported input encoding: ${encoding}`,
284
284
  desc: "Use base64, base64url, or hex"
285
285
  });
286
286
  }
287
287
  const [iv, encryptedWithTag] = encrypted.split(".", 3);
288
- if (!chunk3FJZA77A_cjs.$isStr(iv) || !chunk3FJZA77A_cjs.$isStr(encryptedWithTag)) {
289
- return chunk3FJZA77A_cjs.$err({
290
- msg: `${chunk3FJZA77A_cjs.title("web", "Decryption")}: Invalid encrypted data`,
288
+ if (!chunk3UX5MZ2P_cjs.$isStr(iv) || !chunk3UX5MZ2P_cjs.$isStr(encryptedWithTag)) {
289
+ return chunk3UX5MZ2P_cjs.$err({
290
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Decryption")}: Invalid encrypted data`,
291
291
  desc: "Encrypted data must contain valid IV, encrypted and tag components"
292
292
  });
293
293
  }
294
- const injectedKey = chunk3FJZA77A_cjs.$isSecretKey(secretKey, "web");
294
+ const injectedKey = chunk3UX5MZ2P_cjs.$isSecretKey(secretKey, "web");
295
295
  if (!injectedKey) {
296
- return chunk3FJZA77A_cjs.$err({
297
- msg: `${chunk3FJZA77A_cjs.title("web", "Decryption")}: Invalid Secret Key`,
296
+ return chunk3UX5MZ2P_cjs.$err({
297
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Decryption")}: Invalid Secret Key`,
298
298
  desc: "Expected a Web SecretKey"
299
299
  });
300
300
  }
301
301
  const ivBytes = $convertStrToBytes(iv, encoding);
302
302
  const cipherWithTagBytes = $convertStrToBytes(encryptedWithTag, encoding);
303
303
  if (ivBytes.error || cipherWithTagBytes.error) {
304
- return chunk3FJZA77A_cjs.$err({
305
- msg: `${chunk3FJZA77A_cjs.title("web", "Decryption")}: Failed to convert IV or encrypted data`,
306
- desc: `Conversion error: ${chunk3FJZA77A_cjs.$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`
304
+ return chunk3UX5MZ2P_cjs.$err({
305
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Decryption")}: Failed to convert IV or encrypted data`,
306
+ desc: `Conversion error: ${chunk3UX5MZ2P_cjs.$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`
307
307
  });
308
308
  }
309
309
  try {
@@ -314,87 +314,87 @@ async function $decrypt(encrypted, secretKey, options = {}) {
314
314
  );
315
315
  return $convertBytesToStr(decrypted, "utf8");
316
316
  } catch (error) {
317
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "Decryption")}: Failed to decrypt data`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
317
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "Decryption")}: Failed to decrypt data`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
318
318
  }
319
319
  }
320
320
  async function $encryptObj(data, secretKey, options = {}) {
321
- const { result, error } = chunk3FJZA77A_cjs.$stringifyObj(data);
322
- if (error) return chunk3FJZA77A_cjs.$err(error);
321
+ const { result, error } = chunk3UX5MZ2P_cjs.$stringifyObj(data);
322
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
323
323
  return await $encrypt(result, secretKey, options);
324
324
  }
325
325
  async function $decryptObj(encrypted, secretKey, options = {}) {
326
326
  const { result, error } = await $decrypt(encrypted, secretKey, options);
327
- if (error) return chunk3FJZA77A_cjs.$err(error);
328
- return chunk3FJZA77A_cjs.$parseToObj(result);
327
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
328
+ return chunk3UX5MZ2P_cjs.$parseToObj(result);
329
329
  }
330
330
  async function $hash(data, options = {}) {
331
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
332
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "Hashing")}: Empty data for hashing`, desc: "Data must be a non-empty string" });
331
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
332
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "Hashing")}: Empty data for hashing`, desc: "Data must be a non-empty string" });
333
333
  }
334
334
  const encoding = options.encoding ?? "base64url";
335
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
336
- return chunk3FJZA77A_cjs.$err({
337
- msg: `${chunk3FJZA77A_cjs.title("web", "Hashing")}: Unsupported output encoding: ${encoding}`,
335
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
336
+ return chunk3UX5MZ2P_cjs.$err({
337
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Hashing")}: Unsupported output encoding: ${encoding}`,
338
338
  desc: "Use base64, base64url, or hex"
339
339
  });
340
340
  }
341
341
  const digest = options.digest ?? "sha256";
342
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) {
343
- return chunk3FJZA77A_cjs.$err({
344
- msg: `${chunk3FJZA77A_cjs.title("web", "Hashing")}: Unsupported digest: ${digest}`,
345
- desc: `Supported digests are: ${Object.keys(chunk3FJZA77A_cjs.DIGEST_ALGORITHMS).join(", ")}`
342
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) {
343
+ return chunk3UX5MZ2P_cjs.$err({
344
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Hashing")}: Unsupported digest: ${digest}`,
345
+ desc: `Supported digests are: ${Object.keys(chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS).join(", ")}`
346
346
  });
347
347
  }
348
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
348
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
349
349
  const { result, error } = $convertStrToBytes(data, "utf8");
350
- if (error) return chunk3FJZA77A_cjs.$err(error);
350
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
351
351
  try {
352
352
  const hashed = await crypto.subtle.digest(digestAlgo.web, result);
353
353
  return $convertBytesToStr(hashed, encoding);
354
354
  } catch (error2) {
355
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "Hashing")}: Failed to hash data`, desc: chunk3FJZA77A_cjs.$fmtError(error2) });
355
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "Hashing")}: Failed to hash data`, desc: chunk3UX5MZ2P_cjs.$fmtError(error2) });
356
356
  }
357
357
  }
358
358
  async function $hashPassword(password, options = {}) {
359
- if (!chunk3FJZA77A_cjs.$isStr(password)) {
360
- return chunk3FJZA77A_cjs.$err({
361
- msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Empty password`,
359
+ if (!chunk3UX5MZ2P_cjs.$isStr(password)) {
360
+ return chunk3UX5MZ2P_cjs.$err({
361
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Empty password`,
362
362
  desc: "Password must be a non-empty string"
363
363
  });
364
364
  }
365
365
  const digest = options.digest ?? "sha512";
366
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) {
367
- return chunk3FJZA77A_cjs.$err({
368
- msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Unsupported digest: ${digest}`,
369
- desc: `Supported digests are: ${Object.keys(chunk3FJZA77A_cjs.DIGEST_ALGORITHMS).join(", ")}`
366
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) {
367
+ return chunk3UX5MZ2P_cjs.$err({
368
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Unsupported digest: ${digest}`,
369
+ desc: `Supported digests are: ${Object.keys(chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS).join(", ")}`
370
370
  });
371
371
  }
372
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
372
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
373
373
  const encoding = options.encoding ?? "base64url";
374
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
375
- return chunk3FJZA77A_cjs.$err({
376
- msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Unsupported output encoding: ${encoding}`,
374
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
375
+ return chunk3UX5MZ2P_cjs.$err({
376
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Unsupported output encoding: ${encoding}`,
377
377
  desc: "Use base64, base64url, or hex"
378
378
  });
379
379
  }
380
380
  const saltLength = options.saltLength ?? 16;
381
381
  if (typeof saltLength !== "number" || saltLength < 8) {
382
- return chunk3FJZA77A_cjs.$err({
383
- msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Weak salt length`,
382
+ return chunk3UX5MZ2P_cjs.$err({
383
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Weak salt length`,
384
384
  desc: "Salt length must be a number and at least 8 bytes (recommended 16)"
385
385
  });
386
386
  }
387
387
  const iterations = options.iterations ?? 32e4;
388
388
  if (typeof iterations !== "number" || iterations < 1e3) {
389
- return chunk3FJZA77A_cjs.$err({
390
- msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Weak iteration count`,
389
+ return chunk3UX5MZ2P_cjs.$err({
390
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Weak iteration count`,
391
391
  desc: "Iterations must be a number and at least 1000 (recommended 320,000 or more)"
392
392
  });
393
393
  }
394
394
  const keyLength = options.keyLength ?? 64;
395
395
  if (typeof keyLength !== "number" || keyLength < 16) {
396
- return chunk3FJZA77A_cjs.$err({
397
- msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Weak key length`,
396
+ return chunk3UX5MZ2P_cjs.$err({
397
+ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Weak key length`,
398
398
  desc: "Key length must be a number and at least 16 bytes (recommended 64)"
399
399
  });
400
400
  }
@@ -413,21 +413,21 @@ async function $hashPassword(password, options = {}) {
413
413
  keyLength * 8
414
414
  );
415
415
  const saltStr = $convertBytesToStr(salt, encoding);
416
- if (saltStr.error) return chunk3FJZA77A_cjs.$err(saltStr.error);
416
+ if (saltStr.error) return chunk3UX5MZ2P_cjs.$err(saltStr.error);
417
417
  const hashedPasswordStr = $convertBytesToStr(bits, encoding);
418
- if (hashedPasswordStr.error) return chunk3FJZA77A_cjs.$err(hashedPasswordStr.error);
419
- return chunk3FJZA77A_cjs.$ok({ hash: hashedPasswordStr.result, salt: saltStr.result });
418
+ if (hashedPasswordStr.error) return chunk3UX5MZ2P_cjs.$err(hashedPasswordStr.error);
419
+ return chunk3UX5MZ2P_cjs.$ok({ hash: hashedPasswordStr.result, salt: saltStr.result });
420
420
  } catch (error) {
421
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("web", "Password Hashing")}: Failed to hash password`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
421
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("web", "Password Hashing")}: Failed to hash password`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
422
422
  }
423
423
  }
424
424
  async function $verifyPassword(password, hashedPassword, salt, options = {}) {
425
- if (!chunk3FJZA77A_cjs.$isStr(password) || !chunk3FJZA77A_cjs.$isStr(hashedPassword) || !chunk3FJZA77A_cjs.$isStr(salt)) return false;
425
+ if (!chunk3UX5MZ2P_cjs.$isStr(password) || !chunk3UX5MZ2P_cjs.$isStr(hashedPassword) || !chunk3UX5MZ2P_cjs.$isStr(salt)) return false;
426
426
  const digest = options.digest ?? "sha512";
427
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) return false;
428
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
427
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) return false;
428
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
429
429
  const encoding = options.encoding ?? "base64url";
430
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) return false;
430
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) return false;
431
431
  const iterations = options.iterations ?? 32e4;
432
432
  if (typeof iterations !== "number" || iterations < 1e3) return false;
433
433
  const keyLength = options.keyLength ?? 64;
@@ -470,14 +470,14 @@ async function $verifyPassword(password, hashedPassword, salt, options = {}) {
470
470
 
471
471
  // src/web/kit.ts
472
472
  function isWebSecretKey(x) {
473
- return chunk3FJZA77A_cjs.$isSecretKey(x, "web") !== null;
473
+ return chunk3UX5MZ2P_cjs.$isSecretKey(x, "web") !== null;
474
474
  }
475
475
  function tryGenerateUuid() {
476
476
  return $generateUuid();
477
477
  }
478
478
  function generateUuid() {
479
479
  const { result, error } = $generateUuid();
480
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
480
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
481
481
  return result;
482
482
  }
483
483
  async function tryCreateSecretKey(secret, options = {}) {
@@ -485,7 +485,7 @@ async function tryCreateSecretKey(secret, options = {}) {
485
485
  }
486
486
  async function createSecretKey(secret, options = {}) {
487
487
  const { result, error } = await $createSecretKey(secret, options);
488
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
488
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
489
489
  return result;
490
490
  }
491
491
  async function tryEncrypt(data, secretKey, options = {}) {
@@ -493,7 +493,7 @@ async function tryEncrypt(data, secretKey, options = {}) {
493
493
  }
494
494
  async function encrypt(data, secretKey, options = {}) {
495
495
  const { result, error } = await $encrypt(data, secretKey, options);
496
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
496
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
497
497
  return result;
498
498
  }
499
499
  async function tryDecrypt(encrypted, secretKey, options = {}) {
@@ -501,7 +501,7 @@ async function tryDecrypt(encrypted, secretKey, options = {}) {
501
501
  }
502
502
  async function decrypt(encrypted, secretKey, options = {}) {
503
503
  const { result, error } = await $decrypt(encrypted, secretKey, options);
504
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
504
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
505
505
  return result;
506
506
  }
507
507
  async function tryEncryptObj(data, secretKey, options = {}) {
@@ -509,7 +509,7 @@ async function tryEncryptObj(data, secretKey, options = {}) {
509
509
  }
510
510
  async function encryptObj(data, secretKey, options = {}) {
511
511
  const { result, error } = await $encryptObj(data, secretKey, options);
512
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
512
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
513
513
  return result;
514
514
  }
515
515
  async function tryDecryptObj(encrypted, secretKey, options = {}) {
@@ -517,7 +517,7 @@ async function tryDecryptObj(encrypted, secretKey, options = {}) {
517
517
  }
518
518
  async function decryptObj(encrypted, secretKey, options = {}) {
519
519
  const { result, error } = await $decryptObj(encrypted, secretKey, options);
520
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
520
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
521
521
  return result;
522
522
  }
523
523
  async function tryHash(data, options = {}) {
@@ -525,7 +525,7 @@ async function tryHash(data, options = {}) {
525
525
  }
526
526
  async function hash(data, options = {}) {
527
527
  const { result, error } = await $hash(data, options);
528
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
528
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
529
529
  return result;
530
530
  }
531
531
  async function tryHashPassword(password, options = {}) {
@@ -533,7 +533,7 @@ async function tryHashPassword(password, options = {}) {
533
533
  }
534
534
  async function hashPassword(password, options = {}) {
535
535
  const { hash: hash2, salt, error } = await $hashPassword(password, options);
536
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
536
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
537
537
  return { hash: hash2, salt };
538
538
  }
539
539
  async function verifyPassword(password, hashedPassword, salt, options = {}) {
@@ -544,7 +544,7 @@ function tryConvertStrToBytes(data, inputEncoding = "utf8") {
544
544
  }
545
545
  function convertStrToBytes(data, inputEncoding = "utf8") {
546
546
  const { result, error } = $convertStrToBytes(data, inputEncoding);
547
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
547
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
548
548
  return result;
549
549
  }
550
550
  function tryConvertBytesToStr(data, outputEncoding = "utf8") {
@@ -552,7 +552,7 @@ function tryConvertBytesToStr(data, outputEncoding = "utf8") {
552
552
  }
553
553
  function convertBytesToStr(data, outputEncoding = "utf8") {
554
554
  const { result, error } = $convertBytesToStr(data, outputEncoding);
555
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
555
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
556
556
  return result;
557
557
  }
558
558
  function tryConvertEncoding(data, from, to) {
@@ -560,7 +560,7 @@ function tryConvertEncoding(data, from, to) {
560
560
  }
561
561
  function convertEncoding(data, from, to) {
562
562
  const { result, error } = $convertEncoding(data, from, to);
563
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
563
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
564
564
  return result;
565
565
  }
566
566
 
@@ -589,5 +589,5 @@ exports.tryGenerateUuid = tryGenerateUuid;
589
589
  exports.tryHash = tryHash;
590
590
  exports.tryHashPassword = tryHashPassword;
591
591
  exports.verifyPassword = verifyPassword;
592
- //# sourceMappingURL=chunk-CEXY7GOU.cjs.map
593
- //# sourceMappingURL=chunk-CEXY7GOU.cjs.map
592
+ //# sourceMappingURL=chunk-CVCDAHDW.cjs.map
593
+ //# sourceMappingURL=chunk-CVCDAHDW.cjs.map