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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkRXXVBCWL_cjs = require('./chunk-RXXVBCWL.cjs');
3
+ var chunkZJ32WGAA_cjs = require('./chunk-ZJ32WGAA.cjs');
4
4
  var buffer = require('buffer');
5
5
  var nodeCrypto = require('crypto');
6
6
 
@@ -10,7 +10,7 @@ var nodeCrypto__default = /*#__PURE__*/_interopDefault(nodeCrypto);
10
10
 
11
11
  // src/node/kit.ts
12
12
  var kit_exports = {};
13
- chunkRXXVBCWL_cjs.__export(kit_exports, {
13
+ chunkZJ32WGAA_cjs.__export(kit_exports, {
14
14
  convertBytesToStr: () => convertBytesToStr,
15
15
  convertEncoding: () => convertEncoding,
16
16
  convertStrToBytes: () => convertStrToBytes,
@@ -21,6 +21,7 @@ chunkRXXVBCWL_cjs.__export(kit_exports, {
21
21
  encryptObj: () => encryptObj,
22
22
  generateUuid: () => generateUuid,
23
23
  hash: () => hash,
24
+ hashObj: () => hashObj,
24
25
  hashPassword: () => hashPassword,
25
26
  tryConvertBytesToStr: () => tryConvertBytesToStr,
26
27
  tryConvertEncoding: () => tryConvertEncoding,
@@ -32,107 +33,108 @@ chunkRXXVBCWL_cjs.__export(kit_exports, {
32
33
  tryEncryptObj: () => tryEncryptObj,
33
34
  tryGenerateUuid: () => tryGenerateUuid,
34
35
  tryHash: () => tryHash,
36
+ tryHashObj: () => tryHashObj,
35
37
  tryHashPassword: () => tryHashPassword,
36
38
  verifyPassword: () => verifyPassword
37
39
  });
38
40
  function $convertStrToBytes(data, inputEncoding = "utf8") {
39
- if (!chunkRXXVBCWL_cjs.$isStr(data)) {
40
- return chunkRXXVBCWL_cjs.$err({
41
+ if (!chunkZJ32WGAA_cjs.$isStr(data)) {
42
+ return chunkZJ32WGAA_cjs.$err({
41
43
  msg: "Crypto NodeJS API - String to Bytes: Empty data",
42
44
  desc: "Data must be a non-empty string"
43
45
  });
44
46
  }
45
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(inputEncoding)) {
46
- return chunkRXXVBCWL_cjs.$err({
47
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding)) {
48
+ return chunkZJ32WGAA_cjs.$err({
47
49
  msg: `Crypto NodeJS API - String to Bytes: Unsupported encoding: ${inputEncoding}`,
48
50
  desc: "Use base64, base64url, hex, utf8, or latin1"
49
51
  });
50
52
  }
51
53
  try {
52
- return chunkRXXVBCWL_cjs.$ok({ result: buffer.Buffer.from(data, inputEncoding) });
54
+ return chunkZJ32WGAA_cjs.$ok({ result: buffer.Buffer.from(data, inputEncoding) });
53
55
  } catch (error) {
54
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - String to Bytes: Failed to convert data", desc: chunkRXXVBCWL_cjs.$fmtError(error) });
56
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - String to Bytes: Failed to convert data", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
55
57
  }
56
58
  }
57
59
  function $convertBytesToStr(data, outputEncoding = "utf8") {
58
60
  if (!(data instanceof buffer.Buffer)) {
59
- return chunkRXXVBCWL_cjs.$err({
61
+ return chunkZJ32WGAA_cjs.$err({
60
62
  msg: "Crypto NodeJS API - Bytes to String: Invalid data type",
61
63
  desc: "Data must be a Buffer"
62
64
  });
63
65
  }
64
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(outputEncoding)) {
65
- return chunkRXXVBCWL_cjs.$err({
66
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
67
+ return chunkZJ32WGAA_cjs.$err({
66
68
  msg: `Crypto NodeJS API - Bytes to String: Unsupported encoding: ${outputEncoding}`,
67
69
  desc: "Use base64, base64url, hex, utf8, or latin1"
68
70
  });
69
71
  }
70
72
  try {
71
- return chunkRXXVBCWL_cjs.$ok(buffer.Buffer.from(data).toString(outputEncoding));
73
+ return chunkZJ32WGAA_cjs.$ok(buffer.Buffer.from(data).toString(outputEncoding));
72
74
  } catch (error) {
73
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Bytes to String: Failed to convert data", desc: chunkRXXVBCWL_cjs.$fmtError(error) });
75
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Bytes to String: Failed to convert data", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
74
76
  }
75
77
  }
76
78
  function $convertEncoding(data, from, to) {
77
- if (!chunkRXXVBCWL_cjs.$isStr(data)) {
78
- return chunkRXXVBCWL_cjs.$err({
79
+ if (!chunkZJ32WGAA_cjs.$isStr(data)) {
80
+ return chunkZJ32WGAA_cjs.$err({
79
81
  msg: "Crypto NodeJS API - Convert Format: Empty data",
80
82
  desc: "Data must be a non-empty string"
81
83
  });
82
84
  }
83
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(from) || !chunkRXXVBCWL_cjs.ENCODINGS.includes(to)) {
84
- return chunkRXXVBCWL_cjs.$err({
85
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(from) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(to)) {
86
+ return chunkZJ32WGAA_cjs.$err({
85
87
  msg: `Crypto NodeJS API - Convert Format: Unsupported encoding: from ${from} to ${to}`,
86
88
  desc: "Use base64, base64url, hex, utf8, or latin1"
87
89
  });
88
90
  }
89
91
  const bytes = $convertStrToBytes(data, from);
90
- if (bytes.error) return chunkRXXVBCWL_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
92
+ if (bytes.error) return chunkZJ32WGAA_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
91
93
  const str = $convertBytesToStr(bytes.result, to);
92
- if (str.error) return chunkRXXVBCWL_cjs.$err({ msg: str.error.message, desc: str.error.description });
93
- return chunkRXXVBCWL_cjs.$ok({ result: str.result });
94
+ if (str.error) return chunkZJ32WGAA_cjs.$err({ msg: str.error.message, desc: str.error.description });
95
+ return chunkZJ32WGAA_cjs.$ok({ result: str.result });
94
96
  }
95
97
  function $generateUuid() {
96
98
  try {
97
- return chunkRXXVBCWL_cjs.$ok(nodeCrypto__default.default.randomUUID());
99
+ return chunkZJ32WGAA_cjs.$ok(nodeCrypto__default.default.randomUUID());
98
100
  } catch (error) {
99
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - UUID Generation: Failed to generate UUID", desc: chunkRXXVBCWL_cjs.$fmtError(error) });
101
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - UUID Generation: Failed to generate UUID", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
100
102
  }
101
103
  }
102
104
  function $createSecretKey(secret, options = {}) {
103
- if (!chunkRXXVBCWL_cjs.$isStr(secret)) {
104
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Key Generation: Empty Secret", desc: "Secret must be a non-empty string" });
105
+ if (!chunkZJ32WGAA_cjs.$isStr(secret)) {
106
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Key Generation: Empty Secret", desc: "Secret must be a non-empty string" });
105
107
  }
106
108
  const algorithm = options.algorithm ?? "aes256gcm";
107
- if (!(algorithm in chunkRXXVBCWL_cjs.ENCRYPTION_ALGORITHMS)) {
108
- return chunkRXXVBCWL_cjs.$err({
109
+ if (!(algorithm in chunkZJ32WGAA_cjs.ENCRYPTION_ALGORITHMS)) {
110
+ return chunkZJ32WGAA_cjs.$err({
109
111
  msg: `Crypto NodeJS API - Key Generation: Unsupported algorithm: ${algorithm}`,
110
- desc: `Supported algorithms are: ${Object.keys(chunkRXXVBCWL_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
112
+ desc: `Supported algorithms are: ${Object.keys(chunkZJ32WGAA_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
111
113
  });
112
114
  }
113
115
  const digest = options.digest ?? "sha256";
114
- if (!(digest in chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS)) {
115
- return chunkRXXVBCWL_cjs.$err({
116
+ if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) {
117
+ return chunkZJ32WGAA_cjs.$err({
116
118
  msg: `Crypto NodeJS API - Key Generation: Unsupported digest: ${digest}`,
117
- desc: `Supported digests are: ${Object.keys(chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS).join(", ")}`
119
+ desc: `Supported digests are: ${Object.keys(chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS).join(", ")}`
118
120
  });
119
121
  }
120
122
  const salt = options.salt ?? "cipher-kit-salt";
121
- if (!chunkRXXVBCWL_cjs.$isStr(salt, 8)) {
122
- return chunkRXXVBCWL_cjs.$err({
123
+ if (!chunkZJ32WGAA_cjs.$isStr(salt, 8)) {
124
+ return chunkZJ32WGAA_cjs.$err({
123
125
  msg: "Crypto NodeJS API - Key Generation: Weak salt",
124
126
  desc: "Salt must be a non-empty string with at least 8 characters"
125
127
  });
126
128
  }
127
129
  const info = options.info ?? "cipher-kit";
128
- if (!chunkRXXVBCWL_cjs.$isStr(info)) {
129
- return chunkRXXVBCWL_cjs.$err({
130
+ if (!chunkZJ32WGAA_cjs.$isStr(info)) {
131
+ return chunkZJ32WGAA_cjs.$err({
130
132
  msg: "Crypto NodeJS API - Key Generation: Invalid info",
131
133
  desc: "Info must be a non-empty string"
132
134
  });
133
135
  }
134
- const encryptAlgo = chunkRXXVBCWL_cjs.ENCRYPTION_ALGORITHMS[algorithm];
135
- const digestAlgo = chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS[digest];
136
+ const encryptAlgo = chunkZJ32WGAA_cjs.ENCRYPTION_ALGORITHMS[algorithm];
137
+ const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
136
138
  try {
137
139
  const derivedKey = nodeCrypto__default.default.hkdfSync(
138
140
  digestAlgo.node,
@@ -145,80 +147,82 @@ function $createSecretKey(secret, options = {}) {
145
147
  const secretKey = Object.freeze({
146
148
  platform: "node",
147
149
  digest,
148
- algo: encryptAlgo,
150
+ algorithm,
149
151
  key
150
152
  });
151
- return chunkRXXVBCWL_cjs.$ok({ result: secretKey });
153
+ return chunkZJ32WGAA_cjs.$ok({ result: secretKey });
152
154
  } catch (error) {
153
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Key Generation: Failed to create secret key", desc: chunkRXXVBCWL_cjs.$fmtError(error) });
155
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Key Generation: Failed to create secret key", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
154
156
  }
155
157
  }
156
158
  function $encrypt(data, secretKey, options = {}) {
157
- if (!chunkRXXVBCWL_cjs.$isStr(data)) {
158
- return chunkRXXVBCWL_cjs.$err({
159
+ if (!chunkZJ32WGAA_cjs.$isStr(data)) {
160
+ return chunkZJ32WGAA_cjs.$err({
159
161
  msg: "Crypto NodeJS API - Encryption: Empty data for encryption",
160
162
  desc: "Data must be a non-empty string"
161
163
  });
162
164
  }
163
165
  const inputEncoding = options.inputEncoding ?? "utf8";
164
166
  const outputEncoding = options.outputEncoding ?? "base64url";
165
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(inputEncoding) || !chunkRXXVBCWL_cjs.ENCODINGS.includes(outputEncoding)) {
166
- return chunkRXXVBCWL_cjs.$err({
167
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
168
+ return chunkZJ32WGAA_cjs.$err({
167
169
  msg: `Crypto NodeJS API - Encryption: Unsupported input encoding: ${inputEncoding} or output encoding: ${outputEncoding}`,
168
170
  desc: "Use base64, base64url, hex, utf8, or latin1"
169
171
  });
170
172
  }
171
- if (!chunkRXXVBCWL_cjs.isSecretKey(secretKey, "node")) {
172
- return chunkRXXVBCWL_cjs.$err({
173
+ const injectedKey = chunkZJ32WGAA_cjs.$isSecretKey(secretKey, "node");
174
+ if (!injectedKey) {
175
+ return chunkZJ32WGAA_cjs.$err({
173
176
  msg: "Crypto NodeJS API - Encryption: Invalid Secret Key",
174
177
  desc: "Expected a Node SecretKey"
175
178
  });
176
179
  }
177
180
  const { result, error } = $convertStrToBytes(data, inputEncoding);
178
- if (error) return chunkRXXVBCWL_cjs.$err(error);
181
+ if (error) return chunkZJ32WGAA_cjs.$err(error);
179
182
  try {
180
- const iv = nodeCrypto__default.default.randomBytes(secretKey.algo.ivLength);
181
- const cipher = nodeCrypto__default.default.createCipheriv(secretKey.algo.node, secretKey.key, iv);
183
+ const iv = nodeCrypto__default.default.randomBytes(injectedKey.injected.ivLength);
184
+ const cipher = nodeCrypto__default.default.createCipheriv(injectedKey.injected.node, injectedKey.key, iv);
182
185
  const encrypted = buffer.Buffer.concat([cipher.update(result), cipher.final()]);
183
186
  const tag = cipher.getAuthTag();
184
187
  const ivStr = $convertBytesToStr(iv, outputEncoding);
185
188
  const cipherStr = $convertBytesToStr(encrypted, outputEncoding);
186
189
  const tagStr = $convertBytesToStr(tag, outputEncoding);
187
190
  if (ivStr.error || cipherStr.error || tagStr.error) {
188
- return chunkRXXVBCWL_cjs.$err({
191
+ return chunkZJ32WGAA_cjs.$err({
189
192
  msg: "Crypto NodeJS API - Encryption: Failed to convert IV or encrypted data or tag",
190
193
  desc: `Conversion error: ${ivStr.error || cipherStr.error || tagStr.error}`
191
194
  });
192
195
  }
193
- return chunkRXXVBCWL_cjs.$ok(`${ivStr.result}.${cipherStr.result}.${tagStr.result}.`);
196
+ return chunkZJ32WGAA_cjs.$ok(`${ivStr.result}.${cipherStr.result}.${tagStr.result}.`);
194
197
  } catch (error2) {
195
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Encryption: Failed to encrypt data", desc: chunkRXXVBCWL_cjs.$fmtError(error2) });
198
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Encryption: Failed to encrypt data", desc: chunkZJ32WGAA_cjs.$fmtError(error2) });
196
199
  }
197
200
  }
198
201
  function $decrypt(encrypted, secretKey, options = {}) {
199
- if (chunkRXXVBCWL_cjs.matchPattern(encrypted, "node") === false) {
200
- return chunkRXXVBCWL_cjs.$err({
202
+ if (chunkZJ32WGAA_cjs.matchPattern(encrypted, "node") === false) {
203
+ return chunkZJ32WGAA_cjs.$err({
201
204
  msg: "Crypto NodeJS API - Decryption: Invalid encrypted data format",
202
205
  desc: 'Encrypted data must be in the format "iv.cipher.tag."'
203
206
  });
204
207
  }
205
208
  const inputEncoding = options.inputEncoding ?? "base64url";
206
209
  const outputEncoding = options.outputEncoding ?? "utf8";
207
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(inputEncoding) || !chunkRXXVBCWL_cjs.ENCODINGS.includes(outputEncoding)) {
208
- return chunkRXXVBCWL_cjs.$err({
210
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
211
+ return chunkZJ32WGAA_cjs.$err({
209
212
  msg: `Crypto NodeJS API - Decryption: Unsupported input encoding: ${inputEncoding} or output encoding: ${outputEncoding}`,
210
213
  desc: "Use base64, base64url, hex, utf8, or latin1"
211
214
  });
212
215
  }
213
216
  const [iv, cipher, tag] = encrypted.split(".", 4);
214
- if (!chunkRXXVBCWL_cjs.$isStr(iv) || !chunkRXXVBCWL_cjs.$isStr(cipher) || !chunkRXXVBCWL_cjs.$isStr(tag)) {
215
- return chunkRXXVBCWL_cjs.$err({
217
+ if (!chunkZJ32WGAA_cjs.$isStr(iv) || !chunkZJ32WGAA_cjs.$isStr(cipher) || !chunkZJ32WGAA_cjs.$isStr(tag)) {
218
+ return chunkZJ32WGAA_cjs.$err({
216
219
  msg: "Crypto NodeJS API - Decryption: Invalid encrypted data",
217
220
  desc: "Encrypted data must contain valid IV, encrypted data, and tag components"
218
221
  });
219
222
  }
220
- if (!chunkRXXVBCWL_cjs.isSecretKey(secretKey, "node")) {
221
- return chunkRXXVBCWL_cjs.$err({
223
+ const injectedKey = chunkZJ32WGAA_cjs.$isSecretKey(secretKey, "node");
224
+ if (!injectedKey) {
225
+ return chunkZJ32WGAA_cjs.$err({
222
226
  msg: "Crypto NodeJS API - Decryption: Invalid Secret Key",
223
227
  desc: "Expected a Node SecretKey"
224
228
  });
@@ -227,101 +231,106 @@ function $decrypt(encrypted, secretKey, options = {}) {
227
231
  const cipherBytes = $convertStrToBytes(cipher, inputEncoding);
228
232
  const tagBytes = $convertStrToBytes(tag, inputEncoding);
229
233
  if (ivBytes.error || cipherBytes.error || tagBytes.error) {
230
- return chunkRXXVBCWL_cjs.$err({
234
+ return chunkZJ32WGAA_cjs.$err({
231
235
  msg: "Crypto NodeJS API - Decryption: Failed to convert IV or encrypted data or tag",
232
236
  desc: `Conversion error: ${ivBytes.error || cipherBytes.error || tagBytes.error}`
233
237
  });
234
238
  }
235
239
  try {
236
- const decipher = nodeCrypto__default.default.createDecipheriv(secretKey.algo.node, secretKey.key, ivBytes.result);
240
+ const decipher = nodeCrypto__default.default.createDecipheriv(injectedKey.injected.node, injectedKey.key, ivBytes.result);
237
241
  decipher.setAuthTag(tagBytes.result);
238
242
  const decrypted = buffer.Buffer.concat([decipher.update(cipherBytes.result), decipher.final()]);
239
243
  return $convertBytesToStr(decrypted, outputEncoding);
240
244
  } catch (error) {
241
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Decryption: Failed to decrypt data", desc: chunkRXXVBCWL_cjs.$fmtError(error) });
245
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Decryption: Failed to decrypt data", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
242
246
  }
243
247
  }
244
248
  function $encryptObj(data, secretKey, options = {}) {
245
- const { result, error } = chunkRXXVBCWL_cjs.$stringifyObj(data);
246
- if (error) return chunkRXXVBCWL_cjs.$err(error);
249
+ const { result, error } = chunkZJ32WGAA_cjs.$stringifyObj(data);
250
+ if (error) return chunkZJ32WGAA_cjs.$err(error);
247
251
  return $encrypt(result, secretKey, options);
248
252
  }
249
253
  function $decryptObj(encrypted, secretKey, options = {}) {
250
254
  const { result, error } = $decrypt(encrypted, secretKey, options);
251
- if (error) return chunkRXXVBCWL_cjs.$err(error);
252
- return chunkRXXVBCWL_cjs.$parseToObj(result);
255
+ if (error) return chunkZJ32WGAA_cjs.$err(error);
256
+ return chunkZJ32WGAA_cjs.$parseToObj(result);
253
257
  }
254
258
  function $hash(data, options = {}) {
255
- if (!chunkRXXVBCWL_cjs.$isStr(data)) {
256
- return chunkRXXVBCWL_cjs.$err({
259
+ if (!chunkZJ32WGAA_cjs.$isStr(data)) {
260
+ return chunkZJ32WGAA_cjs.$err({
257
261
  msg: "Crypto NodeJS API - Hashing: Empty data for hashing",
258
262
  desc: "Data must be a non-empty string"
259
263
  });
260
264
  }
261
265
  const inputEncoding = options.inputEncoding ?? "utf8";
262
266
  const outputEncoding = options.outputEncoding ?? "base64url";
263
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(inputEncoding) || !chunkRXXVBCWL_cjs.ENCODINGS.includes(outputEncoding)) {
264
- return chunkRXXVBCWL_cjs.$err({
267
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding) || !chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
268
+ return chunkZJ32WGAA_cjs.$err({
265
269
  msg: `Crypto NodeJS API - Hashing: Unsupported encoding: ${inputEncoding} or ${outputEncoding}`,
266
270
  desc: "Use base64, base64url, hex, utf8, or latin1"
267
271
  });
268
272
  }
269
273
  const digest = options.digest ?? "sha256";
270
- if (!(digest in chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS)) {
271
- return chunkRXXVBCWL_cjs.$err({
274
+ if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) {
275
+ return chunkZJ32WGAA_cjs.$err({
272
276
  msg: `Crypto NodeJS API - Hashing: Unsupported digest: ${digest}`,
273
- desc: `Supported digests are: ${Object.keys(chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS).join(", ")}`
277
+ desc: `Supported digests are: ${Object.keys(chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS).join(", ")}`
274
278
  });
275
279
  }
276
- const digestAlgo = chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS[digest];
280
+ const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
277
281
  const { result, error } = $convertStrToBytes(data, inputEncoding);
278
- if (error) return chunkRXXVBCWL_cjs.$err(error);
282
+ if (error) return chunkZJ32WGAA_cjs.$err(error);
279
283
  try {
280
284
  const hashed = nodeCrypto__default.default.createHash(digestAlgo.node).update(result).digest();
281
285
  return $convertBytesToStr(hashed, outputEncoding);
282
286
  } catch (error2) {
283
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Hashing: Failed to hash data with Crypto NodeJS", desc: chunkRXXVBCWL_cjs.$fmtError(error2) });
287
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Hashing: Failed to hash data with Crypto NodeJS", desc: chunkZJ32WGAA_cjs.$fmtError(error2) });
284
288
  }
285
289
  }
290
+ function $hashObj(data, options = {}) {
291
+ const { result, error } = chunkZJ32WGAA_cjs.$stringifyObj(data);
292
+ if (error) return chunkZJ32WGAA_cjs.$err(error);
293
+ return $hash(result, options);
294
+ }
286
295
  function $hashPassword(password, options = {}) {
287
- if (!chunkRXXVBCWL_cjs.$isStr(password)) {
288
- return chunkRXXVBCWL_cjs.$err({
296
+ if (!chunkZJ32WGAA_cjs.$isStr(password)) {
297
+ return chunkZJ32WGAA_cjs.$err({
289
298
  msg: "Crypto NodeJS API - Password Hashing: Empty password for hashing",
290
299
  desc: "Password must be a non-empty string"
291
300
  });
292
301
  }
293
302
  const digest = options.digest ?? "sha512";
294
- if (!(digest in chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS)) {
295
- return chunkRXXVBCWL_cjs.$err({
303
+ if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) {
304
+ return chunkZJ32WGAA_cjs.$err({
296
305
  msg: `Crypto NodeJS API - Password Hashing: Unsupported digest: ${digest}`,
297
- desc: `Supported digests are: ${Object.keys(chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS).join(", ")}`
306
+ desc: `Supported digests are: ${Object.keys(chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS).join(", ")}`
298
307
  });
299
308
  }
300
- const digestAlgo = chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS[digest];
309
+ const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
301
310
  const outputEncoding = options.outputEncoding ?? "base64url";
302
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(outputEncoding)) {
303
- return chunkRXXVBCWL_cjs.$err({
311
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(outputEncoding)) {
312
+ return chunkZJ32WGAA_cjs.$err({
304
313
  msg: `Crypto NodeJS API - Password Hashing: Unsupported encoding: ${outputEncoding}`,
305
314
  desc: "Use base64, base64url, hex, utf8, or latin1"
306
315
  });
307
316
  }
308
317
  const saltLength = options.saltLength ?? 16;
309
318
  if (typeof saltLength !== "number" || saltLength < 8) {
310
- return chunkRXXVBCWL_cjs.$err({
319
+ return chunkZJ32WGAA_cjs.$err({
311
320
  msg: "Crypto NodeJS API - Password Hashing: Weak salt length",
312
321
  desc: "Salt length must be a number and at least 8 bytes (recommended 16 or more)"
313
322
  });
314
323
  }
315
324
  const iterations = options.iterations ?? 32e4;
316
325
  if (typeof iterations !== "number" || iterations < 1e3) {
317
- return chunkRXXVBCWL_cjs.$err({
326
+ return chunkZJ32WGAA_cjs.$err({
318
327
  msg: "Crypto NodeJS API - Password Hashing: Weak iterations count",
319
328
  desc: "Iterations must be a number and at least 1000 (recommended 320,000 or more)"
320
329
  });
321
330
  }
322
331
  const keyLength = options.keyLength ?? 64;
323
332
  if (typeof keyLength !== "number" || keyLength < 16) {
324
- return chunkRXXVBCWL_cjs.$err({
333
+ return chunkZJ32WGAA_cjs.$err({
325
334
  msg: "Crypto NodeJS API - Password Hashing: Invalid key length",
326
335
  desc: "Key length must be a number and at least 16 bytes (recommended 64 or more)"
327
336
  });
@@ -329,18 +338,18 @@ function $hashPassword(password, options = {}) {
329
338
  try {
330
339
  const salt = nodeCrypto__default.default.randomBytes(saltLength);
331
340
  const hash2 = nodeCrypto__default.default.pbkdf2Sync(password.normalize("NFKC"), salt, iterations, keyLength, digestAlgo.node);
332
- return chunkRXXVBCWL_cjs.$ok({ salt: salt.toString(outputEncoding), hash: hash2.toString(outputEncoding) });
341
+ return chunkZJ32WGAA_cjs.$ok({ salt: salt.toString(outputEncoding), hash: hash2.toString(outputEncoding) });
333
342
  } catch (error) {
334
- return chunkRXXVBCWL_cjs.$err({ msg: "Crypto NodeJS API - Password Hashing: Failed to hash password", desc: chunkRXXVBCWL_cjs.$fmtError(error) });
343
+ return chunkZJ32WGAA_cjs.$err({ msg: "Crypto NodeJS API - Password Hashing: Failed to hash password", desc: chunkZJ32WGAA_cjs.$fmtError(error) });
335
344
  }
336
345
  }
337
346
  function $verifyPassword(password, hashedPassword, salt, options = {}) {
338
- if (!chunkRXXVBCWL_cjs.$isStr(password) || !chunkRXXVBCWL_cjs.$isStr(hashedPassword) || !chunkRXXVBCWL_cjs.$isStr(salt)) return false;
347
+ if (!chunkZJ32WGAA_cjs.$isStr(password) || !chunkZJ32WGAA_cjs.$isStr(hashedPassword) || !chunkZJ32WGAA_cjs.$isStr(salt)) return false;
339
348
  const digest = options.digest ?? "sha512";
340
- if (!(digest in chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS)) return false;
341
- const digestAlgo = chunkRXXVBCWL_cjs.DIGEST_ALGORITHMS[digest];
349
+ if (!(digest in chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS)) return false;
350
+ const digestAlgo = chunkZJ32WGAA_cjs.DIGEST_ALGORITHMS[digest];
342
351
  const inputEncoding = options.inputEncoding ?? "base64url";
343
- if (!chunkRXXVBCWL_cjs.ENCODINGS.includes(inputEncoding)) return false;
352
+ if (!chunkZJ32WGAA_cjs.ENCODINGS.includes(inputEncoding)) return false;
344
353
  const iterations = options.iterations ?? 32e4;
345
354
  if (typeof iterations !== "number" || iterations < 1e3) return false;
346
355
  const keyLength = options.keyLength ?? 64;
@@ -365,7 +374,7 @@ function tryGenerateUuid() {
365
374
  }
366
375
  function generateUuid() {
367
376
  const { result, error } = $generateUuid();
368
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
377
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
369
378
  return result;
370
379
  }
371
380
  function tryCreateSecretKey(secret, options = {}) {
@@ -373,7 +382,7 @@ function tryCreateSecretKey(secret, options = {}) {
373
382
  }
374
383
  function createSecretKey(secret, options = {}) {
375
384
  const { result, error } = $createSecretKey(secret, options);
376
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
385
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
377
386
  return result;
378
387
  }
379
388
  function tryEncrypt(data, secretKey, options = {}) {
@@ -381,7 +390,7 @@ function tryEncrypt(data, secretKey, options = {}) {
381
390
  }
382
391
  function encrypt(data, secretKey, options = {}) {
383
392
  const { result, error } = $encrypt(data, secretKey, options);
384
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
393
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
385
394
  return result;
386
395
  }
387
396
  function tryDecrypt(encrypted, secretKey, options = {}) {
@@ -389,7 +398,7 @@ function tryDecrypt(encrypted, secretKey, options = {}) {
389
398
  }
390
399
  function decrypt(encrypted, secretKey, options = {}) {
391
400
  const { result, error } = $decrypt(encrypted, secretKey, options);
392
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
401
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
393
402
  return result;
394
403
  }
395
404
  function tryEncryptObj(data, secretKey, options = {}) {
@@ -397,7 +406,7 @@ function tryEncryptObj(data, secretKey, options = {}) {
397
406
  }
398
407
  function encryptObj(data, secretKey, options = {}) {
399
408
  const { result, error } = $encryptObj(data, secretKey, options);
400
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
409
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
401
410
  return result;
402
411
  }
403
412
  function tryDecryptObj(encrypted, secretKey, options = {}) {
@@ -405,7 +414,7 @@ function tryDecryptObj(encrypted, secretKey, options = {}) {
405
414
  }
406
415
  function decryptObj(encrypted, secretKey, options = {}) {
407
416
  const { result, error } = $decryptObj(encrypted, secretKey, options);
408
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
417
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
409
418
  return result;
410
419
  }
411
420
  function tryHash(data, options = {}) {
@@ -413,7 +422,15 @@ function tryHash(data, options = {}) {
413
422
  }
414
423
  function hash(data, options = {}) {
415
424
  const { result, error } = $hash(data, options);
416
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
425
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
426
+ return result;
427
+ }
428
+ function tryHashObj(data, options = {}) {
429
+ return $hashObj(data, options);
430
+ }
431
+ function hashObj(data, options = {}) {
432
+ const { result, error } = $hashObj(data, options);
433
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
417
434
  return result;
418
435
  }
419
436
  function tryHashPassword(password, options = {}) {
@@ -421,7 +438,7 @@ function tryHashPassword(password, options = {}) {
421
438
  }
422
439
  function hashPassword(password, options = {}) {
423
440
  const { hash: hash2, salt, error } = $hashPassword(password, options);
424
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
441
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
425
442
  return { hash: hash2, salt };
426
443
  }
427
444
  function verifyPassword(password, hashedPassword, salt, options = {}) {
@@ -432,7 +449,7 @@ function tryConvertStrToBytes(data, inputEncoding = "utf8") {
432
449
  }
433
450
  function convertStrToBytes(data, inputEncoding = "utf8") {
434
451
  const { result, error } = $convertStrToBytes(data, inputEncoding);
435
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
452
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
436
453
  return result;
437
454
  }
438
455
  function tryConvertBytesToStr(data, outputEncoding = "utf8") {
@@ -440,7 +457,7 @@ function tryConvertBytesToStr(data, outputEncoding = "utf8") {
440
457
  }
441
458
  function convertBytesToStr(data, outputEncoding = "utf8") {
442
459
  const { result, error } = $convertBytesToStr(data, outputEncoding);
443
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
460
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
444
461
  return result;
445
462
  }
446
463
  function tryConvertEncoding(data, from, to) {
@@ -448,7 +465,7 @@ function tryConvertEncoding(data, from, to) {
448
465
  }
449
466
  function convertEncoding(data, from, to) {
450
467
  const { result, error } = $convertEncoding(data, from, to);
451
- if (error) throw new Error(chunkRXXVBCWL_cjs.$fmtResultErr(error));
468
+ if (error) throw new Error(chunkZJ32WGAA_cjs.$fmtResultErr(error));
452
469
  return result;
453
470
  }
454
471
 
@@ -462,6 +479,7 @@ exports.encrypt = encrypt;
462
479
  exports.encryptObj = encryptObj;
463
480
  exports.generateUuid = generateUuid;
464
481
  exports.hash = hash;
482
+ exports.hashObj = hashObj;
465
483
  exports.hashPassword = hashPassword;
466
484
  exports.kit_exports = kit_exports;
467
485
  exports.tryConvertBytesToStr = tryConvertBytesToStr;
@@ -474,7 +492,8 @@ exports.tryEncrypt = tryEncrypt;
474
492
  exports.tryEncryptObj = tryEncryptObj;
475
493
  exports.tryGenerateUuid = tryGenerateUuid;
476
494
  exports.tryHash = tryHash;
495
+ exports.tryHashObj = tryHashObj;
477
496
  exports.tryHashPassword = tryHashPassword;
478
497
  exports.verifyPassword = verifyPassword;
479
- //# sourceMappingURL=chunk-3XGARINH.cjs.map
480
- //# sourceMappingURL=chunk-3XGARINH.cjs.map
498
+ //# sourceMappingURL=chunk-UHP3PPXP.cjs.map
499
+ //# sourceMappingURL=chunk-UHP3PPXP.cjs.map