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

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