cipher-kit 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -28
- package/dist/{chunk-N2EW2FDZ.cjs → chunk-56PVVFVM.cjs} +187 -152
- package/dist/chunk-56PVVFVM.cjs.map +1 -0
- package/dist/{chunk-FKSYSPJR.js → chunk-6C4NIWQ4.js} +24 -22
- package/dist/chunk-6C4NIWQ4.js.map +1 -0
- package/dist/{chunk-4MFF6V3R.js → chunk-FSEA3UXJ.js} +80 -45
- package/dist/chunk-FSEA3UXJ.js.map +1 -0
- package/dist/{chunk-CVCDAHDW.cjs → chunk-LTVOIZP5.cjs} +193 -158
- package/dist/chunk-LTVOIZP5.cjs.map +1 -0
- package/dist/{chunk-ACFPMIXO.js → chunk-PWTFVMW6.js} +79 -44
- package/dist/chunk-PWTFVMW6.js.map +1 -0
- package/dist/{chunk-3UX5MZ2P.cjs → chunk-X4CS7UXE.cjs} +25 -22
- package/dist/chunk-X4CS7UXE.cjs.map +1 -0
- package/dist/{export-55tHE0Bw.d.cts → export-C4DbO5zM.d.ts} +200 -26
- package/dist/{export-llM6c7Do.d.ts → export-CpZ7s25O.d.cts} +200 -26
- package/dist/{export-CQNsJFh_.d.cts → export-DO9n7Np-.d.cts} +200 -26
- package/dist/{export-BMvZq46v.d.ts → export-DUgIcobC.d.ts} +200 -26
- package/dist/index.cjs +12 -12
- 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 +33 -33
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +2 -2
- package/dist/{validate-EHuJC5QQ.d.cts → validate-cJEdGlj1.d.cts} +54 -67
- package/dist/{validate-EHuJC5QQ.d.ts → validate-cJEdGlj1.d.ts} +54 -67
- package/dist/web-api.cjs +33 -33
- 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 +6 -7
- package/dist/chunk-3UX5MZ2P.cjs.map +0 -1
- package/dist/chunk-4MFF6V3R.js.map +0 -1
- package/dist/chunk-ACFPMIXO.js.map +0 -1
- package/dist/chunk-CVCDAHDW.cjs.map +0 -1
- package/dist/chunk-FKSYSPJR.js.map +0 -1
- package/dist/chunk-N2EW2FDZ.cjs.map +0 -1
package/dist/node.cjs
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk56PVVFVM_cjs = require('./chunk-56PVVFVM.cjs');
|
|
4
|
+
var chunkX4CS7UXE_cjs = require('./chunk-X4CS7UXE.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 chunk56PVVFVM_cjs.convertBytesToStr; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "convertEncoding", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk56PVVFVM_cjs.convertEncoding; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "convertStrToBytes", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunk56PVVFVM_cjs.convertStrToBytes; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "createSecretKey", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunk56PVVFVM_cjs.createSecretKey; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "decrypt", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunk56PVVFVM_cjs.decrypt; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "decryptObj", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunk56PVVFVM_cjs.decryptObj; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "encrypt", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunk56PVVFVM_cjs.encrypt; }
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "encryptObj", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
38
|
+
get: function () { return chunk56PVVFVM_cjs.encryptObj; }
|
|
39
39
|
});
|
|
40
40
|
Object.defineProperty(exports, "generateUuid", {
|
|
41
41
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunk56PVVFVM_cjs.generateUuid; }
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(exports, "hash", {
|
|
45
45
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
46
|
+
get: function () { return chunk56PVVFVM_cjs.hash; }
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "hashPassword", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function () { return
|
|
50
|
+
get: function () { return chunk56PVVFVM_cjs.hashPassword; }
|
|
51
51
|
});
|
|
52
52
|
Object.defineProperty(exports, "isNodeSecretKey", {
|
|
53
53
|
enumerable: true,
|
|
54
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunk56PVVFVM_cjs.isNodeSecretKey; }
|
|
55
55
|
});
|
|
56
56
|
Object.defineProperty(exports, "tryConvertBytesToStr", {
|
|
57
57
|
enumerable: true,
|
|
58
|
-
get: function () { return
|
|
58
|
+
get: function () { return chunk56PVVFVM_cjs.tryConvertBytesToStr; }
|
|
59
59
|
});
|
|
60
60
|
Object.defineProperty(exports, "tryConvertEncoding", {
|
|
61
61
|
enumerable: true,
|
|
62
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunk56PVVFVM_cjs.tryConvertEncoding; }
|
|
63
63
|
});
|
|
64
64
|
Object.defineProperty(exports, "tryConvertStrToBytes", {
|
|
65
65
|
enumerable: true,
|
|
66
|
-
get: function () { return
|
|
66
|
+
get: function () { return chunk56PVVFVM_cjs.tryConvertStrToBytes; }
|
|
67
67
|
});
|
|
68
68
|
Object.defineProperty(exports, "tryCreateSecretKey", {
|
|
69
69
|
enumerable: true,
|
|
70
|
-
get: function () { return
|
|
70
|
+
get: function () { return chunk56PVVFVM_cjs.tryCreateSecretKey; }
|
|
71
71
|
});
|
|
72
72
|
Object.defineProperty(exports, "tryDecrypt", {
|
|
73
73
|
enumerable: true,
|
|
74
|
-
get: function () { return
|
|
74
|
+
get: function () { return chunk56PVVFVM_cjs.tryDecrypt; }
|
|
75
75
|
});
|
|
76
76
|
Object.defineProperty(exports, "tryDecryptObj", {
|
|
77
77
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
78
|
+
get: function () { return chunk56PVVFVM_cjs.tryDecryptObj; }
|
|
79
79
|
});
|
|
80
80
|
Object.defineProperty(exports, "tryEncrypt", {
|
|
81
81
|
enumerable: true,
|
|
82
|
-
get: function () { return
|
|
82
|
+
get: function () { return chunk56PVVFVM_cjs.tryEncrypt; }
|
|
83
83
|
});
|
|
84
84
|
Object.defineProperty(exports, "tryEncryptObj", {
|
|
85
85
|
enumerable: true,
|
|
86
|
-
get: function () { return
|
|
86
|
+
get: function () { return chunk56PVVFVM_cjs.tryEncryptObj; }
|
|
87
87
|
});
|
|
88
88
|
Object.defineProperty(exports, "tryGenerateUuid", {
|
|
89
89
|
enumerable: true,
|
|
90
|
-
get: function () { return
|
|
90
|
+
get: function () { return chunk56PVVFVM_cjs.tryGenerateUuid; }
|
|
91
91
|
});
|
|
92
92
|
Object.defineProperty(exports, "tryHash", {
|
|
93
93
|
enumerable: true,
|
|
94
|
-
get: function () { return
|
|
94
|
+
get: function () { return chunk56PVVFVM_cjs.tryHash; }
|
|
95
95
|
});
|
|
96
96
|
Object.defineProperty(exports, "tryHashPassword", {
|
|
97
97
|
enumerable: true,
|
|
98
|
-
get: function () { return
|
|
98
|
+
get: function () { return chunk56PVVFVM_cjs.tryHashPassword; }
|
|
99
99
|
});
|
|
100
100
|
Object.defineProperty(exports, "verifyPassword", {
|
|
101
101
|
enumerable: true,
|
|
102
|
-
get: function () { return
|
|
102
|
+
get: function () { return chunk56PVVFVM_cjs.verifyPassword; }
|
|
103
103
|
});
|
|
104
104
|
Object.defineProperty(exports, "ENCRYPTED_REGEX", {
|
|
105
105
|
enumerable: true,
|
|
106
|
-
get: function () { return
|
|
106
|
+
get: function () { return chunkX4CS7UXE_cjs.ENCRYPTED_REGEX; }
|
|
107
107
|
});
|
|
108
|
-
Object.defineProperty(exports, "
|
|
108
|
+
Object.defineProperty(exports, "matchEncryptedPattern", {
|
|
109
109
|
enumerable: true,
|
|
110
|
-
get: function () { return
|
|
110
|
+
get: function () { return chunkX4CS7UXE_cjs.matchEncryptedPattern; }
|
|
111
111
|
});
|
|
112
112
|
Object.defineProperty(exports, "parseToObj", {
|
|
113
113
|
enumerable: true,
|
|
114
|
-
get: function () { return
|
|
114
|
+
get: function () { return chunkX4CS7UXE_cjs.parseToObj; }
|
|
115
115
|
});
|
|
116
116
|
Object.defineProperty(exports, "stringifyObj", {
|
|
117
117
|
enumerable: true,
|
|
118
|
-
get: function () { return
|
|
118
|
+
get: function () { return chunkX4CS7UXE_cjs.stringifyObj; }
|
|
119
119
|
});
|
|
120
120
|
Object.defineProperty(exports, "tryParseToObj", {
|
|
121
121
|
enumerable: true,
|
|
122
|
-
get: function () { return
|
|
122
|
+
get: function () { return chunkX4CS7UXE_cjs.tryParseToObj; }
|
|
123
123
|
});
|
|
124
124
|
Object.defineProperty(exports, "tryStringifyObj", {
|
|
125
125
|
enumerable: true,
|
|
126
|
-
get: function () { return
|
|
126
|
+
get: function () { return chunkX4CS7UXE_cjs.tryStringifyObj; }
|
|
127
127
|
});
|
|
128
128
|
//# sourceMappingURL=node.cjs.map
|
|
129
129
|
//# sourceMappingURL=node.cjs.map
|
package/dist/node.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as CipherEncoding, d as CreateSecretKeyOptions, f as DecryptOptions, D as DigestAlgorithm, E as ENCRYPTED_REGEX, b as Encoding, e as EncryptOptions, c as EncryptionAlgorithm, H as HashOptions, g as HashPasswordOptions, S as SecretKey, V as VerifyPasswordOptions, m as
|
|
2
|
-
export { w as convertBytesToStr, y as convertEncoding, s as convertStrToBytes, c as createSecretKey, f as decrypt, l as decryptObj, e as encrypt, j as encryptObj, g as generateUuid, o as hash, q as hashPassword, i as isNodeSecretKey, u as tryConvertBytesToStr, x as tryConvertEncoding, r as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, k as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, m as tryHash, p as tryHashPassword, v as verifyPassword } from './export-
|
|
1
|
+
export { C as CipherEncoding, d as CreateSecretKeyOptions, f as DecryptOptions, D as DigestAlgorithm, E as ENCRYPTED_REGEX, b as Encoding, e as EncryptOptions, c as EncryptionAlgorithm, H as HashOptions, g as HashPasswordOptions, S as SecretKey, V as VerifyPasswordOptions, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, a as tryStringifyObj } from './validate-cJEdGlj1.cjs';
|
|
2
|
+
export { w as convertBytesToStr, y as convertEncoding, s as convertStrToBytes, c as createSecretKey, f as decrypt, l as decryptObj, e as encrypt, j as encryptObj, g as generateUuid, o as hash, q as hashPassword, i as isNodeSecretKey, u as tryConvertBytesToStr, x as tryConvertEncoding, r as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, k as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, m as tryHash, p as tryHashPassword, v as verifyPassword } from './export-DO9n7Np-.cjs';
|
|
3
3
|
import 'node:crypto';
|
|
4
4
|
import 'node:buffer';
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as CipherEncoding, d as CreateSecretKeyOptions, f as DecryptOptions, D as DigestAlgorithm, E as ENCRYPTED_REGEX, b as Encoding, e as EncryptOptions, c as EncryptionAlgorithm, H as HashOptions, g as HashPasswordOptions, S as SecretKey, V as VerifyPasswordOptions, m as
|
|
2
|
-
export { w as convertBytesToStr, y as convertEncoding, s as convertStrToBytes, c as createSecretKey, f as decrypt, l as decryptObj, e as encrypt, j as encryptObj, g as generateUuid, o as hash, q as hashPassword, i as isNodeSecretKey, u as tryConvertBytesToStr, x as tryConvertEncoding, r as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, k as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, m as tryHash, p as tryHashPassword, v as verifyPassword } from './export-
|
|
1
|
+
export { C as CipherEncoding, d as CreateSecretKeyOptions, f as DecryptOptions, D as DigestAlgorithm, E as ENCRYPTED_REGEX, b as Encoding, e as EncryptOptions, c as EncryptionAlgorithm, H as HashOptions, g as HashPasswordOptions, S as SecretKey, V as VerifyPasswordOptions, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, a as tryStringifyObj } from './validate-cJEdGlj1.js';
|
|
2
|
+
export { w as convertBytesToStr, y as convertEncoding, s as convertStrToBytes, c as createSecretKey, f as decrypt, l as decryptObj, e as encrypt, j as encryptObj, g as generateUuid, o as hash, q as hashPassword, i as isNodeSecretKey, u as tryConvertBytesToStr, x as tryConvertEncoding, r as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, k as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, m as tryHash, p as tryHashPassword, v as verifyPassword } from './export-DUgIcobC.js';
|
|
3
3
|
import 'node:crypto';
|
|
4
4
|
import 'node:buffer';
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, isNodeSecretKey, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword } from './chunk-
|
|
2
|
-
export { ENCRYPTED_REGEX,
|
|
1
|
+
export { convertBytesToStr, convertEncoding, convertStrToBytes, createSecretKey, decrypt, decryptObj, encrypt, encryptObj, generateUuid, hash, hashPassword, isNodeSecretKey, tryConvertBytesToStr, tryConvertEncoding, tryConvertStrToBytes, tryCreateSecretKey, tryDecrypt, tryDecryptObj, tryEncrypt, tryEncryptObj, tryGenerateUuid, tryHash, tryHashPassword, verifyPassword } from './chunk-PWTFVMW6.js';
|
|
2
|
+
export { ENCRYPTED_REGEX, matchEncryptedPattern, parseToObj, stringifyObj, tryParseToObj, tryStringifyObj } from './chunk-6C4NIWQ4.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"];
|
|
@@ -131,10 +130,10 @@ type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
|
|
|
131
130
|
* You can choose how strong the lock is (algorithm), how to make the key (digest),
|
|
132
131
|
* and add some extra secret stuff (salt and info) to make your key unique.
|
|
133
132
|
*
|
|
134
|
-
* - `algorithm
|
|
135
|
-
* - `digest
|
|
136
|
-
* - `salt
|
|
137
|
-
* - `info
|
|
133
|
+
* - `algorithm`: Encryption algorithm to use (default: `'aes256gcm'`)
|
|
134
|
+
* - `digest`: Digest algorithm for HKDF (default: `'sha256'`)
|
|
135
|
+
* - `salt`: Salt for HKDF (default: `'cipher-kit-salt'`, must be ≥ 8 chars)
|
|
136
|
+
* - `info`: Added context for HKDF (default: `'cipher-kit'`)
|
|
138
137
|
*/
|
|
139
138
|
interface CreateSecretKeyOptions {
|
|
140
139
|
/** Encryption algorithm to use (default: `'aes256gcm'`). */
|
|
@@ -152,11 +151,11 @@ interface CreateSecretKeyOptions {
|
|
|
152
151
|
* ### 🍼 Explain Like I'm Five
|
|
153
152
|
* After locking your message, how should we write the locked message down?
|
|
154
153
|
*
|
|
155
|
-
* - `
|
|
154
|
+
* - `outputEncoding`: Output ciphertext encoding (`'base64' | 'base64url' | 'hex'`) (default: `'base64url'`)
|
|
156
155
|
*/
|
|
157
156
|
interface EncryptOptions {
|
|
158
157
|
/** Encoding format for the output ciphertext (default: `'base64url'`). */
|
|
159
|
-
|
|
158
|
+
outputEncoding?: CipherEncoding;
|
|
160
159
|
}
|
|
161
160
|
/**
|
|
162
161
|
* Options for decryption.
|
|
@@ -164,11 +163,11 @@ interface EncryptOptions {
|
|
|
164
163
|
* ### 🍼 Explain Like I'm Five
|
|
165
164
|
* To unlock the message, we must know how it was written down.
|
|
166
165
|
*
|
|
167
|
-
* - `
|
|
166
|
+
* - `inputEncoding`: Input ciphertext encoding (`'base64' | 'base64url' | 'hex'`) (default: `'base64url'`)
|
|
168
167
|
*/
|
|
169
168
|
interface DecryptOptions {
|
|
170
169
|
/** Encoding format for the input ciphertext (default: `'base64url'`). */
|
|
171
|
-
|
|
170
|
+
inputEncoding?: CipherEncoding;
|
|
172
171
|
}
|
|
173
172
|
/**
|
|
174
173
|
* Options for hashing arbitrary data.
|
|
@@ -178,13 +177,13 @@ interface DecryptOptions {
|
|
|
178
177
|
* You can choose how to create the fingerprint (digest) and how to write it down (encoding).
|
|
179
178
|
*
|
|
180
179
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha256'`)
|
|
181
|
-
* - `
|
|
180
|
+
* - `outputEncoding`: Output ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
182
181
|
*/
|
|
183
182
|
interface HashOptions {
|
|
184
183
|
/** Digest algorithm to use (default: `'sha256'`). */
|
|
185
184
|
digest?: DigestAlgorithm;
|
|
186
185
|
/** Encoding format for the output hash (default: `'base64url'`). */
|
|
187
|
-
|
|
186
|
+
outputEncoding?: CipherEncoding;
|
|
188
187
|
}
|
|
189
188
|
/**
|
|
190
189
|
* Options for password hashing (PBKDF2).
|
|
@@ -194,16 +193,16 @@ interface HashOptions {
|
|
|
194
193
|
* stirring many times (iterations), and making a long result (keyLength).
|
|
195
194
|
*
|
|
196
195
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha512'`)
|
|
197
|
-
* - `
|
|
198
|
-
* - `saltLength`:
|
|
199
|
-
* - `iterations`:
|
|
200
|
-
* - `keyLength`:
|
|
196
|
+
* - `outputEncoding`: Output ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
197
|
+
* - `saltLength`: Size of the random salt in bytes (default: `16` bytes)
|
|
198
|
+
* - `iterations`: Number of iterations (default: `320000`)
|
|
199
|
+
* - `keyLength`: Length of the derived key in bytes (default: `64` bytes)
|
|
201
200
|
*/
|
|
202
201
|
interface HashPasswordOptions {
|
|
203
202
|
/** Digest algorithm to use (default: `'sha512'`). */
|
|
204
203
|
digest?: DigestAlgorithm;
|
|
205
204
|
/** Encoding format for the output hash (default: `'base64url'`). */
|
|
206
|
-
|
|
205
|
+
outputEncoding?: CipherEncoding;
|
|
207
206
|
/** Length of the salt in bytes (default: `16` bytes, min: `8` bytes). */
|
|
208
207
|
saltLength?: number;
|
|
209
208
|
/** Number of iterations for key derivation (default: `320000`, min: `1000`). */
|
|
@@ -219,15 +218,15 @@ interface HashPasswordOptions {
|
|
|
219
218
|
* same size—so the new result matches the old one.
|
|
220
219
|
*
|
|
221
220
|
* - `digest`: `'sha256' | 'sha384' | 'sha512'` (default: `'sha512'`)
|
|
222
|
-
* - `
|
|
223
|
-
* - `iterations`:
|
|
224
|
-
* - `keyLength`:
|
|
221
|
+
* - `inputEncoding`: Input ciphertext encoding for the hash (`'base64' | 'base64url' | 'hex'`; default: `'base64url'`)
|
|
222
|
+
* - `iterations`: Number of iterations (default: `320000`)
|
|
223
|
+
* - `keyLength`: Length of the derived key in bytes (default: `64` bytes)
|
|
225
224
|
*/
|
|
226
225
|
interface VerifyPasswordOptions {
|
|
227
226
|
/** Digest algorithm to use (default: `'sha512'`). */
|
|
228
227
|
digest?: DigestAlgorithm;
|
|
229
228
|
/** Encoding format of the input hash (default: `'base64url'`). */
|
|
230
|
-
|
|
229
|
+
inputEncoding?: CipherEncoding;
|
|
231
230
|
/** Number of iterations for key derivation (default: `320000`). */
|
|
232
231
|
iterations?: number;
|
|
233
232
|
/** Length of the derived key in bytes (default: `64` bytes). */
|
|
@@ -250,12 +249,10 @@ interface VerifyPasswordOptions {
|
|
|
250
249
|
*
|
|
251
250
|
* @example
|
|
252
251
|
* ```ts
|
|
253
|
-
* const
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* console.error(res.error.message, res.error.description);
|
|
258
|
-
* }
|
|
252
|
+
* const { result, error, success } = tryStringifyObj({ a: 1 });
|
|
253
|
+
*
|
|
254
|
+
* if (success) console.log(result); // "{\"a\":1}"
|
|
255
|
+
* else console.error(error); // { message: "...", description: "..." }
|
|
259
256
|
* ```
|
|
260
257
|
*/
|
|
261
258
|
declare function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string>;
|
|
@@ -276,11 +273,7 @@ declare function tryStringifyObj<T extends object = Record<string, unknown>>(obj
|
|
|
276
273
|
*
|
|
277
274
|
* @example
|
|
278
275
|
* ```ts
|
|
279
|
-
*
|
|
280
|
-
* const json = stringifyObj({ a: 1 }); // {"a":1}
|
|
281
|
-
* } catch (error: unknown) {
|
|
282
|
-
* console.error(error);
|
|
283
|
-
* }
|
|
276
|
+
* const json = stringifyObj({ a: 1 }); // "{\"a\":1}"
|
|
284
277
|
* ```
|
|
285
278
|
*/
|
|
286
279
|
declare function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string;
|
|
@@ -298,12 +291,10 @@ declare function stringifyObj<T extends object = Record<string, unknown>>(obj: T
|
|
|
298
291
|
*
|
|
299
292
|
* @example
|
|
300
293
|
* ```ts
|
|
301
|
-
* const
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
* console.error(res.error.message, res.error.description);
|
|
306
|
-
* }
|
|
294
|
+
* const {result, error, success} = tryParseToObj<{ a: number }>('{"a":1}');
|
|
295
|
+
*
|
|
296
|
+
* if (success) console.log(result); // { a: 1 }
|
|
297
|
+
* else console.error(error) // { message: "...", description: "..." }
|
|
307
298
|
* ```
|
|
308
299
|
*/
|
|
309
300
|
declare function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{
|
|
@@ -324,11 +315,7 @@ declare function tryParseToObj<T extends object = Record<string, unknown>>(str:
|
|
|
324
315
|
*
|
|
325
316
|
* @example
|
|
326
317
|
* ```ts
|
|
327
|
-
*
|
|
328
|
-
* const obj = parseToObj<{ a: number }>('{"a":1}'); // obj.a === 1
|
|
329
|
-
* } catch (error: unknown) {
|
|
330
|
-
* console.error(error);
|
|
331
|
-
* }
|
|
318
|
+
* const obj = parseToObj<{ a: number }>('{"a":1}'); // obj.a === 1
|
|
332
319
|
* ```
|
|
333
320
|
*/
|
|
334
321
|
declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
|
|
@@ -373,12 +360,12 @@ declare const ENCRYPTED_REGEX: Readonly<{
|
|
|
373
360
|
*
|
|
374
361
|
* @example
|
|
375
362
|
* ```ts
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
363
|
+
* matchEncryptedPattern("abc.def.ghi.", "node"); // true
|
|
364
|
+
* matchEncryptedPattern("abc.def.", "web"); // true
|
|
365
|
+
* matchEncryptedPattern("abc.def.", "node"); // false
|
|
366
|
+
* matchEncryptedPattern("abc.def.ghi.", "general"); // true
|
|
380
367
|
* ```
|
|
381
368
|
*/
|
|
382
|
-
declare function
|
|
369
|
+
declare function matchEncryptedPattern(data: string, format: "node" | "web" | "general"): boolean;
|
|
383
370
|
|
|
384
|
-
export { type CipherEncoding as C, type DigestAlgorithm as D, ENCRYPTED_REGEX as E, type HashOptions as H, type Result as R, type SecretKey as S, type VerifyPasswordOptions as V, tryStringifyObj as a, type Encoding as b, type EncryptionAlgorithm as c, type CreateSecretKeyOptions as d, type EncryptOptions as e, type DecryptOptions as f, type HashPasswordOptions as g,
|
|
371
|
+
export { type CipherEncoding as C, type DigestAlgorithm as D, ENCRYPTED_REGEX as E, type HashOptions as H, type Result as R, type SecretKey as S, type VerifyPasswordOptions as V, tryStringifyObj as a, type Encoding as b, type EncryptionAlgorithm as c, type CreateSecretKeyOptions as d, type EncryptOptions as e, type DecryptOptions as f, type HashPasswordOptions as g, matchEncryptedPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };
|