cipher-kit 2.1.0 → 2.1.2
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 +1 -1
- package/dist/{chunk-UVEMRK5F.cjs → chunk-66WIL32E.cjs} +149 -154
- package/dist/chunk-66WIL32E.cjs.map +1 -0
- package/dist/{chunk-BHG5RSUV.cjs → chunk-HTRGOBZF.cjs} +17 -8
- package/dist/chunk-HTRGOBZF.cjs.map +1 -0
- package/dist/{chunk-CRTOKS3Q.js → chunk-JLFVTZY4.js} +8 -12
- package/dist/chunk-JLFVTZY4.js.map +1 -0
- package/dist/{chunk-RUTGDMVR.js → chunk-LU7QOSQH.js} +16 -9
- package/dist/chunk-LU7QOSQH.js.map +1 -0
- package/dist/{chunk-RAEBT46G.js → chunk-S6SNCTU6.js} +8 -12
- package/dist/chunk-S6SNCTU6.js.map +1 -0
- package/dist/{chunk-HMTHK2IY.cjs → chunk-ZNM5M6RD.cjs} +144 -149
- package/dist/chunk-ZNM5M6RD.cjs.map +1 -0
- package/dist/{export-BF9wW56f.d.ts → export-BaM_OTFk.d.ts} +17 -35
- package/dist/{export-w8sBcKXw.d.ts → export-CCTGAosO.d.ts} +17 -35
- package/dist/{export-DVERZibl.d.cts → export-FYHgb-8E.d.cts} +17 -35
- package/dist/{export-5hmOiU0J.d.cts → export-KFT0YyMg.d.cts} +17 -35
- package/dist/index.cjs +19 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +35 -35
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +2 -2
- package/dist/{validate-B3uHoP8n.d.cts → validate-lkJAHCeJ.d.cts} +73 -46
- package/dist/{validate-B3uHoP8n.d.ts → validate-lkJAHCeJ.d.ts} +73 -46
- package/dist/web-api.cjs +35 -35
- package/dist/web-api.d.cts +2 -2
- package/dist/web-api.d.ts +2 -2
- package/dist/web-api.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-BHG5RSUV.cjs.map +0 -1
- package/dist/chunk-CRTOKS3Q.js.map +0 -1
- package/dist/chunk-HMTHK2IY.cjs.map +0 -1
- package/dist/chunk-RAEBT46G.js.map +0 -1
- package/dist/chunk-RUTGDMVR.js.map +0 -1
- package/dist/chunk-UVEMRK5F.cjs.map +0 -1
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword,
|
|
2
|
-
export { ENCRYPTED_REGEX, matchEncryptedPattern, parseToObj, stringifyObj, tryParseToObj, tryStringifyObj } from './chunk-
|
|
1
|
+
export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword } from './chunk-S6SNCTU6.js';
|
|
2
|
+
export { ENCRYPTED_REGEX, isNodeSecretKey, matchEncryptedPattern, parseToObj, stringifyObj, tryParseToObj, tryStringifyObj } from './chunk-LU7QOSQH.js';
|
|
3
3
|
//# sourceMappingURL=node.js.map
|
|
4
4
|
//# sourceMappingURL=node.js.map
|
|
@@ -4,10 +4,27 @@ import nodeCrypto, { webcrypto } from 'node:crypto';
|
|
|
4
4
|
* Standardized error object for the `Result` type.
|
|
5
5
|
* Always has a brief `message` and a more detailed `description`.
|
|
6
6
|
*/
|
|
7
|
-
interface
|
|
7
|
+
interface ErrorStruct {
|
|
8
8
|
readonly message: string;
|
|
9
9
|
readonly description: string;
|
|
10
10
|
}
|
|
11
|
+
type ReservedWords<Obj extends object> = "success" extends keyof Obj ? never : "error" extends keyof Obj ? never : Obj;
|
|
12
|
+
type OkType<T> = {
|
|
13
|
+
readonly success: true;
|
|
14
|
+
readonly error?: undefined;
|
|
15
|
+
} & (T extends object ? ReservedWords<{
|
|
16
|
+
readonly [K in keyof T]: T[K];
|
|
17
|
+
}> : {
|
|
18
|
+
readonly result: T;
|
|
19
|
+
});
|
|
20
|
+
type ErrType<T> = {
|
|
21
|
+
readonly success: false;
|
|
22
|
+
readonly error: ErrorStruct;
|
|
23
|
+
} & (T extends object ? ReservedWords<{
|
|
24
|
+
readonly [K in keyof T]?: undefined;
|
|
25
|
+
}> : {
|
|
26
|
+
readonly result?: undefined;
|
|
27
|
+
});
|
|
11
28
|
/**
|
|
12
29
|
* Discriminated union for functions that can succeed or fail.
|
|
13
30
|
*
|
|
@@ -34,25 +51,7 @@ interface ResultErr {
|
|
|
34
51
|
* if (r2.success) console.log(r2.name, r2.age); // 'Alice' 30
|
|
35
52
|
* ```
|
|
36
53
|
*/
|
|
37
|
-
type Result<T
|
|
38
|
-
readonly [K in keyof T]: T[K];
|
|
39
|
-
} & {
|
|
40
|
-
readonly success: true;
|
|
41
|
-
readonly error?: undefined;
|
|
42
|
-
}) | ({
|
|
43
|
-
readonly [K in keyof T]?: undefined;
|
|
44
|
-
} & {
|
|
45
|
-
readonly success: false;
|
|
46
|
-
readonly error: E;
|
|
47
|
-
}) : {
|
|
48
|
-
readonly success: true;
|
|
49
|
-
readonly result: T;
|
|
50
|
-
readonly error?: undefined;
|
|
51
|
-
} | {
|
|
52
|
-
readonly success: false;
|
|
53
|
-
readonly error: E;
|
|
54
|
-
readonly result?: undefined;
|
|
55
|
-
};
|
|
54
|
+
type Result<T> = OkType<T> | ErrType<T>;
|
|
56
55
|
|
|
57
56
|
declare const ENCODING: readonly ["base64", "base64url", "hex", "utf8", "latin1"];
|
|
58
57
|
declare const CIPHER_ENCODING: readonly ["base64", "base64url", "hex"];
|
|
@@ -92,19 +91,9 @@ declare const ENCRYPTION_ALGORITHMS: Readonly<{
|
|
|
92
91
|
}>;
|
|
93
92
|
|
|
94
93
|
declare const __brand: unique symbol;
|
|
95
|
-
/** A brand type to distinguish between different types */
|
|
96
94
|
type Brand<T> = {
|
|
97
95
|
readonly [__brand]: T;
|
|
98
96
|
};
|
|
99
|
-
/**
|
|
100
|
-
* A platform-specific secret key for encryption/decryption.
|
|
101
|
-
*
|
|
102
|
-
* ### 🍼 Explain Like I'm Five
|
|
103
|
-
* You have a treasure (your secret data) and want to keep it safe.
|
|
104
|
-
* For that you create a key (the secret key) and lock your treasure with it.
|
|
105
|
-
*
|
|
106
|
-
* @template Platform - 'web' or 'node' to specify the platform of the secret key.
|
|
107
|
-
*/
|
|
108
97
|
type SecretKey<Platform extends "web" | "node"> = {
|
|
109
98
|
/** The platform the key is for ('web' or 'node'). */
|
|
110
99
|
readonly platform: Platform;
|
|
@@ -115,6 +104,10 @@ type SecretKey<Platform extends "web" | "node"> = {
|
|
|
115
104
|
/** The actual secret key object (CryptoKey for web, KeyObject for node). */
|
|
116
105
|
readonly key: Platform extends "web" ? webcrypto.CryptoKey : nodeCrypto.KeyObject;
|
|
117
106
|
} & Brand<`secretKey-${Platform}`>;
|
|
107
|
+
/** A secret key for Node.js platform. */
|
|
108
|
+
type NodeSecretKey = SecretKey<"node">;
|
|
109
|
+
/** A secret key for Web platform. */
|
|
110
|
+
type WebSecretKey = SecretKey<"web">;
|
|
118
111
|
/** Supported **cipher text** encodings for encrypted/hash outputs. */
|
|
119
112
|
type CipherEncoding = (typeof CIPHER_ENCODING)[number];
|
|
120
113
|
/** Supported data encodings for **plain text/bytes** conversions. */
|
|
@@ -131,10 +124,10 @@ type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
|
|
|
131
124
|
* You can choose how strong the lock is (algorithm), how to make the key (digest),
|
|
132
125
|
* and add some extra secret stuff (salt and info) to make your key unique.
|
|
133
126
|
*
|
|
134
|
-
* - `algorithm
|
|
135
|
-
* - `digest
|
|
136
|
-
* - `salt
|
|
137
|
-
* - `info
|
|
127
|
+
* - `algorithm`: Encryption algorithm to use (default: `'aes256gcm'`)
|
|
128
|
+
* - `digest`: Digest algorithm for HKDF (default: `'sha256'`)
|
|
129
|
+
* - `salt`: Salt for HKDF (default: `'cipher-kit-salt'`, must be ≥ 8 chars)
|
|
130
|
+
* - `info`: Added context for HKDF (default: `'cipher-kit'`)
|
|
138
131
|
*/
|
|
139
132
|
interface CreateSecretKeyOptions {
|
|
140
133
|
/** Encryption algorithm to use (default: `'aes256gcm'`). */
|
|
@@ -152,7 +145,7 @@ interface CreateSecretKeyOptions {
|
|
|
152
145
|
* ### 🍼 Explain Like I'm Five
|
|
153
146
|
* After locking your message, how should we write the locked message down?
|
|
154
147
|
*
|
|
155
|
-
* - `outputEncoding`:
|
|
148
|
+
* - `outputEncoding`: Output ciphertext encoding (`'base64' | 'base64url' | 'hex'`) (default: `'base64url'`)
|
|
156
149
|
*/
|
|
157
150
|
interface EncryptOptions {
|
|
158
151
|
/** Encoding format for the output ciphertext (default: `'base64url'`). */
|
|
@@ -164,7 +157,7 @@ interface EncryptOptions {
|
|
|
164
157
|
* ### 🍼 Explain Like I'm Five
|
|
165
158
|
* To unlock the message, we must know how it was written down.
|
|
166
159
|
*
|
|
167
|
-
* - `inputEncoding`:
|
|
160
|
+
* - `inputEncoding`: Input ciphertext encoding (`'base64' | 'base64url' | 'hex'`) (default: `'base64url'`)
|
|
168
161
|
*/
|
|
169
162
|
interface DecryptOptions {
|
|
170
163
|
/** Encoding format for the input ciphertext (default: `'base64url'`). */
|
|
@@ -178,7 +171,7 @@ interface DecryptOptions {
|
|
|
178
171
|
* You can choose how to create the fingerprint (digest) and how to write it down (encoding).
|
|
179
172
|
*
|
|
180
173
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha256'`)
|
|
181
|
-
* - `outputEncoding`:
|
|
174
|
+
* - `outputEncoding`: Output ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
182
175
|
*/
|
|
183
176
|
interface HashOptions {
|
|
184
177
|
/** Digest algorithm to use (default: `'sha256'`). */
|
|
@@ -194,10 +187,10 @@ interface HashOptions {
|
|
|
194
187
|
* stirring many times (iterations), and making a long result (keyLength).
|
|
195
188
|
*
|
|
196
189
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha512'`)
|
|
197
|
-
* - `outputEncoding`:
|
|
198
|
-
* - `saltLength`:
|
|
199
|
-
* - `iterations`:
|
|
200
|
-
* - `keyLength`:
|
|
190
|
+
* - `outputEncoding`: Output ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
191
|
+
* - `saltLength`: Size of the random salt in bytes (default: `16` bytes)
|
|
192
|
+
* - `iterations`: Number of iterations (default: `320000`)
|
|
193
|
+
* - `keyLength`: Length of the derived key in bytes (default: `64` bytes)
|
|
201
194
|
*/
|
|
202
195
|
interface HashPasswordOptions {
|
|
203
196
|
/** Digest algorithm to use (default: `'sha512'`). */
|
|
@@ -219,9 +212,9 @@ interface HashPasswordOptions {
|
|
|
219
212
|
* same size—so the new result matches the old one.
|
|
220
213
|
*
|
|
221
214
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha512'`)
|
|
222
|
-
* - `inputEncoding`:
|
|
223
|
-
* - `iterations`:
|
|
224
|
-
* - `keyLength`:
|
|
215
|
+
* - `inputEncoding`: Input ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
216
|
+
* - `iterations`: Number of iterations (default: `320000`)
|
|
217
|
+
* - `keyLength`: Length of the derived key in bytes (default: `64` bytes)
|
|
225
218
|
*/
|
|
226
219
|
interface VerifyPasswordOptions {
|
|
227
220
|
/** Digest algorithm to use (default: `'sha512'`). */
|
|
@@ -321,6 +314,40 @@ declare function tryParseToObj<T extends object = Record<string, unknown>>(str:
|
|
|
321
314
|
*/
|
|
322
315
|
declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
|
|
323
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Type guard to check if the provided value is a SecretKey object for Node.js environment.
|
|
319
|
+
*
|
|
320
|
+
* ### 🍼 Explain Like I'm Five
|
|
321
|
+
* Checking if the key in your hand is the right kind of key for the lock.
|
|
322
|
+
*
|
|
323
|
+
* @param x - The value to check.
|
|
324
|
+
* @returns True if the value is a SecretKey object for Node.js, false otherwise.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* isNodeSecretKey(nodeKey); // true
|
|
329
|
+
* isNodeSecretKey(webKey); // false
|
|
330
|
+
* isNodeSecretKey({}); // false
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
declare function isNodeSecretKey(x: unknown): x is NodeSecretKey;
|
|
334
|
+
/**
|
|
335
|
+
* Type guard to check if the provided value is a SecretKey object for Web (Deno, Bun, Cloudflare included) environment.
|
|
336
|
+
*
|
|
337
|
+
* ### 🍼 Explain Like I'm Five
|
|
338
|
+
* Checking if the key in your hand is the right kind of key for the lock.
|
|
339
|
+
*
|
|
340
|
+
* @param x - The value to check.
|
|
341
|
+
* @returns True if the value is a SecretKey object for Web, false otherwise.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* isWebSecretKey(webKey); // true
|
|
346
|
+
* isWebSecretKey(nodeKey); // false
|
|
347
|
+
* isWebSecretKey({}); // false
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
declare function isWebSecretKey(x: unknown): x is WebSecretKey;
|
|
324
351
|
/**
|
|
325
352
|
* Regular expressions for encrypted data patterns.
|
|
326
353
|
*
|
|
@@ -367,6 +394,6 @@ declare const ENCRYPTED_REGEX: Readonly<{
|
|
|
367
394
|
* matchEncryptedPattern("abc.def.ghi.", "general"); // true
|
|
368
395
|
* ```
|
|
369
396
|
*/
|
|
370
|
-
declare function matchEncryptedPattern(data: string, format: "
|
|
397
|
+
declare function matchEncryptedPattern(data: string, format: "node" | "web" | "general"): boolean;
|
|
371
398
|
|
|
372
|
-
export { type CipherEncoding as C, type DigestAlgorithm as D, ENCRYPTED_REGEX as E, type HashOptions as H, type
|
|
399
|
+
export { type CipherEncoding as C, type DigestAlgorithm as D, ENCRYPTED_REGEX as E, type HashOptions as H, type NodeSecretKey as N, type Result as R, type VerifyPasswordOptions as V, type WebSecretKey as W, tryStringifyObj as a, isWebSecretKey as b, type Encoding as c, type EncryptionAlgorithm as d, type CreateSecretKeyOptions as e, type EncryptOptions as f, type DecryptOptions as g, type HashPasswordOptions as h, isNodeSecretKey as i, matchEncryptedPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };
|
|
@@ -4,10 +4,27 @@ import nodeCrypto, { webcrypto } from 'node:crypto';
|
|
|
4
4
|
* Standardized error object for the `Result` type.
|
|
5
5
|
* Always has a brief `message` and a more detailed `description`.
|
|
6
6
|
*/
|
|
7
|
-
interface
|
|
7
|
+
interface ErrorStruct {
|
|
8
8
|
readonly message: string;
|
|
9
9
|
readonly description: string;
|
|
10
10
|
}
|
|
11
|
+
type ReservedWords<Obj extends object> = "success" extends keyof Obj ? never : "error" extends keyof Obj ? never : Obj;
|
|
12
|
+
type OkType<T> = {
|
|
13
|
+
readonly success: true;
|
|
14
|
+
readonly error?: undefined;
|
|
15
|
+
} & (T extends object ? ReservedWords<{
|
|
16
|
+
readonly [K in keyof T]: T[K];
|
|
17
|
+
}> : {
|
|
18
|
+
readonly result: T;
|
|
19
|
+
});
|
|
20
|
+
type ErrType<T> = {
|
|
21
|
+
readonly success: false;
|
|
22
|
+
readonly error: ErrorStruct;
|
|
23
|
+
} & (T extends object ? ReservedWords<{
|
|
24
|
+
readonly [K in keyof T]?: undefined;
|
|
25
|
+
}> : {
|
|
26
|
+
readonly result?: undefined;
|
|
27
|
+
});
|
|
11
28
|
/**
|
|
12
29
|
* Discriminated union for functions that can succeed or fail.
|
|
13
30
|
*
|
|
@@ -34,25 +51,7 @@ interface ResultErr {
|
|
|
34
51
|
* if (r2.success) console.log(r2.name, r2.age); // 'Alice' 30
|
|
35
52
|
* ```
|
|
36
53
|
*/
|
|
37
|
-
type Result<T
|
|
38
|
-
readonly [K in keyof T]: T[K];
|
|
39
|
-
} & {
|
|
40
|
-
readonly success: true;
|
|
41
|
-
readonly error?: undefined;
|
|
42
|
-
}) | ({
|
|
43
|
-
readonly [K in keyof T]?: undefined;
|
|
44
|
-
} & {
|
|
45
|
-
readonly success: false;
|
|
46
|
-
readonly error: E;
|
|
47
|
-
}) : {
|
|
48
|
-
readonly success: true;
|
|
49
|
-
readonly result: T;
|
|
50
|
-
readonly error?: undefined;
|
|
51
|
-
} | {
|
|
52
|
-
readonly success: false;
|
|
53
|
-
readonly error: E;
|
|
54
|
-
readonly result?: undefined;
|
|
55
|
-
};
|
|
54
|
+
type Result<T> = OkType<T> | ErrType<T>;
|
|
56
55
|
|
|
57
56
|
declare const ENCODING: readonly ["base64", "base64url", "hex", "utf8", "latin1"];
|
|
58
57
|
declare const CIPHER_ENCODING: readonly ["base64", "base64url", "hex"];
|
|
@@ -92,19 +91,9 @@ declare const ENCRYPTION_ALGORITHMS: Readonly<{
|
|
|
92
91
|
}>;
|
|
93
92
|
|
|
94
93
|
declare const __brand: unique symbol;
|
|
95
|
-
/** A brand type to distinguish between different types */
|
|
96
94
|
type Brand<T> = {
|
|
97
95
|
readonly [__brand]: T;
|
|
98
96
|
};
|
|
99
|
-
/**
|
|
100
|
-
* A platform-specific secret key for encryption/decryption.
|
|
101
|
-
*
|
|
102
|
-
* ### 🍼 Explain Like I'm Five
|
|
103
|
-
* You have a treasure (your secret data) and want to keep it safe.
|
|
104
|
-
* For that you create a key (the secret key) and lock your treasure with it.
|
|
105
|
-
*
|
|
106
|
-
* @template Platform - 'web' or 'node' to specify the platform of the secret key.
|
|
107
|
-
*/
|
|
108
97
|
type SecretKey<Platform extends "web" | "node"> = {
|
|
109
98
|
/** The platform the key is for ('web' or 'node'). */
|
|
110
99
|
readonly platform: Platform;
|
|
@@ -115,6 +104,10 @@ type SecretKey<Platform extends "web" | "node"> = {
|
|
|
115
104
|
/** The actual secret key object (CryptoKey for web, KeyObject for node). */
|
|
116
105
|
readonly key: Platform extends "web" ? webcrypto.CryptoKey : nodeCrypto.KeyObject;
|
|
117
106
|
} & Brand<`secretKey-${Platform}`>;
|
|
107
|
+
/** A secret key for Node.js platform. */
|
|
108
|
+
type NodeSecretKey = SecretKey<"node">;
|
|
109
|
+
/** A secret key for Web platform. */
|
|
110
|
+
type WebSecretKey = SecretKey<"web">;
|
|
118
111
|
/** Supported **cipher text** encodings for encrypted/hash outputs. */
|
|
119
112
|
type CipherEncoding = (typeof CIPHER_ENCODING)[number];
|
|
120
113
|
/** Supported data encodings for **plain text/bytes** conversions. */
|
|
@@ -131,10 +124,10 @@ type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
|
|
|
131
124
|
* You can choose how strong the lock is (algorithm), how to make the key (digest),
|
|
132
125
|
* and add some extra secret stuff (salt and info) to make your key unique.
|
|
133
126
|
*
|
|
134
|
-
* - `algorithm
|
|
135
|
-
* - `digest
|
|
136
|
-
* - `salt
|
|
137
|
-
* - `info
|
|
127
|
+
* - `algorithm`: Encryption algorithm to use (default: `'aes256gcm'`)
|
|
128
|
+
* - `digest`: Digest algorithm for HKDF (default: `'sha256'`)
|
|
129
|
+
* - `salt`: Salt for HKDF (default: `'cipher-kit-salt'`, must be ≥ 8 chars)
|
|
130
|
+
* - `info`: Added context for HKDF (default: `'cipher-kit'`)
|
|
138
131
|
*/
|
|
139
132
|
interface CreateSecretKeyOptions {
|
|
140
133
|
/** Encryption algorithm to use (default: `'aes256gcm'`). */
|
|
@@ -152,7 +145,7 @@ interface CreateSecretKeyOptions {
|
|
|
152
145
|
* ### 🍼 Explain Like I'm Five
|
|
153
146
|
* After locking your message, how should we write the locked message down?
|
|
154
147
|
*
|
|
155
|
-
* - `outputEncoding`:
|
|
148
|
+
* - `outputEncoding`: Output ciphertext encoding (`'base64' | 'base64url' | 'hex'`) (default: `'base64url'`)
|
|
156
149
|
*/
|
|
157
150
|
interface EncryptOptions {
|
|
158
151
|
/** Encoding format for the output ciphertext (default: `'base64url'`). */
|
|
@@ -164,7 +157,7 @@ interface EncryptOptions {
|
|
|
164
157
|
* ### 🍼 Explain Like I'm Five
|
|
165
158
|
* To unlock the message, we must know how it was written down.
|
|
166
159
|
*
|
|
167
|
-
* - `inputEncoding`:
|
|
160
|
+
* - `inputEncoding`: Input ciphertext encoding (`'base64' | 'base64url' | 'hex'`) (default: `'base64url'`)
|
|
168
161
|
*/
|
|
169
162
|
interface DecryptOptions {
|
|
170
163
|
/** Encoding format for the input ciphertext (default: `'base64url'`). */
|
|
@@ -178,7 +171,7 @@ interface DecryptOptions {
|
|
|
178
171
|
* You can choose how to create the fingerprint (digest) and how to write it down (encoding).
|
|
179
172
|
*
|
|
180
173
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha256'`)
|
|
181
|
-
* - `outputEncoding`:
|
|
174
|
+
* - `outputEncoding`: Output ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
182
175
|
*/
|
|
183
176
|
interface HashOptions {
|
|
184
177
|
/** Digest algorithm to use (default: `'sha256'`). */
|
|
@@ -194,10 +187,10 @@ interface HashOptions {
|
|
|
194
187
|
* stirring many times (iterations), and making a long result (keyLength).
|
|
195
188
|
*
|
|
196
189
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha512'`)
|
|
197
|
-
* - `outputEncoding`:
|
|
198
|
-
* - `saltLength`:
|
|
199
|
-
* - `iterations`:
|
|
200
|
-
* - `keyLength`:
|
|
190
|
+
* - `outputEncoding`: Output ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
191
|
+
* - `saltLength`: Size of the random salt in bytes (default: `16` bytes)
|
|
192
|
+
* - `iterations`: Number of iterations (default: `320000`)
|
|
193
|
+
* - `keyLength`: Length of the derived key in bytes (default: `64` bytes)
|
|
201
194
|
*/
|
|
202
195
|
interface HashPasswordOptions {
|
|
203
196
|
/** Digest algorithm to use (default: `'sha512'`). */
|
|
@@ -219,9 +212,9 @@ interface HashPasswordOptions {
|
|
|
219
212
|
* same size—so the new result matches the old one.
|
|
220
213
|
*
|
|
221
214
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha512'`)
|
|
222
|
-
* - `inputEncoding`:
|
|
223
|
-
* - `iterations`:
|
|
224
|
-
* - `keyLength`:
|
|
215
|
+
* - `inputEncoding`: Input ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
216
|
+
* - `iterations`: Number of iterations (default: `320000`)
|
|
217
|
+
* - `keyLength`: Length of the derived key in bytes (default: `64` bytes)
|
|
225
218
|
*/
|
|
226
219
|
interface VerifyPasswordOptions {
|
|
227
220
|
/** Digest algorithm to use (default: `'sha512'`). */
|
|
@@ -321,6 +314,40 @@ declare function tryParseToObj<T extends object = Record<string, unknown>>(str:
|
|
|
321
314
|
*/
|
|
322
315
|
declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
|
|
323
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Type guard to check if the provided value is a SecretKey object for Node.js environment.
|
|
319
|
+
*
|
|
320
|
+
* ### 🍼 Explain Like I'm Five
|
|
321
|
+
* Checking if the key in your hand is the right kind of key for the lock.
|
|
322
|
+
*
|
|
323
|
+
* @param x - The value to check.
|
|
324
|
+
* @returns True if the value is a SecretKey object for Node.js, false otherwise.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* isNodeSecretKey(nodeKey); // true
|
|
329
|
+
* isNodeSecretKey(webKey); // false
|
|
330
|
+
* isNodeSecretKey({}); // false
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
declare function isNodeSecretKey(x: unknown): x is NodeSecretKey;
|
|
334
|
+
/**
|
|
335
|
+
* Type guard to check if the provided value is a SecretKey object for Web (Deno, Bun, Cloudflare included) environment.
|
|
336
|
+
*
|
|
337
|
+
* ### 🍼 Explain Like I'm Five
|
|
338
|
+
* Checking if the key in your hand is the right kind of key for the lock.
|
|
339
|
+
*
|
|
340
|
+
* @param x - The value to check.
|
|
341
|
+
* @returns True if the value is a SecretKey object for Web, false otherwise.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* isWebSecretKey(webKey); // true
|
|
346
|
+
* isWebSecretKey(nodeKey); // false
|
|
347
|
+
* isWebSecretKey({}); // false
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
declare function isWebSecretKey(x: unknown): x is WebSecretKey;
|
|
324
351
|
/**
|
|
325
352
|
* Regular expressions for encrypted data patterns.
|
|
326
353
|
*
|
|
@@ -367,6 +394,6 @@ declare const ENCRYPTED_REGEX: Readonly<{
|
|
|
367
394
|
* matchEncryptedPattern("abc.def.ghi.", "general"); // true
|
|
368
395
|
* ```
|
|
369
396
|
*/
|
|
370
|
-
declare function matchEncryptedPattern(data: string, format: "
|
|
397
|
+
declare function matchEncryptedPattern(data: string, format: "node" | "web" | "general"): boolean;
|
|
371
398
|
|
|
372
|
-
export { type CipherEncoding as C, type DigestAlgorithm as D, ENCRYPTED_REGEX as E, type HashOptions as H, type
|
|
399
|
+
export { type CipherEncoding as C, type DigestAlgorithm as D, ENCRYPTED_REGEX as E, type HashOptions as H, type NodeSecretKey as N, type Result as R, type VerifyPasswordOptions as V, type WebSecretKey as W, tryStringifyObj as a, isWebSecretKey as b, type Encoding as c, type EncryptionAlgorithm as d, type CreateSecretKeyOptions as e, type EncryptOptions as f, type DecryptOptions as g, type HashPasswordOptions as h, isNodeSecretKey as i, matchEncryptedPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };
|
package/dist/web-api.cjs
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk66WIL32E_cjs = require('./chunk-66WIL32E.cjs');
|
|
4
|
+
var chunkHTRGOBZF_cjs = require('./chunk-HTRGOBZF.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "convertBytesToStr", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunk66WIL32E_cjs.convertBytesToStr; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "convertEncoding", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk66WIL32E_cjs.convertEncoding; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "convertStrToBytes", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunk66WIL32E_cjs.convertStrToBytes; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "createSecretKey", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunk66WIL32E_cjs.createSecretKey; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "decrypt", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunk66WIL32E_cjs.decrypt; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "decryptObj", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunk66WIL32E_cjs.decryptObj; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "encrypt", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunk66WIL32E_cjs.encrypt; }
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "encryptObj", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
38
|
+
get: function () { return chunk66WIL32E_cjs.encryptObj; }
|
|
39
39
|
});
|
|
40
40
|
Object.defineProperty(exports, "generateUuid", {
|
|
41
41
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunk66WIL32E_cjs.generateUuid; }
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(exports, "hash", {
|
|
45
45
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
46
|
+
get: function () { return chunk66WIL32E_cjs.hash; }
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "hashPassword", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function () { return
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(exports, "isWebSecretKey", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
get: function () { return chunkUVEMRK5F_cjs.isWebSecretKey; }
|
|
50
|
+
get: function () { return chunk66WIL32E_cjs.hashPassword; }
|
|
55
51
|
});
|
|
56
52
|
Object.defineProperty(exports, "tryConvertBytesToStr", {
|
|
57
53
|
enumerable: true,
|
|
58
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunk66WIL32E_cjs.tryConvertBytesToStr; }
|
|
59
55
|
});
|
|
60
56
|
Object.defineProperty(exports, "tryConvertEncoding", {
|
|
61
57
|
enumerable: true,
|
|
62
|
-
get: function () { return
|
|
58
|
+
get: function () { return chunk66WIL32E_cjs.tryConvertEncoding; }
|
|
63
59
|
});
|
|
64
60
|
Object.defineProperty(exports, "tryConvertStrToBytes", {
|
|
65
61
|
enumerable: true,
|
|
66
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunk66WIL32E_cjs.tryConvertStrToBytes; }
|
|
67
63
|
});
|
|
68
64
|
Object.defineProperty(exports, "tryCreateSecretKey", {
|
|
69
65
|
enumerable: true,
|
|
70
|
-
get: function () { return
|
|
66
|
+
get: function () { return chunk66WIL32E_cjs.tryCreateSecretKey; }
|
|
71
67
|
});
|
|
72
68
|
Object.defineProperty(exports, "tryDecrypt", {
|
|
73
69
|
enumerable: true,
|
|
74
|
-
get: function () { return
|
|
70
|
+
get: function () { return chunk66WIL32E_cjs.tryDecrypt; }
|
|
75
71
|
});
|
|
76
72
|
Object.defineProperty(exports, "tryDecryptObj", {
|
|
77
73
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
74
|
+
get: function () { return chunk66WIL32E_cjs.tryDecryptObj; }
|
|
79
75
|
});
|
|
80
76
|
Object.defineProperty(exports, "tryEncrypt", {
|
|
81
77
|
enumerable: true,
|
|
82
|
-
get: function () { return
|
|
78
|
+
get: function () { return chunk66WIL32E_cjs.tryEncrypt; }
|
|
83
79
|
});
|
|
84
80
|
Object.defineProperty(exports, "tryEncryptObj", {
|
|
85
81
|
enumerable: true,
|
|
86
|
-
get: function () { return
|
|
82
|
+
get: function () { return chunk66WIL32E_cjs.tryEncryptObj; }
|
|
87
83
|
});
|
|
88
84
|
Object.defineProperty(exports, "tryGenerateUuid", {
|
|
89
85
|
enumerable: true,
|
|
90
|
-
get: function () { return
|
|
86
|
+
get: function () { return chunk66WIL32E_cjs.tryGenerateUuid; }
|
|
91
87
|
});
|
|
92
88
|
Object.defineProperty(exports, "tryHash", {
|
|
93
89
|
enumerable: true,
|
|
94
|
-
get: function () { return
|
|
90
|
+
get: function () { return chunk66WIL32E_cjs.tryHash; }
|
|
95
91
|
});
|
|
96
92
|
Object.defineProperty(exports, "tryHashPassword", {
|
|
97
93
|
enumerable: true,
|
|
98
|
-
get: function () { return
|
|
94
|
+
get: function () { return chunk66WIL32E_cjs.tryHashPassword; }
|
|
99
95
|
});
|
|
100
96
|
Object.defineProperty(exports, "verifyPassword", {
|
|
101
97
|
enumerable: true,
|
|
102
|
-
get: function () { return
|
|
98
|
+
get: function () { return chunk66WIL32E_cjs.verifyPassword; }
|
|
103
99
|
});
|
|
104
100
|
Object.defineProperty(exports, "ENCRYPTED_REGEX", {
|
|
105
101
|
enumerable: true,
|
|
106
|
-
get: function () { return
|
|
102
|
+
get: function () { return chunkHTRGOBZF_cjs.ENCRYPTED_REGEX; }
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "isWebSecretKey", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () { return chunkHTRGOBZF_cjs.isWebSecretKey; }
|
|
107
107
|
});
|
|
108
108
|
Object.defineProperty(exports, "matchEncryptedPattern", {
|
|
109
109
|
enumerable: true,
|
|
110
|
-
get: function () { return
|
|
110
|
+
get: function () { return chunkHTRGOBZF_cjs.matchEncryptedPattern; }
|
|
111
111
|
});
|
|
112
112
|
Object.defineProperty(exports, "parseToObj", {
|
|
113
113
|
enumerable: true,
|
|
114
|
-
get: function () { return
|
|
114
|
+
get: function () { return chunkHTRGOBZF_cjs.parseToObj; }
|
|
115
115
|
});
|
|
116
116
|
Object.defineProperty(exports, "stringifyObj", {
|
|
117
117
|
enumerable: true,
|
|
118
|
-
get: function () { return
|
|
118
|
+
get: function () { return chunkHTRGOBZF_cjs.stringifyObj; }
|
|
119
119
|
});
|
|
120
120
|
Object.defineProperty(exports, "tryParseToObj", {
|
|
121
121
|
enumerable: true,
|
|
122
|
-
get: function () { return
|
|
122
|
+
get: function () { return chunkHTRGOBZF_cjs.tryParseToObj; }
|
|
123
123
|
});
|
|
124
124
|
Object.defineProperty(exports, "tryStringifyObj", {
|
|
125
125
|
enumerable: true,
|
|
126
|
-
get: function () { return
|
|
126
|
+
get: function () { return chunkHTRGOBZF_cjs.tryStringifyObj; }
|
|
127
127
|
});
|
|
128
128
|
//# sourceMappingURL=web-api.cjs.map
|
|
129
129
|
//# sourceMappingURL=web-api.cjs.map
|
package/dist/web-api.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CipherEncoding,
|
|
2
|
-
export {
|
|
1
|
+
export { C as CipherEncoding, e as CreateSecretKeyOptions, g as DecryptOptions, D as DigestAlgorithm, E as ENCRYPTED_REGEX, c as Encoding, f as EncryptOptions, d as EncryptionAlgorithm, H as HashOptions, h as HashPasswordOptions, N as NodeSecretKey, V as VerifyPasswordOptions, W as WebSecretKey, b as isWebSecretKey, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, a as tryStringifyObj } from './validate-lkJAHCeJ.cjs';
|
|
2
|
+
export { s as convertBytesToStr, x as convertEncoding, q as convertStrToBytes, c as createSecretKey, f as decrypt, k as decryptObj, e as encrypt, i as encryptObj, g as generateUuid, m as hash, o as hashPassword, r as tryConvertBytesToStr, u as tryConvertEncoding, p as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, j as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, l as tryHash, n as tryHashPassword, v as verifyPassword } from './export-FYHgb-8E.cjs';
|
|
3
3
|
import 'node:crypto';
|
package/dist/web-api.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { C as CipherEncoding,
|
|
2
|
-
export {
|
|
1
|
+
export { C as CipherEncoding, e as CreateSecretKeyOptions, g as DecryptOptions, D as DigestAlgorithm, E as ENCRYPTED_REGEX, c as Encoding, f as EncryptOptions, d as EncryptionAlgorithm, H as HashOptions, h as HashPasswordOptions, N as NodeSecretKey, V as VerifyPasswordOptions, W as WebSecretKey, b as isWebSecretKey, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, a as tryStringifyObj } from './validate-lkJAHCeJ.js';
|
|
2
|
+
export { s as convertBytesToStr, x as convertEncoding, q as convertStrToBytes, c as createSecretKey, f as decrypt, k as decryptObj, e as encrypt, i as encryptObj, g as generateUuid, m as hash, o as hashPassword, r as tryConvertBytesToStr, u as tryConvertEncoding, p as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, j as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, l as tryHash, n as tryHashPassword, v as verifyPassword } from './export-CCTGAosO.js';
|
|
3
3
|
import 'node:crypto';
|
package/dist/web-api.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword,
|
|
2
|
-
export { ENCRYPTED_REGEX, matchEncryptedPattern, parseToObj, stringifyObj, tryParseToObj, tryStringifyObj } from './chunk-
|
|
1
|
+
export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword } from './chunk-JLFVTZY4.js';
|
|
2
|
+
export { ENCRYPTED_REGEX, isWebSecretKey, matchEncryptedPattern, parseToObj, stringifyObj, tryParseToObj, tryStringifyObj } from './chunk-LU7QOSQH.js';
|
|
3
3
|
//# sourceMappingURL=web-api.js.map
|
|
4
4
|
//# sourceMappingURL=web-api.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cipher-kit",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "🔐 Secure, Modern, and Cross-Platform Cryptography Helpers for Web, Node.js, Deno, Bun, and Cloudflare Workers",
|
|
5
5
|
"homepage": "https://github.com/WolfieLeader/npm/tree/main/packages/cipher-kit#readme",
|
|
6
6
|
"repository": {
|