cipher-kit 2.1.3 → 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.
- package/README.md +324 -434
- package/dist/chunk-3A4RTUKO.cjs +509 -0
- package/dist/chunk-3A4RTUKO.cjs.map +1 -0
- package/dist/chunk-7254PEID.cjs +502 -0
- package/dist/chunk-7254PEID.cjs.map +1 -0
- package/dist/chunk-GL32EZRA.js +475 -0
- package/dist/chunk-GL32EZRA.js.map +1 -0
- package/dist/chunk-IY6XGUYO.js +494 -0
- package/dist/chunk-IY6XGUYO.js.map +1 -0
- package/dist/chunk-VCBHSRCS.cjs +523 -0
- package/dist/chunk-VCBHSRCS.cjs.map +1 -0
- package/dist/chunk-X6MX4NDE.js +478 -0
- package/dist/chunk-X6MX4NDE.js.map +1 -0
- package/dist/export-B-3CCZIO.d.cts +389 -0
- package/dist/export-BPo6yPV-.d.ts +389 -0
- package/dist/export-C0_UEEg8.d.ts +396 -0
- package/dist/export-DPuocAr3.d.cts +396 -0
- package/dist/index.cjs +11 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -40
- package/dist/index.d.ts +11 -40
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +39 -35
- package/dist/node.d.cts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +2 -2
- package/dist/validate-vDTesb-X.d.cts +195 -0
- package/dist/validate-vDTesb-X.d.ts +195 -0
- package/dist/web-api.cjs +39 -35
- package/dist/web-api.d.cts +2 -3
- package/dist/web-api.d.ts +2 -3
- package/dist/web-api.js +2 -2
- package/package.json +82 -92
- package/dist/chunk-BMX42IZM.cjs +0 -623
- package/dist/chunk-BMX42IZM.cjs.map +0 -1
- package/dist/chunk-HTRGOBZF.cjs +0 -169
- package/dist/chunk-HTRGOBZF.cjs.map +0 -1
- package/dist/chunk-LU7QOSQH.js +0 -141
- package/dist/chunk-LU7QOSQH.js.map +0 -1
- package/dist/chunk-S6SNCTU6.js +0 -485
- package/dist/chunk-S6SNCTU6.js.map +0 -1
- package/dist/chunk-T36BEDPY.js +0 -598
- package/dist/chunk-T36BEDPY.js.map +0 -1
- package/dist/chunk-ZNM5M6RD.cjs +0 -514
- package/dist/chunk-ZNM5M6RD.cjs.map +0 -1
- package/dist/export-BaM_OTFk.d.ts +0 -573
- package/dist/export-CCTGAosO.d.ts +0 -572
- package/dist/export-FYHgb-8E.d.cts +0 -572
- package/dist/export-KFT0YyMg.d.cts +0 -573
- package/dist/validate-lkJAHCeJ.d.cts +0 -399
- package/dist/validate-lkJAHCeJ.d.ts +0 -399
|
@@ -1,573 +0,0 @@
|
|
|
1
|
-
import { R as Result, e as CreateSecretKeyOptions, N as NodeSecretKey, f as EncryptOptions, g as DecryptOptions, H as HashOptions, h as HashPasswordOptions, V as VerifyPasswordOptions, c as Encoding } from './validate-lkJAHCeJ.js';
|
|
2
|
-
import { Buffer } from 'node:buffer';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Safely generates a UUID (v4) (non-throwing).
|
|
6
|
-
*
|
|
7
|
-
* ### 🍼 Explain Like I'm Five
|
|
8
|
-
* It's like giving your pet a name tag with a super random name made of numbers and letters.
|
|
9
|
-
* The chance of two pets getting the same name tag is practically zero, and it's very hard to guess!
|
|
10
|
-
*
|
|
11
|
-
* @returns A `Result` containing the UUID string or an error.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const {result, error, success} = tryGenerateUuid();
|
|
16
|
-
*
|
|
17
|
-
* if (success) console.log(result); // "..." (a UUID string)
|
|
18
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare function tryGenerateUuid(): Result<string>;
|
|
22
|
-
/**
|
|
23
|
-
* Generates a UUID (v4) (throwing).
|
|
24
|
-
*
|
|
25
|
-
* ### 🍼 Explain Like I'm Five
|
|
26
|
-
* It's like giving your pet a name tag with a super random name made of numbers and letters.
|
|
27
|
-
* The chance of two pets getting the same name tag is practically zero, and it's very hard to guess!
|
|
28
|
-
*
|
|
29
|
-
* @returns A UUID string.
|
|
30
|
-
* @throws {Error} If UUID generation fails.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const uuid = generateUuid(); // "..." (a UUID string)
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
declare function generateUuid(): string;
|
|
38
|
-
/**
|
|
39
|
-
* Safely derives a `SecretKey` from the provided string for encryption/decryption (non-throwing).
|
|
40
|
-
*
|
|
41
|
-
* Uses HKDF to derive a key from the input string.
|
|
42
|
-
*
|
|
43
|
-
* ### 🍼 Explain Like I'm Five
|
|
44
|
-
* Imagine you want to create a special key for future use to lock your treasure box (data).
|
|
45
|
-
* So, you stir in some secret ingredients (like salt and info) to make sure your key is one-of-a-kind.
|
|
46
|
-
*
|
|
47
|
-
* @param secret - The input string to derive the `SecretKey` from, must be at least 8 characters.
|
|
48
|
-
* @param options.algorithm - The encryption algorithm to use (default: `'aes256gcm'`).
|
|
49
|
-
* @param options.digest - The hash algorithm for HKDF (default: `'sha256'`).
|
|
50
|
-
* @param options.salt - A salt string (default: `'cipher-kit-salt'`, must be ≥ 8 chars).
|
|
51
|
-
* @param options.info - An info string (default: `'cipher-kit'`).
|
|
52
|
-
* @returns A `Result` containing the derived `SecretKey` or an error.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* const {result, error, success} = tryCreateSecretKey("my-secret");
|
|
57
|
-
*
|
|
58
|
-
* if (success) console.log(result); // SecretKey object
|
|
59
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function tryCreateSecretKey(secret: string, options?: CreateSecretKeyOptions): Result<{
|
|
63
|
-
result: NodeSecretKey;
|
|
64
|
-
}>;
|
|
65
|
-
/**
|
|
66
|
-
* Derives a `SecretKey` from the provided string for encryption/decryption (throwing).
|
|
67
|
-
*
|
|
68
|
-
* Uses HKDF to derive a key from the input string.
|
|
69
|
-
*
|
|
70
|
-
* ### 🍼 Explain Like I'm Five
|
|
71
|
-
* Imagine you want to create a special key for future use to lock your treasure box (data).
|
|
72
|
-
* So, you stir in some secret ingredients (like salt and info) to make sure your key is one-of-a-kind.
|
|
73
|
-
*
|
|
74
|
-
* @param secret - The input string to derive the `SecretKey` from, must be at least 8 characters.
|
|
75
|
-
* @param options.algorithm - The encryption algorithm to use (default: `'aes256gcm'`).
|
|
76
|
-
* @param options.digest - The hash algorithm for HKDF (default: `'sha256'`).
|
|
77
|
-
* @param options.salt - A salt string (default: `'cipher-kit-salt'`, must be ≥ 8 chars).
|
|
78
|
-
* @param options.info - An info string (default: `'cipher-kit'`).
|
|
79
|
-
* @returns The derived `SecretKey`.
|
|
80
|
-
* @throws {Error} If key derivation fails.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* const secretKey = createSecretKey("my-secret"); // SecretKey object
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
declare function createSecretKey(secret: string, options?: CreateSecretKeyOptions): NodeSecretKey;
|
|
88
|
-
/**
|
|
89
|
-
* Safely encrypts a UTF-8 string using the provided `SecretKey` (non-throwing).
|
|
90
|
-
*
|
|
91
|
-
* Output format: "iv.cipher.tag."
|
|
92
|
-
*
|
|
93
|
-
* ### 🍼 Explain Like I'm Five
|
|
94
|
-
* You scramble a secret message with your special key,
|
|
95
|
-
* creating a jumbled code that only someone with the right key can read.
|
|
96
|
-
*
|
|
97
|
-
* @param data - A UTF-8 string to encrypt.
|
|
98
|
-
* @param secretKey - The `SecretKey` object used for encryption.
|
|
99
|
-
* @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).
|
|
100
|
-
* @returns A `Result` containing the encrypted string in the specified format or an error.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* const secretKey = createSecretKey("my-secret");
|
|
105
|
-
* const {result, error, success} = tryEncrypt("Hello, World!", secretKey);
|
|
106
|
-
*
|
|
107
|
-
* if (success) console.log(result); // "iv.cipher.tag." (Encrypted string)
|
|
108
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
declare function tryEncrypt(data: string, secretKey: NodeSecretKey, options?: EncryptOptions): Result<string>;
|
|
112
|
-
/**
|
|
113
|
-
* Encrypts a UTF-8 string using the provided `SecretKey` (throwing).
|
|
114
|
-
*
|
|
115
|
-
* Output format: "iv.cipher.tag."
|
|
116
|
-
*
|
|
117
|
-
* ### 🍼 Explain Like I'm Five
|
|
118
|
-
* You scramble a secret message with your special key,
|
|
119
|
-
* creating a jumbled code that only someone with the right key can read.
|
|
120
|
-
*
|
|
121
|
-
* @param data - A UTF-8 string to encrypt.
|
|
122
|
-
* @param secretKey - The `SecretKey` object used for encryption.
|
|
123
|
-
* @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).
|
|
124
|
-
* @returns The encrypted string in the specified format.
|
|
125
|
-
* @throws {Error} If the input data or key is invalid, or if encryption fails.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```ts
|
|
129
|
-
* const secretKey = createSecretKey("my-secret");
|
|
130
|
-
* const encrypted = encrypt("Hello, World!", secretKey); // "iv.cipher.tag." (Encrypted string)
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
declare function encrypt(data: string, secretKey: NodeSecretKey, options?: EncryptOptions): string;
|
|
134
|
-
/**
|
|
135
|
-
* Safely decrypts the input string using the provided `SecretKey` (non-throwing).
|
|
136
|
-
*
|
|
137
|
-
* Expects input in the format "iv.cipher.tag." and returns the decrypted UTF-8 string.
|
|
138
|
-
*
|
|
139
|
-
* ### 🍼 Explain Like I'm Five
|
|
140
|
-
* You take a scrambled secret message and use your special key to unscramble it,
|
|
141
|
-
* revealing the original message inside.
|
|
142
|
-
*
|
|
143
|
-
* @param encrypted - The input string to decrypt, in the format "iv.cipher.tag.".
|
|
144
|
-
* @param secretKey - The `SecretKey` object used for decryption.
|
|
145
|
-
* @param options.inputEncoding - The encoding format for the input ciphertext (default: `'base64url'`).
|
|
146
|
-
* @returns A `Result` containing the decrypted UTF-8 string or an error.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```ts
|
|
150
|
-
* const secretKey = createSecretKey("my-secret");
|
|
151
|
-
* const encrypted = encrypt("Hello, World!", secretKey);
|
|
152
|
-
* const {result, error, success} = tryDecrypt(encrypted, secretKey);
|
|
153
|
-
*
|
|
154
|
-
* if (success) console.log(result); // "Hello, World!" (Decrypted string)
|
|
155
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
declare function tryDecrypt(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): Result<string>;
|
|
159
|
-
/**
|
|
160
|
-
* Decrypts the input string using the provided `SecretKey` (throwing).
|
|
161
|
-
*
|
|
162
|
-
* Expects input in the format "iv.cipher.tag." and returns the decrypted UTF-8 string.
|
|
163
|
-
*
|
|
164
|
-
* ### 🍼 Explain Like I'm Five
|
|
165
|
-
* You take a scrambled secret message and use your special key to unscramble it,
|
|
166
|
-
* revealing the original message inside.
|
|
167
|
-
*
|
|
168
|
-
* @param encrypted - The input string to decrypt, in the format "iv.cipher.tag.".
|
|
169
|
-
* @param secretKey - The `SecretKey` object used for decryption.
|
|
170
|
-
* @param options.inputEncoding - The encoding format for the input ciphertext (default: `'base64url'`).
|
|
171
|
-
* @returns The decrypted UTF-8 string.
|
|
172
|
-
* @throws {Error} If the input data or key is invalid, or if decryption fails.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* const secretKey = createSecretKey("my-secret");
|
|
177
|
-
* const encrypted = encrypt("Hello, World!", secretKey);
|
|
178
|
-
* const decrypted = decrypt(encrypted, secretKey); // "Hello, World!" (Decrypted string)
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
declare function decrypt(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): string;
|
|
182
|
-
/**
|
|
183
|
-
* Safely encrypts a plain object using the provided `SecretKey` (non-throwing).
|
|
184
|
-
*
|
|
185
|
-
* Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.
|
|
186
|
-
*
|
|
187
|
-
* Output format: "iv.cipher.tag."
|
|
188
|
-
*
|
|
189
|
-
* ### 🍼 Explain Like I'm Five
|
|
190
|
-
* Imagine you have a toy box (an object) that you want to keep secret.
|
|
191
|
-
* So, you take a picture of your toy box (convert it to JSON), and scramble that with
|
|
192
|
-
* your special key, creating a jumbled code that only someone with the right key can read.
|
|
193
|
-
*
|
|
194
|
-
* @template T - The type of the plain object to encrypt.
|
|
195
|
-
* @param obj - A plain object to encrypt.
|
|
196
|
-
* @param secretKey - The `SecretKey` object used for encryption.
|
|
197
|
-
* @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).
|
|
198
|
-
* @returns A `Result` containing the encrypted string in the specified format or an error.
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```ts
|
|
202
|
-
* const secretKey = createSecretKey("my-secret");
|
|
203
|
-
* const {result, error, success} = tryEncryptObj({ a: 1 }, secretKey);
|
|
204
|
-
*
|
|
205
|
-
* if (success) console.log(result); // "iv.cipher.tag." (Encrypted string)
|
|
206
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
declare function tryEncryptObj<T extends object = Record<string, unknown>>(obj: T, secretKey: NodeSecretKey, options?: EncryptOptions): Result<string>;
|
|
210
|
-
/**
|
|
211
|
-
* Encrypts a plain object using the provided `SecretKey` (throwing).
|
|
212
|
-
*
|
|
213
|
-
* Only plain objects (POJOs) are accepted. Class instances, Maps, Sets, etc. are rejected.
|
|
214
|
-
*
|
|
215
|
-
* Output format: "iv.cipher.tag."
|
|
216
|
-
*
|
|
217
|
-
* ### 🍼 Explain Like I'm Five
|
|
218
|
-
* Imagine you have a toy box (an object) that you want to keep secret.
|
|
219
|
-
* So, you take a picture of your toy box (convert it to JSON), and scramble that with
|
|
220
|
-
* your special key, creating a jumbled code that only someone with the right key can read.
|
|
221
|
-
*
|
|
222
|
-
* @template T - The type of the plain object to encrypt.
|
|
223
|
-
* @param obj - A plain object to encrypt.
|
|
224
|
-
* @param secretKey - The `SecretKey` object used for encryption.
|
|
225
|
-
* @param options.outputEncoding - The encoding format for the output ciphertext (default: `'base64url'`).
|
|
226
|
-
* @returns The encrypted string in the specified format.
|
|
227
|
-
* @throws {Error} If the input data or key is invalid, or if encryption fails.
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```ts
|
|
231
|
-
* const secretKey = createSecretKey("my-secret");
|
|
232
|
-
* const encrypted = encryptObj({ a: 1 }, secretKey); // "iv.cipher.tag." (Encrypted string)
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
declare function encryptObj<T extends object = Record<string, unknown>>(obj: T, secretKey: NodeSecretKey, options?: EncryptOptions): string;
|
|
236
|
-
/**
|
|
237
|
-
* Safely decrypts an encrypted JSON string into a plain object (non-throwing).
|
|
238
|
-
*
|
|
239
|
-
* Expects input in the format `"iv.cipher.tag."` and returns a plain object.
|
|
240
|
-
*
|
|
241
|
-
* ### 🍼 Explain Like I'm Five
|
|
242
|
-
* You rebuild your toy box (an object) by unscrambling the jumbled code (encrypted text),
|
|
243
|
-
* using your special key to open it.
|
|
244
|
-
*
|
|
245
|
-
* @template T - The expected shape of the decrypted object.
|
|
246
|
-
* @param encrypted - The encrypted string (format: `"iv.cipher.tag."`).
|
|
247
|
-
* @param secretKey - The `SecretKey` used for decryption.
|
|
248
|
-
* @param options.inputEncoding - Input ciphertext encoding (default: `'base64url'`).
|
|
249
|
-
* @returns A `Result` with the decrypted object on success, or an error.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* const secretKey = createSecretKey("my-secret");
|
|
254
|
-
* const encrypted = encryptObj({ a: 1 }, secretKey);
|
|
255
|
-
* const {result, error, success} = tryDecryptObj<{ a: number }>(encrypted, secretKey);
|
|
256
|
-
*
|
|
257
|
-
* if (success) console.log(result); // { a: 1 } (Decrypted object)
|
|
258
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
declare function tryDecryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): Result<{
|
|
262
|
-
result: T;
|
|
263
|
-
}>;
|
|
264
|
-
/**
|
|
265
|
-
* Decrypts an encrypted JSON string into a plain object (throwing).
|
|
266
|
-
*
|
|
267
|
-
* Expects input in the format `"iv.cipher.tag."` and returns a plain object.
|
|
268
|
-
*
|
|
269
|
-
* ### 🍼 Explain Like I'm Five
|
|
270
|
-
* You rebuild your toy box (an object) by unscrambling the jumbled code (encrypted text),
|
|
271
|
-
* using your special key to open it.
|
|
272
|
-
*
|
|
273
|
-
* @template T - The expected shape of the decrypted object.
|
|
274
|
-
* @param encrypted - The encrypted string (format: `"iv.cipher.tag."`).
|
|
275
|
-
* @param secretKey - The `SecretKey` used for decryption.
|
|
276
|
-
* @param options.inputEncoding - Input ciphertext encoding (default: `'base64url'`).
|
|
277
|
-
* @returns The decrypted object.
|
|
278
|
-
* @throws {Error} If decryption or JSON parsing fails.
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```ts
|
|
282
|
-
* const secretKey = createSecretKey("my-secret");
|
|
283
|
-
* const encrypted = encryptObj({ a: 1 }, secretKey);
|
|
284
|
-
* const obj = decryptObj<{ a: number }>(encrypted, secretKey); // obj.a === 1
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
declare function decryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): T;
|
|
288
|
-
/**
|
|
289
|
-
* Safely hashes a UTF-8 string (non-throwing).
|
|
290
|
-
*
|
|
291
|
-
* Uses the selected digest (default: `'sha256'`) and returns the hash
|
|
292
|
-
* in the chosen encoding (default: `'base64url'`).
|
|
293
|
-
*
|
|
294
|
-
* ### 🍼 Explain Like I'm Five
|
|
295
|
-
* Like putting something in a blender and getting a smoothie, you can’t get the original ingredients back,
|
|
296
|
-
* but the smoothie is always the same if you use the same ingredients.
|
|
297
|
-
*
|
|
298
|
-
* @param data - The input string to hash.
|
|
299
|
-
* @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`, default: `'sha256'`).
|
|
300
|
-
* @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`, default: `'base64url'`).
|
|
301
|
-
* @returns A `Result` with the hash string or an error.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```ts
|
|
305
|
-
* const {result, error, success} = tryHash("my data");
|
|
306
|
-
*
|
|
307
|
-
* if (success) console.log(result); // "..." (Hashed string)
|
|
308
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
declare function tryHash(data: string, options?: HashOptions): Result<string>;
|
|
312
|
-
/**
|
|
313
|
-
* Hashes a UTF-8 string (throwing).
|
|
314
|
-
*
|
|
315
|
-
* Uses the selected digest (default: `'sha256'`) and returns the hash
|
|
316
|
-
* in the chosen encoding (default: `'base64url'`).
|
|
317
|
-
*
|
|
318
|
-
* ### 🍼 Explain Like I'm Five
|
|
319
|
-
* Like putting something in a blender and getting a smoothie, you can’t get the original ingredients back,
|
|
320
|
-
* but the smoothie is always the same if you use the same ingredients.
|
|
321
|
-
*
|
|
322
|
-
* @param data - The input string to hash.
|
|
323
|
-
* @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha256'`).
|
|
324
|
-
* @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).
|
|
325
|
-
* @returns The hashed string.
|
|
326
|
-
* @throws {Error} If input is invalid or hashing fails.
|
|
327
|
-
*
|
|
328
|
-
* @example
|
|
329
|
-
* ```ts
|
|
330
|
-
* const hash = hash("my data"); // "..." (Hashed string)
|
|
331
|
-
* ```
|
|
332
|
-
*/
|
|
333
|
-
declare function hash(data: string, options?: HashOptions): string;
|
|
334
|
-
/**
|
|
335
|
-
* Safely hashes a password using PBKDF2 (non-throwing).
|
|
336
|
-
*
|
|
337
|
-
* Uses strong defaults (`sha512`, 320k iterations, 64-byte key, 16-byte salt) and
|
|
338
|
-
* returns `{ hash, salt }` encoded (default: `'base64url'`).
|
|
339
|
-
*
|
|
340
|
-
* ### 🍼 Explain Like I'm Five
|
|
341
|
-
* We take your password, mix in some random salt, and stir many times.
|
|
342
|
-
* The result is a super-secret soup that’s hard to copy.
|
|
343
|
-
*
|
|
344
|
-
* @param password - The password to hash.
|
|
345
|
-
* @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).
|
|
346
|
-
* @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).
|
|
347
|
-
* @param options.saltLength - Length of the random salt in bytes (default: `16` bytes, min: `8` bytes).
|
|
348
|
-
* @param options.iterations - Number of iterations (default: `320000`, min: `1000`).
|
|
349
|
-
* @param options.keyLength - Length of the derived key in bytes (default: `64` bytes, min: `16` bytes).
|
|
350
|
-
* @returns A `Result` with `{ result, salt }` or an error.
|
|
351
|
-
*
|
|
352
|
-
* @example
|
|
353
|
-
* ```ts
|
|
354
|
-
* const {result, salt, error, success} = tryHashPassword("my-password");
|
|
355
|
-
*
|
|
356
|
-
* if (success) console.log(result, salt); // "..." (Hashed password string), "..." (salt)
|
|
357
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
358
|
-
* ```
|
|
359
|
-
*/
|
|
360
|
-
declare function tryHashPassword(password: string, options?: HashPasswordOptions): Result<{
|
|
361
|
-
result: string;
|
|
362
|
-
salt: string;
|
|
363
|
-
}>;
|
|
364
|
-
/**
|
|
365
|
-
* Hashes a password using PBKDF2 (throwing).
|
|
366
|
-
*
|
|
367
|
-
* Uses strong defaults (`sha512`, 320k iterations, 64-byte key, 16-byte salt) and
|
|
368
|
-
* returns `{ hash, salt }` encoded (default: `'base64url'`).
|
|
369
|
-
*
|
|
370
|
-
* ### 🍼 Explain Like I'm Five
|
|
371
|
-
* We take your password, mix in some random salt, and stir many times.
|
|
372
|
-
* The result is a super-secret soup that’s hard to copy.
|
|
373
|
-
*
|
|
374
|
-
* @param password - The password to hash.
|
|
375
|
-
* @param options.digest - Hash algorithm (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).
|
|
376
|
-
* @param options.outputEncoding - Output encoding (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).
|
|
377
|
-
* @param options.saltLength - Length of the random salt in bytes (default: `16` bytes, min: `8` bytes).
|
|
378
|
-
* @param options.iterations - Number of iterations (default: `320000`, min: `1000`).
|
|
379
|
-
* @param options.keyLength - Length of the derived key in bytes (default: `64` bytes, min: `16` bytes).
|
|
380
|
-
* @returns `{ result, salt }` for storage.
|
|
381
|
-
* @throws {Error} If inputs are invalid or hashing fails.
|
|
382
|
-
*
|
|
383
|
-
* @example
|
|
384
|
-
* ```ts
|
|
385
|
-
* const { result, salt } = hashPassword("my-password"); // "..." (Hashed password string), "..." (salt)
|
|
386
|
-
* ```
|
|
387
|
-
*/
|
|
388
|
-
declare function hashPassword(password: string, options?: HashPasswordOptions): {
|
|
389
|
-
result: string;
|
|
390
|
-
salt: string;
|
|
391
|
-
};
|
|
392
|
-
/**
|
|
393
|
-
* Verifies a password against a stored PBKDF2 hash (non-throwing).
|
|
394
|
-
*
|
|
395
|
-
* Re-derives the key using the same parameters and compares in constant time, to prevent timing attacks.
|
|
396
|
-
*
|
|
397
|
-
* ### 🍼 Explain Like I'm Five
|
|
398
|
-
* We follow the same recipe as when we made the secret.
|
|
399
|
-
* If the new soup tastes exactly the same, the password is correct.
|
|
400
|
-
*
|
|
401
|
-
* @param password - The plain password to verify.
|
|
402
|
-
* @param hashedPassword - The stored hash (encoded).
|
|
403
|
-
* @param salt - The stored salt (encoded).
|
|
404
|
-
* @param options.digest - Hash algorithm used during hashing (`'sha256' | 'sha384' | 'sha512'`; default: `'sha512'`).
|
|
405
|
-
* @param options.inputEncoding - Encoding of the stored hash and salt (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`).
|
|
406
|
-
* @param options.iterations - Number of iterations used during hashing (default: `320000`).
|
|
407
|
-
* @param options.keyLength - Length of the derived key in bytes used during hashing (default: `64` bytes).
|
|
408
|
-
* @returns `true` if the password matches, otherwise `false`.
|
|
409
|
-
*
|
|
410
|
-
* @example
|
|
411
|
-
* ```ts
|
|
412
|
-
* const { result, salt } = hashPassword("my-password");
|
|
413
|
-
*
|
|
414
|
-
* verifyPassword("my-password", result, salt); // true
|
|
415
|
-
* verifyPassword("wrong-password", result, salt); // false
|
|
416
|
-
* ```
|
|
417
|
-
*/
|
|
418
|
-
declare function verifyPassword(password: string, hashedPassword: string, salt: string, options?: VerifyPasswordOptions): boolean;
|
|
419
|
-
/**
|
|
420
|
-
* Safely converts a string to a Node.js `Buffer` using the specified encoding (non-throwing).
|
|
421
|
-
*
|
|
422
|
-
* Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).
|
|
423
|
-
*
|
|
424
|
-
* ### 🍼 Explain Like I'm Five
|
|
425
|
-
* This turns your words into tiny computer building blocks (bytes) so computers can work with them.
|
|
426
|
-
*
|
|
427
|
-
* @param data - The input string to convert.
|
|
428
|
-
* @param inputEncoding - The encoding of the input string (default: `'utf8'`).
|
|
429
|
-
* @returns A `Result` with `{ result: Buffer }` or an error.
|
|
430
|
-
*
|
|
431
|
-
* @example
|
|
432
|
-
* ```ts
|
|
433
|
-
* const {result, error, success} = tryConvertStrToBytes("Hello", "utf8");
|
|
434
|
-
*
|
|
435
|
-
* if (success) console.log(result); // <Buffer ...>
|
|
436
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
437
|
-
* ```
|
|
438
|
-
*/
|
|
439
|
-
declare function tryConvertStrToBytes(data: string, inputEncoding?: Encoding): Result<{
|
|
440
|
-
result: Buffer;
|
|
441
|
-
}>;
|
|
442
|
-
/**
|
|
443
|
-
* Converts a string to a Node.js `Buffer` using the specified encoding (throwing).
|
|
444
|
-
*
|
|
445
|
-
* Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).
|
|
446
|
-
*
|
|
447
|
-
* ### 🍼 Explain Like I'm Five
|
|
448
|
-
* This turns your words into tiny computer building blocks (bytes) so computers can work with them.
|
|
449
|
-
*
|
|
450
|
-
* @param data - The input string to convert.
|
|
451
|
-
* @param inputEncoding - The encoding of the input string (default: `'utf8'`).
|
|
452
|
-
* @returns A `Buffer` containing the bytes.
|
|
453
|
-
* @throws {Error} If input is invalid or conversion fails.
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* ```ts
|
|
457
|
-
* const bytes = convertStrToBytes("Hello", "utf8"); // <Buffer ...>
|
|
458
|
-
* ```
|
|
459
|
-
*/
|
|
460
|
-
declare function convertStrToBytes(data: string, inputEncoding?: Encoding): Buffer;
|
|
461
|
-
/**
|
|
462
|
-
* Safely converts a Node.js `Buffer` to a string using the specified encoding (non-throwing).
|
|
463
|
-
*
|
|
464
|
-
* Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).
|
|
465
|
-
*
|
|
466
|
-
* ### 🍼 Explain Like I'm Five
|
|
467
|
-
* This turns the tiny computer building blocks (bytes) back into a readable sentence.
|
|
468
|
-
*
|
|
469
|
-
* @param data - The `Buffer` to convert.
|
|
470
|
-
* @param outputEncoding - The output encoding (default: `'utf8'`).
|
|
471
|
-
* @returns A `Result` with the string or an error.
|
|
472
|
-
*
|
|
473
|
-
* @example
|
|
474
|
-
* ```ts
|
|
475
|
-
* const bytes = convertStrToBytes("Hello", "utf8"); // <Buffer ...>
|
|
476
|
-
* const {result, error, success} = tryConvertBytesToStr(bytes, "utf8");
|
|
477
|
-
*
|
|
478
|
-
* if (success) console.log(result); // "Hello"
|
|
479
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
480
|
-
* ```
|
|
481
|
-
*/
|
|
482
|
-
declare function tryConvertBytesToStr(data: Buffer, outputEncoding?: Encoding): Result<string>;
|
|
483
|
-
/**
|
|
484
|
-
* Converts a Node.js `Buffer` to a string using the specified encoding (throwing).
|
|
485
|
-
*
|
|
486
|
-
* Supported encodings: `'base64' | 'base64url' | 'hex' | 'utf8' | 'latin1'` (default: `'utf8'`).
|
|
487
|
-
*
|
|
488
|
-
* ### 🍼 Explain Like I'm Five
|
|
489
|
-
* This turns the tiny computer building blocks (bytes) back into a readable sentence.
|
|
490
|
-
*
|
|
491
|
-
* @param data - The `Buffer` to convert.
|
|
492
|
-
* @param outputEncoding - The output encoding (default: `'utf8'`).
|
|
493
|
-
* @returns The encoded string.
|
|
494
|
-
* @throws {Error} If input is invalid or conversion fails.
|
|
495
|
-
*
|
|
496
|
-
* @example
|
|
497
|
-
* ```ts
|
|
498
|
-
* const bytes = convertStrToBytes("Hello", "utf8"); // <Buffer ...>
|
|
499
|
-
* const str = convertBytesToStr(bytes, "utf8"); // "Hello"
|
|
500
|
-
* ```
|
|
501
|
-
*/
|
|
502
|
-
declare function convertBytesToStr(data: Buffer, outputEncoding?: Encoding): string;
|
|
503
|
-
/**
|
|
504
|
-
* Safely converts text between encodings (non-throwing).
|
|
505
|
-
*
|
|
506
|
-
* Example: convert `'utf8'` text to `'base64url'`, or `'hex'` to `'utf8'`.
|
|
507
|
-
*
|
|
508
|
-
* ### 🍼 Explain Like I'm Five
|
|
509
|
-
* It’s like translating your sentence from one alphabet to another.
|
|
510
|
-
*
|
|
511
|
-
* @param data - The input string to convert.
|
|
512
|
-
* @param from - The current encoding of `data`.
|
|
513
|
-
* @param to - The target encoding for `data`.
|
|
514
|
-
* @returns A `Result` with a string or an error.
|
|
515
|
-
*
|
|
516
|
-
* @example
|
|
517
|
-
* ```ts
|
|
518
|
-
* const {result, error, success} = tryConvertEncoding("Hello", "utf8", "base64url");
|
|
519
|
-
*
|
|
520
|
-
* if (success) console.log(result); // "..." (Base64url encoded string)
|
|
521
|
-
* else console.error(error); // { message: "...", description: "..." }
|
|
522
|
-
* ```
|
|
523
|
-
*/
|
|
524
|
-
declare function tryConvertEncoding(data: string, from: Encoding, to: Encoding): Result<string>;
|
|
525
|
-
/**
|
|
526
|
-
* Converts text between encodings (throwing).
|
|
527
|
-
*
|
|
528
|
-
* Example: convert `'utf8'` text to `'base64url'`, or `'hex'` to `'utf8'`.
|
|
529
|
-
*
|
|
530
|
-
* ### 🍼 Explain Like I'm Five
|
|
531
|
-
* It’s like translating your sentence from one alphabet to another.
|
|
532
|
-
*
|
|
533
|
-
* @param data - The input string to convert.
|
|
534
|
-
* @param from - The current encoding of `data`.
|
|
535
|
-
* @param to - The target encoding for `data`.
|
|
536
|
-
* @returns The converted string.
|
|
537
|
-
* @throws {Error} If encodings are invalid or conversion fails.
|
|
538
|
-
*
|
|
539
|
-
* @example
|
|
540
|
-
* ```ts
|
|
541
|
-
* const encoded = convertEncoding("Hello", "utf8", "base64url"); // "..." (Base64url encoded string)
|
|
542
|
-
* ```
|
|
543
|
-
*/
|
|
544
|
-
declare function convertEncoding(data: string, from: Encoding, to: Encoding): string;
|
|
545
|
-
|
|
546
|
-
declare const nodeCryptoKit_convertBytesToStr: typeof convertBytesToStr;
|
|
547
|
-
declare const nodeCryptoKit_convertEncoding: typeof convertEncoding;
|
|
548
|
-
declare const nodeCryptoKit_convertStrToBytes: typeof convertStrToBytes;
|
|
549
|
-
declare const nodeCryptoKit_createSecretKey: typeof createSecretKey;
|
|
550
|
-
declare const nodeCryptoKit_decrypt: typeof decrypt;
|
|
551
|
-
declare const nodeCryptoKit_decryptObj: typeof decryptObj;
|
|
552
|
-
declare const nodeCryptoKit_encrypt: typeof encrypt;
|
|
553
|
-
declare const nodeCryptoKit_encryptObj: typeof encryptObj;
|
|
554
|
-
declare const nodeCryptoKit_generateUuid: typeof generateUuid;
|
|
555
|
-
declare const nodeCryptoKit_hash: typeof hash;
|
|
556
|
-
declare const nodeCryptoKit_hashPassword: typeof hashPassword;
|
|
557
|
-
declare const nodeCryptoKit_tryConvertBytesToStr: typeof tryConvertBytesToStr;
|
|
558
|
-
declare const nodeCryptoKit_tryConvertEncoding: typeof tryConvertEncoding;
|
|
559
|
-
declare const nodeCryptoKit_tryConvertStrToBytes: typeof tryConvertStrToBytes;
|
|
560
|
-
declare const nodeCryptoKit_tryCreateSecretKey: typeof tryCreateSecretKey;
|
|
561
|
-
declare const nodeCryptoKit_tryDecrypt: typeof tryDecrypt;
|
|
562
|
-
declare const nodeCryptoKit_tryDecryptObj: typeof tryDecryptObj;
|
|
563
|
-
declare const nodeCryptoKit_tryEncrypt: typeof tryEncrypt;
|
|
564
|
-
declare const nodeCryptoKit_tryEncryptObj: typeof tryEncryptObj;
|
|
565
|
-
declare const nodeCryptoKit_tryGenerateUuid: typeof tryGenerateUuid;
|
|
566
|
-
declare const nodeCryptoKit_tryHash: typeof tryHash;
|
|
567
|
-
declare const nodeCryptoKit_tryHashPassword: typeof tryHashPassword;
|
|
568
|
-
declare const nodeCryptoKit_verifyPassword: typeof verifyPassword;
|
|
569
|
-
declare namespace nodeCryptoKit {
|
|
570
|
-
export { nodeCryptoKit_convertBytesToStr as convertBytesToStr, nodeCryptoKit_convertEncoding as convertEncoding, nodeCryptoKit_convertStrToBytes as convertStrToBytes, nodeCryptoKit_createSecretKey as createSecretKey, nodeCryptoKit_decrypt as decrypt, nodeCryptoKit_decryptObj as decryptObj, nodeCryptoKit_encrypt as encrypt, nodeCryptoKit_encryptObj as encryptObj, nodeCryptoKit_generateUuid as generateUuid, nodeCryptoKit_hash as hash, nodeCryptoKit_hashPassword as hashPassword, nodeCryptoKit_tryConvertBytesToStr as tryConvertBytesToStr, nodeCryptoKit_tryConvertEncoding as tryConvertEncoding, nodeCryptoKit_tryConvertStrToBytes as tryConvertStrToBytes, nodeCryptoKit_tryCreateSecretKey as tryCreateSecretKey, nodeCryptoKit_tryDecrypt as tryDecrypt, nodeCryptoKit_tryDecryptObj as tryDecryptObj, nodeCryptoKit_tryEncrypt as tryEncrypt, nodeCryptoKit_tryEncryptObj as tryEncryptObj, nodeCryptoKit_tryGenerateUuid as tryGenerateUuid, nodeCryptoKit_tryHash as tryHash, nodeCryptoKit_tryHashPassword as tryHashPassword, nodeCryptoKit_verifyPassword as verifyPassword };
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
export { tryCreateSecretKey as a, tryEncrypt as b, createSecretKey as c, tryDecrypt as d, encrypt as e, decrypt as f, generateUuid as g, tryEncryptObj as h, encryptObj as i, tryDecryptObj as j, decryptObj as k, tryHash as l, hash as m, nodeCryptoKit as n, tryHashPassword as o, hashPassword as p, tryConvertStrToBytes as q, convertStrToBytes as r, tryConvertBytesToStr as s, tryGenerateUuid as t, convertBytesToStr as u, verifyPassword as v, tryConvertEncoding as w, convertEncoding as x };
|