cipher-kit 2.0.0-beta.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +241 -66
  2. package/dist/{chunk-3FJZA77A.cjs → chunk-3UX5MZ2P.cjs} +2 -2
  3. package/dist/chunk-3UX5MZ2P.cjs.map +1 -0
  4. package/dist/{chunk-7WPZVN7G.js → chunk-4MFF6V3R.js} +3 -3
  5. package/dist/chunk-4MFF6V3R.js.map +1 -0
  6. package/dist/{chunk-BWE6JWHY.js → chunk-ACFPMIXO.js} +3 -3
  7. package/dist/chunk-ACFPMIXO.js.map +1 -0
  8. package/dist/{chunk-CEXY7GOU.cjs → chunk-CVCDAHDW.cjs} +130 -130
  9. package/dist/chunk-CVCDAHDW.cjs.map +1 -0
  10. package/dist/{chunk-YAZRJN6X.js → chunk-FKSYSPJR.js} +2 -2
  11. package/dist/chunk-FKSYSPJR.js.map +1 -0
  12. package/dist/{chunk-WLLCFK4U.cjs → chunk-N2EW2FDZ.cjs} +125 -125
  13. package/dist/chunk-N2EW2FDZ.cjs.map +1 -0
  14. package/dist/{export-DX7bFv-3.d.cts → export-55tHE0Bw.d.cts} +12 -12
  15. package/dist/{export-DPAoLdh1.d.ts → export-BMvZq46v.d.ts} +12 -12
  16. package/dist/{export-Du70yDea.d.cts → export-CQNsJFh_.d.cts} +12 -12
  17. package/dist/{export-DjUgZ7dz.d.ts → export-llM6c7Do.d.ts} +12 -12
  18. package/dist/index.cjs +11 -11
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +3 -3
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +3 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/node.cjs +32 -32
  25. package/dist/node.d.cts +2 -2
  26. package/dist/node.d.ts +2 -2
  27. package/dist/node.js +2 -2
  28. package/dist/{validate-DrBddQyu.d.cts → validate-EHuJC5QQ.d.cts} +3 -3
  29. package/dist/{validate-DrBddQyu.d.ts → validate-EHuJC5QQ.d.ts} +3 -3
  30. package/dist/web-api.cjs +32 -32
  31. package/dist/web-api.d.cts +2 -2
  32. package/dist/web-api.d.ts +2 -2
  33. package/dist/web-api.js +2 -2
  34. package/package.json +4 -3
  35. package/dist/chunk-3FJZA77A.cjs.map +0 -1
  36. package/dist/chunk-7WPZVN7G.js.map +0 -1
  37. package/dist/chunk-BWE6JWHY.js.map +0 -1
  38. package/dist/chunk-CEXY7GOU.cjs.map +0 -1
  39. package/dist/chunk-WLLCFK4U.cjs.map +0 -1
  40. package/dist/chunk-YAZRJN6X.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk3FJZA77A_cjs = require('./chunk-3FJZA77A.cjs');
3
+ var chunk3UX5MZ2P_cjs = require('./chunk-3UX5MZ2P.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
- chunk3FJZA77A_cjs.__export(kit_exports, {
13
+ chunk3UX5MZ2P_cjs.__export(kit_exports, {
14
14
  convertBytesToStr: () => convertBytesToStr,
15
15
  convertEncoding: () => convertEncoding,
16
16
  convertStrToBytes: () => convertStrToBytes,
@@ -37,103 +37,103 @@ chunk3FJZA77A_cjs.__export(kit_exports, {
37
37
  verifyPassword: () => verifyPassword
38
38
  });
39
39
  function $convertStrToBytes(data, inputEncoding = "utf8") {
40
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
41
- return chunk3FJZA77A_cjs.$err({
40
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
41
+ return chunk3UX5MZ2P_cjs.$err({
42
42
  msg: "Crypto NodeJS API - String to Bytes: Empty data",
43
43
  desc: "Data must be a non-empty string"
44
44
  });
45
45
  }
46
- if (!chunk3FJZA77A_cjs.ENCODING.includes(inputEncoding)) {
47
- return chunk3FJZA77A_cjs.$err({
46
+ if (!chunk3UX5MZ2P_cjs.ENCODING.includes(inputEncoding)) {
47
+ return chunk3UX5MZ2P_cjs.$err({
48
48
  msg: `Crypto NodeJS API - String to Bytes: Unsupported encoding: ${inputEncoding}`,
49
49
  desc: "Use base64, base64url, hex, utf8, or latin1"
50
50
  });
51
51
  }
52
52
  try {
53
- return chunk3FJZA77A_cjs.$ok({ result: buffer.Buffer.from(data, inputEncoding) });
53
+ return chunk3UX5MZ2P_cjs.$ok({ result: buffer.Buffer.from(data, inputEncoding) });
54
54
  } catch (error) {
55
- return chunk3FJZA77A_cjs.$err({ msg: "Crypto NodeJS API - String to Bytes: Failed to convert data", desc: chunk3FJZA77A_cjs.$fmtError(error) });
55
+ return chunk3UX5MZ2P_cjs.$err({ msg: "Crypto NodeJS API - String to Bytes: Failed to convert data", desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
56
56
  }
57
57
  }
58
58
  function $convertBytesToStr(data, outputEncoding = "utf8") {
59
59
  if (!(data instanceof buffer.Buffer)) {
60
- return chunk3FJZA77A_cjs.$err({
60
+ return chunk3UX5MZ2P_cjs.$err({
61
61
  msg: "Crypto NodeJS API - Bytes to String: Invalid data type",
62
62
  desc: "Data must be a Buffer"
63
63
  });
64
64
  }
65
- if (!chunk3FJZA77A_cjs.ENCODING.includes(outputEncoding)) {
66
- return chunk3FJZA77A_cjs.$err({
65
+ if (!chunk3UX5MZ2P_cjs.ENCODING.includes(outputEncoding)) {
66
+ return chunk3UX5MZ2P_cjs.$err({
67
67
  msg: `Crypto NodeJS API - Bytes to String: Unsupported encoding: ${outputEncoding}`,
68
68
  desc: "Use base64, base64url, hex, utf8, or latin1"
69
69
  });
70
70
  }
71
71
  try {
72
- return chunk3FJZA77A_cjs.$ok(buffer.Buffer.from(data).toString(outputEncoding));
72
+ return chunk3UX5MZ2P_cjs.$ok(buffer.Buffer.from(data).toString(outputEncoding));
73
73
  } catch (error) {
74
- return chunk3FJZA77A_cjs.$err({ msg: "Crypto NodeJS API - Bytes to String: Failed to convert data", desc: chunk3FJZA77A_cjs.$fmtError(error) });
74
+ return chunk3UX5MZ2P_cjs.$err({ msg: "Crypto NodeJS API - Bytes to String: Failed to convert data", desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
75
75
  }
76
76
  }
77
77
  function $convertEncoding(data, from, to) {
78
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
79
- return chunk3FJZA77A_cjs.$err({
78
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
79
+ return chunk3UX5MZ2P_cjs.$err({
80
80
  msg: "Crypto NodeJS API - Convert Format: Empty data",
81
81
  desc: "Data must be a non-empty string"
82
82
  });
83
83
  }
84
- if (!chunk3FJZA77A_cjs.ENCODING.includes(from) || !chunk3FJZA77A_cjs.ENCODING.includes(to)) {
85
- return chunk3FJZA77A_cjs.$err({
84
+ if (!chunk3UX5MZ2P_cjs.ENCODING.includes(from) || !chunk3UX5MZ2P_cjs.ENCODING.includes(to)) {
85
+ return chunk3UX5MZ2P_cjs.$err({
86
86
  msg: `Crypto NodeJS API - Convert Format: Unsupported encoding: from ${from} to ${to}`,
87
87
  desc: "Use base64, base64url, hex, utf8, or latin1"
88
88
  });
89
89
  }
90
90
  const bytes = $convertStrToBytes(data, from);
91
- if (bytes.error) return chunk3FJZA77A_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
91
+ if (bytes.error) return chunk3UX5MZ2P_cjs.$err({ msg: bytes.error.message, desc: bytes.error.description });
92
92
  const str = $convertBytesToStr(bytes.result, to);
93
- if (str.error) return chunk3FJZA77A_cjs.$err({ msg: str.error.message, desc: str.error.description });
94
- return chunk3FJZA77A_cjs.$ok({ result: str.result });
93
+ if (str.error) return chunk3UX5MZ2P_cjs.$err({ msg: str.error.message, desc: str.error.description });
94
+ return chunk3UX5MZ2P_cjs.$ok({ result: str.result });
95
95
  }
96
96
  function $generateUuid() {
97
97
  try {
98
- return chunk3FJZA77A_cjs.$ok(nodeCrypto__default.default.randomUUID());
98
+ return chunk3UX5MZ2P_cjs.$ok(nodeCrypto__default.default.randomUUID());
99
99
  } catch (error) {
100
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "UUID Generation")}: Failed to generate UUID`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
100
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "UUID Generation")}: Failed to generate UUID`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
101
101
  }
102
102
  }
103
103
  function $createSecretKey(secret, options = {}) {
104
- if (!chunk3FJZA77A_cjs.$isStr(secret)) {
105
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "Key Generation")}: Empty Secret`, desc: "Secret must be a non-empty string" });
104
+ if (!chunk3UX5MZ2P_cjs.$isStr(secret)) {
105
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "Key Generation")}: Empty Secret`, desc: "Secret must be a non-empty string" });
106
106
  }
107
107
  const algorithm = options.algorithm ?? "aes256gcm";
108
- if (!(algorithm in chunk3FJZA77A_cjs.ENCRYPTION_ALGORITHMS)) {
109
- return chunk3FJZA77A_cjs.$err({
110
- msg: `${chunk3FJZA77A_cjs.title("node", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
111
- desc: `Supported algorithms are: ${Object.keys(chunk3FJZA77A_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
108
+ if (!(algorithm in chunk3UX5MZ2P_cjs.ENCRYPTION_ALGORITHMS)) {
109
+ return chunk3UX5MZ2P_cjs.$err({
110
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Key Generation")}: Unsupported algorithm: ${algorithm}`,
111
+ desc: `Supported algorithms are: ${Object.keys(chunk3UX5MZ2P_cjs.ENCRYPTION_ALGORITHMS).join(", ")}`
112
112
  });
113
113
  }
114
114
  const digest = options.digest ?? "sha256";
115
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) {
116
- return chunk3FJZA77A_cjs.$err({
117
- msg: `${chunk3FJZA77A_cjs.title("node", "Key Generation")}: Unsupported digest: ${digest}`,
118
- desc: `Supported digests are: ${Object.keys(chunk3FJZA77A_cjs.DIGEST_ALGORITHMS).join(", ")}`
115
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) {
116
+ return chunk3UX5MZ2P_cjs.$err({
117
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Key Generation")}: Unsupported digest: ${digest}`,
118
+ desc: `Supported digests are: ${Object.keys(chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS).join(", ")}`
119
119
  });
120
120
  }
121
121
  const salt = options.salt ?? "cipher-kit-salt";
122
- if (!chunk3FJZA77A_cjs.$isStr(salt, 8)) {
123
- return chunk3FJZA77A_cjs.$err({
124
- msg: `${chunk3FJZA77A_cjs.title("node", "Key Generation")}: Weak salt`,
122
+ if (!chunk3UX5MZ2P_cjs.$isStr(salt, 8)) {
123
+ return chunk3UX5MZ2P_cjs.$err({
124
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Key Generation")}: Weak salt`,
125
125
  desc: "Salt must be a non-empty string with at least 8 characters"
126
126
  });
127
127
  }
128
128
  const info = options.info ?? "cipher-kit";
129
- if (!chunk3FJZA77A_cjs.$isStr(info)) {
130
- return chunk3FJZA77A_cjs.$err({
131
- msg: `${chunk3FJZA77A_cjs.title("node", "Key Generation")}: Invalid info`,
129
+ if (!chunk3UX5MZ2P_cjs.$isStr(info)) {
130
+ return chunk3UX5MZ2P_cjs.$err({
131
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Key Generation")}: Invalid info`,
132
132
  desc: "Info must be a non-empty string"
133
133
  });
134
134
  }
135
- const encryptAlgo = chunk3FJZA77A_cjs.ENCRYPTION_ALGORITHMS[algorithm];
136
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
135
+ const encryptAlgo = chunk3UX5MZ2P_cjs.ENCRYPTION_ALGORITHMS[algorithm];
136
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
137
137
  try {
138
138
  const derivedKey = nodeCrypto__default.default.hkdfSync(
139
139
  digestAlgo.node,
@@ -149,34 +149,34 @@ function $createSecretKey(secret, options = {}) {
149
149
  algorithm,
150
150
  key
151
151
  });
152
- return chunk3FJZA77A_cjs.$ok({ result: secretKey });
152
+ return chunk3UX5MZ2P_cjs.$ok({ result: secretKey });
153
153
  } catch (error) {
154
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "Key Generation")}: Failed to create secret key`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
154
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "Key Generation")}: Failed to create secret key`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
155
155
  }
156
156
  }
157
157
  function $encrypt(data, secretKey, options = {}) {
158
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
159
- return chunk3FJZA77A_cjs.$err({
160
- msg: `${chunk3FJZA77A_cjs.title("node", "Encryption")}: Empty data for encryption`,
158
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
159
+ return chunk3UX5MZ2P_cjs.$err({
160
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Encryption")}: Empty data for encryption`,
161
161
  desc: "Data must be a non-empty string"
162
162
  });
163
163
  }
164
164
  const encoding = options.encoding ?? "base64url";
165
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
166
- return chunk3FJZA77A_cjs.$err({
167
- msg: `${chunk3FJZA77A_cjs.title("node", "Encryption")}: Unsupported output encoding: ${encoding}`,
165
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
166
+ return chunk3UX5MZ2P_cjs.$err({
167
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Encryption")}: Unsupported output encoding: ${encoding}`,
168
168
  desc: "Use base64, base64url, or hex"
169
169
  });
170
170
  }
171
- const injectedKey = chunk3FJZA77A_cjs.$isSecretKey(secretKey, "node");
171
+ const injectedKey = chunk3UX5MZ2P_cjs.$isSecretKey(secretKey, "node");
172
172
  if (!injectedKey) {
173
- return chunk3FJZA77A_cjs.$err({
174
- msg: `${chunk3FJZA77A_cjs.title("node", "Encryption")}: Invalid Secret Key`,
173
+ return chunk3UX5MZ2P_cjs.$err({
174
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Encryption")}: Invalid Secret Key`,
175
175
  desc: "Expected a Node SecretKey"
176
176
  });
177
177
  }
178
178
  const { result, error } = $convertStrToBytes(data, "utf8");
179
- if (error) return chunk3FJZA77A_cjs.$err(error);
179
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
180
180
  try {
181
181
  const iv = nodeCrypto__default.default.randomBytes(injectedKey.injected.ivLength);
182
182
  const cipher = nodeCrypto__default.default.createCipheriv(injectedKey.injected.node, injectedKey.key, iv);
@@ -186,40 +186,40 @@ function $encrypt(data, secretKey, options = {}) {
186
186
  const cipherStr = $convertBytesToStr(encrypted, encoding);
187
187
  const tagStr = $convertBytesToStr(tag, encoding);
188
188
  if (ivStr.error || cipherStr.error || tagStr.error) {
189
- return chunk3FJZA77A_cjs.$err({
189
+ return chunk3UX5MZ2P_cjs.$err({
190
190
  msg: "Crypto NodeJS API - Encryption: Failed to convert IV or encrypted data or tag",
191
- desc: `Conversion error: ${chunk3FJZA77A_cjs.$fmtResultErr(ivStr.error || cipherStr.error || tagStr.error)}`
191
+ desc: `Conversion error: ${chunk3UX5MZ2P_cjs.$fmtResultErr(ivStr.error || cipherStr.error || tagStr.error)}`
192
192
  });
193
193
  }
194
- return chunk3FJZA77A_cjs.$ok(`${ivStr.result}.${cipherStr.result}.${tagStr.result}.`);
194
+ return chunk3UX5MZ2P_cjs.$ok(`${ivStr.result}.${cipherStr.result}.${tagStr.result}.`);
195
195
  } catch (error2) {
196
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "Encryption")}: Failed to encrypt data`, desc: chunk3FJZA77A_cjs.$fmtError(error2) });
196
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "Encryption")}: Failed to encrypt data`, desc: chunk3UX5MZ2P_cjs.$fmtError(error2) });
197
197
  }
198
198
  }
199
199
  function $decrypt(encrypted, secretKey, options = {}) {
200
- if (chunk3FJZA77A_cjs.matchPattern(encrypted, "node") === false) {
201
- return chunk3FJZA77A_cjs.$err({
202
- msg: `${chunk3FJZA77A_cjs.title("node", "Decryption")}: Invalid encrypted data format`,
200
+ if (chunk3UX5MZ2P_cjs.matchPattern(encrypted, "node") === false) {
201
+ return chunk3UX5MZ2P_cjs.$err({
202
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Decryption")}: Invalid encrypted data format`,
203
203
  desc: 'Encrypted data must be in the format "iv.cipher.tag."'
204
204
  });
205
205
  }
206
206
  const encoding = options.encoding ?? "base64url";
207
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
208
- return chunk3FJZA77A_cjs.$err({
209
- msg: `${chunk3FJZA77A_cjs.title("node", "Decryption")}: Unsupported input encoding: ${encoding}`,
207
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
208
+ return chunk3UX5MZ2P_cjs.$err({
209
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Decryption")}: Unsupported input encoding: ${encoding}`,
210
210
  desc: "Use base64, base64url, or hex"
211
211
  });
212
212
  }
213
213
  const [iv, cipher, tag] = encrypted.split(".", 4);
214
- if (!chunk3FJZA77A_cjs.$isStr(iv) || !chunk3FJZA77A_cjs.$isStr(cipher) || !chunk3FJZA77A_cjs.$isStr(tag)) {
215
- return chunk3FJZA77A_cjs.$err({
216
- msg: `${chunk3FJZA77A_cjs.title("node", "Decryption")}: Invalid encrypted data`,
214
+ if (!chunk3UX5MZ2P_cjs.$isStr(iv) || !chunk3UX5MZ2P_cjs.$isStr(cipher) || !chunk3UX5MZ2P_cjs.$isStr(tag)) {
215
+ return chunk3UX5MZ2P_cjs.$err({
216
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Decryption")}: Invalid encrypted data`,
217
217
  desc: "Encrypted data must contain valid IV, encrypted data, and tag components"
218
218
  });
219
219
  }
220
- const injectedKey = chunk3FJZA77A_cjs.$isSecretKey(secretKey, "node");
220
+ const injectedKey = chunk3UX5MZ2P_cjs.$isSecretKey(secretKey, "node");
221
221
  if (!injectedKey) {
222
- return chunk3FJZA77A_cjs.$err({
222
+ return chunk3UX5MZ2P_cjs.$err({
223
223
  msg: "Crypto NodeJS API - Decryption: Invalid Secret Key",
224
224
  desc: "Expected a Node SecretKey"
225
225
  });
@@ -228,9 +228,9 @@ function $decrypt(encrypted, secretKey, options = {}) {
228
228
  const cipherBytes = $convertStrToBytes(cipher, encoding);
229
229
  const tagBytes = $convertStrToBytes(tag, encoding);
230
230
  if (ivBytes.error || cipherBytes.error || tagBytes.error) {
231
- return chunk3FJZA77A_cjs.$err({
232
- msg: `${chunk3FJZA77A_cjs.title("node", "Decryption")}: Failed to convert IV or encrypted data or tag`,
233
- desc: `Conversion error: ${chunk3FJZA77A_cjs.$fmtResultErr(ivBytes.error || cipherBytes.error || tagBytes.error)}`
231
+ return chunk3UX5MZ2P_cjs.$err({
232
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Decryption")}: Failed to convert IV or encrypted data or tag`,
233
+ desc: `Conversion error: ${chunk3UX5MZ2P_cjs.$fmtResultErr(ivBytes.error || cipherBytes.error || tagBytes.error)}`
234
234
  });
235
235
  }
236
236
  try {
@@ -239,108 +239,108 @@ function $decrypt(encrypted, secretKey, options = {}) {
239
239
  const decrypted = buffer.Buffer.concat([decipher.update(cipherBytes.result), decipher.final()]);
240
240
  return $convertBytesToStr(decrypted, "utf8");
241
241
  } catch (error) {
242
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "Decryption")}: Failed to decrypt data`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
242
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "Decryption")}: Failed to decrypt data`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
243
243
  }
244
244
  }
245
245
  function $encryptObj(data, secretKey, options = {}) {
246
- const { result, error } = chunk3FJZA77A_cjs.$stringifyObj(data);
247
- if (error) return chunk3FJZA77A_cjs.$err(error);
246
+ const { result, error } = chunk3UX5MZ2P_cjs.$stringifyObj(data);
247
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
248
248
  return $encrypt(result, secretKey, options);
249
249
  }
250
250
  function $decryptObj(encrypted, secretKey, options = {}) {
251
251
  const { result, error } = $decrypt(encrypted, secretKey, options);
252
- if (error) return chunk3FJZA77A_cjs.$err(error);
253
- return chunk3FJZA77A_cjs.$parseToObj(result);
252
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
253
+ return chunk3UX5MZ2P_cjs.$parseToObj(result);
254
254
  }
255
255
  function $hash(data, options = {}) {
256
- if (!chunk3FJZA77A_cjs.$isStr(data)) {
257
- return chunk3FJZA77A_cjs.$err({
258
- msg: `${chunk3FJZA77A_cjs.title("node", "Hashing")}: Empty data for hashing`,
256
+ if (!chunk3UX5MZ2P_cjs.$isStr(data)) {
257
+ return chunk3UX5MZ2P_cjs.$err({
258
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Hashing")}: Empty data for hashing`,
259
259
  desc: "Data must be a non-empty string"
260
260
  });
261
261
  }
262
262
  const encoding = options.encoding ?? "base64url";
263
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
264
- return chunk3FJZA77A_cjs.$err({
265
- msg: `${chunk3FJZA77A_cjs.title("node", "Hashing")}: Unsupported output encoding: ${encoding}`,
263
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
264
+ return chunk3UX5MZ2P_cjs.$err({
265
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Hashing")}: Unsupported output encoding: ${encoding}`,
266
266
  desc: "Use base64, base64url, or hex"
267
267
  });
268
268
  }
269
269
  const digest = options.digest ?? "sha256";
270
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) {
271
- return chunk3FJZA77A_cjs.$err({
272
- msg: `${chunk3FJZA77A_cjs.title("node", "Hashing")}: Unsupported digest: ${digest}`,
273
- desc: `Supported digests are: ${Object.keys(chunk3FJZA77A_cjs.DIGEST_ALGORITHMS).join(", ")}`
270
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) {
271
+ return chunk3UX5MZ2P_cjs.$err({
272
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Hashing")}: Unsupported digest: ${digest}`,
273
+ desc: `Supported digests are: ${Object.keys(chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS).join(", ")}`
274
274
  });
275
275
  }
276
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
276
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
277
277
  const { result, error } = $convertStrToBytes(data, "utf8");
278
- if (error) return chunk3FJZA77A_cjs.$err(error);
278
+ if (error) return chunk3UX5MZ2P_cjs.$err(error);
279
279
  try {
280
280
  const hashed = nodeCrypto__default.default.createHash(digestAlgo.node).update(result).digest();
281
281
  return $convertBytesToStr(hashed, encoding);
282
282
  } catch (error2) {
283
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "Hashing")}: Failed to hash data with Crypto NodeJS`, desc: chunk3FJZA77A_cjs.$fmtError(error2) });
283
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "Hashing")}: Failed to hash data with Crypto NodeJS`, desc: chunk3UX5MZ2P_cjs.$fmtError(error2) });
284
284
  }
285
285
  }
286
286
  function $hashPassword(password, options = {}) {
287
- if (!chunk3FJZA77A_cjs.$isStr(password)) {
288
- return chunk3FJZA77A_cjs.$err({
289
- msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Empty password for hashing`,
287
+ if (!chunk3UX5MZ2P_cjs.$isStr(password)) {
288
+ return chunk3UX5MZ2P_cjs.$err({
289
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Empty password for hashing`,
290
290
  desc: "Password must be a non-empty string"
291
291
  });
292
292
  }
293
293
  const digest = options.digest ?? "sha512";
294
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) {
295
- return chunk3FJZA77A_cjs.$err({
296
- msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Unsupported digest: ${digest}`,
297
- desc: `Supported digests are: ${Object.keys(chunk3FJZA77A_cjs.DIGEST_ALGORITHMS).join(", ")}`
294
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) {
295
+ return chunk3UX5MZ2P_cjs.$err({
296
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Unsupported digest: ${digest}`,
297
+ desc: `Supported digests are: ${Object.keys(chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS).join(", ")}`
298
298
  });
299
299
  }
300
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
300
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
301
301
  const encoding = options.encoding ?? "base64url";
302
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) {
303
- return chunk3FJZA77A_cjs.$err({
304
- msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Unsupported encoding: ${encoding}`,
302
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) {
303
+ return chunk3UX5MZ2P_cjs.$err({
304
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Unsupported encoding: ${encoding}`,
305
305
  desc: "Use base64, base64url, or hex"
306
306
  });
307
307
  }
308
308
  const saltLength = options.saltLength ?? 16;
309
309
  if (typeof saltLength !== "number" || saltLength < 8) {
310
- return chunk3FJZA77A_cjs.$err({
311
- msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Weak salt length`,
310
+ return chunk3UX5MZ2P_cjs.$err({
311
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Weak salt length`,
312
312
  desc: "Salt length must be a number and at least 8 bytes (recommended 16 or more)"
313
313
  });
314
314
  }
315
315
  const iterations = options.iterations ?? 32e4;
316
316
  if (typeof iterations !== "number" || iterations < 1e3) {
317
- return chunk3FJZA77A_cjs.$err({
318
- msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Weak iterations count`,
317
+ return chunk3UX5MZ2P_cjs.$err({
318
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Weak iterations count`,
319
319
  desc: "Iterations must be a number and at least 1000 (recommended 320,000 or more)"
320
320
  });
321
321
  }
322
322
  const keyLength = options.keyLength ?? 64;
323
323
  if (typeof keyLength !== "number" || keyLength < 16) {
324
- return chunk3FJZA77A_cjs.$err({
325
- msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Invalid key length`,
324
+ return chunk3UX5MZ2P_cjs.$err({
325
+ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Invalid key length`,
326
326
  desc: "Key length must be a number and at least 16 bytes (recommended 64 or more)"
327
327
  });
328
328
  }
329
329
  try {
330
330
  const salt = nodeCrypto__default.default.randomBytes(saltLength);
331
331
  const hash2 = nodeCrypto__default.default.pbkdf2Sync(password.normalize("NFKC"), salt, iterations, keyLength, digestAlgo.node);
332
- return chunk3FJZA77A_cjs.$ok({ salt: salt.toString(encoding), hash: hash2.toString(encoding) });
332
+ return chunk3UX5MZ2P_cjs.$ok({ salt: salt.toString(encoding), hash: hash2.toString(encoding) });
333
333
  } catch (error) {
334
- return chunk3FJZA77A_cjs.$err({ msg: `${chunk3FJZA77A_cjs.title("node", "Password Hashing")}: Failed to hash password`, desc: chunk3FJZA77A_cjs.$fmtError(error) });
334
+ return chunk3UX5MZ2P_cjs.$err({ msg: `${chunk3UX5MZ2P_cjs.title("node", "Password Hashing")}: Failed to hash password`, desc: chunk3UX5MZ2P_cjs.$fmtError(error) });
335
335
  }
336
336
  }
337
337
  function $verifyPassword(password, hashedPassword, salt, options = {}) {
338
- if (!chunk3FJZA77A_cjs.$isStr(password) || !chunk3FJZA77A_cjs.$isStr(hashedPassword) || !chunk3FJZA77A_cjs.$isStr(salt)) return false;
338
+ if (!chunk3UX5MZ2P_cjs.$isStr(password) || !chunk3UX5MZ2P_cjs.$isStr(hashedPassword) || !chunk3UX5MZ2P_cjs.$isStr(salt)) return false;
339
339
  const digest = options.digest ?? "sha512";
340
- if (!(digest in chunk3FJZA77A_cjs.DIGEST_ALGORITHMS)) return false;
341
- const digestAlgo = chunk3FJZA77A_cjs.DIGEST_ALGORITHMS[digest];
340
+ if (!(digest in chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS)) return false;
341
+ const digestAlgo = chunk3UX5MZ2P_cjs.DIGEST_ALGORITHMS[digest];
342
342
  const encoding = options.encoding ?? "base64url";
343
- if (!chunk3FJZA77A_cjs.CIPHER_ENCODING.includes(encoding)) return false;
343
+ if (!chunk3UX5MZ2P_cjs.CIPHER_ENCODING.includes(encoding)) return false;
344
344
  const iterations = options.iterations ?? 32e4;
345
345
  if (typeof iterations !== "number" || iterations < 1e3) return false;
346
346
  const keyLength = options.keyLength ?? 64;
@@ -361,14 +361,14 @@ function $verifyPassword(password, hashedPassword, salt, options = {}) {
361
361
 
362
362
  // src/node/kit.ts
363
363
  function isNodeSecretKey(x) {
364
- return chunk3FJZA77A_cjs.$isSecretKey(x, "node") !== null;
364
+ return chunk3UX5MZ2P_cjs.$isSecretKey(x, "node") !== null;
365
365
  }
366
366
  function tryGenerateUuid() {
367
367
  return $generateUuid();
368
368
  }
369
369
  function generateUuid() {
370
370
  const { result, error } = $generateUuid();
371
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
371
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
372
372
  return result;
373
373
  }
374
374
  function tryCreateSecretKey(secret, options = {}) {
@@ -376,7 +376,7 @@ function tryCreateSecretKey(secret, options = {}) {
376
376
  }
377
377
  function createSecretKey(secret, options = {}) {
378
378
  const { result, error } = $createSecretKey(secret, options);
379
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
379
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
380
380
  return result;
381
381
  }
382
382
  function tryEncrypt(data, secretKey, options = {}) {
@@ -384,7 +384,7 @@ function tryEncrypt(data, secretKey, options = {}) {
384
384
  }
385
385
  function encrypt(data, secretKey, options = {}) {
386
386
  const { result, error } = $encrypt(data, secretKey, options);
387
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
387
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
388
388
  return result;
389
389
  }
390
390
  function tryDecrypt(encrypted, secretKey, options = {}) {
@@ -392,7 +392,7 @@ function tryDecrypt(encrypted, secretKey, options = {}) {
392
392
  }
393
393
  function decrypt(encrypted, secretKey, options = {}) {
394
394
  const { result, error } = $decrypt(encrypted, secretKey, options);
395
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
395
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
396
396
  return result;
397
397
  }
398
398
  function tryEncryptObj(data, secretKey, options = {}) {
@@ -400,7 +400,7 @@ function tryEncryptObj(data, secretKey, options = {}) {
400
400
  }
401
401
  function encryptObj(data, secretKey, options = {}) {
402
402
  const { result, error } = $encryptObj(data, secretKey, options);
403
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
403
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
404
404
  return result;
405
405
  }
406
406
  function tryDecryptObj(encrypted, secretKey, options = {}) {
@@ -408,7 +408,7 @@ function tryDecryptObj(encrypted, secretKey, options = {}) {
408
408
  }
409
409
  function decryptObj(encrypted, secretKey, options = {}) {
410
410
  const { result, error } = $decryptObj(encrypted, secretKey, options);
411
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
411
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
412
412
  return result;
413
413
  }
414
414
  function tryHash(data, options = {}) {
@@ -416,7 +416,7 @@ function tryHash(data, options = {}) {
416
416
  }
417
417
  function hash(data, options = {}) {
418
418
  const { result, error } = $hash(data, options);
419
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
419
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
420
420
  return result;
421
421
  }
422
422
  function tryHashPassword(password, options = {}) {
@@ -424,7 +424,7 @@ function tryHashPassword(password, options = {}) {
424
424
  }
425
425
  function hashPassword(password, options = {}) {
426
426
  const { hash: hash2, salt, error } = $hashPassword(password, options);
427
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
427
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
428
428
  return { hash: hash2, salt };
429
429
  }
430
430
  function verifyPassword(password, hashedPassword, salt, options = {}) {
@@ -435,7 +435,7 @@ function tryConvertStrToBytes(data, inputEncoding = "utf8") {
435
435
  }
436
436
  function convertStrToBytes(data, inputEncoding = "utf8") {
437
437
  const { result, error } = $convertStrToBytes(data, inputEncoding);
438
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
438
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
439
439
  return result;
440
440
  }
441
441
  function tryConvertBytesToStr(data, outputEncoding = "utf8") {
@@ -443,7 +443,7 @@ function tryConvertBytesToStr(data, outputEncoding = "utf8") {
443
443
  }
444
444
  function convertBytesToStr(data, outputEncoding = "utf8") {
445
445
  const { result, error } = $convertBytesToStr(data, outputEncoding);
446
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
446
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
447
447
  return result;
448
448
  }
449
449
  function tryConvertEncoding(data, from, to) {
@@ -451,7 +451,7 @@ function tryConvertEncoding(data, from, to) {
451
451
  }
452
452
  function convertEncoding(data, from, to) {
453
453
  const { result, error } = $convertEncoding(data, from, to);
454
- if (error) throw new Error(chunk3FJZA77A_cjs.$fmtResultErr(error));
454
+ if (error) throw new Error(chunk3UX5MZ2P_cjs.$fmtResultErr(error));
455
455
  return result;
456
456
  }
457
457
 
@@ -480,5 +480,5 @@ exports.tryGenerateUuid = tryGenerateUuid;
480
480
  exports.tryHash = tryHash;
481
481
  exports.tryHashPassword = tryHashPassword;
482
482
  exports.verifyPassword = verifyPassword;
483
- //# sourceMappingURL=chunk-WLLCFK4U.cjs.map
484
- //# sourceMappingURL=chunk-WLLCFK4U.cjs.map
483
+ //# sourceMappingURL=chunk-N2EW2FDZ.cjs.map
484
+ //# sourceMappingURL=chunk-N2EW2FDZ.cjs.map