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

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