cipher-kit 1.0.0 → 2.0.0-beta.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 +123 -1
- package/dist/chunk-4IOWANDJ.cjs +376 -0
- package/dist/chunk-4IOWANDJ.cjs.map +1 -0
- package/dist/chunk-D656BYPA.cjs +133 -0
- package/dist/chunk-D656BYPA.cjs.map +1 -0
- package/dist/chunk-IYMK2O3K.cjs +473 -0
- package/dist/chunk-IYMK2O3K.cjs.map +1 -0
- package/dist/chunk-J5YHHXDC.js +108 -0
- package/dist/chunk-J5YHHXDC.js.map +1 -0
- package/dist/chunk-M7V4HSRH.js +347 -0
- package/dist/chunk-M7V4HSRH.js.map +1 -0
- package/dist/chunk-N2ZI2CIT.js +448 -0
- package/dist/chunk-N2ZI2CIT.js.map +1 -0
- package/dist/export-Bh49U7Yf.d.ts +254 -0
- package/dist/export-CrT_Y2Cy.d.cts +254 -0
- package/dist/export-VUQLKGvM.d.ts +255 -0
- package/dist/export-VtQvdOuA.d.cts +255 -0
- package/dist/index.cjs +86 -38
- package/dist/index.d.cts +3 -22
- package/dist/index.d.ts +3 -22
- package/dist/index.js +3 -3
- package/dist/node.cjs +84 -28
- package/dist/node.d.cts +3 -22
- package/dist/node.d.ts +3 -22
- package/dist/node.js +2 -2
- package/dist/validate-CPWPEEAt.d.cts +86 -0
- package/dist/validate-CPWPEEAt.d.ts +86 -0
- package/dist/web-api.cjs +84 -28
- package/dist/web-api.d.cts +2 -21
- package/dist/web-api.d.ts +2 -21
- package/dist/web-api.js +2 -2
- package/package.json +9 -5
- package/dist/chunk-A7EF2XVZ.js +0 -141
- package/dist/chunk-A7EF2XVZ.js.map +0 -1
- package/dist/chunk-BQTBKP4M.js +0 -214
- package/dist/chunk-BQTBKP4M.js.map +0 -1
- package/dist/chunk-PDLO733W.cjs +0 -225
- package/dist/chunk-PDLO733W.cjs.map +0 -1
- package/dist/chunk-QGYPW6G5.cjs +0 -156
- package/dist/chunk-QGYPW6G5.cjs.map +0 -1
- package/dist/chunk-SBXDW4MY.cjs +0 -99
- package/dist/chunk-SBXDW4MY.cjs.map +0 -1
- package/dist/chunk-THMEBIZB.js +0 -79
- package/dist/chunk-THMEBIZB.js.map +0 -1
- package/dist/utils-Bryp07ny.d.cts +0 -48
- package/dist/utils-Bryp07ny.d.ts +0 -48
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { R as Result, W as WebSecretKey, c as EncodingFormat, b as isWebSecretKey } from './validate-CPWPEEAt.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates a UUID (v4).
|
|
5
|
+
*
|
|
6
|
+
* @returns A Result containing a string representing the generated UUID or an error.
|
|
7
|
+
*/
|
|
8
|
+
declare function tryGenerateUuid(): Result<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Generates a UUID (v4).
|
|
11
|
+
*
|
|
12
|
+
* @returns A string representing the generated UUID.
|
|
13
|
+
* @throws {Error} If UUID generation fails.
|
|
14
|
+
*/
|
|
15
|
+
declare function generateUuid(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Derives a secret key from the provided string for encryption/decryption.
|
|
18
|
+
* Internally, the key is hashed using SHA-256 to ensure it meets the required length.
|
|
19
|
+
*
|
|
20
|
+
* @param key - The input string to derive the secret key from.
|
|
21
|
+
* @returns A Result containing a WebApiKey object representing the derived secret key or an error.
|
|
22
|
+
*/
|
|
23
|
+
declare function tryCreateSecretKey(key: string): Promise<Result<{
|
|
24
|
+
result: WebSecretKey;
|
|
25
|
+
}>>;
|
|
26
|
+
/**
|
|
27
|
+
* Derives a secret key from the provided string for encryption/decryption.
|
|
28
|
+
* Internally, the key is hashed using SHA-256 to ensure it meets the required length.
|
|
29
|
+
*
|
|
30
|
+
* @param key - The input string to derive the secret key from.
|
|
31
|
+
* @returns A WebApiKey object representing the derived secret key.
|
|
32
|
+
* @throws {Error} If the input key is invalid or key generation fails.
|
|
33
|
+
*/
|
|
34
|
+
declare function createSecretKey(key: string): Promise<WebSecretKey>;
|
|
35
|
+
/**
|
|
36
|
+
* Encrypts the input string using the provided secret key.
|
|
37
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
38
|
+
*
|
|
39
|
+
* @param data - The input string to encrypt.
|
|
40
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
41
|
+
* @returns A Result containing a string representing the encrypted data in the specified format or an error.
|
|
42
|
+
*/
|
|
43
|
+
declare function tryEncrypt(data: string, secretKey: WebSecretKey): Promise<Result<string>>;
|
|
44
|
+
/**
|
|
45
|
+
* Encrypts the input string using the provided secret key.
|
|
46
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
47
|
+
*
|
|
48
|
+
* @param data - The input string to encrypt.
|
|
49
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
50
|
+
* @returns A string representing the encrypted data in the specified format.
|
|
51
|
+
* @throws {Error} If the input data or key is invalid, or if encryption fails.
|
|
52
|
+
*/
|
|
53
|
+
declare function encrypt(data: string, secretKey: WebSecretKey): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Decrypts the input string using the provided secret key.
|
|
56
|
+
* The input must be in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
57
|
+
*
|
|
58
|
+
* @param encrypted - The input string to decrypt.
|
|
59
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
60
|
+
* @returns A Result containing a string representing the decrypted data or an error.
|
|
61
|
+
*/
|
|
62
|
+
declare function tryDecrypt(encrypted: string, secretKey: WebSecretKey): Promise<Result<string>>;
|
|
63
|
+
/**
|
|
64
|
+
* Decrypts the input string using the provided secret key.
|
|
65
|
+
* The input must be in the format "iv.cipherWithTag" where each component is base64url encoded.
|
|
66
|
+
*
|
|
67
|
+
* @param encrypted - The input string to decrypt.
|
|
68
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
69
|
+
* @returns A string representing the decrypted data.
|
|
70
|
+
* @throws {Error} If the input data or key is invalid, or if decryption fails.
|
|
71
|
+
*/
|
|
72
|
+
declare function decrypt(encrypted: string, secretKey: WebSecretKey): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Encrypts the input object using the provided secret key.
|
|
75
|
+
* The object is first serialized to a JSON string before encryption.
|
|
76
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
77
|
+
*
|
|
78
|
+
* @param data - The input object to encrypt.
|
|
79
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
80
|
+
* @returns A Result containing a string representing the encrypted object in the specified format or an error.
|
|
81
|
+
*/
|
|
82
|
+
declare function tryEncryptObj<T extends object = Record<string, unknown>>(data: T, secretKey: WebSecretKey): Promise<Result<string>>;
|
|
83
|
+
/**
|
|
84
|
+
* Encrypts the input object using the provided secret key.
|
|
85
|
+
* The object is first serialized to a JSON string before encryption.
|
|
86
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
87
|
+
*
|
|
88
|
+
* @param data - The input object to encrypt.
|
|
89
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
90
|
+
* @returns A string representing the encrypted object in the specified format.
|
|
91
|
+
* @throws {Error} If the input data or key is invalid, or if encryption fails.
|
|
92
|
+
*/
|
|
93
|
+
declare function encryptObj<T extends object = Record<string, unknown>>(data: T, secretKey: WebSecretKey): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Decrypts the input string to an object using the provided secret key.
|
|
96
|
+
* The input must be in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
97
|
+
* The decrypted string is parsed as JSON to reconstruct the original object.
|
|
98
|
+
*
|
|
99
|
+
* @param encrypted - The input string to decrypt.
|
|
100
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
101
|
+
* @returns A Result containing an object representing the decrypted data or an error.
|
|
102
|
+
*/
|
|
103
|
+
declare function tryDecryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: WebSecretKey): Promise<Result<{
|
|
104
|
+
result: T;
|
|
105
|
+
}>>;
|
|
106
|
+
/**
|
|
107
|
+
* Decrypts the input string to an object using the provided secret key.
|
|
108
|
+
* The input must be in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
109
|
+
* The decrypted string is parsed as JSON to reconstruct the original object.
|
|
110
|
+
*
|
|
111
|
+
* @param encrypted - The input string to decrypt.
|
|
112
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
113
|
+
* @returns An object representing the decrypted data.
|
|
114
|
+
* @throws {Error} If the input data or key is invalid, or if decryption fails.
|
|
115
|
+
*/
|
|
116
|
+
declare function decryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: WebSecretKey): Promise<{
|
|
117
|
+
result: T;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Hashes the input string using SHA-256 and returns the hash in base64url format.
|
|
121
|
+
*
|
|
122
|
+
* @param data - The input string to hash.
|
|
123
|
+
* @returns A Result containing a string representing the SHA-256 hash in base64url format or an error.
|
|
124
|
+
*/
|
|
125
|
+
declare function tryHash(data: string): Promise<Result<string>>;
|
|
126
|
+
/**
|
|
127
|
+
* Hashes the input string using SHA-256 and returns the hash in base64url format.
|
|
128
|
+
*
|
|
129
|
+
* @param data - The input string to hash.
|
|
130
|
+
* @returns A string representing the SHA-256 hash in base64url format.
|
|
131
|
+
* @throws {Error} If the input data is invalid or hashing fails.
|
|
132
|
+
*/
|
|
133
|
+
declare function hash(data: string): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Hashes a password using PBKDF2 with SHA-512.
|
|
136
|
+
*
|
|
137
|
+
* @param password - The password to hash.
|
|
138
|
+
* @returns A Result containing an object with the hash and salt, or an error.
|
|
139
|
+
*/
|
|
140
|
+
declare function tryHashPassword(password: string): Promise<Result<{
|
|
141
|
+
hash: string;
|
|
142
|
+
salt: string;
|
|
143
|
+
}>>;
|
|
144
|
+
/**
|
|
145
|
+
* Hashes a password using PBKDF2 with SHA-512.
|
|
146
|
+
*
|
|
147
|
+
* @param password - The password to hash.
|
|
148
|
+
* @returns An object with the hash and salt.
|
|
149
|
+
* @throws {Error} If the input password is invalid or hashing fails.
|
|
150
|
+
*/
|
|
151
|
+
declare function hashPassword(password: string): Promise<{
|
|
152
|
+
hash: string;
|
|
153
|
+
salt: string;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Verifies a password against a hashed password and salt.
|
|
157
|
+
*
|
|
158
|
+
* @param password - The password to verify.
|
|
159
|
+
* @param hashedPassword - The hashed password to compare against (in base64url format).
|
|
160
|
+
* @param salt - The salt used during hashing (in base64url format).
|
|
161
|
+
* @returns A boolean indicating whether the password matches the hashed password.
|
|
162
|
+
*/
|
|
163
|
+
declare function verifyPassword(password: string, hashedPassword: string, salt: string): Promise<boolean>;
|
|
164
|
+
/**
|
|
165
|
+
* Converts a string to a Buffer (byte array) using the specified encoding format.
|
|
166
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
167
|
+
*
|
|
168
|
+
* @param data - The input string to convert.
|
|
169
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
170
|
+
* @returns A Result containing a Uint8Array with the encoded data or an error.
|
|
171
|
+
*/
|
|
172
|
+
declare function tryConvertStrToBytes(data: string, format?: EncodingFormat): Result<{
|
|
173
|
+
result: Uint8Array<ArrayBuffer>;
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a string to a Buffer (byte array) using the specified encoding format.
|
|
177
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
178
|
+
*
|
|
179
|
+
* @param data - The input string to convert.
|
|
180
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
181
|
+
* @returns A Uint8Array containing the encoded data.
|
|
182
|
+
* @throws {Error} If the input data is invalid or conversion fails.
|
|
183
|
+
*/
|
|
184
|
+
declare function convertStrToBytes(data: string, format?: EncodingFormat): Uint8Array<ArrayBuffer>;
|
|
185
|
+
/**
|
|
186
|
+
* Converts a Uint8Array or ArrayBuffer (byte array) to a string using the specified encoding format.
|
|
187
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
188
|
+
*
|
|
189
|
+
* @param data - The input Uint8Array or ArrayBuffer to convert.
|
|
190
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
191
|
+
* @returns A Result containing the string representation of the Uint8Array or an error.
|
|
192
|
+
*/
|
|
193
|
+
declare function tryConvertBytesToStr(data: Uint8Array | ArrayBuffer, format?: EncodingFormat): Result<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Converts a Uint8Array or ArrayBuffer (byte array) to a string using the specified encoding format.
|
|
196
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
197
|
+
*
|
|
198
|
+
* @param data - The input Uint8Array or ArrayBuffer to convert.
|
|
199
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
200
|
+
* @returns A string representation of the Uint8Array in the specified format.
|
|
201
|
+
* @throws {Error} If the input data is invalid or conversion fails.
|
|
202
|
+
*/
|
|
203
|
+
declare function convertBytesToStr(data: Uint8Array | ArrayBuffer, format?: EncodingFormat): string;
|
|
204
|
+
/**
|
|
205
|
+
* Convert data from one encoding format to another.
|
|
206
|
+
*
|
|
207
|
+
* @param data - The input data to convert.
|
|
208
|
+
* @param from - The encoding format to convert from.
|
|
209
|
+
* @param to - The encoding format to convert to.
|
|
210
|
+
* @returns A Result containing the converted string or an error.
|
|
211
|
+
*/
|
|
212
|
+
declare function tryConvertFormat(data: string, from: EncodingFormat, to: EncodingFormat): Result<{
|
|
213
|
+
result: string;
|
|
214
|
+
}>;
|
|
215
|
+
/**
|
|
216
|
+
* Convert data from one encoding format to another.
|
|
217
|
+
*
|
|
218
|
+
* @param data - The input data to convert.
|
|
219
|
+
* @param from - The encoding format to convert from.
|
|
220
|
+
* @param to - The encoding format to convert to.
|
|
221
|
+
* @returns A converted string.
|
|
222
|
+
* @throws {Error} If the input data is invalid or conversion fails.
|
|
223
|
+
*/
|
|
224
|
+
declare function convertFormat(data: string, from: EncodingFormat, to: EncodingFormat): string;
|
|
225
|
+
|
|
226
|
+
declare const kit_convertBytesToStr: typeof convertBytesToStr;
|
|
227
|
+
declare const kit_convertFormat: typeof convertFormat;
|
|
228
|
+
declare const kit_convertStrToBytes: typeof convertStrToBytes;
|
|
229
|
+
declare const kit_createSecretKey: typeof createSecretKey;
|
|
230
|
+
declare const kit_decrypt: typeof decrypt;
|
|
231
|
+
declare const kit_decryptObj: typeof decryptObj;
|
|
232
|
+
declare const kit_encrypt: typeof encrypt;
|
|
233
|
+
declare const kit_encryptObj: typeof encryptObj;
|
|
234
|
+
declare const kit_generateUuid: typeof generateUuid;
|
|
235
|
+
declare const kit_hash: typeof hash;
|
|
236
|
+
declare const kit_hashPassword: typeof hashPassword;
|
|
237
|
+
declare const kit_isWebSecretKey: typeof isWebSecretKey;
|
|
238
|
+
declare const kit_tryConvertBytesToStr: typeof tryConvertBytesToStr;
|
|
239
|
+
declare const kit_tryConvertFormat: typeof tryConvertFormat;
|
|
240
|
+
declare const kit_tryConvertStrToBytes: typeof tryConvertStrToBytes;
|
|
241
|
+
declare const kit_tryCreateSecretKey: typeof tryCreateSecretKey;
|
|
242
|
+
declare const kit_tryDecrypt: typeof tryDecrypt;
|
|
243
|
+
declare const kit_tryDecryptObj: typeof tryDecryptObj;
|
|
244
|
+
declare const kit_tryEncrypt: typeof tryEncrypt;
|
|
245
|
+
declare const kit_tryEncryptObj: typeof tryEncryptObj;
|
|
246
|
+
declare const kit_tryGenerateUuid: typeof tryGenerateUuid;
|
|
247
|
+
declare const kit_tryHash: typeof tryHash;
|
|
248
|
+
declare const kit_tryHashPassword: typeof tryHashPassword;
|
|
249
|
+
declare const kit_verifyPassword: typeof verifyPassword;
|
|
250
|
+
declare namespace kit {
|
|
251
|
+
export { kit_convertBytesToStr as convertBytesToStr, kit_convertFormat as convertFormat, kit_convertStrToBytes as convertStrToBytes, kit_createSecretKey as createSecretKey, kit_decrypt as decrypt, kit_decryptObj as decryptObj, kit_encrypt as encrypt, kit_encryptObj as encryptObj, kit_generateUuid as generateUuid, kit_hash as hash, kit_hashPassword as hashPassword, kit_isWebSecretKey as isWebSecretKey, kit_tryConvertBytesToStr as tryConvertBytesToStr, kit_tryConvertFormat as tryConvertFormat, kit_tryConvertStrToBytes as tryConvertStrToBytes, kit_tryCreateSecretKey as tryCreateSecretKey, kit_tryDecrypt as tryDecrypt, kit_tryDecryptObj as tryDecryptObj, kit_tryEncrypt as tryEncrypt, kit_tryEncryptObj as tryEncryptObj, kit_tryGenerateUuid as tryGenerateUuid, kit_tryHash as tryHash, kit_tryHashPassword as tryHashPassword, kit_verifyPassword as verifyPassword };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
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, kit as k, decryptObj as l, tryHash as m, hash 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, tryConvertFormat as w, convertFormat as x };
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { R as Result, W as WebSecretKey, c as EncodingFormat, b as isWebSecretKey } from './validate-CPWPEEAt.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates a UUID (v4).
|
|
5
|
+
*
|
|
6
|
+
* @returns A Result containing a string representing the generated UUID or an error.
|
|
7
|
+
*/
|
|
8
|
+
declare function tryGenerateUuid(): Result<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Generates a UUID (v4).
|
|
11
|
+
*
|
|
12
|
+
* @returns A string representing the generated UUID.
|
|
13
|
+
* @throws {Error} If UUID generation fails.
|
|
14
|
+
*/
|
|
15
|
+
declare function generateUuid(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Derives a secret key from the provided string for encryption/decryption.
|
|
18
|
+
* Internally, the key is hashed using SHA-256 to ensure it meets the required length.
|
|
19
|
+
*
|
|
20
|
+
* @param key - The input string to derive the secret key from.
|
|
21
|
+
* @returns A Result containing a WebApiKey object representing the derived secret key or an error.
|
|
22
|
+
*/
|
|
23
|
+
declare function tryCreateSecretKey(key: string): Promise<Result<{
|
|
24
|
+
result: WebSecretKey;
|
|
25
|
+
}>>;
|
|
26
|
+
/**
|
|
27
|
+
* Derives a secret key from the provided string for encryption/decryption.
|
|
28
|
+
* Internally, the key is hashed using SHA-256 to ensure it meets the required length.
|
|
29
|
+
*
|
|
30
|
+
* @param key - The input string to derive the secret key from.
|
|
31
|
+
* @returns A WebApiKey object representing the derived secret key.
|
|
32
|
+
* @throws {Error} If the input key is invalid or key generation fails.
|
|
33
|
+
*/
|
|
34
|
+
declare function createSecretKey(key: string): Promise<WebSecretKey>;
|
|
35
|
+
/**
|
|
36
|
+
* Encrypts the input string using the provided secret key.
|
|
37
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
38
|
+
*
|
|
39
|
+
* @param data - The input string to encrypt.
|
|
40
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
41
|
+
* @returns A Result containing a string representing the encrypted data in the specified format or an error.
|
|
42
|
+
*/
|
|
43
|
+
declare function tryEncrypt(data: string, secretKey: WebSecretKey): Promise<Result<string>>;
|
|
44
|
+
/**
|
|
45
|
+
* Encrypts the input string using the provided secret key.
|
|
46
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
47
|
+
*
|
|
48
|
+
* @param data - The input string to encrypt.
|
|
49
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
50
|
+
* @returns A string representing the encrypted data in the specified format.
|
|
51
|
+
* @throws {Error} If the input data or key is invalid, or if encryption fails.
|
|
52
|
+
*/
|
|
53
|
+
declare function encrypt(data: string, secretKey: WebSecretKey): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Decrypts the input string using the provided secret key.
|
|
56
|
+
* The input must be in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
57
|
+
*
|
|
58
|
+
* @param encrypted - The input string to decrypt.
|
|
59
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
60
|
+
* @returns A Result containing a string representing the decrypted data or an error.
|
|
61
|
+
*/
|
|
62
|
+
declare function tryDecrypt(encrypted: string, secretKey: WebSecretKey): Promise<Result<string>>;
|
|
63
|
+
/**
|
|
64
|
+
* Decrypts the input string using the provided secret key.
|
|
65
|
+
* The input must be in the format "iv.cipherWithTag" where each component is base64url encoded.
|
|
66
|
+
*
|
|
67
|
+
* @param encrypted - The input string to decrypt.
|
|
68
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
69
|
+
* @returns A string representing the decrypted data.
|
|
70
|
+
* @throws {Error} If the input data or key is invalid, or if decryption fails.
|
|
71
|
+
*/
|
|
72
|
+
declare function decrypt(encrypted: string, secretKey: WebSecretKey): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Encrypts the input object using the provided secret key.
|
|
75
|
+
* The object is first serialized to a JSON string before encryption.
|
|
76
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
77
|
+
*
|
|
78
|
+
* @param data - The input object to encrypt.
|
|
79
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
80
|
+
* @returns A Result containing a string representing the encrypted object in the specified format or an error.
|
|
81
|
+
*/
|
|
82
|
+
declare function tryEncryptObj<T extends object = Record<string, unknown>>(data: T, secretKey: WebSecretKey): Promise<Result<string>>;
|
|
83
|
+
/**
|
|
84
|
+
* Encrypts the input object using the provided secret key.
|
|
85
|
+
* The object is first serialized to a JSON string before encryption.
|
|
86
|
+
* The output is a string in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
87
|
+
*
|
|
88
|
+
* @param data - The input object to encrypt.
|
|
89
|
+
* @param secretKey - The WebApiKey object used for encryption.
|
|
90
|
+
* @returns A string representing the encrypted object in the specified format.
|
|
91
|
+
* @throws {Error} If the input data or key is invalid, or if encryption fails.
|
|
92
|
+
*/
|
|
93
|
+
declare function encryptObj<T extends object = Record<string, unknown>>(data: T, secretKey: WebSecretKey): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Decrypts the input string to an object using the provided secret key.
|
|
96
|
+
* The input must be in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
97
|
+
* The decrypted string is parsed as JSON to reconstruct the original object.
|
|
98
|
+
*
|
|
99
|
+
* @param encrypted - The input string to decrypt.
|
|
100
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
101
|
+
* @returns A Result containing an object representing the decrypted data or an error.
|
|
102
|
+
*/
|
|
103
|
+
declare function tryDecryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: WebSecretKey): Promise<Result<{
|
|
104
|
+
result: T;
|
|
105
|
+
}>>;
|
|
106
|
+
/**
|
|
107
|
+
* Decrypts the input string to an object using the provided secret key.
|
|
108
|
+
* The input must be in the format "iv.cipherWithTag." where each component is base64url encoded.
|
|
109
|
+
* The decrypted string is parsed as JSON to reconstruct the original object.
|
|
110
|
+
*
|
|
111
|
+
* @param encrypted - The input string to decrypt.
|
|
112
|
+
* @param secretKey - The WebApiKey object used for decryption.
|
|
113
|
+
* @returns An object representing the decrypted data.
|
|
114
|
+
* @throws {Error} If the input data or key is invalid, or if decryption fails.
|
|
115
|
+
*/
|
|
116
|
+
declare function decryptObj<T extends object = Record<string, unknown>>(encrypted: string, secretKey: WebSecretKey): Promise<{
|
|
117
|
+
result: T;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Hashes the input string using SHA-256 and returns the hash in base64url format.
|
|
121
|
+
*
|
|
122
|
+
* @param data - The input string to hash.
|
|
123
|
+
* @returns A Result containing a string representing the SHA-256 hash in base64url format or an error.
|
|
124
|
+
*/
|
|
125
|
+
declare function tryHash(data: string): Promise<Result<string>>;
|
|
126
|
+
/**
|
|
127
|
+
* Hashes the input string using SHA-256 and returns the hash in base64url format.
|
|
128
|
+
*
|
|
129
|
+
* @param data - The input string to hash.
|
|
130
|
+
* @returns A string representing the SHA-256 hash in base64url format.
|
|
131
|
+
* @throws {Error} If the input data is invalid or hashing fails.
|
|
132
|
+
*/
|
|
133
|
+
declare function hash(data: string): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Hashes a password using PBKDF2 with SHA-512.
|
|
136
|
+
*
|
|
137
|
+
* @param password - The password to hash.
|
|
138
|
+
* @returns A Result containing an object with the hash and salt, or an error.
|
|
139
|
+
*/
|
|
140
|
+
declare function tryHashPassword(password: string): Promise<Result<{
|
|
141
|
+
hash: string;
|
|
142
|
+
salt: string;
|
|
143
|
+
}>>;
|
|
144
|
+
/**
|
|
145
|
+
* Hashes a password using PBKDF2 with SHA-512.
|
|
146
|
+
*
|
|
147
|
+
* @param password - The password to hash.
|
|
148
|
+
* @returns An object with the hash and salt.
|
|
149
|
+
* @throws {Error} If the input password is invalid or hashing fails.
|
|
150
|
+
*/
|
|
151
|
+
declare function hashPassword(password: string): Promise<{
|
|
152
|
+
hash: string;
|
|
153
|
+
salt: string;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Verifies a password against a hashed password and salt.
|
|
157
|
+
*
|
|
158
|
+
* @param password - The password to verify.
|
|
159
|
+
* @param hashedPassword - The hashed password to compare against (in base64url format).
|
|
160
|
+
* @param salt - The salt used during hashing (in base64url format).
|
|
161
|
+
* @returns A boolean indicating whether the password matches the hashed password.
|
|
162
|
+
*/
|
|
163
|
+
declare function verifyPassword(password: string, hashedPassword: string, salt: string): Promise<boolean>;
|
|
164
|
+
/**
|
|
165
|
+
* Converts a string to a Buffer (byte array) using the specified encoding format.
|
|
166
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
167
|
+
*
|
|
168
|
+
* @param data - The input string to convert.
|
|
169
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
170
|
+
* @returns A Result containing a Uint8Array with the encoded data or an error.
|
|
171
|
+
*/
|
|
172
|
+
declare function tryConvertStrToBytes(data: string, format?: EncodingFormat): Result<{
|
|
173
|
+
result: Uint8Array<ArrayBuffer>;
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a string to a Buffer (byte array) using the specified encoding format.
|
|
177
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
178
|
+
*
|
|
179
|
+
* @param data - The input string to convert.
|
|
180
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
181
|
+
* @returns A Uint8Array containing the encoded data.
|
|
182
|
+
* @throws {Error} If the input data is invalid or conversion fails.
|
|
183
|
+
*/
|
|
184
|
+
declare function convertStrToBytes(data: string, format?: EncodingFormat): Uint8Array<ArrayBuffer>;
|
|
185
|
+
/**
|
|
186
|
+
* Converts a Uint8Array or ArrayBuffer (byte array) to a string using the specified encoding format.
|
|
187
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
188
|
+
*
|
|
189
|
+
* @param data - The input Uint8Array or ArrayBuffer to convert.
|
|
190
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
191
|
+
* @returns A Result containing the string representation of the Uint8Array or an error.
|
|
192
|
+
*/
|
|
193
|
+
declare function tryConvertBytesToStr(data: Uint8Array | ArrayBuffer, format?: EncodingFormat): Result<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Converts a Uint8Array or ArrayBuffer (byte array) to a string using the specified encoding format.
|
|
196
|
+
* Supported formats: 'base64', 'base64url', 'hex', 'utf8', 'latin1'.
|
|
197
|
+
*
|
|
198
|
+
* @param data - The input Uint8Array or ArrayBuffer to convert.
|
|
199
|
+
* @param format - The encoding format to use (default is 'utf8').
|
|
200
|
+
* @returns A string representation of the Uint8Array in the specified format.
|
|
201
|
+
* @throws {Error} If the input data is invalid or conversion fails.
|
|
202
|
+
*/
|
|
203
|
+
declare function convertBytesToStr(data: Uint8Array | ArrayBuffer, format?: EncodingFormat): string;
|
|
204
|
+
/**
|
|
205
|
+
* Convert data from one encoding format to another.
|
|
206
|
+
*
|
|
207
|
+
* @param data - The input data to convert.
|
|
208
|
+
* @param from - The encoding format to convert from.
|
|
209
|
+
* @param to - The encoding format to convert to.
|
|
210
|
+
* @returns A Result containing the converted string or an error.
|
|
211
|
+
*/
|
|
212
|
+
declare function tryConvertFormat(data: string, from: EncodingFormat, to: EncodingFormat): Result<{
|
|
213
|
+
result: string;
|
|
214
|
+
}>;
|
|
215
|
+
/**
|
|
216
|
+
* Convert data from one encoding format to another.
|
|
217
|
+
*
|
|
218
|
+
* @param data - The input data to convert.
|
|
219
|
+
* @param from - The encoding format to convert from.
|
|
220
|
+
* @param to - The encoding format to convert to.
|
|
221
|
+
* @returns A converted string.
|
|
222
|
+
* @throws {Error} If the input data is invalid or conversion fails.
|
|
223
|
+
*/
|
|
224
|
+
declare function convertFormat(data: string, from: EncodingFormat, to: EncodingFormat): string;
|
|
225
|
+
|
|
226
|
+
declare const kit_convertBytesToStr: typeof convertBytesToStr;
|
|
227
|
+
declare const kit_convertFormat: typeof convertFormat;
|
|
228
|
+
declare const kit_convertStrToBytes: typeof convertStrToBytes;
|
|
229
|
+
declare const kit_createSecretKey: typeof createSecretKey;
|
|
230
|
+
declare const kit_decrypt: typeof decrypt;
|
|
231
|
+
declare const kit_decryptObj: typeof decryptObj;
|
|
232
|
+
declare const kit_encrypt: typeof encrypt;
|
|
233
|
+
declare const kit_encryptObj: typeof encryptObj;
|
|
234
|
+
declare const kit_generateUuid: typeof generateUuid;
|
|
235
|
+
declare const kit_hash: typeof hash;
|
|
236
|
+
declare const kit_hashPassword: typeof hashPassword;
|
|
237
|
+
declare const kit_isWebSecretKey: typeof isWebSecretKey;
|
|
238
|
+
declare const kit_tryConvertBytesToStr: typeof tryConvertBytesToStr;
|
|
239
|
+
declare const kit_tryConvertFormat: typeof tryConvertFormat;
|
|
240
|
+
declare const kit_tryConvertStrToBytes: typeof tryConvertStrToBytes;
|
|
241
|
+
declare const kit_tryCreateSecretKey: typeof tryCreateSecretKey;
|
|
242
|
+
declare const kit_tryDecrypt: typeof tryDecrypt;
|
|
243
|
+
declare const kit_tryDecryptObj: typeof tryDecryptObj;
|
|
244
|
+
declare const kit_tryEncrypt: typeof tryEncrypt;
|
|
245
|
+
declare const kit_tryEncryptObj: typeof tryEncryptObj;
|
|
246
|
+
declare const kit_tryGenerateUuid: typeof tryGenerateUuid;
|
|
247
|
+
declare const kit_tryHash: typeof tryHash;
|
|
248
|
+
declare const kit_tryHashPassword: typeof tryHashPassword;
|
|
249
|
+
declare const kit_verifyPassword: typeof verifyPassword;
|
|
250
|
+
declare namespace kit {
|
|
251
|
+
export { kit_convertBytesToStr as convertBytesToStr, kit_convertFormat as convertFormat, kit_convertStrToBytes as convertStrToBytes, kit_createSecretKey as createSecretKey, kit_decrypt as decrypt, kit_decryptObj as decryptObj, kit_encrypt as encrypt, kit_encryptObj as encryptObj, kit_generateUuid as generateUuid, kit_hash as hash, kit_hashPassword as hashPassword, kit_isWebSecretKey as isWebSecretKey, kit_tryConvertBytesToStr as tryConvertBytesToStr, kit_tryConvertFormat as tryConvertFormat, kit_tryConvertStrToBytes as tryConvertStrToBytes, kit_tryCreateSecretKey as tryCreateSecretKey, kit_tryDecrypt as tryDecrypt, kit_tryDecryptObj as tryDecryptObj, kit_tryEncrypt as tryEncrypt, kit_tryEncryptObj as tryEncryptObj, kit_tryGenerateUuid as tryGenerateUuid, kit_tryHash as tryHash, kit_tryHashPassword as tryHashPassword, kit_verifyPassword as verifyPassword };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
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, kit as k, decryptObj as l, tryHash as m, hash 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, tryConvertFormat as w, convertFormat as x };
|