cipher-kit 2.1.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +324 -434
  2. package/dist/chunk-3A4RTUKO.cjs +509 -0
  3. package/dist/chunk-3A4RTUKO.cjs.map +1 -0
  4. package/dist/chunk-7254PEID.cjs +502 -0
  5. package/dist/chunk-7254PEID.cjs.map +1 -0
  6. package/dist/chunk-GL32EZRA.js +475 -0
  7. package/dist/chunk-GL32EZRA.js.map +1 -0
  8. package/dist/chunk-IY6XGUYO.js +494 -0
  9. package/dist/chunk-IY6XGUYO.js.map +1 -0
  10. package/dist/chunk-VCBHSRCS.cjs +523 -0
  11. package/dist/chunk-VCBHSRCS.cjs.map +1 -0
  12. package/dist/chunk-X6MX4NDE.js +478 -0
  13. package/dist/chunk-X6MX4NDE.js.map +1 -0
  14. package/dist/export-B-3CCZIO.d.cts +389 -0
  15. package/dist/export-BPo6yPV-.d.ts +389 -0
  16. package/dist/export-C0_UEEg8.d.ts +396 -0
  17. package/dist/export-DPuocAr3.d.cts +396 -0
  18. package/dist/index.cjs +11 -19
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +11 -40
  21. package/dist/index.d.ts +11 -40
  22. package/dist/index.js +3 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/node.cjs +39 -35
  25. package/dist/node.d.cts +3 -3
  26. package/dist/node.d.ts +3 -3
  27. package/dist/node.js +2 -2
  28. package/dist/validate-vDTesb-X.d.cts +195 -0
  29. package/dist/validate-vDTesb-X.d.ts +195 -0
  30. package/dist/web-api.cjs +39 -35
  31. package/dist/web-api.d.cts +2 -3
  32. package/dist/web-api.d.ts +2 -3
  33. package/dist/web-api.js +2 -2
  34. package/package.json +82 -92
  35. package/dist/chunk-BMX42IZM.cjs +0 -623
  36. package/dist/chunk-BMX42IZM.cjs.map +0 -1
  37. package/dist/chunk-HTRGOBZF.cjs +0 -169
  38. package/dist/chunk-HTRGOBZF.cjs.map +0 -1
  39. package/dist/chunk-LU7QOSQH.js +0 -141
  40. package/dist/chunk-LU7QOSQH.js.map +0 -1
  41. package/dist/chunk-S6SNCTU6.js +0 -485
  42. package/dist/chunk-S6SNCTU6.js.map +0 -1
  43. package/dist/chunk-T36BEDPY.js +0 -598
  44. package/dist/chunk-T36BEDPY.js.map +0 -1
  45. package/dist/chunk-ZNM5M6RD.cjs +0 -514
  46. package/dist/chunk-ZNM5M6RD.cjs.map +0 -1
  47. package/dist/export-BaM_OTFk.d.ts +0 -573
  48. package/dist/export-CCTGAosO.d.ts +0 -572
  49. package/dist/export-FYHgb-8E.d.cts +0 -572
  50. package/dist/export-KFT0YyMg.d.cts +0 -573
  51. package/dist/validate-lkJAHCeJ.d.cts +0 -399
  52. package/dist/validate-lkJAHCeJ.d.ts +0 -399
package/dist/node.cjs CHANGED
@@ -1,129 +1,133 @@
1
1
  'use strict';
2
2
 
3
- var chunkZNM5M6RD_cjs = require('./chunk-ZNM5M6RD.cjs');
4
- var chunkHTRGOBZF_cjs = require('./chunk-HTRGOBZF.cjs');
3
+ var chunk3A4RTUKO_cjs = require('./chunk-3A4RTUKO.cjs');
4
+ var chunkVCBHSRCS_cjs = require('./chunk-VCBHSRCS.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "convertBytesToStr", {
9
9
  enumerable: true,
10
- get: function () { return chunkZNM5M6RD_cjs.convertBytesToStr; }
10
+ get: function () { return chunk3A4RTUKO_cjs.convertBytesToStr; }
11
11
  });
12
12
  Object.defineProperty(exports, "convertEncoding", {
13
13
  enumerable: true,
14
- get: function () { return chunkZNM5M6RD_cjs.convertEncoding; }
14
+ get: function () { return chunk3A4RTUKO_cjs.convertEncoding; }
15
15
  });
16
16
  Object.defineProperty(exports, "convertStrToBytes", {
17
17
  enumerable: true,
18
- get: function () { return chunkZNM5M6RD_cjs.convertStrToBytes; }
18
+ get: function () { return chunk3A4RTUKO_cjs.convertStrToBytes; }
19
19
  });
20
20
  Object.defineProperty(exports, "createSecretKey", {
21
21
  enumerable: true,
22
- get: function () { return chunkZNM5M6RD_cjs.createSecretKey; }
22
+ get: function () { return chunk3A4RTUKO_cjs.createSecretKey; }
23
23
  });
24
24
  Object.defineProperty(exports, "decrypt", {
25
25
  enumerable: true,
26
- get: function () { return chunkZNM5M6RD_cjs.decrypt; }
26
+ get: function () { return chunk3A4RTUKO_cjs.decrypt; }
27
27
  });
28
28
  Object.defineProperty(exports, "decryptObj", {
29
29
  enumerable: true,
30
- get: function () { return chunkZNM5M6RD_cjs.decryptObj; }
30
+ get: function () { return chunk3A4RTUKO_cjs.decryptObj; }
31
31
  });
32
32
  Object.defineProperty(exports, "encrypt", {
33
33
  enumerable: true,
34
- get: function () { return chunkZNM5M6RD_cjs.encrypt; }
34
+ get: function () { return chunk3A4RTUKO_cjs.encrypt; }
35
35
  });
36
36
  Object.defineProperty(exports, "encryptObj", {
37
37
  enumerable: true,
38
- get: function () { return chunkZNM5M6RD_cjs.encryptObj; }
38
+ get: function () { return chunk3A4RTUKO_cjs.encryptObj; }
39
39
  });
40
40
  Object.defineProperty(exports, "generateUuid", {
41
41
  enumerable: true,
42
- get: function () { return chunkZNM5M6RD_cjs.generateUuid; }
42
+ get: function () { return chunk3A4RTUKO_cjs.generateUuid; }
43
43
  });
44
44
  Object.defineProperty(exports, "hash", {
45
45
  enumerable: true,
46
- get: function () { return chunkZNM5M6RD_cjs.hash; }
46
+ get: function () { return chunk3A4RTUKO_cjs.hash; }
47
47
  });
48
48
  Object.defineProperty(exports, "hashPassword", {
49
49
  enumerable: true,
50
- get: function () { return chunkZNM5M6RD_cjs.hashPassword; }
50
+ get: function () { return chunk3A4RTUKO_cjs.hashPassword; }
51
+ });
52
+ Object.defineProperty(exports, "isNodeSecretKey", {
53
+ enumerable: true,
54
+ get: function () { return chunk3A4RTUKO_cjs.isNodeSecretKey; }
51
55
  });
52
56
  Object.defineProperty(exports, "tryConvertBytesToStr", {
53
57
  enumerable: true,
54
- get: function () { return chunkZNM5M6RD_cjs.tryConvertBytesToStr; }
58
+ get: function () { return chunk3A4RTUKO_cjs.tryConvertBytesToStr; }
55
59
  });
56
60
  Object.defineProperty(exports, "tryConvertEncoding", {
57
61
  enumerable: true,
58
- get: function () { return chunkZNM5M6RD_cjs.tryConvertEncoding; }
62
+ get: function () { return chunk3A4RTUKO_cjs.tryConvertEncoding; }
59
63
  });
60
64
  Object.defineProperty(exports, "tryConvertStrToBytes", {
61
65
  enumerable: true,
62
- get: function () { return chunkZNM5M6RD_cjs.tryConvertStrToBytes; }
66
+ get: function () { return chunk3A4RTUKO_cjs.tryConvertStrToBytes; }
63
67
  });
64
68
  Object.defineProperty(exports, "tryCreateSecretKey", {
65
69
  enumerable: true,
66
- get: function () { return chunkZNM5M6RD_cjs.tryCreateSecretKey; }
70
+ get: function () { return chunk3A4RTUKO_cjs.tryCreateSecretKey; }
67
71
  });
68
72
  Object.defineProperty(exports, "tryDecrypt", {
69
73
  enumerable: true,
70
- get: function () { return chunkZNM5M6RD_cjs.tryDecrypt; }
74
+ get: function () { return chunk3A4RTUKO_cjs.tryDecrypt; }
71
75
  });
72
76
  Object.defineProperty(exports, "tryDecryptObj", {
73
77
  enumerable: true,
74
- get: function () { return chunkZNM5M6RD_cjs.tryDecryptObj; }
78
+ get: function () { return chunk3A4RTUKO_cjs.tryDecryptObj; }
75
79
  });
76
80
  Object.defineProperty(exports, "tryEncrypt", {
77
81
  enumerable: true,
78
- get: function () { return chunkZNM5M6RD_cjs.tryEncrypt; }
82
+ get: function () { return chunk3A4RTUKO_cjs.tryEncrypt; }
79
83
  });
80
84
  Object.defineProperty(exports, "tryEncryptObj", {
81
85
  enumerable: true,
82
- get: function () { return chunkZNM5M6RD_cjs.tryEncryptObj; }
86
+ get: function () { return chunk3A4RTUKO_cjs.tryEncryptObj; }
83
87
  });
84
88
  Object.defineProperty(exports, "tryGenerateUuid", {
85
89
  enumerable: true,
86
- get: function () { return chunkZNM5M6RD_cjs.tryGenerateUuid; }
90
+ get: function () { return chunk3A4RTUKO_cjs.tryGenerateUuid; }
87
91
  });
88
92
  Object.defineProperty(exports, "tryHash", {
89
93
  enumerable: true,
90
- get: function () { return chunkZNM5M6RD_cjs.tryHash; }
94
+ get: function () { return chunk3A4RTUKO_cjs.tryHash; }
91
95
  });
92
96
  Object.defineProperty(exports, "tryHashPassword", {
93
97
  enumerable: true,
94
- get: function () { return chunkZNM5M6RD_cjs.tryHashPassword; }
98
+ get: function () { return chunk3A4RTUKO_cjs.tryHashPassword; }
95
99
  });
96
- Object.defineProperty(exports, "verifyPassword", {
100
+ Object.defineProperty(exports, "tryVerifyPassword", {
97
101
  enumerable: true,
98
- get: function () { return chunkZNM5M6RD_cjs.verifyPassword; }
102
+ get: function () { return chunk3A4RTUKO_cjs.tryVerifyPassword; }
99
103
  });
100
- Object.defineProperty(exports, "ENCRYPTED_REGEX", {
104
+ Object.defineProperty(exports, "verifyPassword", {
101
105
  enumerable: true,
102
- get: function () { return chunkHTRGOBZF_cjs.ENCRYPTED_REGEX; }
106
+ get: function () { return chunk3A4RTUKO_cjs.verifyPassword; }
103
107
  });
104
- Object.defineProperty(exports, "isNodeSecretKey", {
108
+ Object.defineProperty(exports, "ENCRYPTED_REGEX", {
105
109
  enumerable: true,
106
- get: function () { return chunkHTRGOBZF_cjs.isNodeSecretKey; }
110
+ get: function () { return chunkVCBHSRCS_cjs.ENCRYPTED_REGEX; }
107
111
  });
108
112
  Object.defineProperty(exports, "matchEncryptedPattern", {
109
113
  enumerable: true,
110
- get: function () { return chunkHTRGOBZF_cjs.matchEncryptedPattern; }
114
+ get: function () { return chunkVCBHSRCS_cjs.matchEncryptedPattern; }
111
115
  });
112
116
  Object.defineProperty(exports, "parseToObj", {
113
117
  enumerable: true,
114
- get: function () { return chunkHTRGOBZF_cjs.parseToObj; }
118
+ get: function () { return chunkVCBHSRCS_cjs.parseToObj; }
115
119
  });
116
120
  Object.defineProperty(exports, "stringifyObj", {
117
121
  enumerable: true,
118
- get: function () { return chunkHTRGOBZF_cjs.stringifyObj; }
122
+ get: function () { return chunkVCBHSRCS_cjs.stringifyObj; }
119
123
  });
120
124
  Object.defineProperty(exports, "tryParseToObj", {
121
125
  enumerable: true,
122
- get: function () { return chunkHTRGOBZF_cjs.tryParseToObj; }
126
+ get: function () { return chunkVCBHSRCS_cjs.tryParseToObj; }
123
127
  });
124
128
  Object.defineProperty(exports, "tryStringifyObj", {
125
129
  enumerable: true,
126
- get: function () { return chunkHTRGOBZF_cjs.tryStringifyObj; }
130
+ get: function () { return chunkVCBHSRCS_cjs.tryStringifyObj; }
127
131
  });
128
132
  //# sourceMappingURL=node.cjs.map
129
133
  //# sourceMappingURL=node.cjs.map
package/dist/node.d.cts CHANGED
@@ -1,4 +1,4 @@
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, i as isNodeSecretKey, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, a as tryStringifyObj } from './validate-lkJAHCeJ.cjs';
2
- export { u as convertBytesToStr, x as convertEncoding, r as convertStrToBytes, c as createSecretKey, f as decrypt, k as decryptObj, e as encrypt, i as encryptObj, g as generateUuid, m as hash, p as hashPassword, s as tryConvertBytesToStr, w as tryConvertEncoding, q as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, j as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, l as tryHash, o as tryHashPassword, v as verifyPassword } from './export-KFT0YyMg.cjs';
3
- import 'node:crypto';
1
+ export { C as CipherEncoding, a as CreateSecretKeyOptions, D as DecryptOptions, b as DigestAlgorithm, E as ENCRYPTED_REGEX, c as Encoding, d as EncryptOptions, e as EncryptionAlgorithm, f as ErrorStruct, H as HashOptions, g as HashPasswordOptions, R as Result, V as VerifyPasswordOptions, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, h as tryStringifyObj } from './validate-vDTesb-X.cjs';
2
+ export { N as NodeSecretKey, c as convertBytesToStr, a as convertEncoding, b as convertStrToBytes, d as createSecretKey, e as decrypt, f as decryptObj, g as encrypt, h as encryptObj, i as generateUuid, j as hash, k as hashPassword, l as isNodeSecretKey, t as tryConvertBytesToStr, m as tryConvertEncoding, o as tryConvertStrToBytes, p as tryCreateSecretKey, q as tryDecrypt, r as tryDecryptObj, s as tryEncrypt, u as tryEncryptObj, v as tryGenerateUuid, w as tryHash, x as tryHashPassword, y as tryVerifyPassword, z as verifyPassword } from './export-DPuocAr3.cjs';
4
3
  import 'node:buffer';
4
+ import 'node:crypto';
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
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, i as isNodeSecretKey, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, a as tryStringifyObj } from './validate-lkJAHCeJ.js';
2
- export { u as convertBytesToStr, x as convertEncoding, r as convertStrToBytes, c as createSecretKey, f as decrypt, k as decryptObj, e as encrypt, i as encryptObj, g as generateUuid, m as hash, p as hashPassword, s as tryConvertBytesToStr, w as tryConvertEncoding, q as tryConvertStrToBytes, a as tryCreateSecretKey, d as tryDecrypt, j as tryDecryptObj, b as tryEncrypt, h as tryEncryptObj, t as tryGenerateUuid, l as tryHash, o as tryHashPassword, v as verifyPassword } from './export-BaM_OTFk.js';
3
- import 'node:crypto';
1
+ export { C as CipherEncoding, a as CreateSecretKeyOptions, D as DecryptOptions, b as DigestAlgorithm, E as ENCRYPTED_REGEX, c as Encoding, d as EncryptOptions, e as EncryptionAlgorithm, f as ErrorStruct, H as HashOptions, g as HashPasswordOptions, R as Result, V as VerifyPasswordOptions, m as matchEncryptedPattern, p as parseToObj, s as stringifyObj, t as tryParseToObj, h as tryStringifyObj } from './validate-vDTesb-X.js';
2
+ export { N as NodeSecretKey, c as convertBytesToStr, a as convertEncoding, b as convertStrToBytes, d as createSecretKey, e as decrypt, f as decryptObj, g as encrypt, h as encryptObj, i as generateUuid, j as hash, k as hashPassword, l as isNodeSecretKey, t as tryConvertBytesToStr, m as tryConvertEncoding, o as tryConvertStrToBytes, p as tryCreateSecretKey, q as tryDecrypt, r as tryDecryptObj, s as tryEncrypt, u as tryEncryptObj, v as tryGenerateUuid, w as tryHash, x as tryHashPassword, y as tryVerifyPassword, z as verifyPassword } from './export-C0_UEEg8.js';
4
3
  import 'node:buffer';
4
+ import 'node:crypto';
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
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';
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, tryVerifyPassword, verifyPassword } from './chunk-X6MX4NDE.js';
2
+ export { ENCRYPTED_REGEX, matchEncryptedPattern, parseToObj, stringifyObj, tryParseToObj, tryStringifyObj } from './chunk-IY6XGUYO.js';
3
3
  //# sourceMappingURL=node.js.map
4
4
  //# sourceMappingURL=node.js.map
@@ -0,0 +1,195 @@
1
+ interface ErrorStruct {
2
+ readonly message: string;
3
+ readonly description: string;
4
+ }
5
+ type ReservedResultKeys = "success" | "error";
6
+ type ShouldWrapObject<T extends object> = Extract<keyof T, ReservedResultKeys> extends never ? false : true;
7
+ type OkType<T> = {
8
+ readonly success: true;
9
+ readonly error?: undefined;
10
+ } & (T extends object ? ShouldWrapObject<T> extends true ? {
11
+ readonly result: T;
12
+ } : {
13
+ readonly [K in keyof T]: T[K];
14
+ } : {
15
+ readonly result: T;
16
+ });
17
+ type ErrType<T> = {
18
+ readonly success: false;
19
+ readonly error: ErrorStruct;
20
+ } & (T extends object ? ShouldWrapObject<T> extends true ? {
21
+ readonly result?: undefined;
22
+ } : {
23
+ readonly [K in keyof T]?: undefined;
24
+ } : {
25
+ readonly result?: undefined;
26
+ });
27
+ type Result<T> = OkType<T> | ErrType<T>;
28
+ declare const ENCODING: readonly ["base64", "base64url", "hex", "utf8", "latin1"];
29
+ declare const CIPHER_ENCODING: readonly ["base64", "base64url", "hex"];
30
+
31
+ declare const DIGEST_ALGORITHMS: Readonly<{
32
+ readonly sha256: {
33
+ readonly node: "sha256";
34
+ readonly web: "SHA-256";
35
+ };
36
+ readonly sha384: {
37
+ readonly node: "sha384";
38
+ readonly web: "SHA-384";
39
+ };
40
+ readonly sha512: {
41
+ readonly node: "sha512";
42
+ readonly web: "SHA-512";
43
+ };
44
+ }>;
45
+ declare const ENCRYPTION_ALGORITHMS: Readonly<{
46
+ readonly aes256gcm: {
47
+ readonly keyBytes: 32;
48
+ readonly node: "aes-256-gcm";
49
+ readonly web: "AES-GCM";
50
+ };
51
+ readonly aes192gcm: {
52
+ readonly keyBytes: 24;
53
+ readonly node: "aes-192-gcm";
54
+ readonly web: "AES-GCM";
55
+ };
56
+ readonly aes128gcm: {
57
+ readonly keyBytes: 16;
58
+ readonly node: "aes-128-gcm";
59
+ readonly web: "AES-GCM";
60
+ };
61
+ }>;
62
+
63
+ type CipherEncoding = (typeof CIPHER_ENCODING)[number];
64
+ type Encoding = (typeof ENCODING)[number];
65
+ type EncryptionAlgorithm = keyof typeof ENCRYPTION_ALGORITHMS;
66
+ type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
67
+ /**
68
+ * Options for creating a secret key (`NodeSecretKey` / `WebSecretKey`) via HKDF derivation.
69
+ *
70
+ * **Security note:** HKDF is a key expansion function, not a key stretching function.
71
+ * It provides no brute-force resistance. The `secret` parameter must be high-entropy
72
+ * (e.g., a 256-bit random key or a cryptographically strong passphrase).
73
+ * For human-chosen passwords, use {@link HashPasswordOptions | PBKDF2} instead.
74
+ */
75
+ interface CreateSecretKeyOptions {
76
+ /** Encryption algorithm to use (default: `'aes256gcm'`). */
77
+ algorithm?: EncryptionAlgorithm;
78
+ /** Digest algorithm for HKDF (default: `'sha256'`). */
79
+ digest?: DigestAlgorithm;
80
+ /**
81
+ * Salt for HKDF (default: `'cipher-kit'`, must be ≥ 8 characters).
82
+ *
83
+ * For per-user or per-deployment uniqueness, provide your own unique random salt.
84
+ */
85
+ salt?: string;
86
+ /** Optional context info for HKDF (default: `'cipher-kit'`). */
87
+ info?: string;
88
+ /**
89
+ * Whether the derived Web CryptoKey is extractable (default: `false`).
90
+ * Set to `true` only if you need to export the raw key material via `crypto.subtle.exportKey()`.
91
+ * Has no effect on Node.js keys.
92
+ */
93
+ extractable?: boolean;
94
+ }
95
+ /** Options for encryption. */
96
+ interface EncryptOptions {
97
+ /** Encoding format for the output ciphertext (default: `'base64url'`). */
98
+ outputEncoding?: CipherEncoding;
99
+ }
100
+ /** Options for decryption. */
101
+ interface DecryptOptions {
102
+ /** Encoding format for the input ciphertext (default: `'base64url'`). */
103
+ inputEncoding?: CipherEncoding;
104
+ }
105
+ /** Options for hashing arbitrary data. */
106
+ interface HashOptions {
107
+ /** Digest algorithm to use (default: `'sha256'`). */
108
+ digest?: DigestAlgorithm;
109
+ /** Encoding format for the output hash (default: `'base64url'`). */
110
+ outputEncoding?: CipherEncoding;
111
+ }
112
+ /** Options for password hashing (PBKDF2). */
113
+ interface HashPasswordOptions {
114
+ /** Digest algorithm to use (default: `'sha512'`). */
115
+ digest?: DigestAlgorithm;
116
+ /** Encoding format for the output hash (default: `'base64url'`). */
117
+ outputEncoding?: CipherEncoding;
118
+ /** Length of the salt in bytes (default: `16`; min: `8`; max: `1024`). */
119
+ saltLength?: number;
120
+ /** Number of iterations for key derivation (default: `320000`; min: `100000`; max: `10000000`). */
121
+ iterations?: number;
122
+ /** Length of the derived key in bytes (default: `64`; min: `16`; max: `1024`). */
123
+ keyLength?: number;
124
+ }
125
+ /** Options for verifying a password hash (must match the parameters used to hash). */
126
+ interface VerifyPasswordOptions {
127
+ /** Digest algorithm to use (default: `'sha512'`). */
128
+ digest?: DigestAlgorithm;
129
+ /** Encoding format of the input hash (default: `'base64url'`). */
130
+ inputEncoding?: CipherEncoding;
131
+ /** Number of iterations for key derivation (default: `320000`; min: `100000`; max: `10000000`). */
132
+ iterations?: number;
133
+ /** Length of the derived key in bytes (default: `64`; min: `16`; max: `1024`). */
134
+ keyLength?: number;
135
+ }
136
+
137
+ /**
138
+ * Serializes a plain object to JSON (non-throwing).
139
+ *
140
+ * @returns `Result<string>` with the JSON string or error.
141
+ * @see {@link stringifyObj} For full parameter/behavior docs.
142
+ */
143
+ declare function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string>;
144
+ /**
145
+ * Serializes a plain object to JSON.
146
+ *
147
+ * @remarks
148
+ * Only plain objects (POJOs) are accepted; class instances, Maps, Sets, etc. are rejected.
149
+ *
150
+ * @param obj - The object to stringify.
151
+ * @returns JSON string representation of the object.
152
+ * @throws {Error} If `obj` is not a plain object or serialization fails.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const json = stringifyObj({ a: 1 }); // '{"a":1}'
157
+ * ```
158
+ *
159
+ * @see {@link tryStringifyObj} Non-throwing variant returning `Result<string>`.
160
+ */
161
+ declare function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string;
162
+ /**
163
+ * Parses a JSON string to a plain object (non-throwing).
164
+ *
165
+ * @returns `Result<{ result: T }>` with the parsed object or error.
166
+ * @see {@link parseToObj} For full parameter/behavior docs.
167
+ */
168
+ declare function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{
169
+ result: T;
170
+ }>;
171
+ /**
172
+ * Parses a JSON string to a plain object.
173
+ *
174
+ * @param str - The JSON string to parse.
175
+ * @returns The parsed plain object.
176
+ * @throws {Error} If the string can't be parsed or doesn't represent a plain object.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const obj = parseToObj<{ a: number }>('{"a":1}'); // obj.a === 1
181
+ * ```
182
+ *
183
+ * @see {@link tryParseToObj} Non-throwing variant returning `Result<{ result: T }>`.
184
+ */
185
+ declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
186
+
187
+ /** Matches the `"iv.cipher.tag."` encrypted payload format. */
188
+ declare const ENCRYPTED_REGEX: RegExp;
189
+ /**
190
+ * Structural check only — validates the dot-separated `"iv.cipher.tag."` format
191
+ * but does NOT verify that individual segments contain valid base64, base64url, or hex encoding.
192
+ */
193
+ declare function matchEncryptedPattern(data: string): boolean;
194
+
195
+ export { type CipherEncoding as C, type DecryptOptions as D, ENCRYPTED_REGEX as E, type HashOptions as H, type Result as R, type VerifyPasswordOptions as V, type CreateSecretKeyOptions as a, type DigestAlgorithm as b, type Encoding as c, type EncryptOptions as d, type EncryptionAlgorithm as e, type ErrorStruct as f, type HashPasswordOptions as g, tryStringifyObj as h, DIGEST_ALGORITHMS as i, ENCRYPTION_ALGORITHMS as j, matchEncryptedPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };
@@ -0,0 +1,195 @@
1
+ interface ErrorStruct {
2
+ readonly message: string;
3
+ readonly description: string;
4
+ }
5
+ type ReservedResultKeys = "success" | "error";
6
+ type ShouldWrapObject<T extends object> = Extract<keyof T, ReservedResultKeys> extends never ? false : true;
7
+ type OkType<T> = {
8
+ readonly success: true;
9
+ readonly error?: undefined;
10
+ } & (T extends object ? ShouldWrapObject<T> extends true ? {
11
+ readonly result: T;
12
+ } : {
13
+ readonly [K in keyof T]: T[K];
14
+ } : {
15
+ readonly result: T;
16
+ });
17
+ type ErrType<T> = {
18
+ readonly success: false;
19
+ readonly error: ErrorStruct;
20
+ } & (T extends object ? ShouldWrapObject<T> extends true ? {
21
+ readonly result?: undefined;
22
+ } : {
23
+ readonly [K in keyof T]?: undefined;
24
+ } : {
25
+ readonly result?: undefined;
26
+ });
27
+ type Result<T> = OkType<T> | ErrType<T>;
28
+ declare const ENCODING: readonly ["base64", "base64url", "hex", "utf8", "latin1"];
29
+ declare const CIPHER_ENCODING: readonly ["base64", "base64url", "hex"];
30
+
31
+ declare const DIGEST_ALGORITHMS: Readonly<{
32
+ readonly sha256: {
33
+ readonly node: "sha256";
34
+ readonly web: "SHA-256";
35
+ };
36
+ readonly sha384: {
37
+ readonly node: "sha384";
38
+ readonly web: "SHA-384";
39
+ };
40
+ readonly sha512: {
41
+ readonly node: "sha512";
42
+ readonly web: "SHA-512";
43
+ };
44
+ }>;
45
+ declare const ENCRYPTION_ALGORITHMS: Readonly<{
46
+ readonly aes256gcm: {
47
+ readonly keyBytes: 32;
48
+ readonly node: "aes-256-gcm";
49
+ readonly web: "AES-GCM";
50
+ };
51
+ readonly aes192gcm: {
52
+ readonly keyBytes: 24;
53
+ readonly node: "aes-192-gcm";
54
+ readonly web: "AES-GCM";
55
+ };
56
+ readonly aes128gcm: {
57
+ readonly keyBytes: 16;
58
+ readonly node: "aes-128-gcm";
59
+ readonly web: "AES-GCM";
60
+ };
61
+ }>;
62
+
63
+ type CipherEncoding = (typeof CIPHER_ENCODING)[number];
64
+ type Encoding = (typeof ENCODING)[number];
65
+ type EncryptionAlgorithm = keyof typeof ENCRYPTION_ALGORITHMS;
66
+ type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
67
+ /**
68
+ * Options for creating a secret key (`NodeSecretKey` / `WebSecretKey`) via HKDF derivation.
69
+ *
70
+ * **Security note:** HKDF is a key expansion function, not a key stretching function.
71
+ * It provides no brute-force resistance. The `secret` parameter must be high-entropy
72
+ * (e.g., a 256-bit random key or a cryptographically strong passphrase).
73
+ * For human-chosen passwords, use {@link HashPasswordOptions | PBKDF2} instead.
74
+ */
75
+ interface CreateSecretKeyOptions {
76
+ /** Encryption algorithm to use (default: `'aes256gcm'`). */
77
+ algorithm?: EncryptionAlgorithm;
78
+ /** Digest algorithm for HKDF (default: `'sha256'`). */
79
+ digest?: DigestAlgorithm;
80
+ /**
81
+ * Salt for HKDF (default: `'cipher-kit'`, must be ≥ 8 characters).
82
+ *
83
+ * For per-user or per-deployment uniqueness, provide your own unique random salt.
84
+ */
85
+ salt?: string;
86
+ /** Optional context info for HKDF (default: `'cipher-kit'`). */
87
+ info?: string;
88
+ /**
89
+ * Whether the derived Web CryptoKey is extractable (default: `false`).
90
+ * Set to `true` only if you need to export the raw key material via `crypto.subtle.exportKey()`.
91
+ * Has no effect on Node.js keys.
92
+ */
93
+ extractable?: boolean;
94
+ }
95
+ /** Options for encryption. */
96
+ interface EncryptOptions {
97
+ /** Encoding format for the output ciphertext (default: `'base64url'`). */
98
+ outputEncoding?: CipherEncoding;
99
+ }
100
+ /** Options for decryption. */
101
+ interface DecryptOptions {
102
+ /** Encoding format for the input ciphertext (default: `'base64url'`). */
103
+ inputEncoding?: CipherEncoding;
104
+ }
105
+ /** Options for hashing arbitrary data. */
106
+ interface HashOptions {
107
+ /** Digest algorithm to use (default: `'sha256'`). */
108
+ digest?: DigestAlgorithm;
109
+ /** Encoding format for the output hash (default: `'base64url'`). */
110
+ outputEncoding?: CipherEncoding;
111
+ }
112
+ /** Options for password hashing (PBKDF2). */
113
+ interface HashPasswordOptions {
114
+ /** Digest algorithm to use (default: `'sha512'`). */
115
+ digest?: DigestAlgorithm;
116
+ /** Encoding format for the output hash (default: `'base64url'`). */
117
+ outputEncoding?: CipherEncoding;
118
+ /** Length of the salt in bytes (default: `16`; min: `8`; max: `1024`). */
119
+ saltLength?: number;
120
+ /** Number of iterations for key derivation (default: `320000`; min: `100000`; max: `10000000`). */
121
+ iterations?: number;
122
+ /** Length of the derived key in bytes (default: `64`; min: `16`; max: `1024`). */
123
+ keyLength?: number;
124
+ }
125
+ /** Options for verifying a password hash (must match the parameters used to hash). */
126
+ interface VerifyPasswordOptions {
127
+ /** Digest algorithm to use (default: `'sha512'`). */
128
+ digest?: DigestAlgorithm;
129
+ /** Encoding format of the input hash (default: `'base64url'`). */
130
+ inputEncoding?: CipherEncoding;
131
+ /** Number of iterations for key derivation (default: `320000`; min: `100000`; max: `10000000`). */
132
+ iterations?: number;
133
+ /** Length of the derived key in bytes (default: `64`; min: `16`; max: `1024`). */
134
+ keyLength?: number;
135
+ }
136
+
137
+ /**
138
+ * Serializes a plain object to JSON (non-throwing).
139
+ *
140
+ * @returns `Result<string>` with the JSON string or error.
141
+ * @see {@link stringifyObj} For full parameter/behavior docs.
142
+ */
143
+ declare function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string>;
144
+ /**
145
+ * Serializes a plain object to JSON.
146
+ *
147
+ * @remarks
148
+ * Only plain objects (POJOs) are accepted; class instances, Maps, Sets, etc. are rejected.
149
+ *
150
+ * @param obj - The object to stringify.
151
+ * @returns JSON string representation of the object.
152
+ * @throws {Error} If `obj` is not a plain object or serialization fails.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const json = stringifyObj({ a: 1 }); // '{"a":1}'
157
+ * ```
158
+ *
159
+ * @see {@link tryStringifyObj} Non-throwing variant returning `Result<string>`.
160
+ */
161
+ declare function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string;
162
+ /**
163
+ * Parses a JSON string to a plain object (non-throwing).
164
+ *
165
+ * @returns `Result<{ result: T }>` with the parsed object or error.
166
+ * @see {@link parseToObj} For full parameter/behavior docs.
167
+ */
168
+ declare function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{
169
+ result: T;
170
+ }>;
171
+ /**
172
+ * Parses a JSON string to a plain object.
173
+ *
174
+ * @param str - The JSON string to parse.
175
+ * @returns The parsed plain object.
176
+ * @throws {Error} If the string can't be parsed or doesn't represent a plain object.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const obj = parseToObj<{ a: number }>('{"a":1}'); // obj.a === 1
181
+ * ```
182
+ *
183
+ * @see {@link tryParseToObj} Non-throwing variant returning `Result<{ result: T }>`.
184
+ */
185
+ declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
186
+
187
+ /** Matches the `"iv.cipher.tag."` encrypted payload format. */
188
+ declare const ENCRYPTED_REGEX: RegExp;
189
+ /**
190
+ * Structural check only — validates the dot-separated `"iv.cipher.tag."` format
191
+ * but does NOT verify that individual segments contain valid base64, base64url, or hex encoding.
192
+ */
193
+ declare function matchEncryptedPattern(data: string): boolean;
194
+
195
+ export { type CipherEncoding as C, type DecryptOptions as D, ENCRYPTED_REGEX as E, type HashOptions as H, type Result as R, type VerifyPasswordOptions as V, type CreateSecretKeyOptions as a, type DigestAlgorithm as b, type Encoding as c, type EncryptOptions as d, type EncryptionAlgorithm as e, type ErrorStruct as f, type HashPasswordOptions as g, tryStringifyObj as h, DIGEST_ALGORITHMS as i, ENCRYPTION_ALGORITHMS as j, matchEncryptedPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };