cipher-kit 2.0.0-beta.3 → 2.0.0-beta.5

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 (46) hide show
  1. package/README.md +199 -111
  2. package/dist/{chunk-ZJ32WGAA.cjs → chunk-3FJZA77A.cjs} +15 -12
  3. package/dist/chunk-3FJZA77A.cjs.map +1 -0
  4. package/dist/{chunk-BNQERV4S.js → chunk-7WPZVN7G.js} +71 -84
  5. package/dist/chunk-7WPZVN7G.js.map +1 -0
  6. package/dist/{chunk-6GBH7YTP.js → chunk-BWE6JWHY.js} +67 -81
  7. package/dist/chunk-BWE6JWHY.js.map +1 -0
  8. package/dist/{chunk-NKLNWTQA.cjs → chunk-CEXY7GOU.cjs} +159 -173
  9. package/dist/chunk-CEXY7GOU.cjs.map +1 -0
  10. package/dist/{chunk-UHP3PPXP.cjs → chunk-WLLCFK4U.cjs} +150 -165
  11. package/dist/chunk-WLLCFK4U.cjs.map +1 -0
  12. package/dist/{chunk-YPYDYYV2.js → chunk-YAZRJN6X.js} +13 -11
  13. package/dist/chunk-YAZRJN6X.js.map +1 -0
  14. package/dist/export-DPAoLdh1.d.ts +417 -0
  15. package/dist/export-DX7bFv-3.d.cts +416 -0
  16. package/dist/export-DjUgZ7dz.d.ts +416 -0
  17. package/dist/export-Du70yDea.d.cts +417 -0
  18. package/dist/index.cjs +14 -22
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +52 -4
  21. package/dist/index.d.ts +52 -4
  22. package/dist/index.js +9 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/node.cjs +34 -42
  25. package/dist/node.d.cts +2 -2
  26. package/dist/node.d.ts +2 -2
  27. package/dist/node.js +2 -2
  28. package/dist/validate-DrBddQyu.d.cts +384 -0
  29. package/dist/validate-DrBddQyu.d.ts +384 -0
  30. package/dist/web-api.cjs +34 -42
  31. package/dist/web-api.d.cts +2 -2
  32. package/dist/web-api.d.ts +2 -2
  33. package/dist/web-api.js +2 -2
  34. package/package.json +1 -1
  35. package/dist/chunk-6GBH7YTP.js.map +0 -1
  36. package/dist/chunk-BNQERV4S.js.map +0 -1
  37. package/dist/chunk-NKLNWTQA.cjs.map +0 -1
  38. package/dist/chunk-UHP3PPXP.cjs.map +0 -1
  39. package/dist/chunk-YPYDYYV2.js.map +0 -1
  40. package/dist/chunk-ZJ32WGAA.cjs.map +0 -1
  41. package/dist/export--ndIQ3j3.d.cts +0 -271
  42. package/dist/export-C2M5UPLX.d.cts +0 -270
  43. package/dist/export-CPUbAFZA.d.ts +0 -271
  44. package/dist/export-v9ULdDL0.d.ts +0 -270
  45. package/dist/validate-CULVlPck.d.cts +0 -157
  46. package/dist/validate-CULVlPck.d.ts +0 -157
@@ -1,157 +0,0 @@
1
- import nodeCrypto, { webcrypto } from 'node:crypto';
2
-
3
- interface ResultErr {
4
- readonly message: string;
5
- readonly description: string;
6
- }
7
- type Result<T, E = ResultErr> = T extends object ? ({
8
- readonly [K in keyof T]: T[K];
9
- } & {
10
- readonly success: true;
11
- readonly error?: undefined;
12
- }) | ({
13
- readonly [K in keyof T]?: undefined;
14
- } & {
15
- readonly success: false;
16
- readonly error: E;
17
- }) : {
18
- readonly success: true;
19
- readonly result: T;
20
- readonly error?: undefined;
21
- } | {
22
- readonly success: false;
23
- readonly error: E;
24
- readonly result?: undefined;
25
- };
26
-
27
- /**
28
- * Stringify an object.
29
- *
30
- * @param obj - The object to stringify.
31
- * @returns An JSON string.
32
- * @throws {Error} If the object cannot be stringified.
33
- */
34
- declare function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string;
35
- /**
36
- * Stringify an object.
37
- *
38
- * @param obj - The object to stringify.
39
- * @returns A Result containing the JSON string or an error.
40
- */
41
- declare function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string>;
42
- /**
43
- * Parse a string to an object.
44
- *
45
- * @param str - The JSON string to parse.
46
- * @returns A Result containing the parsed object or an error.
47
- */
48
- declare function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{
49
- result: T;
50
- }>;
51
- /**
52
- * Parse a string to an object.
53
- *
54
- * @param str - The JSON string to parse.
55
- * @returns A parsed object.
56
- * @throws {Error} If the string cannot be parsed or is not a valid object.
57
- */
58
- declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
59
-
60
- declare const ENCODINGS: readonly ["base64", "base64url", "hex", "utf8", "latin1"];
61
- declare const DIGEST_ALGORITHMS: Readonly<{
62
- readonly sha256: {
63
- readonly node: "sha256";
64
- readonly web: "SHA-256";
65
- };
66
- readonly sha384: {
67
- readonly node: "sha384";
68
- readonly web: "SHA-384";
69
- };
70
- readonly sha512: {
71
- readonly node: "sha512";
72
- readonly web: "SHA-512";
73
- };
74
- }>;
75
- declare const ENCRYPTION_ALGORITHMS: Readonly<{
76
- readonly aes256gcm: {
77
- readonly keyBytes: 32;
78
- readonly ivLength: 12;
79
- readonly node: "aes-256-gcm";
80
- readonly web: "AES-GCM";
81
- };
82
- readonly aes192gcm: {
83
- readonly keyBytes: 24;
84
- readonly ivLength: 12;
85
- readonly node: "aes-192-gcm";
86
- readonly web: "AES-GCM";
87
- };
88
- readonly aes128gcm: {
89
- readonly keyBytes: 16;
90
- readonly ivLength: 12;
91
- readonly node: "aes-128-gcm";
92
- readonly web: "AES-GCM";
93
- };
94
- }>;
95
-
96
- declare const __brand: unique symbol;
97
- type Brand<T> = {
98
- readonly [__brand]: T;
99
- };
100
- /** Secret Key Type */
101
- type SecretKey<Platform extends 'web' | 'node'> = {
102
- readonly platform: Platform;
103
- readonly digest: keyof typeof DIGEST_ALGORITHMS;
104
- readonly algorithm: keyof typeof ENCRYPTION_ALGORITHMS;
105
- readonly key: Platform extends 'web' ? webcrypto.CryptoKey : nodeCrypto.KeyObject;
106
- } & Brand<`secretKey-${Platform}`>;
107
- type CipherEncoding = Exclude<Encoding, 'utf8' | 'latin1'>;
108
- /** Supported encoding formats */
109
- type Encoding = (typeof ENCODINGS)[number];
110
- /** Supported encryption algorithms */
111
- type EncryptionAlgorithm = keyof typeof ENCRYPTION_ALGORITHMS;
112
- /** Supported digest algorithms */
113
- type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
114
- interface CreateSecretKeyOptions {
115
- algorithm?: EncryptionAlgorithm;
116
- digest?: DigestAlgorithm;
117
- salt?: string;
118
- info?: string;
119
- }
120
- interface EncryptOptions {
121
- inputEncoding?: Encoding;
122
- outputEncoding?: CipherEncoding;
123
- }
124
- interface DecryptOptions {
125
- inputEncoding?: CipherEncoding;
126
- outputEncoding?: Encoding;
127
- }
128
- interface HashOptions {
129
- digest?: DigestAlgorithm;
130
- inputEncoding?: Encoding;
131
- outputEncoding?: CipherEncoding;
132
- }
133
- interface HashPasswordOptions {
134
- digest?: DigestAlgorithm;
135
- outputEncoding?: CipherEncoding;
136
- saltLength?: number;
137
- iterations?: number;
138
- keyLength?: number;
139
- }
140
- interface VerifyPasswordOptions {
141
- digest?: DigestAlgorithm;
142
- inputEncoding?: CipherEncoding;
143
- iterations?: number;
144
- keyLength?: number;
145
- }
146
-
147
- declare function isSecretKey<Platform extends 'node' | 'web'>(x: unknown, platform: Platform): x is SecretKey<Platform>;
148
- /** Regular expressions for encrypted data patterns */
149
- declare const ENCRYPTED_REGEX: Readonly<{
150
- node: RegExp;
151
- web: RegExp;
152
- general: RegExp;
153
- }>;
154
- /** Checks if the input string matches the specified encrypted data pattern. */
155
- declare function matchPattern(data: string, format: 'general' | 'node' | 'web'): boolean;
156
-
157
- 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, isSecretKey as i, matchPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };
@@ -1,157 +0,0 @@
1
- import nodeCrypto, { webcrypto } from 'node:crypto';
2
-
3
- interface ResultErr {
4
- readonly message: string;
5
- readonly description: string;
6
- }
7
- type Result<T, E = ResultErr> = T extends object ? ({
8
- readonly [K in keyof T]: T[K];
9
- } & {
10
- readonly success: true;
11
- readonly error?: undefined;
12
- }) | ({
13
- readonly [K in keyof T]?: undefined;
14
- } & {
15
- readonly success: false;
16
- readonly error: E;
17
- }) : {
18
- readonly success: true;
19
- readonly result: T;
20
- readonly error?: undefined;
21
- } | {
22
- readonly success: false;
23
- readonly error: E;
24
- readonly result?: undefined;
25
- };
26
-
27
- /**
28
- * Stringify an object.
29
- *
30
- * @param obj - The object to stringify.
31
- * @returns An JSON string.
32
- * @throws {Error} If the object cannot be stringified.
33
- */
34
- declare function stringifyObj<T extends object = Record<string, unknown>>(obj: T): string;
35
- /**
36
- * Stringify an object.
37
- *
38
- * @param obj - The object to stringify.
39
- * @returns A Result containing the JSON string or an error.
40
- */
41
- declare function tryStringifyObj<T extends object = Record<string, unknown>>(obj: T): Result<string>;
42
- /**
43
- * Parse a string to an object.
44
- *
45
- * @param str - The JSON string to parse.
46
- * @returns A Result containing the parsed object or an error.
47
- */
48
- declare function tryParseToObj<T extends object = Record<string, unknown>>(str: string): Result<{
49
- result: T;
50
- }>;
51
- /**
52
- * Parse a string to an object.
53
- *
54
- * @param str - The JSON string to parse.
55
- * @returns A parsed object.
56
- * @throws {Error} If the string cannot be parsed or is not a valid object.
57
- */
58
- declare function parseToObj<T extends object = Record<string, unknown>>(str: string): T;
59
-
60
- declare const ENCODINGS: readonly ["base64", "base64url", "hex", "utf8", "latin1"];
61
- declare const DIGEST_ALGORITHMS: Readonly<{
62
- readonly sha256: {
63
- readonly node: "sha256";
64
- readonly web: "SHA-256";
65
- };
66
- readonly sha384: {
67
- readonly node: "sha384";
68
- readonly web: "SHA-384";
69
- };
70
- readonly sha512: {
71
- readonly node: "sha512";
72
- readonly web: "SHA-512";
73
- };
74
- }>;
75
- declare const ENCRYPTION_ALGORITHMS: Readonly<{
76
- readonly aes256gcm: {
77
- readonly keyBytes: 32;
78
- readonly ivLength: 12;
79
- readonly node: "aes-256-gcm";
80
- readonly web: "AES-GCM";
81
- };
82
- readonly aes192gcm: {
83
- readonly keyBytes: 24;
84
- readonly ivLength: 12;
85
- readonly node: "aes-192-gcm";
86
- readonly web: "AES-GCM";
87
- };
88
- readonly aes128gcm: {
89
- readonly keyBytes: 16;
90
- readonly ivLength: 12;
91
- readonly node: "aes-128-gcm";
92
- readonly web: "AES-GCM";
93
- };
94
- }>;
95
-
96
- declare const __brand: unique symbol;
97
- type Brand<T> = {
98
- readonly [__brand]: T;
99
- };
100
- /** Secret Key Type */
101
- type SecretKey<Platform extends 'web' | 'node'> = {
102
- readonly platform: Platform;
103
- readonly digest: keyof typeof DIGEST_ALGORITHMS;
104
- readonly algorithm: keyof typeof ENCRYPTION_ALGORITHMS;
105
- readonly key: Platform extends 'web' ? webcrypto.CryptoKey : nodeCrypto.KeyObject;
106
- } & Brand<`secretKey-${Platform}`>;
107
- type CipherEncoding = Exclude<Encoding, 'utf8' | 'latin1'>;
108
- /** Supported encoding formats */
109
- type Encoding = (typeof ENCODINGS)[number];
110
- /** Supported encryption algorithms */
111
- type EncryptionAlgorithm = keyof typeof ENCRYPTION_ALGORITHMS;
112
- /** Supported digest algorithms */
113
- type DigestAlgorithm = keyof typeof DIGEST_ALGORITHMS;
114
- interface CreateSecretKeyOptions {
115
- algorithm?: EncryptionAlgorithm;
116
- digest?: DigestAlgorithm;
117
- salt?: string;
118
- info?: string;
119
- }
120
- interface EncryptOptions {
121
- inputEncoding?: Encoding;
122
- outputEncoding?: CipherEncoding;
123
- }
124
- interface DecryptOptions {
125
- inputEncoding?: CipherEncoding;
126
- outputEncoding?: Encoding;
127
- }
128
- interface HashOptions {
129
- digest?: DigestAlgorithm;
130
- inputEncoding?: Encoding;
131
- outputEncoding?: CipherEncoding;
132
- }
133
- interface HashPasswordOptions {
134
- digest?: DigestAlgorithm;
135
- outputEncoding?: CipherEncoding;
136
- saltLength?: number;
137
- iterations?: number;
138
- keyLength?: number;
139
- }
140
- interface VerifyPasswordOptions {
141
- digest?: DigestAlgorithm;
142
- inputEncoding?: CipherEncoding;
143
- iterations?: number;
144
- keyLength?: number;
145
- }
146
-
147
- declare function isSecretKey<Platform extends 'node' | 'web'>(x: unknown, platform: Platform): x is SecretKey<Platform>;
148
- /** Regular expressions for encrypted data patterns */
149
- declare const ENCRYPTED_REGEX: Readonly<{
150
- node: RegExp;
151
- web: RegExp;
152
- general: RegExp;
153
- }>;
154
- /** Checks if the input string matches the specified encrypted data pattern. */
155
- declare function matchPattern(data: string, format: 'general' | 'node' | 'web'): boolean;
156
-
157
- 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, isSecretKey as i, matchPattern as m, parseToObj as p, stringifyObj as s, tryParseToObj as t };