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