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