cipher-kit 2.0.0-beta.3 → 2.0.0-beta.4

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 (45) hide show
  1. package/dist/{chunk-BNQERV4S.js → chunk-LHB5NXYW.js} +71 -84
  2. package/dist/chunk-LHB5NXYW.js.map +1 -0
  3. package/dist/{chunk-6GBH7YTP.js → chunk-N5T4PNG7.js} +67 -81
  4. package/dist/chunk-N5T4PNG7.js.map +1 -0
  5. package/dist/{chunk-UHP3PPXP.cjs → chunk-OL2AIXWK.cjs} +150 -165
  6. package/dist/chunk-OL2AIXWK.cjs.map +1 -0
  7. package/dist/{chunk-ZJ32WGAA.cjs → chunk-UIV6DG54.cjs} +15 -12
  8. package/dist/chunk-UIV6DG54.cjs.map +1 -0
  9. package/dist/{chunk-NKLNWTQA.cjs → chunk-XIWV7XVI.cjs} +159 -173
  10. package/dist/chunk-XIWV7XVI.cjs.map +1 -0
  11. package/dist/{chunk-YPYDYYV2.js → chunk-YMNOTRET.js} +13 -11
  12. package/dist/chunk-YMNOTRET.js.map +1 -0
  13. package/dist/export-D1Vh79Qw.d.ts +417 -0
  14. package/dist/export-DGrELdz_.d.ts +416 -0
  15. package/dist/export-DXRl-ncG.d.cts +417 -0
  16. package/dist/export-Gd8hafl6.d.cts +416 -0
  17. package/dist/index.cjs +14 -22
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +52 -4
  20. package/dist/index.d.ts +52 -4
  21. package/dist/index.js +9 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/node.cjs +34 -42
  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-Cb7IOrPo.d.cts +373 -0
  28. package/dist/validate-Cb7IOrPo.d.ts +373 -0
  29. package/dist/web-api.cjs +34 -42
  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-6GBH7YTP.js.map +0 -1
  35. package/dist/chunk-BNQERV4S.js.map +0 -1
  36. package/dist/chunk-NKLNWTQA.cjs.map +0 -1
  37. package/dist/chunk-UHP3PPXP.cjs.map +0 -1
  38. package/dist/chunk-YPYDYYV2.js.map +0 -1
  39. package/dist/chunk-ZJ32WGAA.cjs.map +0 -1
  40. package/dist/export--ndIQ3j3.d.cts +0 -271
  41. package/dist/export-C2M5UPLX.d.cts +0 -270
  42. package/dist/export-CPUbAFZA.d.ts +0 -271
  43. package/dist/export-v9ULdDL0.d.ts +0 -270
  44. package/dist/validate-CULVlPck.d.cts +0 -157
  45. package/dist/validate-CULVlPck.d.ts +0 -157
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkZJ32WGAA_cjs = require('./chunk-ZJ32WGAA.cjs');
3
+ var chunkUIV6DG54_cjs = require('./chunk-UIV6DG54.cjs');
4
4
 
5
5
  // src/web/kit.ts
6
6
  var kit_exports = {};
7
- chunkZJ32WGAA_cjs.__export(kit_exports, {
7
+ chunkUIV6DG54_cjs.__export(kit_exports, {
8
8
  convertBytesToStr: () => convertBytesToStr,
9
9
  convertEncoding: () => convertEncoding,
10
10
  convertStrToBytes: () => convertStrToBytes,
@@ -15,8 +15,8 @@ chunkZJ32WGAA_cjs.__export(kit_exports, {
15
15
  encryptObj: () => encryptObj,
16
16
  generateUuid: () => generateUuid,
17
17
  hash: () => hash,
18
- hashObj: () => hashObj,
19
18
  hashPassword: () => hashPassword,
19
+ isWebSecretKey: () => isWebSecretKey,
20
20
  tryConvertBytesToStr: () => tryConvertBytesToStr,
21
21
  tryConvertEncoding: () => tryConvertEncoding,
22
22
  tryConvertStrToBytes: () => tryConvertStrToBytes,
@@ -27,7 +27,6 @@ chunkZJ32WGAA_cjs.__export(kit_exports, {
27
27
  tryEncryptObj: () => tryEncryptObj,
28
28
  tryGenerateUuid: () => tryGenerateUuid,
29
29
  tryHash: () => tryHash,
30
- tryHashObj: () => tryHashObj,
31
30
  tryHashPassword: () => tryHashPassword,
32
31
  verifyPassword: () => verifyPassword
33
32
  });
@@ -36,34 +35,34 @@ chunkZJ32WGAA_cjs.__export(kit_exports, {
36
35
  var textEncoder = new TextEncoder();
37
36
  var textDecoder = new TextDecoder();
38
37
  function $convertStrToBytes(data, inputEncoding = "utf8") {
39
- if (!chunkZJ32WGAA_cjs.$isStr(data)) {
40
- return chunkZJ32WGAA_cjs.$err({
38
+ if (!chunkUIV6DG54_cjs.$isStr(data)) {
39
+ return chunkUIV6DG54_cjs.$err({
41
40
  msg: "Crypto Web API - String to Bytes: Empty data",
42
41
  desc: "Data must be a non-empty string"
43
42
  });
44
43
  }
45
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding)) {
46
- return chunkZJ32WGAA_cjs.$err({
44
+ if (!chunkUIV6DG54_cjs.ENCODING.includes(inputEncoding)) {
45
+ return chunkUIV6DG54_cjs.$err({
47
46
  msg: `Crypto Web API - String to Bytes: Unsupported encoding: ${inputEncoding}`,
48
47
  desc: "Use base64, base64url, hex, utf8, or latin1"
49
48
  });
50
49
  }
51
50
  try {
52
51
  const bytes = strToBytes[inputEncoding](data);
53
- return chunkZJ32WGAA_cjs.$ok({ result: bytes });
52
+ return chunkUIV6DG54_cjs.$ok({ result: bytes });
54
53
  } catch (error) {
55
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - String to Bytes: Failed to convert data", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
54
+ return chunkUIV6DG54_cjs.$err({ msg: "Crypto Web API - String to Bytes: Failed to convert data", desc: chunkUIV6DG54_cjs.$fmtError(error) });
56
55
  }
57
56
  }
58
57
  function $convertBytesToStr(data, outputEncoding = "utf8") {
59
58
  if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) {
60
- return chunkZJ32WGAA_cjs.$err({
59
+ return chunkUIV6DG54_cjs.$err({
61
60
  msg: "Crypto Web API - Bytes to String: Invalid data type",
62
61
  desc: "Data must be an ArrayBuffer or Uint8Array"
63
62
  });
64
63
  }
65
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
66
- return chunkZJ32WGAA_cjs.$err({
64
+ if (!chunkUIV6DG54_cjs.ENCODING.includes(outputEncoding)) {
65
+ return chunkUIV6DG54_cjs.$err({
67
66
  msg: `Crypto Web API - Bytes to String: Unsupported encoding: ${outputEncoding}`,
68
67
  desc: "Use base64, base64url, hex, utf8, or latin1"
69
68
  });
@@ -71,29 +70,29 @@ function $convertBytesToStr(data, outputEncoding = "utf8") {
71
70
  try {
72
71
  const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
73
72
  const str = bytesToStr[outputEncoding](bytes);
74
- return chunkZJ32WGAA_cjs.$ok(str);
73
+ return chunkUIV6DG54_cjs.$ok(str);
75
74
  } catch (error) {
76
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Bytes to String: Failed to convert data", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
75
+ return chunkUIV6DG54_cjs.$err({ msg: "Crypto Web API - Bytes to String: Failed to convert data", desc: chunkUIV6DG54_cjs.$fmtError(error) });
77
76
  }
78
77
  }
79
78
  function $convertEncoding(data, from, to) {
80
- if (!chunkZJ32WGAA_cjs.$isStr(data)) {
81
- return chunkZJ32WGAA_cjs.$err({
79
+ if (!chunkUIV6DG54_cjs.$isStr(data)) {
80
+ return chunkUIV6DG54_cjs.$err({
82
81
  msg: "Crypto Web API - Convert Format: Empty data",
83
82
  desc: "Data must be a non-empty string"
84
83
  });
85
84
  }
86
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(from) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(to)) {
87
- return chunkZJ32WGAA_cjs.$err({
85
+ if (!chunkUIV6DG54_cjs.ENCODING.includes(from) || !chunkUIV6DG54_cjs.ENCODING.includes(to)) {
86
+ return chunkUIV6DG54_cjs.$err({
88
87
  msg: `Crypto Web API - Convert Format: Unsupported encoding: from ${from} to ${to}`,
89
88
  desc: "Use base64, base64url, hex, utf8, or latin1"
90
89
  });
91
90
  }
92
91
  const bytes = $convertStrToBytes(data, from);
93
- if (bytes.error) return chunkZJ32WGAA_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
92
+ if (bytes.error) return chunkUIV6DG54_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
94
93
  const str = $convertBytesToStr(bytes.result, to);
95
- if (str.error) return chunkZJ32WGAA_cjs.$err({ msg: str.error.message, desc: str.error.description });
96
- return chunkZJ32WGAA_cjs.$ok({ result: str.result });
94
+ if (str.error) return chunkUIV6DG54_cjs.$err({ msg: str.error.message, desc: str.error.description });
95
+ return chunkUIV6DG54_cjs.$ok({ result: str.result });
97
96
  }
98
97
  var strToBytes = {
99
98
  base64: $fromBase64,
@@ -159,45 +158,45 @@ function $fromHex(data) {
159
158
  // src/web/web-encrypt.ts
160
159
  function $generateUuid() {
161
160
  try {
162
- return chunkZJ32WGAA_cjs.$ok(crypto.randomUUID());
161
+ return chunkUIV6DG54_cjs.$ok(crypto.randomUUID());
163
162
  } catch (error) {
164
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - UUID Generation: Failed to generate UUID", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
163
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "UUID Generation")}: Failed to generate UUID`, desc: chunkUIV6DG54_cjs.$fmtError(error) });
165
164
  }
166
165
  }
167
166
  async function $createSecretKey(secret, options = {}) {
168
- if (!chunkZJ32WGAA_cjs.$isStr(secret)) {
169
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Key Generation: Empty Secret", desc: "Secret must be a non-empty string" });
167
+ if (!chunkUIV6DG54_cjs.$isStr(secret)) {
168
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "Key Generation")}: Empty Secret`, desc: "Secret must be a non-empty string" });
170
169
  }
171
170
  const algorithm = options.algorithm ?? "aes256gcm";
172
- if (!(algorithm in chunkZJ32WGAA_cjs.ENCRYPTION_ALGORITHMS)) {
173
- return chunkZJ32WGAA_cjs.$err({
174
- msg: `Crypto NodeJS API - Key Generation: Unsupported algorithm: ${algorithm}`,
175
- desc: `Supported algorithms are: ${Object.keys(chunkZJ32WGAA_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
171
+ if (!(algorithm in chunkUIV6DG54_cjs.ENCRYPTION_ALGORITHMS)) {
172
+ return chunkUIV6DG54_cjs.$err({
173
+ msg: `${chunkUIV6DG54_cjs.title("web", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
174
+ desc: `Supported algorithms are: ${Object.keys(chunkUIV6DG54_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
176
175
  });
177
176
  }
178
177
  const digest = options.digest ?? "sha256";
179
- if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) {
180
- return chunkZJ32WGAA_cjs.$err({
181
- msg: `Crypto NodeJS API - Key Generation: Unsupported digest: ${digest}`,
182
- desc: `Supported digests are: ${Object.keys(chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS).join(", ")}`
178
+ if (!(digest in chunkUIV6DG54_cjs.DIGEST_ALGORITHMS)) {
179
+ return chunkUIV6DG54_cjs.$err({
180
+ msg: `${chunkUIV6DG54_cjs.title("web", "Key Generation")}: Unsupported digest: ${digest}`,
181
+ desc: `Supported digests are: ${Object.keys(chunkUIV6DG54_cjs.DIGEST_ALGORITHMS).join(", ")}`
183
182
  });
184
183
  }
185
184
  const salt = options.salt ?? "cipher-kit-salt";
186
- if (!chunkZJ32WGAA_cjs.$isStr(salt, 8)) {
187
- return chunkZJ32WGAA_cjs.$err({
188
- msg: "Crypto NodeJS API - Key Generation: Weak salt",
185
+ if (!chunkUIV6DG54_cjs.$isStr(salt, 8)) {
186
+ return chunkUIV6DG54_cjs.$err({
187
+ msg: `${chunkUIV6DG54_cjs.title("web", "Key Generation")}: Weak salt`,
189
188
  desc: "Salt must be a non-empty string with at least 8 characters"
190
189
  });
191
190
  }
192
191
  const info = options.info ?? "cipher-kit";
193
- if (!chunkZJ32WGAA_cjs.$isStr(info)) {
194
- return chunkZJ32WGAA_cjs.$err({
195
- msg: "Crypto NodeJS API - Key Generation: Invalid info",
192
+ if (!chunkUIV6DG54_cjs.$isStr(info)) {
193
+ return chunkUIV6DG54_cjs.$err({
194
+ msg: `${chunkUIV6DG54_cjs.title("web", "Key Generation")}: Invalid info`,
196
195
  desc: "Info must be a non-empty string"
197
196
  });
198
197
  }
199
- const encryptAlgo = chunkZJ32WGAA_cjs.ENCRYPTION_ALGORITHMS[algorithm];
200
- const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
198
+ const encryptAlgo = chunkUIV6DG54_cjs.ENCRYPTION_ALGORITHMS[algorithm];
199
+ const digestAlgo = chunkUIV6DG54_cjs.DIGEST_ALGORITHMS[digest];
201
200
  try {
202
201
  const ikm = await crypto.subtle.importKey("raw", textEncoder.encode(secret.normalize("NFKC")), "HKDF", false, [
203
202
  "deriveKey"
@@ -220,38 +219,37 @@ async function $createSecretKey(secret, options = {}) {
220
219
  algorithm,
221
220
  key
222
221
  });
223
- return chunkZJ32WGAA_cjs.$ok({ result: secretKey });
222
+ return chunkUIV6DG54_cjs.$ok({ result: secretKey });
224
223
  } catch (error) {
225
- return chunkZJ32WGAA_cjs.$err({
226
- msg: "Crypto Web API - Key Generation: Failed to create secret key",
227
- desc: chunkZJ32WGAA_cjs.$fmtError(error)
224
+ return chunkUIV6DG54_cjs.$err({
225
+ msg: `${chunkUIV6DG54_cjs.title("web", "Key Generation")}: Failed to create secret key`,
226
+ desc: chunkUIV6DG54_cjs.$fmtError(error)
228
227
  });
229
228
  }
230
229
  }
231
230
  async function $encrypt(data, secretKey, options = {}) {
232
- if (!chunkZJ32WGAA_cjs.$isStr(data)) {
233
- return chunkZJ32WGAA_cjs.$err({
234
- msg: "Crypto Web API - Encryption: Empty data for encryption",
231
+ if (!chunkUIV6DG54_cjs.$isStr(data)) {
232
+ return chunkUIV6DG54_cjs.$err({
233
+ msg: `${chunkUIV6DG54_cjs.title("web", "Encryption")}: Empty data for encryption`,
235
234
  desc: "Data must be a non-empty string"
236
235
  });
237
236
  }
238
- const inputEncoding = options.inputEncoding ?? "utf8";
239
- const outputEncoding = options.outputEncoding ?? "base64url";
240
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
241
- return chunkZJ32WGAA_cjs.$err({
242
- msg: `Crypto Web API - Encryption: Unsupported encoding: input ${inputEncoding} or output ${outputEncoding}`,
243
- desc: "Use base64, base64url, hex, utf8, or latin1"
237
+ const encoding = options.encoding ?? "base64url";
238
+ if (!chunkUIV6DG54_cjs.CIPHER_ENCODING.includes(encoding)) {
239
+ return chunkUIV6DG54_cjs.$err({
240
+ msg: `${chunkUIV6DG54_cjs.title("web", "Encryption")}: Unsupported output encoding: ${encoding}`,
241
+ desc: "Use base64, base64url, or hex"
244
242
  });
245
243
  }
246
- const injectedKey = chunkZJ32WGAA_cjs.$isSecretKey(secretKey, "web");
244
+ const injectedKey = chunkUIV6DG54_cjs.$isSecretKey(secretKey, "web");
247
245
  if (!injectedKey) {
248
- return chunkZJ32WGAA_cjs.$err({
249
- msg: "Crypto Web API - Encryption: Invalid Secret Key",
246
+ return chunkUIV6DG54_cjs.$err({
247
+ msg: `${chunkUIV6DG54_cjs.title("web", "Encryption")}: Invalid Secret Key`,
250
248
  desc: "Expected a Web SecretKey"
251
249
  });
252
250
  }
253
- const { result, error } = $convertStrToBytes(data, inputEncoding);
254
- if (error) return chunkZJ32WGAA_cjs.$err(error);
251
+ const { result, error } = $convertStrToBytes(data, "utf8");
252
+ if (error) return chunkUIV6DG54_cjs.$err(error);
255
253
  try {
256
254
  const iv = crypto.getRandomValues(new Uint8Array(injectedKey.injected.ivLength));
257
255
  const cipherWithTag = await crypto.subtle.encrypt(
@@ -259,54 +257,53 @@ async function $encrypt(data, secretKey, options = {}) {
259
257
  injectedKey.key,
260
258
  result
261
259
  );
262
- const ivStr = $convertBytesToStr(iv, outputEncoding);
263
- const cipherStr = $convertBytesToStr(cipherWithTag, outputEncoding);
260
+ const ivStr = $convertBytesToStr(iv, encoding);
261
+ const cipherStr = $convertBytesToStr(cipherWithTag, encoding);
264
262
  if (ivStr.error || cipherStr.error) {
265
- return chunkZJ32WGAA_cjs.$err({
266
- msg: "Crypto Web API - Encryption: Failed to convert IV or encrypted data",
267
- desc: `Conversion error: ${ivStr.error || cipherStr.error}`
263
+ return chunkUIV6DG54_cjs.$err({
264
+ msg: `${chunkUIV6DG54_cjs.title("web", "Encryption")}: Failed to convert IV or encrypted data`,
265
+ desc: `Conversion error: ${chunkUIV6DG54_cjs.$fmtResultErr(ivStr.error || cipherStr.error)}`
268
266
  });
269
267
  }
270
- return chunkZJ32WGAA_cjs.$ok(`${ivStr.result}.${cipherStr.result}.`);
268
+ return chunkUIV6DG54_cjs.$ok(`${ivStr.result}.${cipherStr.result}.`);
271
269
  } catch (error2) {
272
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Encryption: Failed to encrypt data", desc: chunkZJ32WGAA_cjs.$fmtError(error2) });
270
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "Encryption")}: Failed to encrypt data`, desc: chunkUIV6DG54_cjs.$fmtError(error2) });
273
271
  }
274
272
  }
275
273
  async function $decrypt(encrypted, secretKey, options = {}) {
276
- if (chunkZJ32WGAA_cjs.matchPattern(encrypted, "web") === false) {
277
- return chunkZJ32WGAA_cjs.$err({
278
- msg: "Crypto Web API - Decryption: Invalid encrypted data format",
274
+ if (chunkUIV6DG54_cjs.matchPattern(encrypted, "web") === false) {
275
+ return chunkUIV6DG54_cjs.$err({
276
+ msg: `${chunkUIV6DG54_cjs.title("web", "Decryption")}: Invalid encrypted data format`,
279
277
  desc: 'Encrypted data must be in the format "iv.cipherWithTag."'
280
278
  });
281
279
  }
282
- const inputEncoding = options.inputEncoding ?? "base64url";
283
- const outputEncoding = options.outputEncoding ?? "utf8";
284
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
285
- return chunkZJ32WGAA_cjs.$err({
286
- msg: `Crypto Web API - Decryption: Unsupported encoding: input ${inputEncoding} or output ${outputEncoding}`,
287
- desc: "Use base64, base64url, hex, utf8, or latin1"
280
+ const encoding = options.encoding ?? "base64url";
281
+ if (!chunkUIV6DG54_cjs.CIPHER_ENCODING.includes(encoding)) {
282
+ return chunkUIV6DG54_cjs.$err({
283
+ msg: `${chunkUIV6DG54_cjs.title("web", "Decryption")}: Unsupported input encoding: ${encoding}`,
284
+ desc: "Use base64, base64url, or hex"
288
285
  });
289
286
  }
290
287
  const [iv, encryptedWithTag] = encrypted.split(".", 3);
291
- if (!chunkZJ32WGAA_cjs.$isStr(iv) || !chunkZJ32WGAA_cjs.$isStr(encryptedWithTag)) {
292
- return chunkZJ32WGAA_cjs.$err({
293
- msg: "Crypto Web API - Decryption: Invalid encrypted data",
288
+ if (!chunkUIV6DG54_cjs.$isStr(iv) || !chunkUIV6DG54_cjs.$isStr(encryptedWithTag)) {
289
+ return chunkUIV6DG54_cjs.$err({
290
+ msg: `${chunkUIV6DG54_cjs.title("web", "Decryption")}: Invalid encrypted data`,
294
291
  desc: "Encrypted data must contain valid IV, encrypted and tag components"
295
292
  });
296
293
  }
297
- const injectedKey = chunkZJ32WGAA_cjs.$isSecretKey(secretKey, "web");
294
+ const injectedKey = chunkUIV6DG54_cjs.$isSecretKey(secretKey, "web");
298
295
  if (!injectedKey) {
299
- return chunkZJ32WGAA_cjs.$err({
300
- msg: "Crypto Web API - Decryption: Invalid Secret Key",
296
+ return chunkUIV6DG54_cjs.$err({
297
+ msg: `${chunkUIV6DG54_cjs.title("web", "Decryption")}: Invalid Secret Key`,
301
298
  desc: "Expected a Web SecretKey"
302
299
  });
303
300
  }
304
- const ivBytes = $convertStrToBytes(iv, inputEncoding);
305
- const cipherWithTagBytes = $convertStrToBytes(encryptedWithTag, inputEncoding);
301
+ const ivBytes = $convertStrToBytes(iv, encoding);
302
+ const cipherWithTagBytes = $convertStrToBytes(encryptedWithTag, encoding);
306
303
  if (ivBytes.error || cipherWithTagBytes.error) {
307
- return chunkZJ32WGAA_cjs.$err({
308
- msg: "Crypto Web API - Decryption: Failed to convert IV or encrypted data",
309
- desc: `Conversion error: ${ivBytes.error || cipherWithTagBytes.error}`
304
+ return chunkUIV6DG54_cjs.$err({
305
+ msg: `${chunkUIV6DG54_cjs.title("web", "Decryption")}: Failed to convert IV or encrypted data`,
306
+ desc: `Conversion error: ${chunkUIV6DG54_cjs.$fmtResultErr(ivBytes.error || cipherWithTagBytes.error)}`
310
307
  });
311
308
  }
312
309
  try {
@@ -317,93 +314,87 @@ async function $decrypt(encrypted, secretKey, options = {}) {
317
314
  );
318
315
  return $convertBytesToStr(decrypted, "utf8");
319
316
  } catch (error) {
320
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Decryption: Failed to decrypt data", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
317
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "Decryption")}: Failed to decrypt data`, desc: chunkUIV6DG54_cjs.$fmtError(error) });
321
318
  }
322
319
  }
323
320
  async function $encryptObj(data, secretKey, options = {}) {
324
- const { result, error } = chunkZJ32WGAA_cjs.$stringifyObj(data);
325
- if (error) return chunkZJ32WGAA_cjs.$err(error);
321
+ const { result, error } = chunkUIV6DG54_cjs.$stringifyObj(data);
322
+ if (error) return chunkUIV6DG54_cjs.$err(error);
326
323
  return await $encrypt(result, secretKey, options);
327
324
  }
328
325
  async function $decryptObj(encrypted, secretKey, options = {}) {
329
326
  const { result, error } = await $decrypt(encrypted, secretKey, options);
330
- if (error) return chunkZJ32WGAA_cjs.$err(error);
331
- return chunkZJ32WGAA_cjs.$parseToObj(result);
327
+ if (error) return chunkUIV6DG54_cjs.$err(error);
328
+ return chunkUIV6DG54_cjs.$parseToObj(result);
332
329
  }
333
330
  async function $hash(data, options = {}) {
334
- if (!chunkZJ32WGAA_cjs.$isStr(data)) {
335
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Hashing: Empty data for hashing", desc: "Data must be a non-empty string" });
336
- }
337
- const inputEncoding = options.inputEncoding ?? "utf8";
338
- const outputEncoding = options.outputEncoding ?? "base64url";
339
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
340
- return chunkZJ32WGAA_cjs.$err({
341
- msg: `Crypto Web API - Hashing: Unsupported input encoding: ${inputEncoding} or output encoding: ${outputEncoding}`,
342
- desc: "Use base64, base64url, hex, utf8, or latin1"
331
+ if (!chunkUIV6DG54_cjs.$isStr(data)) {
332
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "Hashing")}: Empty data for hashing`, desc: "Data must be a non-empty string" });
333
+ }
334
+ const encoding = options.encoding ?? "base64url";
335
+ if (!chunkUIV6DG54_cjs.CIPHER_ENCODING.includes(encoding)) {
336
+ return chunkUIV6DG54_cjs.$err({
337
+ msg: `${chunkUIV6DG54_cjs.title("web", "Hashing")}: Unsupported output encoding: ${encoding}`,
338
+ desc: "Use base64, base64url, or hex"
343
339
  });
344
340
  }
345
341
  const digest = options.digest ?? "sha256";
346
- if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) {
347
- return chunkZJ32WGAA_cjs.$err({
348
- msg: `Crypto Web API - Hashing: Unsupported digest: ${digest}`,
349
- desc: `Supported digests are: ${Object.keys(chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS).join(", ")}`
342
+ if (!(digest in chunkUIV6DG54_cjs.DIGEST_ALGORITHMS)) {
343
+ return chunkUIV6DG54_cjs.$err({
344
+ msg: `${chunkUIV6DG54_cjs.title("web", "Hashing")}: Unsupported digest: ${digest}`,
345
+ desc: `Supported digests are: ${Object.keys(chunkUIV6DG54_cjs.DIGEST_ALGORITHMS).join(", ")}`
350
346
  });
351
347
  }
352
- const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
353
- const { result, error } = $convertStrToBytes(data, inputEncoding);
354
- if (error) return chunkZJ32WGAA_cjs.$err(error);
348
+ const digestAlgo = chunkUIV6DG54_cjs.DIGEST_ALGORITHMS[digest];
349
+ const { result, error } = $convertStrToBytes(data, "utf8");
350
+ if (error) return chunkUIV6DG54_cjs.$err(error);
355
351
  try {
356
352
  const hashed = await crypto.subtle.digest(digestAlgo.web, result);
357
- return $convertBytesToStr(hashed, outputEncoding);
353
+ return $convertBytesToStr(hashed, encoding);
358
354
  } catch (error2) {
359
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Hashing: Failed to hash data", desc: chunkZJ32WGAA_cjs.$fmtError(error2) });
355
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "Hashing")}: Failed to hash data`, desc: chunkUIV6DG54_cjs.$fmtError(error2) });
360
356
  }
361
357
  }
362
- async function $hashObj(data, options = {}) {
363
- const { result, error } = chunkZJ32WGAA_cjs.$stringifyObj(data);
364
- if (error) return chunkZJ32WGAA_cjs.$err(error);
365
- return await $hash(result, options);
366
- }
367
358
  async function $hashPassword(password, options = {}) {
368
- if (!chunkZJ32WGAA_cjs.$isStr(password)) {
369
- return chunkZJ32WGAA_cjs.$err({
370
- msg: "Crypto Web API - Password Hashing: Empty password",
359
+ if (!chunkUIV6DG54_cjs.$isStr(password)) {
360
+ return chunkUIV6DG54_cjs.$err({
361
+ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Empty password`,
371
362
  desc: "Password must be a non-empty string"
372
363
  });
373
364
  }
374
365
  const digest = options.digest ?? "sha512";
375
- if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) {
376
- return chunkZJ32WGAA_cjs.$err({
377
- msg: `Crypto Web API - Password Hashing: Unsupported digest: ${digest}`,
378
- desc: `Supported digests are: ${Object.keys(chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS).join(", ")}`
366
+ if (!(digest in chunkUIV6DG54_cjs.DIGEST_ALGORITHMS)) {
367
+ return chunkUIV6DG54_cjs.$err({
368
+ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Unsupported digest: ${digest}`,
369
+ desc: `Supported digests are: ${Object.keys(chunkUIV6DG54_cjs.DIGEST_ALGORITHMS).join(", ")}`
379
370
  });
380
371
  }
381
- const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
382
- const outputEncoding = options.outputEncoding ?? "base64url";
383
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
384
- return chunkZJ32WGAA_cjs.$err({
385
- msg: `Crypto Web API - Password Hashing: Unsupported output encoding: ${outputEncoding}`,
386
- desc: "Use base64, base64url, hex, utf8, or latin1"
372
+ const digestAlgo = chunkUIV6DG54_cjs.DIGEST_ALGORITHMS[digest];
373
+ const encoding = options.encoding ?? "base64url";
374
+ if (!chunkUIV6DG54_cjs.CIPHER_ENCODING.includes(encoding)) {
375
+ return chunkUIV6DG54_cjs.$err({
376
+ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Unsupported output encoding: ${encoding}`,
377
+ desc: "Use base64, base64url, or hex"
387
378
  });
388
379
  }
389
380
  const saltLength = options.saltLength ?? 16;
390
381
  if (typeof saltLength !== "number" || saltLength < 8) {
391
- return chunkZJ32WGAA_cjs.$err({
392
- msg: "Crypto Web API - Password Hashing: Weak salt length",
382
+ return chunkUIV6DG54_cjs.$err({
383
+ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Weak salt length`,
393
384
  desc: "Salt length must be a number and at least 8 bytes (recommended 16)"
394
385
  });
395
386
  }
396
387
  const iterations = options.iterations ?? 32e4;
397
388
  if (typeof iterations !== "number" || iterations < 1e3) {
398
- return chunkZJ32WGAA_cjs.$err({
399
- msg: "Crypto Web API - Password Hashing: Weak iteration count",
389
+ return chunkUIV6DG54_cjs.$err({
390
+ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Weak iteration count`,
400
391
  desc: "Iterations must be a number and at least 1000 (recommended 320,000 or more)"
401
392
  });
402
393
  }
403
394
  const keyLength = options.keyLength ?? 64;
404
395
  if (typeof keyLength !== "number" || keyLength < 16) {
405
- return chunkZJ32WGAA_cjs.$err({
406
- msg: "Crypto Web API - Password Hashing: Weak key length",
396
+ return chunkUIV6DG54_cjs.$err({
397
+ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Weak key length`,
407
398
  desc: "Key length must be a number and at least 16 bytes (recommended 64)"
408
399
  });
409
400
  }
@@ -421,29 +412,29 @@ async function $hashPassword(password, options = {}) {
421
412
  baseKey,
422
413
  keyLength * 8
423
414
  );
424
- const saltStr = $convertBytesToStr(salt, outputEncoding);
425
- if (saltStr.error) return chunkZJ32WGAA_cjs.$err(saltStr.error);
426
- const hashedPasswordStr = $convertBytesToStr(bits, outputEncoding);
427
- if (hashedPasswordStr.error) return chunkZJ32WGAA_cjs.$err(hashedPasswordStr.error);
428
- return chunkZJ32WGAA_cjs.$ok({ hash: hashedPasswordStr.result, salt: saltStr.result });
415
+ const saltStr = $convertBytesToStr(salt, encoding);
416
+ if (saltStr.error) return chunkUIV6DG54_cjs.$err(saltStr.error);
417
+ const hashedPasswordStr = $convertBytesToStr(bits, encoding);
418
+ if (hashedPasswordStr.error) return chunkUIV6DG54_cjs.$err(hashedPasswordStr.error);
419
+ return chunkUIV6DG54_cjs.$ok({ hash: hashedPasswordStr.result, salt: saltStr.result });
429
420
  } catch (error) {
430
- return chunkZJ32WGAA_cjs.$err({ msg: "Crypto Web API - Password Hashing: Failed to hash password", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
421
+ return chunkUIV6DG54_cjs.$err({ msg: `${chunkUIV6DG54_cjs.title("web", "Password Hashing")}: Failed to hash password`, desc: chunkUIV6DG54_cjs.$fmtError(error) });
431
422
  }
432
423
  }
433
424
  async function $verifyPassword(password, hashedPassword, salt, options = {}) {
434
- if (!chunkZJ32WGAA_cjs.$isStr(password) || !chunkZJ32WGAA_cjs.$isStr(hashedPassword) || !chunkZJ32WGAA_cjs.$isStr(salt)) return false;
425
+ if (!chunkUIV6DG54_cjs.$isStr(password) || !chunkUIV6DG54_cjs.$isStr(hashedPassword) || !chunkUIV6DG54_cjs.$isStr(salt)) return false;
435
426
  const digest = options.digest ?? "sha512";
436
- if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) return false;
437
- const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
438
- const inputEncoding = options.inputEncoding ?? "base64url";
439
- if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding)) return false;
427
+ if (!(digest in chunkUIV6DG54_cjs.DIGEST_ALGORITHMS)) return false;
428
+ const digestAlgo = chunkUIV6DG54_cjs.DIGEST_ALGORITHMS[digest];
429
+ const encoding = options.encoding ?? "base64url";
430
+ if (!chunkUIV6DG54_cjs.CIPHER_ENCODING.includes(encoding)) return false;
440
431
  const iterations = options.iterations ?? 32e4;
441
432
  if (typeof iterations !== "number" || iterations < 1e3) return false;
442
433
  const keyLength = options.keyLength ?? 64;
443
434
  if (typeof keyLength !== "number" || keyLength < 16) return false;
444
- const saltBytes = $convertStrToBytes(salt, "base64url");
435
+ const saltBytes = $convertStrToBytes(salt, encoding);
445
436
  if (saltBytes.error) return false;
446
- const hashedPasswordBytes = $convertStrToBytes(hashedPassword, "base64url");
437
+ const hashedPasswordBytes = $convertStrToBytes(hashedPassword, encoding);
447
438
  if (hashedPasswordBytes.error) return false;
448
439
  try {
449
440
  const baseKey = await crypto.subtle.importKey(
@@ -465,24 +456,28 @@ async function $verifyPassword(password, hashedPassword, salt, options = {}) {
465
456
  keyLength * 8
466
457
  )
467
458
  );
459
+ if (bits === void 0 || hashedPasswordBytes.result === void 0) return false;
468
460
  if (bits.length !== hashedPasswordBytes.result.length) return false;
469
- let isMatch = true;
461
+ let diff = 0;
470
462
  for (let i = 0; i < bits.length; i++) {
471
- if (bits[i] !== hashedPasswordBytes.result[i]) isMatch = false;
463
+ diff |= bits[i] ^ hashedPasswordBytes.result[i];
472
464
  }
473
- return isMatch;
465
+ return diff === 0;
474
466
  } catch {
475
467
  return false;
476
468
  }
477
469
  }
478
470
 
479
471
  // src/web/kit.ts
472
+ function isWebSecretKey(x) {
473
+ return chunkUIV6DG54_cjs.$isSecretKey(x, "web") !== null;
474
+ }
480
475
  function tryGenerateUuid() {
481
476
  return $generateUuid();
482
477
  }
483
478
  function generateUuid() {
484
479
  const { result, error } = $generateUuid();
485
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
480
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
486
481
  return result;
487
482
  }
488
483
  async function tryCreateSecretKey(secret, options = {}) {
@@ -490,7 +485,7 @@ async function tryCreateSecretKey(secret, options = {}) {
490
485
  }
491
486
  async function createSecretKey(secret, options = {}) {
492
487
  const { result, error } = await $createSecretKey(secret, options);
493
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
488
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
494
489
  return result;
495
490
  }
496
491
  async function tryEncrypt(data, secretKey, options = {}) {
@@ -498,7 +493,7 @@ async function tryEncrypt(data, secretKey, options = {}) {
498
493
  }
499
494
  async function encrypt(data, secretKey, options = {}) {
500
495
  const { result, error } = await $encrypt(data, secretKey, options);
501
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
496
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
502
497
  return result;
503
498
  }
504
499
  async function tryDecrypt(encrypted, secretKey, options = {}) {
@@ -506,7 +501,7 @@ async function tryDecrypt(encrypted, secretKey, options = {}) {
506
501
  }
507
502
  async function decrypt(encrypted, secretKey, options = {}) {
508
503
  const { result, error } = await $decrypt(encrypted, secretKey, options);
509
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
504
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
510
505
  return result;
511
506
  }
512
507
  async function tryEncryptObj(data, secretKey, options = {}) {
@@ -514,7 +509,7 @@ async function tryEncryptObj(data, secretKey, options = {}) {
514
509
  }
515
510
  async function encryptObj(data, secretKey, options = {}) {
516
511
  const { result, error } = await $encryptObj(data, secretKey, options);
517
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
512
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
518
513
  return result;
519
514
  }
520
515
  async function tryDecryptObj(encrypted, secretKey, options = {}) {
@@ -522,7 +517,7 @@ async function tryDecryptObj(encrypted, secretKey, options = {}) {
522
517
  }
523
518
  async function decryptObj(encrypted, secretKey, options = {}) {
524
519
  const { result, error } = await $decryptObj(encrypted, secretKey, options);
525
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
520
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
526
521
  return result;
527
522
  }
528
523
  async function tryHash(data, options = {}) {
@@ -530,15 +525,7 @@ async function tryHash(data, options = {}) {
530
525
  }
531
526
  async function hash(data, options = {}) {
532
527
  const { result, error } = await $hash(data, options);
533
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
534
- return result;
535
- }
536
- async function tryHashObj(data, options = {}) {
537
- return await $hashObj(data, options);
538
- }
539
- async function hashObj(data, options = {}) {
540
- const { result, error } = await $hashObj(data, options);
541
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
528
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
542
529
  return result;
543
530
  }
544
531
  async function tryHashPassword(password, options = {}) {
@@ -546,7 +533,7 @@ async function tryHashPassword(password, options = {}) {
546
533
  }
547
534
  async function hashPassword(password, options = {}) {
548
535
  const { hash: hash2, salt, error } = await $hashPassword(password, options);
549
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
536
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
550
537
  return { hash: hash2, salt };
551
538
  }
552
539
  async function verifyPassword(password, hashedPassword, salt, options = {}) {
@@ -557,7 +544,7 @@ function tryConvertStrToBytes(data, inputEncoding = "utf8") {
557
544
  }
558
545
  function convertStrToBytes(data, inputEncoding = "utf8") {
559
546
  const { result, error } = $convertStrToBytes(data, inputEncoding);
560
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
547
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
561
548
  return result;
562
549
  }
563
550
  function tryConvertBytesToStr(data, outputEncoding = "utf8") {
@@ -565,7 +552,7 @@ function tryConvertBytesToStr(data, outputEncoding = "utf8") {
565
552
  }
566
553
  function convertBytesToStr(data, outputEncoding = "utf8") {
567
554
  const { result, error } = $convertBytesToStr(data, outputEncoding);
568
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
555
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
569
556
  return result;
570
557
  }
571
558
  function tryConvertEncoding(data, from, to) {
@@ -573,7 +560,7 @@ function tryConvertEncoding(data, from, to) {
573
560
  }
574
561
  function convertEncoding(data, from, to) {
575
562
  const { result, error } = $convertEncoding(data, from, to);
576
- if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
563
+ if (error) throw new Error(chunkUIV6DG54_cjs.$fmtResultErr(error));
577
564
  return result;
578
565
  }
579
566
 
@@ -587,8 +574,8 @@ exports.encrypt = encrypt;
587
574
  exports.encryptObj = encryptObj;
588
575
  exports.generateUuid = generateUuid;
589
576
  exports.hash = hash;
590
- exports.hashObj = hashObj;
591
577
  exports.hashPassword = hashPassword;
578
+ exports.isWebSecretKey = isWebSecretKey;
592
579
  exports.kit_exports = kit_exports;
593
580
  exports.tryConvertBytesToStr = tryConvertBytesToStr;
594
581
  exports.tryConvertEncoding = tryConvertEncoding;
@@ -600,8 +587,7 @@ exports.tryEncrypt = tryEncrypt;
600
587
  exports.tryEncryptObj = tryEncryptObj;
601
588
  exports.tryGenerateUuid = tryGenerateUuid;
602
589
  exports.tryHash = tryHash;
603
- exports.tryHashObj = tryHashObj;
604
590
  exports.tryHashPassword = tryHashPassword;
605
591
  exports.verifyPassword = verifyPassword;
606
- //# sourceMappingURL=chunk-NKLNWTQA.cjs.map
607
- //# sourceMappingURL=chunk-NKLNWTQA.cjs.map
592
+ //# sourceMappingURL=chunk-XIWV7XVI.cjs.map
593
+ //# sourceMappingURL=chunk-XIWV7XVI.cjs.map