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
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { i as DIGEST_ALGORITHMS, j as ENCRYPTION_ALGORITHMS, c as Encoding, a as CreateSecretKeyOptions, D as DecryptOptions, d as EncryptOptions, H as HashOptions, g as HashPasswordOptions, R as Result, V as VerifyPasswordOptions } from './validate-vDTesb-X.js';
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
import nodeCrypto from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
declare const __brand: unique symbol;
|
|
6
|
+
type NodeSecretKey = {
|
|
7
|
+
readonly platform: "node";
|
|
8
|
+
readonly digest: keyof typeof DIGEST_ALGORITHMS;
|
|
9
|
+
readonly algorithm: keyof typeof ENCRYPTION_ALGORITHMS;
|
|
10
|
+
readonly key: nodeCrypto.KeyObject;
|
|
11
|
+
readonly injected: (typeof ENCRYPTION_ALGORITHMS)[keyof typeof ENCRYPTION_ALGORITHMS];
|
|
12
|
+
} & {
|
|
13
|
+
readonly [__brand]: "secretKey-node";
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether a value is a `NodeSecretKey` for the Node.js platform.
|
|
18
|
+
*
|
|
19
|
+
* @param x - The value to check.
|
|
20
|
+
* @returns `true` if `x` is a `NodeSecretKey`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* isNodeSecretKey(nodeKey); // true
|
|
25
|
+
* isNodeSecretKey({}); // false
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function isNodeSecretKey(x: unknown): x is NodeSecretKey;
|
|
29
|
+
/**
|
|
30
|
+
* Generates a UUID (v4) (non-throwing).
|
|
31
|
+
*
|
|
32
|
+
* @returns `Result<string>` with the UUID or error.
|
|
33
|
+
* @see {@link generateUuid} For full parameter/behavior docs.
|
|
34
|
+
*/
|
|
35
|
+
declare function tryGenerateUuid(): Result<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Generates a cryptographically random UUID (v4).
|
|
38
|
+
*
|
|
39
|
+
* @returns A UUID string.
|
|
40
|
+
* @throws {Error} If UUID generation fails.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const uuid = generateUuid();
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @see {@link tryGenerateUuid} Non-throwing variant returning `Result<string>`.
|
|
48
|
+
*/
|
|
49
|
+
declare function generateUuid(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Derives a `NodeSecretKey` from a high-entropy secret (non-throwing).
|
|
52
|
+
*
|
|
53
|
+
* @returns `Result<{ result: NodeSecretKey }>` with the derived key or error.
|
|
54
|
+
* @see {@link createSecretKey} For full parameter/behavior docs.
|
|
55
|
+
*/
|
|
56
|
+
declare function tryCreateSecretKey(secret: string, options?: CreateSecretKeyOptions): Result<{
|
|
57
|
+
result: NodeSecretKey;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Derives a `NodeSecretKey` from a high-entropy secret for encryption/decryption.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Uses HKDF to derive a symmetric key from the input string.
|
|
64
|
+
*
|
|
65
|
+
* @param secret - High-entropy secret (min 8 chars). For human-chosen passwords, use {@link hashPassword} instead.
|
|
66
|
+
* @param options - Key derivation options.
|
|
67
|
+
* @returns The derived `NodeSecretKey`.
|
|
68
|
+
* @throws {Error} If key derivation fails.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const secretKey = createSecretKey("my-32-char-high-entropy-secret!!");
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see {@link tryCreateSecretKey} Non-throwing variant returning `Result`.
|
|
76
|
+
*/
|
|
77
|
+
declare function createSecretKey(secret: string, options?: CreateSecretKeyOptions): NodeSecretKey;
|
|
78
|
+
/**
|
|
79
|
+
* Encrypts a UTF-8 string (non-throwing).
|
|
80
|
+
*
|
|
81
|
+
* @returns `Result<string>` with the ciphertext or error.
|
|
82
|
+
* @see {@link encrypt} For full parameter/behavior docs.
|
|
83
|
+
*/
|
|
84
|
+
declare function tryEncrypt(data: string, secretKey: NodeSecretKey, options?: EncryptOptions): Result<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Encrypts a UTF-8 string using the provided `NodeSecretKey`.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Output format: `"iv.cipher.tag."` (three dot-separated base64url segments plus trailing dot).
|
|
90
|
+
* Cross-platform compatible — data encrypted on Node can be decrypted on Web and vice versa.
|
|
91
|
+
* AES-GCM uses random 96-bit IVs. Rotate keys before ~2^32 encryptions with the same key to avoid nonce collision.
|
|
92
|
+
*
|
|
93
|
+
* @param data - UTF-8 string to encrypt. Must be a non-empty string (whitespace-only strings are rejected).
|
|
94
|
+
* @param secretKey - The `NodeSecretKey` used for encryption.
|
|
95
|
+
* @param options - Encryption options.
|
|
96
|
+
* @returns The encrypted string.
|
|
97
|
+
* @throws {Error} If the input or key is invalid, or encryption fails.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const secretKey = createSecretKey("my-secret");
|
|
102
|
+
* const encrypted = encrypt("Hello, World!", secretKey);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @see {@link tryEncrypt} Non-throwing variant returning `Result<string>`.
|
|
106
|
+
*/
|
|
107
|
+
declare function encrypt(data: string, secretKey: NodeSecretKey, options?: EncryptOptions): string;
|
|
108
|
+
/**
|
|
109
|
+
* Decrypts a ciphertext string (non-throwing).
|
|
110
|
+
*
|
|
111
|
+
* @returns `Result<string>` with the plaintext or error.
|
|
112
|
+
* @see {@link decrypt} For full parameter/behavior docs.
|
|
113
|
+
*/
|
|
114
|
+
declare function tryDecrypt(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): Result<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Decrypts a ciphertext string using the provided `NodeSecretKey`.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* Expects input in the format `"iv.cipher.tag."`.
|
|
120
|
+
* Cross-platform compatible — data encrypted on Web can be decrypted on Node and vice versa.
|
|
121
|
+
*
|
|
122
|
+
* @param encrypted - The encrypted string to decrypt.
|
|
123
|
+
* @param secretKey - The `NodeSecretKey` used for decryption.
|
|
124
|
+
* @param options - Decryption options.
|
|
125
|
+
* @returns The decrypted UTF-8 string.
|
|
126
|
+
* @throws {Error} If the input or key is invalid, or decryption fails.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const secretKey = createSecretKey("my-secret");
|
|
131
|
+
* const encrypted = encrypt("Hello, World!", secretKey);
|
|
132
|
+
* const decrypted = decrypt(encrypted, secretKey); // "Hello, World!"
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @see {@link tryDecrypt} Non-throwing variant returning `Result<string>`.
|
|
136
|
+
*/
|
|
137
|
+
declare function decrypt(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): string;
|
|
138
|
+
/**
|
|
139
|
+
* Encrypts a plain object (non-throwing).
|
|
140
|
+
*
|
|
141
|
+
* @returns `Result<string>` with the ciphertext or error.
|
|
142
|
+
* @see {@link encryptObj} For full parameter/behavior docs.
|
|
143
|
+
*/
|
|
144
|
+
declare function tryEncryptObj<T extends object = Record<string, unknown>>(obj: T, secretKey: NodeSecretKey, options?: EncryptOptions): Result<string>;
|
|
145
|
+
/**
|
|
146
|
+
* Encrypts a plain object using the provided `NodeSecretKey`.
|
|
147
|
+
*
|
|
148
|
+
* @remarks
|
|
149
|
+
* Only plain objects (POJOs) are accepted; class instances, Maps, Sets, etc. are rejected.
|
|
150
|
+
* Output format: `"iv.cipher.tag."`.
|
|
151
|
+
*
|
|
152
|
+
* @param obj - Plain object to encrypt.
|
|
153
|
+
* @param secretKey - The `NodeSecretKey` used for encryption.
|
|
154
|
+
* @param options - Encryption options.
|
|
155
|
+
* @returns The encrypted string.
|
|
156
|
+
* @throws {Error} If the input or key is invalid, or encryption fails.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const secretKey = createSecretKey("my-secret");
|
|
161
|
+
* const encrypted = encryptObj({ a: 1 }, secretKey);
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @see {@link tryEncryptObj} Non-throwing variant returning `Result<string>`.
|
|
165
|
+
*/
|
|
166
|
+
declare function encryptObj<T extends object = Record<string, unknown>>(obj: T, secretKey: NodeSecretKey, options?: EncryptOptions): string;
|
|
167
|
+
/**
|
|
168
|
+
* Decrypts an encrypted JSON string into a plain object (non-throwing).
|
|
169
|
+
*
|
|
170
|
+
* @returns `Result<{ result: T }>` with the object or error.
|
|
171
|
+
* @see {@link decryptObj} For full parameter/behavior docs.
|
|
172
|
+
*/
|
|
173
|
+
declare function tryDecryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): Result<{
|
|
174
|
+
result: T;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Decrypts an encrypted JSON string into a plain object.
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* Expects input in the format `"iv.cipher.tag."`.
|
|
181
|
+
*
|
|
182
|
+
* @param encrypted - The encrypted string.
|
|
183
|
+
* @param secretKey - The `NodeSecretKey` used for decryption.
|
|
184
|
+
* @param options - Decryption options.
|
|
185
|
+
* @returns The decrypted object.
|
|
186
|
+
* @throws {Error} If decryption or JSON parsing fails.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const secretKey = createSecretKey("my-secret");
|
|
191
|
+
* const encrypted = encryptObj({ a: 1 }, secretKey);
|
|
192
|
+
* const obj = decryptObj<{ a: number }>(encrypted, secretKey); // obj.a === 1
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @see {@link tryDecryptObj} Non-throwing variant returning `Result`.
|
|
196
|
+
*/
|
|
197
|
+
declare function decryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: NodeSecretKey, options?: DecryptOptions): T;
|
|
198
|
+
/**
|
|
199
|
+
* Hashes a UTF-8 string (non-throwing).
|
|
200
|
+
*
|
|
201
|
+
* @returns `Result<string>` with the hash or error.
|
|
202
|
+
* @see {@link hash} For full parameter/behavior docs.
|
|
203
|
+
*/
|
|
204
|
+
declare function tryHash(data: string, options?: HashOptions): Result<string>;
|
|
205
|
+
/**
|
|
206
|
+
* Hashes a UTF-8 string using the specified digest algorithm.
|
|
207
|
+
*
|
|
208
|
+
* @param data - The input string to hash.
|
|
209
|
+
* @param options - Hash options.
|
|
210
|
+
* @returns The hashed string.
|
|
211
|
+
* @throws {Error} If input is invalid or hashing fails.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* const hashed = hash("my data");
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @see {@link tryHash} Non-throwing variant returning `Result<string>`.
|
|
219
|
+
*/
|
|
220
|
+
declare function hash(data: string, options?: HashOptions): string;
|
|
221
|
+
/**
|
|
222
|
+
* Hashes a password using PBKDF2 (non-throwing).
|
|
223
|
+
*
|
|
224
|
+
* @returns `Result<{ result: string; salt: string }>` with the hash/salt or error.
|
|
225
|
+
* @see {@link hashPassword} For full parameter/behavior docs.
|
|
226
|
+
*/
|
|
227
|
+
declare function tryHashPassword(password: string, options?: HashPasswordOptions): Result<{
|
|
228
|
+
result: string;
|
|
229
|
+
salt: string;
|
|
230
|
+
}>;
|
|
231
|
+
/**
|
|
232
|
+
* Hashes a password using PBKDF2.
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* Defaults: `sha512`, 320 000 iterations, 64-byte key, 16-byte random salt.
|
|
236
|
+
*
|
|
237
|
+
* **Performance note:** Uses synchronous `pbkdf2Sync` which blocks the event loop
|
|
238
|
+
* (~100-300 ms at default iterations). For server-side use under load, prefer the
|
|
239
|
+
* Web Crypto API (async) via `webKit.hashPassword` instead.
|
|
240
|
+
*
|
|
241
|
+
* @param password - The password to hash.
|
|
242
|
+
* @param options - Password hashing options.
|
|
243
|
+
* @returns `{ result, salt }` for storage.
|
|
244
|
+
* @throws {Error} If inputs are invalid or hashing fails.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* const { result, salt } = hashPassword("my-password");
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* @see {@link tryHashPassword} Non-throwing variant returning `Result`.
|
|
252
|
+
*/
|
|
253
|
+
declare function hashPassword(password: string, options?: HashPasswordOptions): {
|
|
254
|
+
result: string;
|
|
255
|
+
salt: string;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Verifies a password against a stored PBKDF2 hash (non-throwing).
|
|
259
|
+
*
|
|
260
|
+
* @returns `Result<boolean>` — `true` if the password matches, `false` if not, or an error for invalid inputs/options.
|
|
261
|
+
* @see {@link verifyPassword} For full parameter/behavior docs.
|
|
262
|
+
*/
|
|
263
|
+
declare function tryVerifyPassword(password: string, hashedPassword: string, salt: string, options?: VerifyPasswordOptions): Result<boolean>;
|
|
264
|
+
/**
|
|
265
|
+
* Verifies a password against a stored PBKDF2 hash.
|
|
266
|
+
*
|
|
267
|
+
* @remarks
|
|
268
|
+
* Re-derives the key with the same parameters and compares in constant time to prevent timing attacks.
|
|
269
|
+
* Throws for invalid inputs/options (bad encoding, wrong parameters, non-decodable salt/hash).
|
|
270
|
+
* Returns `false` for password mismatch or length-mismatched hash.
|
|
271
|
+
*
|
|
272
|
+
* **Performance note:** Uses synchronous `pbkdf2Sync` which blocks the event loop
|
|
273
|
+
* (~100-300 ms at default iterations). For server-side use under load, prefer the
|
|
274
|
+
* Web Crypto API (async) via `webKit.verifyPassword` instead.
|
|
275
|
+
*
|
|
276
|
+
* @param password - The plain password to verify.
|
|
277
|
+
* @param hashedPassword - The stored hash (encoded).
|
|
278
|
+
* @param salt - The stored salt (encoded).
|
|
279
|
+
* @param options - Verification options (must match the parameters used to hash).
|
|
280
|
+
* @returns `true` if the password matches, otherwise `false`.
|
|
281
|
+
* @throws {Error} If verification input/options are invalid.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const { result, salt } = hashPassword("my-password");
|
|
286
|
+
* verifyPassword("my-password", result, salt); // true
|
|
287
|
+
* verifyPassword("wrong-password", result, salt); // false
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @see {@link tryVerifyPassword} Non-throwing variant returning `Result<boolean>`.
|
|
291
|
+
*/
|
|
292
|
+
declare function verifyPassword(password: string, hashedPassword: string, salt: string, options?: VerifyPasswordOptions): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Converts a string to a `Buffer` (non-throwing).
|
|
295
|
+
*
|
|
296
|
+
* @returns `Result<{ result: Buffer }>` with the buffer or error.
|
|
297
|
+
* @see {@link convertStrToBytes} For full parameter/behavior docs.
|
|
298
|
+
*/
|
|
299
|
+
declare function tryConvertStrToBytes(data: string, inputEncoding?: Encoding): Result<{
|
|
300
|
+
result: Buffer;
|
|
301
|
+
}>;
|
|
302
|
+
/**
|
|
303
|
+
* Converts a string to a Node.js `Buffer` using the specified encoding.
|
|
304
|
+
*
|
|
305
|
+
* @param data - The input string to convert.
|
|
306
|
+
* @param inputEncoding - Source encoding (default: `'utf8'`).
|
|
307
|
+
* @returns A `Buffer` containing the bytes.
|
|
308
|
+
* @throws {Error} If input is invalid or conversion fails.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const bytes = convertStrToBytes("Hello", "utf8");
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @see {@link tryConvertStrToBytes} Non-throwing variant returning `Result`.
|
|
316
|
+
*/
|
|
317
|
+
declare function convertStrToBytes(data: string, inputEncoding?: Encoding): Buffer;
|
|
318
|
+
/**
|
|
319
|
+
* Converts a `Buffer` to a string (non-throwing).
|
|
320
|
+
*
|
|
321
|
+
* @returns `Result<string>` with the encoded string or error.
|
|
322
|
+
* @see {@link convertBytesToStr} For full parameter/behavior docs.
|
|
323
|
+
*/
|
|
324
|
+
declare function tryConvertBytesToStr(data: Buffer, outputEncoding?: Encoding): Result<string>;
|
|
325
|
+
/**
|
|
326
|
+
* Converts a Node.js `Buffer` to a string using the specified encoding.
|
|
327
|
+
*
|
|
328
|
+
* @param data - The `Buffer` to convert.
|
|
329
|
+
* @param outputEncoding - Target encoding (default: `'utf8'`).
|
|
330
|
+
* @returns The encoded string.
|
|
331
|
+
* @throws {Error} If input is invalid or conversion fails.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```ts
|
|
335
|
+
* const bytes = convertStrToBytes("Hello", "utf8");
|
|
336
|
+
* const str = convertBytesToStr(bytes, "utf8"); // "Hello"
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @see {@link tryConvertBytesToStr} Non-throwing variant returning `Result<string>`.
|
|
340
|
+
*/
|
|
341
|
+
declare function convertBytesToStr(data: Buffer, outputEncoding?: Encoding): string;
|
|
342
|
+
/**
|
|
343
|
+
* Converts text between encodings (non-throwing).
|
|
344
|
+
*
|
|
345
|
+
* @returns `Result<string>` with the re-encoded string or error.
|
|
346
|
+
* @see {@link convertEncoding} For full parameter/behavior docs.
|
|
347
|
+
*/
|
|
348
|
+
declare function tryConvertEncoding(data: string, from: Encoding, to: Encoding): Result<string>;
|
|
349
|
+
/**
|
|
350
|
+
* Converts text between encodings.
|
|
351
|
+
*
|
|
352
|
+
* @param data - The input string.
|
|
353
|
+
* @param from - Current encoding of `data`.
|
|
354
|
+
* @param to - Target encoding.
|
|
355
|
+
* @returns The re-encoded string.
|
|
356
|
+
* @throws {Error} If encodings are invalid or conversion fails.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* const encoded = convertEncoding("Hello", "utf8", "base64url");
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
363
|
+
* @see {@link tryConvertEncoding} Non-throwing variant returning `Result<string>`.
|
|
364
|
+
*/
|
|
365
|
+
declare function convertEncoding(data: string, from: Encoding, to: Encoding): string;
|
|
366
|
+
|
|
367
|
+
declare const nodeCryptoKit_convertBytesToStr: typeof convertBytesToStr;
|
|
368
|
+
declare const nodeCryptoKit_convertEncoding: typeof convertEncoding;
|
|
369
|
+
declare const nodeCryptoKit_convertStrToBytes: typeof convertStrToBytes;
|
|
370
|
+
declare const nodeCryptoKit_createSecretKey: typeof createSecretKey;
|
|
371
|
+
declare const nodeCryptoKit_decrypt: typeof decrypt;
|
|
372
|
+
declare const nodeCryptoKit_decryptObj: typeof decryptObj;
|
|
373
|
+
declare const nodeCryptoKit_encrypt: typeof encrypt;
|
|
374
|
+
declare const nodeCryptoKit_encryptObj: typeof encryptObj;
|
|
375
|
+
declare const nodeCryptoKit_generateUuid: typeof generateUuid;
|
|
376
|
+
declare const nodeCryptoKit_hash: typeof hash;
|
|
377
|
+
declare const nodeCryptoKit_hashPassword: typeof hashPassword;
|
|
378
|
+
declare const nodeCryptoKit_isNodeSecretKey: typeof isNodeSecretKey;
|
|
379
|
+
declare const nodeCryptoKit_tryConvertBytesToStr: typeof tryConvertBytesToStr;
|
|
380
|
+
declare const nodeCryptoKit_tryConvertEncoding: typeof tryConvertEncoding;
|
|
381
|
+
declare const nodeCryptoKit_tryConvertStrToBytes: typeof tryConvertStrToBytes;
|
|
382
|
+
declare const nodeCryptoKit_tryCreateSecretKey: typeof tryCreateSecretKey;
|
|
383
|
+
declare const nodeCryptoKit_tryDecrypt: typeof tryDecrypt;
|
|
384
|
+
declare const nodeCryptoKit_tryDecryptObj: typeof tryDecryptObj;
|
|
385
|
+
declare const nodeCryptoKit_tryEncrypt: typeof tryEncrypt;
|
|
386
|
+
declare const nodeCryptoKit_tryEncryptObj: typeof tryEncryptObj;
|
|
387
|
+
declare const nodeCryptoKit_tryGenerateUuid: typeof tryGenerateUuid;
|
|
388
|
+
declare const nodeCryptoKit_tryHash: typeof tryHash;
|
|
389
|
+
declare const nodeCryptoKit_tryHashPassword: typeof tryHashPassword;
|
|
390
|
+
declare const nodeCryptoKit_tryVerifyPassword: typeof tryVerifyPassword;
|
|
391
|
+
declare const nodeCryptoKit_verifyPassword: typeof verifyPassword;
|
|
392
|
+
declare namespace nodeCryptoKit {
|
|
393
|
+
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_isNodeSecretKey as isNodeSecretKey, 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_tryVerifyPassword as tryVerifyPassword, nodeCryptoKit_verifyPassword as verifyPassword };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { type NodeSecretKey as N, convertEncoding as a, convertStrToBytes as b, convertBytesToStr as c, createSecretKey as d, decrypt as e, decryptObj as f, encrypt as g, encryptObj as h, generateUuid as i, hash as j, hashPassword as k, isNodeSecretKey as l, tryConvertEncoding as m, nodeCryptoKit as n, tryConvertStrToBytes as o, tryCreateSecretKey as p, tryDecrypt as q, tryDecryptObj as r, tryEncrypt as s, tryConvertBytesToStr as t, tryEncryptObj as u, tryGenerateUuid as v, tryHash as w, tryHashPassword as x, tryVerifyPassword as y, verifyPassword as z };
|