cipher-kit 3.0.0-beta.0 → 3.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 (38) hide show
  1. package/README.md +3 -1
  2. package/dist/{chunk-ZYX6MYHS.cjs → chunk-3A4RTUKO.cjs} +101 -101
  3. package/dist/chunk-3A4RTUKO.cjs.map +1 -0
  4. package/dist/{chunk-LC5HP75W.cjs → chunk-7254PEID.cjs} +102 -102
  5. package/dist/chunk-7254PEID.cjs.map +1 -0
  6. package/dist/{chunk-ZN7EFZ7Z.js → chunk-GL32EZRA.js} +5 -5
  7. package/dist/chunk-GL32EZRA.js.map +1 -0
  8. package/dist/{chunk-4YR2SBOH.js → chunk-IY6XGUYO.js} +8 -2
  9. package/dist/chunk-IY6XGUYO.js.map +1 -0
  10. package/dist/{chunk-X7IPAA7B.cjs → chunk-VCBHSRCS.cjs} +8 -2
  11. package/dist/chunk-VCBHSRCS.cjs.map +1 -0
  12. package/dist/{chunk-3NFJMV33.js → chunk-X6MX4NDE.js} +3 -3
  13. package/dist/chunk-X6MX4NDE.js.map +1 -0
  14. package/dist/{export-DAIDJRX3.d.ts → export-B-3CCZIO.d.cts} +2 -1
  15. package/dist/{export-BEp4DFEB.d.cts → export-BPo6yPV-.d.ts} +2 -1
  16. package/dist/{export-Cxfev8fi.d.ts → export-C0_UEEg8.d.ts} +2 -1
  17. package/dist/{export-e7IN_bU5.d.cts → export-DPuocAr3.d.cts} +2 -1
  18. package/dist/index.cjs +11 -11
  19. package/dist/index.d.cts +5 -5
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.js +3 -3
  22. package/dist/node.cjs +33 -33
  23. package/dist/node.d.cts +2 -2
  24. package/dist/node.d.ts +2 -2
  25. package/dist/node.js +2 -2
  26. package/dist/{validate-DN59A2-Y.d.cts → validate-vDTesb-X.d.cts} +4 -1
  27. package/dist/{validate-DN59A2-Y.d.ts → validate-vDTesb-X.d.ts} +4 -1
  28. package/dist/web-api.cjs +33 -33
  29. package/dist/web-api.d.cts +2 -2
  30. package/dist/web-api.d.ts +2 -2
  31. package/dist/web-api.js +2 -2
  32. package/package.json +2 -2
  33. package/dist/chunk-3NFJMV33.js.map +0 -1
  34. package/dist/chunk-4YR2SBOH.js.map +0 -1
  35. package/dist/chunk-LC5HP75W.cjs.map +0 -1
  36. package/dist/chunk-X7IPAA7B.cjs.map +0 -1
  37. package/dist/chunk-ZN7EFZ7Z.js.map +0 -1
  38. package/dist/chunk-ZYX6MYHS.cjs.map +0 -1
package/README.md CHANGED
@@ -137,6 +137,8 @@ if (result.success) {
137
137
  ```
138
138
 
139
139
  > **Wire format:** Both platforms output `iv.cipher.tag.` (3 dot-separated segments with trailing dot). The format is **cross-platform compatible** — data encrypted on Node can be decrypted on Web and vice versa.
140
+ >
141
+ > **Nonce exhaustion:** AES-GCM uses random 96-bit IVs. Rotate keys before ~2^32 encryptions with the same key to avoid nonce collision.
140
142
 
141
143
  ### `encryptObj` / `decryptObj` / `tryEncryptObj` / `tryDecryptObj`
142
144
 
@@ -245,7 +247,7 @@ isWebSecretKey(key); // true if key is WebSecretKey
245
247
 
246
248
  ### Regex Utilities
247
249
 
248
- Validate the structural shape of encrypted payloads before decryption.
250
+ Validate the structural shape of encrypted payloads before decryption. This is a **structural** check only — it validates the dot-separated format but does not verify whether individual segments contain valid base64, base64url, or hex encoding.
249
251
 
250
252
  ```typescript
251
253
  import { ENCRYPTED_REGEX, matchEncryptedPattern } from "cipher-kit";
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkX7IPAA7B_cjs = require('./chunk-X7IPAA7B.cjs');
3
+ var chunkVCBHSRCS_cjs = require('./chunk-VCBHSRCS.cjs');
4
4
  var nodeCrypto3 = require('crypto');
5
5
  var buffer = require('buffer');
6
6
 
@@ -10,7 +10,7 @@ var nodeCrypto3__default = /*#__PURE__*/_interopDefault(nodeCrypto3);
10
10
 
11
11
  // src/node/kit.ts
12
12
  var kit_exports = {};
13
- chunkX7IPAA7B_cjs.__export(kit_exports, {
13
+ chunkVCBHSRCS_cjs.__export(kit_exports, {
14
14
  convertBytesToStr: () => convertBytesToStr,
15
15
  convertEncoding: () => convertEncoding,
16
16
  convertStrToBytes: () => convertStrToBytes,
@@ -39,13 +39,13 @@ chunkX7IPAA7B_cjs.__export(kit_exports, {
39
39
  });
40
40
  function $convertStrToBytes(data, inputEncoding = "utf8") {
41
41
  if (typeof data !== "string") {
42
- return chunkX7IPAA7B_cjs.$err({
42
+ return chunkVCBHSRCS_cjs.$err({
43
43
  message: "node strToBytes: Data must be a string",
44
44
  description: `Expected a string value, received ${typeof data}`
45
45
  });
46
46
  }
47
- if (!chunkX7IPAA7B_cjs.ENCODING.includes(inputEncoding)) {
48
- return chunkX7IPAA7B_cjs.$err({
47
+ if (!chunkVCBHSRCS_cjs.ENCODING.includes(inputEncoding)) {
48
+ return chunkVCBHSRCS_cjs.$err({
49
49
  message: `node strToBytes: Unsupported encoding: ${inputEncoding}`,
50
50
  description: "Use base64, base64url, hex, utf8, or latin1"
51
51
  });
@@ -53,16 +53,16 @@ function $convertStrToBytes(data, inputEncoding = "utf8") {
53
53
  if (inputEncoding === "hex") {
54
54
  const clean = /^0x/i.test(data) ? data.slice(2) : data;
55
55
  if (clean.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(clean)) {
56
- return chunkX7IPAA7B_cjs.$err({
56
+ return chunkVCBHSRCS_cjs.$err({
57
57
  message: "node strToBytes: Invalid hex string",
58
58
  description: "Hex string contains non-hex characters or has odd length"
59
59
  });
60
60
  }
61
- return chunkX7IPAA7B_cjs.$ok({ result: buffer.Buffer.from(clean, "hex") });
61
+ return chunkVCBHSRCS_cjs.$ok({ result: buffer.Buffer.from(clean, "hex") });
62
62
  }
63
63
  if (inputEncoding === "base64") {
64
64
  if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}={2}|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
65
- return chunkX7IPAA7B_cjs.$err({
65
+ return chunkVCBHSRCS_cjs.$err({
66
66
  message: "node strToBytes: Invalid base64 string",
67
67
  description: "Base64 string contains invalid characters or has incorrect padding"
68
68
  });
@@ -70,58 +70,58 @@ function $convertStrToBytes(data, inputEncoding = "utf8") {
70
70
  }
71
71
  if (inputEncoding === "base64url") {
72
72
  if (!/^[A-Za-z0-9_-]*={0,2}$/.test(data) || data.replace(/=+$/, "").length % 4 === 1) {
73
- return chunkX7IPAA7B_cjs.$err({
73
+ return chunkVCBHSRCS_cjs.$err({
74
74
  message: "node strToBytes: Invalid base64url string",
75
75
  description: "Base64url string contains invalid characters or has incorrect length"
76
76
  });
77
77
  }
78
78
  }
79
79
  try {
80
- return chunkX7IPAA7B_cjs.$ok({ result: buffer.Buffer.from(data, inputEncoding) });
80
+ return chunkVCBHSRCS_cjs.$ok({ result: buffer.Buffer.from(data, inputEncoding) });
81
81
  } catch (error) {
82
- return chunkX7IPAA7B_cjs.$err({ message: "node strToBytes: Failed to convert data", description: chunkX7IPAA7B_cjs.$fmtError(error) });
82
+ return chunkVCBHSRCS_cjs.$err({ message: "node strToBytes: Failed to convert data", description: chunkVCBHSRCS_cjs.$fmtError(error) });
83
83
  }
84
84
  }
85
85
  function $convertBytesToStr(data, outputEncoding = "utf8") {
86
86
  if (!(data instanceof buffer.Buffer)) {
87
- return chunkX7IPAA7B_cjs.$err({
87
+ return chunkVCBHSRCS_cjs.$err({
88
88
  message: "node bytesToStr: Data must be a Buffer",
89
89
  description: "Received a non-Buffer value"
90
90
  });
91
91
  }
92
- if (!chunkX7IPAA7B_cjs.ENCODING.includes(outputEncoding)) {
93
- return chunkX7IPAA7B_cjs.$err({
92
+ if (!chunkVCBHSRCS_cjs.ENCODING.includes(outputEncoding)) {
93
+ return chunkVCBHSRCS_cjs.$err({
94
94
  message: `node bytesToStr: Unsupported encoding: ${outputEncoding}`,
95
95
  description: "Use base64, base64url, hex, utf8, or latin1"
96
96
  });
97
97
  }
98
98
  try {
99
- return chunkX7IPAA7B_cjs.$ok(data.toString(outputEncoding));
99
+ return chunkVCBHSRCS_cjs.$ok(data.toString(outputEncoding));
100
100
  } catch (error) {
101
- return chunkX7IPAA7B_cjs.$err({ message: "node bytesToStr: Failed to convert data", description: chunkX7IPAA7B_cjs.$fmtError(error) });
101
+ return chunkVCBHSRCS_cjs.$err({ message: "node bytesToStr: Failed to convert data", description: chunkVCBHSRCS_cjs.$fmtError(error) });
102
102
  }
103
103
  }
104
104
  function $convertEncoding(data, from, to) {
105
- if (!chunkX7IPAA7B_cjs.$isStr(data)) {
106
- return chunkX7IPAA7B_cjs.$err({
105
+ if (!chunkVCBHSRCS_cjs.$isStr(data)) {
106
+ return chunkVCBHSRCS_cjs.$err({
107
107
  message: "node convertEncoding: Data must be a non-empty string",
108
108
  description: "Received empty or non-string value"
109
109
  });
110
110
  }
111
- if (!chunkX7IPAA7B_cjs.ENCODING.includes(from) || !chunkX7IPAA7B_cjs.ENCODING.includes(to)) {
112
- return chunkX7IPAA7B_cjs.$err({
111
+ if (!chunkVCBHSRCS_cjs.ENCODING.includes(from) || !chunkVCBHSRCS_cjs.ENCODING.includes(to)) {
112
+ return chunkVCBHSRCS_cjs.$err({
113
113
  message: `node convertEncoding: Unsupported encoding: from ${from} to ${to}`,
114
114
  description: "Use base64, base64url, hex, utf8, or latin1"
115
115
  });
116
116
  }
117
117
  const bytes = $convertStrToBytes(data, from);
118
- if (bytes.error) return chunkX7IPAA7B_cjs.$err(bytes.error);
118
+ if (bytes.error) return chunkVCBHSRCS_cjs.$err(bytes.error);
119
119
  const str = $convertBytesToStr(bytes.result, to);
120
- if (str.error) return chunkX7IPAA7B_cjs.$err(str.error);
121
- return chunkX7IPAA7B_cjs.$ok(str.result);
120
+ if (str.error) return chunkVCBHSRCS_cjs.$err(str.error);
121
+ return chunkVCBHSRCS_cjs.$ok(str.result);
122
122
  }
123
123
  function $isNodeSecretKey(x) {
124
- const base = chunkX7IPAA7B_cjs.$validateSecretKeyBase(x, "node");
124
+ const base = chunkVCBHSRCS_cjs.$validateSecretKeyBase(x, "node");
125
125
  if (!base) return null;
126
126
  if (!(base.obj.key instanceof nodeCrypto3__default.default.KeyObject) || typeof base.obj.key.symmetricKeySize === "number" && base.obj.key.symmetricKeySize !== base.algorithm.keyBytes) {
127
127
  return null;
@@ -129,8 +129,8 @@ function $isNodeSecretKey(x) {
129
129
  return x;
130
130
  }
131
131
  function $createSecretKey(secret, options) {
132
- const validated = chunkX7IPAA7B_cjs.$validateCreateSecretKeyOptions(secret, options, "node");
133
- if (validated.error) return chunkX7IPAA7B_cjs.$err(validated.error);
132
+ const validated = chunkVCBHSRCS_cjs.$validateCreateSecretKeyOptions(secret, options, "node");
133
+ if (validated.error) return chunkVCBHSRCS_cjs.$err(validated.error);
134
134
  const { algorithm, digest, salt, info, encryptAlgo, digestAlgo } = validated;
135
135
  try {
136
136
  const derivedKey = Buffer.from(
@@ -151,47 +151,47 @@ function $createSecretKey(secret, options) {
151
151
  key,
152
152
  injected: encryptAlgo
153
153
  });
154
- return chunkX7IPAA7B_cjs.$ok({ result: secretKey });
154
+ return chunkVCBHSRCS_cjs.$ok({ result: secretKey });
155
155
  } finally {
156
156
  derivedKey.fill(0);
157
157
  }
158
158
  } catch (error) {
159
- return chunkX7IPAA7B_cjs.$err({ message: "node createSecretKey: Failed to derive key", description: chunkX7IPAA7B_cjs.$fmtError(error) });
159
+ return chunkVCBHSRCS_cjs.$err({ message: "node createSecretKey: Failed to derive key", description: chunkVCBHSRCS_cjs.$fmtError(error) });
160
160
  }
161
161
  }
162
162
 
163
163
  // src/node/node-encrypt.ts
164
164
  function $encrypt(data, secretKey, options) {
165
- if (!chunkX7IPAA7B_cjs.$isStr(data)) {
166
- return chunkX7IPAA7B_cjs.$err({
165
+ if (!chunkVCBHSRCS_cjs.$isStr(data)) {
166
+ return chunkVCBHSRCS_cjs.$err({
167
167
  message: "node encrypt: Data must be a non-empty string",
168
168
  description: "Received empty or non-string value"
169
169
  });
170
170
  }
171
- if (!chunkX7IPAA7B_cjs.$isPlainObj(options)) {
172
- return chunkX7IPAA7B_cjs.$err({
171
+ if (!chunkVCBHSRCS_cjs.$isPlainObj(options)) {
172
+ return chunkVCBHSRCS_cjs.$err({
173
173
  message: "node encrypt: Options must be a plain object",
174
174
  description: 'Pass an object like { outputEncoding: "base64url" }'
175
175
  });
176
176
  }
177
177
  const outputEncoding = options.outputEncoding ?? "base64url";
178
- if (!chunkX7IPAA7B_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
179
- return chunkX7IPAA7B_cjs.$err({
178
+ if (!chunkVCBHSRCS_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
179
+ return chunkVCBHSRCS_cjs.$err({
180
180
  message: `node encrypt: Unsupported output encoding: ${outputEncoding}`,
181
181
  description: "Use base64, base64url, or hex"
182
182
  });
183
183
  }
184
184
  const injectedKey = $isNodeSecretKey(secretKey);
185
185
  if (!injectedKey) {
186
- return chunkX7IPAA7B_cjs.$err({
186
+ return chunkVCBHSRCS_cjs.$err({
187
187
  message: "node encrypt: Invalid secret key",
188
188
  description: "Expected a NodeSecretKey created by nodeKit.createSecretKey()"
189
189
  });
190
190
  }
191
191
  const { result, error } = $convertStrToBytes(data, "utf8");
192
- if (error) return chunkX7IPAA7B_cjs.$err(error);
192
+ if (error) return chunkVCBHSRCS_cjs.$err(error);
193
193
  try {
194
- const iv = nodeCrypto3__default.default.randomBytes(chunkX7IPAA7B_cjs.GCM_IV_LENGTH);
194
+ const iv = nodeCrypto3__default.default.randomBytes(chunkVCBHSRCS_cjs.GCM_IV_LENGTH);
195
195
  const cipher = nodeCrypto3__default.default.createCipheriv(injectedKey.injected.node, injectedKey.key, iv);
196
196
  const encrypted = buffer.Buffer.concat([cipher.update(result), cipher.final()]);
197
197
  const tag = cipher.getAuthTag();
@@ -199,34 +199,34 @@ function $encrypt(data, secretKey, options) {
199
199
  const cipherStr = $convertBytesToStr(encrypted, outputEncoding);
200
200
  const tagStr = $convertBytesToStr(tag, outputEncoding);
201
201
  if (ivStr.error || cipherStr.error || tagStr.error) {
202
- return chunkX7IPAA7B_cjs.$err({
202
+ return chunkVCBHSRCS_cjs.$err({
203
203
  message: "node encrypt: Failed to encode output",
204
- description: `Conversion error: ${chunkX7IPAA7B_cjs.$fmtResultErr(ivStr.error || cipherStr.error || tagStr.error)}`
204
+ description: `Conversion error: ${chunkVCBHSRCS_cjs.$fmtResultErr(ivStr.error || cipherStr.error || tagStr.error)}`
205
205
  });
206
206
  }
207
- return chunkX7IPAA7B_cjs.$ok(`${ivStr.result}.${cipherStr.result}.${tagStr.result}.`);
207
+ return chunkVCBHSRCS_cjs.$ok(`${ivStr.result}.${cipherStr.result}.${tagStr.result}.`);
208
208
  } catch (error2) {
209
- return chunkX7IPAA7B_cjs.$err({ message: "node encrypt: Failed to encrypt data", description: chunkX7IPAA7B_cjs.$fmtError(error2) });
209
+ return chunkVCBHSRCS_cjs.$err({ message: "node encrypt: Failed to encrypt data", description: chunkVCBHSRCS_cjs.$fmtError(error2) });
210
210
  } finally {
211
211
  result.fill(0);
212
212
  }
213
213
  }
214
214
  function $decrypt(encrypted, secretKey, options) {
215
- if (!chunkX7IPAA7B_cjs.matchEncryptedPattern(encrypted)) {
216
- return chunkX7IPAA7B_cjs.$err({
215
+ if (!chunkVCBHSRCS_cjs.matchEncryptedPattern(encrypted)) {
216
+ return chunkVCBHSRCS_cjs.$err({
217
217
  message: "node decrypt: Invalid encrypted data format",
218
218
  description: 'Encrypted data must be in the format "iv.cipher.tag."'
219
219
  });
220
220
  }
221
- if (!chunkX7IPAA7B_cjs.$isPlainObj(options)) {
222
- return chunkX7IPAA7B_cjs.$err({
221
+ if (!chunkVCBHSRCS_cjs.$isPlainObj(options)) {
222
+ return chunkVCBHSRCS_cjs.$err({
223
223
  message: "node decrypt: Options must be a plain object",
224
224
  description: 'Pass an object like { inputEncoding: "base64url" }'
225
225
  });
226
226
  }
227
227
  const inputEncoding = options.inputEncoding ?? "base64url";
228
- if (!chunkX7IPAA7B_cjs.CIPHER_ENCODING.includes(inputEncoding)) {
229
- return chunkX7IPAA7B_cjs.$err({
228
+ if (!chunkVCBHSRCS_cjs.CIPHER_ENCODING.includes(inputEncoding)) {
229
+ return chunkVCBHSRCS_cjs.$err({
230
230
  message: `node decrypt: Unsupported input encoding: ${inputEncoding}`,
231
231
  description: "Use base64, base64url, or hex"
232
232
  });
@@ -234,7 +234,7 @@ function $decrypt(encrypted, secretKey, options) {
234
234
  const [iv, cipher, tag] = encrypted.split(".", 4);
235
235
  const injectedKey = $isNodeSecretKey(secretKey);
236
236
  if (!injectedKey) {
237
- return chunkX7IPAA7B_cjs.$err({
237
+ return chunkVCBHSRCS_cjs.$err({
238
238
  message: "node decrypt: Invalid secret key",
239
239
  description: "Expected a NodeSecretKey created by nodeKit.createSecretKey()"
240
240
  });
@@ -243,21 +243,21 @@ function $decrypt(encrypted, secretKey, options) {
243
243
  const cipherBytes = $convertStrToBytes(cipher, inputEncoding);
244
244
  const tagBytes = $convertStrToBytes(tag, inputEncoding);
245
245
  if (ivBytes.error || cipherBytes.error || tagBytes.error) {
246
- return chunkX7IPAA7B_cjs.$err({
246
+ return chunkVCBHSRCS_cjs.$err({
247
247
  message: "node decrypt: Failed to decode input",
248
- description: `Conversion error: ${chunkX7IPAA7B_cjs.$fmtResultErr(ivBytes.error || cipherBytes.error || tagBytes.error)}`
248
+ description: `Conversion error: ${chunkVCBHSRCS_cjs.$fmtResultErr(ivBytes.error || cipherBytes.error || tagBytes.error)}`
249
249
  });
250
250
  }
251
- if (ivBytes.result.byteLength !== chunkX7IPAA7B_cjs.GCM_IV_LENGTH) {
252
- return chunkX7IPAA7B_cjs.$err({
251
+ if (ivBytes.result.byteLength !== chunkVCBHSRCS_cjs.GCM_IV_LENGTH) {
252
+ return chunkVCBHSRCS_cjs.$err({
253
253
  message: "node decrypt: Invalid IV length",
254
- description: `Expected ${chunkX7IPAA7B_cjs.GCM_IV_LENGTH} bytes, got ${ivBytes.result.byteLength}`
254
+ description: `Expected ${chunkVCBHSRCS_cjs.GCM_IV_LENGTH} bytes, got ${ivBytes.result.byteLength}`
255
255
  });
256
256
  }
257
- if (tagBytes.result.byteLength !== chunkX7IPAA7B_cjs.GCM_TAG_BYTES) {
258
- return chunkX7IPAA7B_cjs.$err({
257
+ if (tagBytes.result.byteLength !== chunkVCBHSRCS_cjs.GCM_TAG_BYTES) {
258
+ return chunkVCBHSRCS_cjs.$err({
259
259
  message: "node decrypt: Invalid auth tag length",
260
- description: `Expected ${chunkX7IPAA7B_cjs.GCM_TAG_BYTES} bytes, got ${tagBytes.result.byteLength}`
260
+ description: `Expected ${chunkVCBHSRCS_cjs.GCM_TAG_BYTES} bytes, got ${tagBytes.result.byteLength}`
261
261
  });
262
262
  }
263
263
  let decrypted;
@@ -267,86 +267,86 @@ function $decrypt(encrypted, secretKey, options) {
267
267
  decrypted = buffer.Buffer.concat([decipher.update(cipherBytes.result), decipher.final()]);
268
268
  return $convertBytesToStr(decrypted, "utf8");
269
269
  } catch (error) {
270
- return chunkX7IPAA7B_cjs.$err({ message: "node decrypt: Failed to decrypt data", description: chunkX7IPAA7B_cjs.$fmtError(error) });
270
+ return chunkVCBHSRCS_cjs.$err({ message: "node decrypt: Failed to decrypt data", description: chunkVCBHSRCS_cjs.$fmtError(error) });
271
271
  } finally {
272
272
  decrypted?.fill(0);
273
273
  }
274
274
  }
275
275
  function $encryptObj(data, secretKey, options) {
276
- const { result, error } = chunkX7IPAA7B_cjs.$stringifyObj(data);
277
- if (error) return chunkX7IPAA7B_cjs.$err(error);
276
+ const { result, error } = chunkVCBHSRCS_cjs.$stringifyObj(data);
277
+ if (error) return chunkVCBHSRCS_cjs.$err(error);
278
278
  return $encrypt(result, secretKey, options);
279
279
  }
280
280
  function $decryptObj(encrypted, secretKey, options) {
281
281
  const { result, error } = $decrypt(encrypted, secretKey, options);
282
- if (error) return chunkX7IPAA7B_cjs.$err(error);
283
- return chunkX7IPAA7B_cjs.$parseToObj(result);
282
+ if (error) return chunkVCBHSRCS_cjs.$err(error);
283
+ return chunkVCBHSRCS_cjs.$parseToObj(result);
284
284
  }
285
285
  function $hash(data, options = {}) {
286
- if (!chunkX7IPAA7B_cjs.$isStr(data)) {
287
- return chunkX7IPAA7B_cjs.$err({
286
+ if (!chunkVCBHSRCS_cjs.$isStr(data)) {
287
+ return chunkVCBHSRCS_cjs.$err({
288
288
  message: "node hash: Data must be a non-empty string",
289
289
  description: "Received empty or non-string value"
290
290
  });
291
291
  }
292
- if (!chunkX7IPAA7B_cjs.$isPlainObj(options)) {
293
- return chunkX7IPAA7B_cjs.$err({
292
+ if (!chunkVCBHSRCS_cjs.$isPlainObj(options)) {
293
+ return chunkVCBHSRCS_cjs.$err({
294
294
  message: "node hash: Options must be a plain object",
295
295
  description: 'Pass an object like { digest: "sha256" }'
296
296
  });
297
297
  }
298
298
  const outputEncoding = options.outputEncoding ?? "base64url";
299
- if (!chunkX7IPAA7B_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
300
- return chunkX7IPAA7B_cjs.$err({
299
+ if (!chunkVCBHSRCS_cjs.CIPHER_ENCODING.includes(outputEncoding)) {
300
+ return chunkVCBHSRCS_cjs.$err({
301
301
  message: `node hash: Unsupported output encoding: ${outputEncoding}`,
302
302
  description: "Use base64, base64url, or hex"
303
303
  });
304
304
  }
305
305
  const digest = options.digest ?? "sha256";
306
- if (!(digest in chunkX7IPAA7B_cjs.DIGEST_ALGORITHMS)) {
307
- return chunkX7IPAA7B_cjs.$err({
306
+ if (!(digest in chunkVCBHSRCS_cjs.DIGEST_ALGORITHMS)) {
307
+ return chunkVCBHSRCS_cjs.$err({
308
308
  message: `node hash: Unsupported digest: ${digest}`,
309
- description: `Supported digests are: ${Object.keys(chunkX7IPAA7B_cjs.DIGEST_ALGORITHMS).join(", ")}`
309
+ description: `Supported digests are: ${Object.keys(chunkVCBHSRCS_cjs.DIGEST_ALGORITHMS).join(", ")}`
310
310
  });
311
311
  }
312
- const digestAlgo = chunkX7IPAA7B_cjs.DIGEST_ALGORITHMS[digest];
312
+ const digestAlgo = chunkVCBHSRCS_cjs.DIGEST_ALGORITHMS[digest];
313
313
  const { result, error } = $convertStrToBytes(data, "utf8");
314
- if (error) return chunkX7IPAA7B_cjs.$err(error);
314
+ if (error) return chunkVCBHSRCS_cjs.$err(error);
315
315
  try {
316
316
  const hashed = nodeCrypto3__default.default.createHash(digestAlgo.node).update(result).digest();
317
317
  return $convertBytesToStr(hashed, outputEncoding);
318
318
  } catch (error2) {
319
- return chunkX7IPAA7B_cjs.$err({ message: "node hash: Failed to hash data", description: chunkX7IPAA7B_cjs.$fmtError(error2) });
319
+ return chunkVCBHSRCS_cjs.$err({ message: "node hash: Failed to hash data", description: chunkVCBHSRCS_cjs.$fmtError(error2) });
320
320
  }
321
321
  }
322
322
  function $hashPassword(password, options) {
323
- const validated = chunkX7IPAA7B_cjs.$validateHashPasswordOptions(password, options, "node");
324
- if (validated.error) return chunkX7IPAA7B_cjs.$err(validated.error);
323
+ const validated = chunkVCBHSRCS_cjs.$validateHashPasswordOptions(password, options, "node");
324
+ if (validated.error) return chunkVCBHSRCS_cjs.$err(validated.error);
325
325
  const { digestAlgo, outputEncoding, saltLength, iterations, keyLength } = validated;
326
326
  const salt = nodeCrypto3__default.default.randomBytes(saltLength);
327
327
  const hash2 = nodeCrypto3__default.default.pbkdf2Sync(password.normalize("NFKC"), salt, iterations, keyLength, digestAlgo.node);
328
328
  try {
329
329
  const saltStr = $convertBytesToStr(salt, outputEncoding);
330
- if (saltStr.error) return chunkX7IPAA7B_cjs.$err(saltStr.error);
330
+ if (saltStr.error) return chunkVCBHSRCS_cjs.$err(saltStr.error);
331
331
  const hashStr = $convertBytesToStr(hash2, outputEncoding);
332
- if (hashStr.error) return chunkX7IPAA7B_cjs.$err(hashStr.error);
333
- return chunkX7IPAA7B_cjs.$ok({ result: hashStr.result, salt: saltStr.result });
332
+ if (hashStr.error) return chunkVCBHSRCS_cjs.$err(hashStr.error);
333
+ return chunkVCBHSRCS_cjs.$ok({ result: hashStr.result, salt: saltStr.result });
334
334
  } catch (error) {
335
- return chunkX7IPAA7B_cjs.$err({ message: "node hashPassword: Failed to hash password", description: chunkX7IPAA7B_cjs.$fmtError(error) });
335
+ return chunkVCBHSRCS_cjs.$err({ message: "node hashPassword: Failed to hash password", description: chunkVCBHSRCS_cjs.$fmtError(error) });
336
336
  } finally {
337
337
  salt.fill(0);
338
338
  hash2.fill(0);
339
339
  }
340
340
  }
341
341
  function $verifyPassword(password, hashedPassword, salt, options) {
342
- const validated = chunkX7IPAA7B_cjs.$validateVerifyPasswordOptions(password, hashedPassword, salt, options, "node");
343
- if (validated.error) return chunkX7IPAA7B_cjs.$err(validated.error);
342
+ const validated = chunkVCBHSRCS_cjs.$validateVerifyPasswordOptions(password, hashedPassword, salt, options, "node");
343
+ if (validated.error) return chunkVCBHSRCS_cjs.$err(validated.error);
344
344
  const { digestAlgo, inputEncoding, iterations, keyLength } = validated;
345
345
  const saltBytes = $convertStrToBytes(salt, inputEncoding);
346
- if (saltBytes.error) return chunkX7IPAA7B_cjs.$err(saltBytes.error);
346
+ if (saltBytes.error) return chunkVCBHSRCS_cjs.$err(saltBytes.error);
347
347
  const hashedPasswordBytes = $convertStrToBytes(hashedPassword, inputEncoding);
348
- if (hashedPasswordBytes.error) return chunkX7IPAA7B_cjs.$err(hashedPasswordBytes.error);
349
- if (hashedPasswordBytes.result.byteLength !== keyLength) return chunkX7IPAA7B_cjs.$ok(false);
348
+ if (hashedPasswordBytes.error) return chunkVCBHSRCS_cjs.$err(hashedPasswordBytes.error);
349
+ if (hashedPasswordBytes.result.byteLength !== keyLength) return chunkVCBHSRCS_cjs.$ok(false);
350
350
  try {
351
351
  const derived = nodeCrypto3__default.default.pbkdf2Sync(
352
352
  password.normalize("NFKC"),
@@ -362,14 +362,14 @@ function $verifyPassword(password, hashedPassword, salt, options) {
362
362
  expected.copy(right);
363
363
  try {
364
364
  const matches = nodeCrypto3__default.default.timingSafeEqual(left, right);
365
- return chunkX7IPAA7B_cjs.$ok(matches);
365
+ return chunkVCBHSRCS_cjs.$ok(matches);
366
366
  } finally {
367
367
  left.fill(0);
368
368
  right.fill(0);
369
369
  derived.fill(0);
370
370
  }
371
371
  } catch (error) {
372
- return chunkX7IPAA7B_cjs.$err({ message: "node verifyPassword: Verification failed", description: chunkX7IPAA7B_cjs.$fmtError(error) });
372
+ return chunkVCBHSRCS_cjs.$err({ message: "node verifyPassword: Verification failed", description: chunkVCBHSRCS_cjs.$fmtError(error) });
373
373
  } finally {
374
374
  saltBytes.result.fill(0);
375
375
  hashedPasswordBytes.result.fill(0);
@@ -382,9 +382,9 @@ function isNodeSecretKey(x) {
382
382
  }
383
383
  function tryGenerateUuid() {
384
384
  try {
385
- return chunkX7IPAA7B_cjs.$ok(nodeCrypto3__default.default.randomUUID());
385
+ return chunkVCBHSRCS_cjs.$ok(nodeCrypto3__default.default.randomUUID());
386
386
  } catch (error) {
387
- return chunkX7IPAA7B_cjs.$err({ message: "node generateUuid: Failed to generate UUID", description: chunkX7IPAA7B_cjs.$fmtError(error) });
387
+ return chunkVCBHSRCS_cjs.$err({ message: "node generateUuid: Failed to generate UUID", description: chunkVCBHSRCS_cjs.$fmtError(error) });
388
388
  }
389
389
  }
390
390
  function generateUuid() {
@@ -395,7 +395,7 @@ function tryCreateSecretKey(secret, options = {}) {
395
395
  }
396
396
  function createSecretKey(secret, options = {}) {
397
397
  const { result, error } = $createSecretKey(secret, options);
398
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
398
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
399
399
  return result;
400
400
  }
401
401
  function tryEncrypt(data, secretKey, options = {}) {
@@ -403,7 +403,7 @@ function tryEncrypt(data, secretKey, options = {}) {
403
403
  }
404
404
  function encrypt(data, secretKey, options = {}) {
405
405
  const { result, error } = $encrypt(data, secretKey, options);
406
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
406
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
407
407
  return result;
408
408
  }
409
409
  function tryDecrypt(encrypted, secretKey, options = {}) {
@@ -411,7 +411,7 @@ function tryDecrypt(encrypted, secretKey, options = {}) {
411
411
  }
412
412
  function decrypt(encrypted, secretKey, options = {}) {
413
413
  const { result, error } = $decrypt(encrypted, secretKey, options);
414
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
414
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
415
415
  return result;
416
416
  }
417
417
  function tryEncryptObj(obj, secretKey, options = {}) {
@@ -419,7 +419,7 @@ function tryEncryptObj(obj, secretKey, options = {}) {
419
419
  }
420
420
  function encryptObj(obj, secretKey, options = {}) {
421
421
  const { result, error } = $encryptObj(obj, secretKey, options);
422
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
422
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
423
423
  return result;
424
424
  }
425
425
  function tryDecryptObj(encrypted, secretKey, options = {}) {
@@ -427,7 +427,7 @@ function tryDecryptObj(encrypted, secretKey, options = {}) {
427
427
  }
428
428
  function decryptObj(encrypted, secretKey, options = {}) {
429
429
  const { result, error } = $decryptObj(encrypted, secretKey, options);
430
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
430
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
431
431
  return result;
432
432
  }
433
433
  function tryHash(data, options = {}) {
@@ -435,7 +435,7 @@ function tryHash(data, options = {}) {
435
435
  }
436
436
  function hash(data, options = {}) {
437
437
  const { result, error } = $hash(data, options);
438
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
438
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
439
439
  return result;
440
440
  }
441
441
  function tryHashPassword(password, options = {}) {
@@ -443,7 +443,7 @@ function tryHashPassword(password, options = {}) {
443
443
  }
444
444
  function hashPassword(password, options = {}) {
445
445
  const { result, salt, error } = $hashPassword(password, options);
446
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
446
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
447
447
  return { result, salt };
448
448
  }
449
449
  function tryVerifyPassword(password, hashedPassword, salt, options = {}) {
@@ -451,7 +451,7 @@ function tryVerifyPassword(password, hashedPassword, salt, options = {}) {
451
451
  }
452
452
  function verifyPassword(password, hashedPassword, salt, options = {}) {
453
453
  const { result, error } = $verifyPassword(password, hashedPassword, salt, options);
454
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
454
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
455
455
  return result;
456
456
  }
457
457
  function tryConvertStrToBytes(data, inputEncoding = "utf8") {
@@ -459,7 +459,7 @@ function tryConvertStrToBytes(data, inputEncoding = "utf8") {
459
459
  }
460
460
  function convertStrToBytes(data, inputEncoding = "utf8") {
461
461
  const { result, error } = $convertStrToBytes(data, inputEncoding);
462
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
462
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
463
463
  return result;
464
464
  }
465
465
  function tryConvertBytesToStr(data, outputEncoding = "utf8") {
@@ -467,7 +467,7 @@ function tryConvertBytesToStr(data, outputEncoding = "utf8") {
467
467
  }
468
468
  function convertBytesToStr(data, outputEncoding = "utf8") {
469
469
  const { result, error } = $convertBytesToStr(data, outputEncoding);
470
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
470
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
471
471
  return result;
472
472
  }
473
473
  function tryConvertEncoding(data, from, to) {
@@ -475,7 +475,7 @@ function tryConvertEncoding(data, from, to) {
475
475
  }
476
476
  function convertEncoding(data, from, to) {
477
477
  const { result, error } = $convertEncoding(data, from, to);
478
- if (error) throw new Error(chunkX7IPAA7B_cjs.$fmtResultErr(error));
478
+ if (error) throw new Error(chunkVCBHSRCS_cjs.$fmtResultErr(error));
479
479
  return result;
480
480
  }
481
481
 
@@ -505,5 +505,5 @@ exports.tryHash = tryHash;
505
505
  exports.tryHashPassword = tryHashPassword;
506
506
  exports.tryVerifyPassword = tryVerifyPassword;
507
507
  exports.verifyPassword = verifyPassword;
508
- //# sourceMappingURL=chunk-ZYX6MYHS.cjs.map
509
- //# sourceMappingURL=chunk-ZYX6MYHS.cjs.map
508
+ //# sourceMappingURL=chunk-3A4RTUKO.cjs.map
509
+ //# sourceMappingURL=chunk-3A4RTUKO.cjs.map