wilcocrypt 2.1.1 → 2.2.1
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/.github/ISSUE_TEMPLATE/bug.md +72 -0
- package/.github/ISSUE_TEMPLATE/config.yml +6 -0
- package/.github/ISSUE_TEMPLATE/feature.yml +38 -0
- package/.github/dependabot.yml +11 -0
- package/CHANGELOG.md +100 -0
- package/DOCS.md +527 -0
- package/README.md +61 -65
- package/SECURITY.md +48 -0
- package/package.json +14 -8
- package/src/cli.js +57 -37
- package/src/wilcocrypt.js +429 -102
- package/types/wilcocrypt.d.ts +309 -24
package/types/wilcocrypt.d.ts
CHANGED
|
@@ -1,72 +1,357 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for all WilcoCrypt-specific errors.
|
|
5
|
+
*/
|
|
3
6
|
export class WilcoCryptError extends Error {
|
|
4
7
|
code: string;
|
|
5
|
-
constructor(message: string, code?: string);
|
|
6
|
-
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
version: string;
|
|
9
|
+
/**
|
|
10
|
+
* @param message Human-readable error message
|
|
11
|
+
* @param code Machine-readable error code (default: WILCOCRYPT_ERROR)
|
|
12
|
+
*/
|
|
13
|
+
constructor(message: string, code?: string);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Internal helper namespace used by WilcoCrypt.
|
|
18
|
+
*/
|
|
16
19
|
export interface InternalNamespace {
|
|
20
|
+
/**
|
|
21
|
+
* WilcoCrypt version (must match during decryption).
|
|
22
|
+
*/
|
|
17
23
|
VERSION: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Minimum allowed password length.
|
|
27
|
+
*/
|
|
18
28
|
MIN_PASSWORD_LENGTH: number;
|
|
19
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Internal header used to identify valid WilcoCrypt payloads.
|
|
32
|
+
*/
|
|
33
|
+
HEADER: Buffer;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Internal error class used by WilcoCrypt.
|
|
37
|
+
*/
|
|
20
38
|
WilcoCryptError: typeof WilcoCryptError;
|
|
21
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Validates AES-256-GCM key and IV.
|
|
42
|
+
*
|
|
43
|
+
* @param key AES-256 encryption key (32-byte Buffer)
|
|
44
|
+
* @param iv GCM initialization vector (12-byte Buffer)
|
|
45
|
+
*
|
|
46
|
+
* @throws WilcoCryptError
|
|
47
|
+
*/
|
|
22
48
|
assertKeyAndIv(key: Buffer, iv: Buffer): void;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Validates password strength.
|
|
52
|
+
*
|
|
53
|
+
* @param password Password to validate
|
|
54
|
+
*
|
|
55
|
+
* @throws WilcoCryptError
|
|
56
|
+
*/
|
|
23
57
|
assertPassword(password: string): void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Constant-time buffer comparison.
|
|
61
|
+
* Reserved for future extensions.
|
|
62
|
+
*
|
|
63
|
+
* @param a First buffer
|
|
64
|
+
* @param b Second buffer
|
|
65
|
+
* @returns True if both buffers are identical
|
|
66
|
+
*/
|
|
24
67
|
constantTimeEqual(a: Buffer, b: Buffer): boolean;
|
|
25
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Encrypts raw data using AES-256-GCM.
|
|
71
|
+
*
|
|
72
|
+
* @param plainData Raw data to encrypt
|
|
73
|
+
* @param key AES-256 encryption key
|
|
74
|
+
* @param iv GCM initialization vector
|
|
75
|
+
* @returns Ciphertext and authentication tag
|
|
76
|
+
*/
|
|
26
77
|
encryptData(
|
|
27
78
|
plainData: Buffer,
|
|
28
79
|
key: Buffer,
|
|
29
|
-
iv: Buffer
|
|
80
|
+
iv: Buffer,
|
|
30
81
|
): {
|
|
31
82
|
ciphertext: Buffer;
|
|
32
83
|
authTag: Buffer;
|
|
33
84
|
};
|
|
34
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Decrypts AES-256-GCM encrypted data.
|
|
88
|
+
*
|
|
89
|
+
* @param cipherBuffer Encrypted ciphertext
|
|
90
|
+
* @param authTagBuffer AES-GCM authentication tag
|
|
91
|
+
* @param key AES-256 encryption key
|
|
92
|
+
* @param iv GCM initialization vector
|
|
93
|
+
* @returns Decrypted raw data
|
|
94
|
+
*
|
|
95
|
+
* @throws WilcoCryptError
|
|
96
|
+
*/
|
|
35
97
|
decryptData(
|
|
36
|
-
|
|
37
|
-
|
|
98
|
+
cipherBuffer: Buffer,
|
|
99
|
+
authTagBuffer: Buffer,
|
|
38
100
|
key: Buffer,
|
|
39
|
-
iv: Buffer
|
|
101
|
+
iv: Buffer,
|
|
40
102
|
): Buffer;
|
|
41
103
|
}
|
|
42
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Main WilcoCrypt API.
|
|
107
|
+
*/
|
|
43
108
|
export interface WilcoCrypt {
|
|
44
109
|
_: InternalNamespace;
|
|
45
110
|
|
|
46
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Encrypts data using password-based AES-256-GCM.
|
|
113
|
+
*
|
|
114
|
+
* Output format:
|
|
115
|
+
* [HEADER (10 bytes)] + [VERSION (dynamic)] + [salt (16)] + [iv (12)] + [ciphertext] + [authTag (16)]
|
|
116
|
+
*
|
|
117
|
+
* @param plaindata Raw data to encrypt
|
|
118
|
+
* @param password Password used for key derivation
|
|
119
|
+
* @param gzip Whether to compress data before encryption (default: true)
|
|
120
|
+
* @returns Binary-encoded encrypted payload
|
|
121
|
+
*
|
|
122
|
+
* @throws WilcoCryptError If password is invalid
|
|
123
|
+
*/
|
|
124
|
+
encryptData(plaindata: Buffer, password: string, gzip?: boolean): Buffer;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Decrypts encrypted data using password-based AES-256-GCM.
|
|
128
|
+
*
|
|
129
|
+
* Validates internal header and version, then extracts:
|
|
130
|
+
* salt, iv, authTag and ciphertext from the binary payload.
|
|
131
|
+
*
|
|
132
|
+
* @param encryptedData Binary-encoded encrypted payload
|
|
133
|
+
* @param password Password used for decryption
|
|
134
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
135
|
+
* @returns Decrypted raw data
|
|
136
|
+
*
|
|
137
|
+
* @throws WilcoCryptError on:
|
|
138
|
+
* - invalid header
|
|
139
|
+
* - version mismatch
|
|
140
|
+
* - wrong password
|
|
141
|
+
* - corrupted data
|
|
142
|
+
*/
|
|
143
|
+
decryptData(encryptedData: Buffer, password: string, gzip?: boolean): Buffer;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Encrypts a file and writes the result to `<filePath>.enc`.
|
|
147
|
+
*
|
|
148
|
+
* @param filePath Path to the file to encrypt
|
|
149
|
+
* @param password Password used for encryption
|
|
150
|
+
* @param gzip Whether to compress before encryption (default: true)
|
|
151
|
+
*
|
|
152
|
+
* @throws WilcoCryptError If password is invalid
|
|
153
|
+
*/
|
|
154
|
+
encryptFile(filePath: string, password: string, gzip?: boolean): void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Decrypts an encrypted `.enc` file.
|
|
158
|
+
*
|
|
159
|
+
* If `outputPath` is provided, the decrypted data is written to that file
|
|
160
|
+
* and `undefined` is returned. Otherwise the decrypted Buffer is returned.
|
|
161
|
+
*
|
|
162
|
+
* @param filePath Path to the `.enc` file
|
|
163
|
+
* @param password Password used for decryption
|
|
164
|
+
* @param outputPath Optional path to write decrypted output to.
|
|
165
|
+
* If omitted, the function returns the decrypted Buffer instead.
|
|
166
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
167
|
+
* @returns Undefined when outputPath is provided
|
|
168
|
+
*
|
|
169
|
+
* @throws WilcoCryptError on:
|
|
170
|
+
* - invalid file extension
|
|
171
|
+
* - invalid header
|
|
172
|
+
* - version mismatch
|
|
173
|
+
* - wrong password
|
|
174
|
+
* - corrupted data
|
|
175
|
+
*/
|
|
176
|
+
decryptFile(
|
|
177
|
+
filePath: string,
|
|
178
|
+
password: string,
|
|
179
|
+
outputPath: string,
|
|
180
|
+
gzip?: boolean,
|
|
181
|
+
): undefined;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Decrypts an encrypted `.enc` file.
|
|
185
|
+
*
|
|
186
|
+
* If `outputPath` is omitted, the decrypted Buffer is returned.
|
|
187
|
+
*
|
|
188
|
+
* @param filePath Path to the `.enc` file
|
|
189
|
+
* @param password Password used for decryption
|
|
190
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
191
|
+
* @returns Decrypted file contents
|
|
192
|
+
*
|
|
193
|
+
* @throws WilcoCryptError on:
|
|
194
|
+
* - invalid file extension
|
|
195
|
+
* - invalid header
|
|
196
|
+
* - version mismatch
|
|
197
|
+
* - wrong password
|
|
198
|
+
* - corrupted data
|
|
199
|
+
*/
|
|
200
|
+
decryptFile(filePath: string, password: string, gzip?: boolean): Buffer;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Encrypts data asynchronously using password-based AES-256-GCM.
|
|
204
|
+
*
|
|
205
|
+
* Output format:
|
|
206
|
+
* [HEADER (10 bytes)] + [VERSION (dynamic)] + [salt (16)] + [iv (12)] + [ciphertext] + [authTag (16)]
|
|
207
|
+
*
|
|
208
|
+
* @param plaindata Raw data to encrypt
|
|
209
|
+
* @param password Password used for key derivation
|
|
210
|
+
* @param gzip Whether to compress data before encryption (default: true)
|
|
211
|
+
* @returns Binary-encoded encrypted payload
|
|
212
|
+
*
|
|
213
|
+
* @throws WilcoCryptError If password is invalid
|
|
214
|
+
*/
|
|
215
|
+
encryptDataAsync(
|
|
47
216
|
plaindata: Buffer,
|
|
48
217
|
password: string,
|
|
49
|
-
gzip?: boolean
|
|
50
|
-
): Buffer
|
|
218
|
+
gzip?: boolean,
|
|
219
|
+
): Promise<Buffer>;
|
|
51
220
|
|
|
52
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Decrypts encrypted data asynchronously using password-based AES-256-GCM.
|
|
223
|
+
*
|
|
224
|
+
* Validates internal header and version, then extracts:
|
|
225
|
+
* salt, iv, authTag and ciphertext from the binary payload.
|
|
226
|
+
*
|
|
227
|
+
* @param encryptedData Binary-encoded encrypted payload
|
|
228
|
+
* @param password Password used for decryption
|
|
229
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
230
|
+
* @returns Decrypted raw data
|
|
231
|
+
*
|
|
232
|
+
* @throws WilcoCryptError on:
|
|
233
|
+
* - invalid header
|
|
234
|
+
* - version mismatch
|
|
235
|
+
* - wrong password
|
|
236
|
+
* - corrupted data
|
|
237
|
+
*/
|
|
238
|
+
decryptDataAsync(
|
|
53
239
|
encryptedData: Buffer,
|
|
54
240
|
password: string,
|
|
55
|
-
gzip?: boolean
|
|
56
|
-
): Buffer
|
|
241
|
+
gzip?: boolean,
|
|
242
|
+
): Promise<Buffer>;
|
|
57
243
|
|
|
58
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Encrypts a file asynchronously and writes the result to `<filePath>.enc`.
|
|
246
|
+
*
|
|
247
|
+
* @param filePath Path to the file to encrypt
|
|
248
|
+
* @param password Password used for encryption
|
|
249
|
+
* @param gzip Whether to compress before encryption (default: true)
|
|
250
|
+
*
|
|
251
|
+
* @throws WilcoCryptError If password is invalid
|
|
252
|
+
*/
|
|
253
|
+
encryptFileAsync(
|
|
59
254
|
filePath: string,
|
|
60
255
|
password: string,
|
|
61
|
-
gzip?: boolean
|
|
62
|
-
): void
|
|
256
|
+
gzip?: boolean,
|
|
257
|
+
): Promise<void>;
|
|
63
258
|
|
|
64
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Decrypts a `.enc` file asynchronously.
|
|
261
|
+
*
|
|
262
|
+
* If `outputPath` is provided, the decrypted data is written to that file
|
|
263
|
+
* and `undefined` is returned. Otherwise the decrypted Buffer is returned.
|
|
264
|
+
*
|
|
265
|
+
* @param filePath Path to the `.enc` file
|
|
266
|
+
* @param password Password used for decryption
|
|
267
|
+
* @param outputPath Optional path to write decrypted output to
|
|
268
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
269
|
+
* @returns Undefined when outputPath is provided
|
|
270
|
+
*
|
|
271
|
+
* @throws WilcoCryptError on:
|
|
272
|
+
* - invalid file extension
|
|
273
|
+
* - invalid header
|
|
274
|
+
* - version mismatch
|
|
275
|
+
* - wrong password
|
|
276
|
+
* - corrupted data
|
|
277
|
+
*/
|
|
278
|
+
decryptFileAsync(
|
|
65
279
|
filePath: string,
|
|
66
280
|
password: string,
|
|
67
|
-
|
|
68
|
-
|
|
281
|
+
outputPath: string,
|
|
282
|
+
gzip?: boolean,
|
|
283
|
+
): Promise<undefined>;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Decrypts an encrypted `.enc` file asynchronously.
|
|
287
|
+
*
|
|
288
|
+
* If `outputPath` is omitted, the decrypted Buffer is returned.
|
|
289
|
+
*
|
|
290
|
+
* @param filePath Path to the `.enc` file
|
|
291
|
+
* @param password Password used for decryption
|
|
292
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
293
|
+
* @returns Decrypted file contents
|
|
294
|
+
*
|
|
295
|
+
* @throws WilcoCryptError on:
|
|
296
|
+
* - invalid file extension
|
|
297
|
+
* - invalid header
|
|
298
|
+
* - version mismatch
|
|
299
|
+
* - wrong password
|
|
300
|
+
* - corrupted data
|
|
301
|
+
*/
|
|
302
|
+
decryptFileAsync(
|
|
303
|
+
filePath: string,
|
|
304
|
+
password: string,
|
|
305
|
+
gzip?: boolean,
|
|
306
|
+
): Promise<Buffer>;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Encrypts a file using streams and writes the result to `outputPath`.
|
|
310
|
+
* Memory-efficient alternative to `encryptFile` for large files.
|
|
311
|
+
*
|
|
312
|
+
* Output format:
|
|
313
|
+
* [HEADER] + [VERSION] + [salt (16)] + [iv (12)] + [ciphertext] + [authTag (16)]
|
|
314
|
+
*
|
|
315
|
+
* @param inputPath Path to the file to encrypt
|
|
316
|
+
* @param outputPath Path to write the encrypted output to
|
|
317
|
+
* @param password Password used for key derivation
|
|
318
|
+
* @param gzip Whether to compress data before encryption (default: true)
|
|
319
|
+
*
|
|
320
|
+
* @throws WilcoCryptError If password is invalid
|
|
321
|
+
*/
|
|
322
|
+
encryptFileStream(
|
|
323
|
+
inputPath: string,
|
|
324
|
+
outputPath: string,
|
|
325
|
+
password: string,
|
|
326
|
+
gzip?: boolean,
|
|
327
|
+
): Promise<void>;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Decrypts an encrypted file using streams.
|
|
331
|
+
* Memory-efficient alternative to `decryptFile` for large files.
|
|
332
|
+
* Cleans up the output file automatically if decryption or integrity check fails.
|
|
333
|
+
*
|
|
334
|
+
* @param inputPath Path to the encrypted file
|
|
335
|
+
* @param outputPath Path to write the decrypted output to
|
|
336
|
+
* @param password Password used for decryption
|
|
337
|
+
* @param gzip Whether to decompress after decryption (default: true)
|
|
338
|
+
*
|
|
339
|
+
* @throws WilcoCryptError on:
|
|
340
|
+
* - invalid header
|
|
341
|
+
* - version mismatch
|
|
342
|
+
* - decryption/integrity failure
|
|
343
|
+
*/
|
|
344
|
+
decryptFileStream(
|
|
345
|
+
inputPath: string,
|
|
346
|
+
outputPath: string,
|
|
347
|
+
password: string,
|
|
348
|
+
gzip?: boolean,
|
|
349
|
+
): Promise<void>;
|
|
69
350
|
}
|
|
70
351
|
|
|
352
|
+
/**
|
|
353
|
+
* WilcoCrypt main instance.
|
|
354
|
+
*/
|
|
71
355
|
declare const wilcocrypt: WilcoCrypt;
|
|
356
|
+
|
|
72
357
|
export default wilcocrypt;
|