typesecure 0.1.0 → 0.2.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 CHANGED
@@ -1,18 +1,29 @@
1
1
  # typesecure
2
2
 
3
- A focused TypeScript cryptography package that provides secure encryption and hashing utilities with strong typing and runtime validation using Zod.
3
+ `typesecure` is a **classification-first security core** for TypeScript projects.
4
+
5
+ Instead of starting with crypto primitives, it starts with what actually causes most security incidents in web apps: **data leaving the boundary it should never cross** (logs, analytics, error trackers, headers, client bundles, etc).
6
+
7
+ You “type” your data as `public | pii | secret | token | credential`, and `typesecure` helps you **enforce** safe handling using TypeScript + runtime checks.
4
8
 
5
9
  ## Features
6
10
 
7
- - 🔐 **Strong Typing**: Built with TypeScript for complete type safety.
8
- - **Runtime Validation**: Uses Zod to validate inputs and ensure security.
9
- - 🔍 **Advanced Encryption**: AES encryption with multiple modes (CBC, CTR, GCM, ECB).
10
- - 🛡️ **Authenticated Encryption**: GCM mode for authenticated encryption with additional data (AAD).
11
- - 🔏 **Cryptographic Hashing**: SHA-256, SHA-512, SHA-3, and more.
12
- - 📝 **HMAC Signatures**: Create and verify message authentication codes.
13
- - ⏱️ **Timing-Safe Comparison**: Prevent timing attacks with constant-time string comparison.
14
- - 🚦 **Security Level Assessment**: Analyze and report the security level of encryption configurations.
15
- - 🔑 **Password Hashing**: PBKDF2 for secure password hashing with salt and configurable iterations.
11
+ - **Classification types**: `PublicString`, `PIIString`, `SecretString`, `TokenString`, `CredentialString`.
12
+ - **Runtime validation**: Zod-backed constructors (`secretText()`, `piiText()`, ...).
13
+ - **Redaction**: `redact()` and `safeJsonStringify()` prevent secret/PII leakage.
14
+ - **Policy enforcement**: `defaultPolicy()`, `assertAllowed()`, `audit()` help block unsafe crossings.
15
+
16
+ ## Good for / Use when
17
+
18
+ - **You need to stop leaks early**: preventing secrets/PII from ending up in logs, analytics, error trackers, or client bundles.
19
+ - **You want safe defaults**: making insecure behavior harder than secure behavior.
20
+ - **You want guardrails at the boundary**: before logging, emitting telemetry, making network calls, or writing to storage.
21
+
22
+ ## Not a fit / Don’t use when
23
+
24
+ - **You need a full security platform** (hosted policy registry, enterprise controls). `typesecure` is a library.
25
+ - **You need production-grade crypto primitives**. Use well-reviewed, purpose-built libraries and treat crypto carefully.
26
+ - **You only want compile-time types with zero runtime behavior**. `typesecure` deliberately includes runtime checks/redaction.
16
27
 
17
28
  ## Installation
18
29
 
@@ -29,113 +40,94 @@ pnpm add typesecure
29
40
 
30
41
  ## Usage
31
42
 
32
- ### Encryption with Security Assessment
43
+ ### Classification-first data handling
33
44
 
34
45
  ```typescript
35
- import { encrypt, decrypt, generateKey, getSecurityLevel, SecurityLevel } from 'typesecure';
36
-
37
- // Generate a secure key
38
- const key = generateKey();
39
-
40
- // Encrypt data with GCM (authenticated encryption)
41
- const encrypted = encrypt('Sensitive information', key, {
42
- mode: 'aes-gcm',
43
- aad: 'Additional authenticated data' // Optional
44
- });
45
-
46
- // Decrypt data
47
- const decrypted = decrypt(encrypted, key, {
48
- mode: 'aes-gcm',
49
- aad: 'Additional authenticated data' // Must match encryption
50
- });
51
-
52
- // Assess security level of encryption options
53
- const securityLevel = getSecurityLevel({ mode: 'aes-cbc', padding: 'Pkcs7' });
54
- if (securityLevel === SecurityLevel.HIGH) {
55
- console.log('Using high security encryption configuration');
56
- }
46
+ import {
47
+ piiText,
48
+ secretText,
49
+ token,
50
+ publicText,
51
+ redact,
52
+ safeJsonStringify,
53
+ defaultPolicy,
54
+ assertAllowed,
55
+ policyLog,
56
+ } from "typesecure";
57
+
58
+ const userEmail = piiText("user@example.com");
59
+ const sessionToken = token("abc.def.ghi");
60
+ const dbPassword = secretText(process.env.DB_PASSWORD ?? "");
61
+
62
+ // Redact before logging / serialization
63
+ console.log(redact({ userEmail, sessionToken, dbPassword }));
64
+ console.log(
65
+ safeJsonStringify({ userEmail, sessionToken, dbPassword }, undefined, 2),
66
+ );
67
+
68
+ // Enforce policy before a boundary crossing
69
+ const policy = defaultPolicy();
70
+ assertAllowed(policy, "network", { sessionToken }); // allowed
71
+ // assertAllowed(policy, 'log', { dbPassword }); // throws
72
+
73
+ // Safe logging helper with enforcement
74
+ policyLog(policy, console, "info", publicText("login_ok"), { userEmail });
57
75
  ```
58
76
 
59
- ### Secure Password Storage
77
+ ### Express / Next.js examples
60
78
 
61
79
  ```typescript
62
- import { hashPassword, verifyPassword } from 'typesecure';
63
-
64
- // Hash a password with PBKDF2
65
- const { hash, salt, params } = hashPassword('userPassword123', {
66
- algorithm: 'pbkdf2',
67
- iterations: 10000,
68
- saltLength: 32,
69
- keyLength: 64
70
- });
71
-
72
- // Store hash, salt, and params in your database
73
-
74
- // Later, verify the password
75
- const isValid = verifyPassword('userPassword123', hash, salt, params);
76
- ```
77
-
78
- ### Timing-Safe Comparison and Random Bytes Generation
79
-
80
- ```typescript
81
- import { timingSafeEqual, generateRandomBytes } from 'typesecure';
82
-
83
- // Compare strings in constant time to prevent timing attacks
84
- const isEqual = timingSafeEqual(userProvidedToken, storedToken);
85
-
86
- // Generate cryptographically secure random bytes
87
- const randomBytes = generateRandomBytes(32, 'hex');
88
- ```
89
-
90
- ### Hashing and HMAC
91
-
92
- ```typescript
93
- import { hash, verifyHash, hmac } from 'typesecure';
94
-
95
- // Create a hash
96
- const hashedValue = hash('data to hash', {
97
- algorithm: 'sha256',
98
- encoding: 'hex'
99
- });
100
-
101
- // Verify a hash
102
- const isMatch = verifyHash('data to hash', hashedValue, {
103
- algorithm: 'sha256',
104
- encoding: 'hex'
105
- });
106
-
107
- // Create an HMAC
108
- const signature = hmac('message', 'secret key', {
109
- algorithm: 'sha256',
110
- encoding: 'base64'
80
+ // Express middleware example
81
+ import {
82
+ safeLoggerAdapter,
83
+ defaultPolicy,
84
+ assertAllowed,
85
+ token,
86
+ } from "typesecure";
87
+
88
+ const log = safeLoggerAdapter(console);
89
+ const policy = defaultPolicy();
90
+
91
+ app.use((req, _res, next) => {
92
+ const auth = req.headers.authorization?.replace(/^Bearer\s+/i, "");
93
+ if (auth) {
94
+ const t = token(auth);
95
+ assertAllowed(policy, "network", { t });
96
+ log.info({ route: req.path, auth: t }); // will be redacted
97
+ }
98
+ next();
111
99
  });
112
100
  ```
113
101
 
114
102
  ## API Reference
115
103
 
116
- ### Encryption
104
+ ### Classification
117
105
 
118
- - `encrypt(text: string, key: string, options?: Partial<EncryptionOptions>): string`
119
- - `decrypt(encryptedText: string, key: string, options?: Partial<EncryptionOptions>): string`
120
- - `generateKey(length?: number): string`
121
- - `getSecurityLevel(options: EncryptionOptions): SecurityLevel`
106
+ - `publicText(value: string): PublicString`
107
+ - `piiText(value: string): PIIString`
108
+ - `secretText(value: string): SecretString`
109
+ - `token(value: string): TokenString`
110
+ - `credential(value: string): CredentialString`
111
+ - `reveal(value): string` (intentionally explicit)
122
112
 
123
- ### Secure Password Storage
113
+ ### Redaction
124
114
 
125
- - `hashPassword(password: string, options?: Partial<PasswordHashOptions>): { hash: string; salt: string; params: PasswordHashOptions }`
126
- - `verifyPassword(password: string, hash: string, salt: string, options?: Partial<PasswordHashOptions>): boolean`
127
- - `timingSafeEqual(a: string, b: string, options?: Partial<TimingSafeOptions>): boolean`
128
- - `generateRandomBytes(length?: number, encoding?: 'hex' | 'base64'): string`
115
+ - `redact(value): value` (deep traversal)
116
+ - `safeJsonStringify(value): string`
117
+ - `safeLoggerAdapter(consoleLike)`
129
118
 
130
- ### Hashing
119
+ ### Policy
131
120
 
132
- - `hash(input: string, options?: Partial<HashOptions>): string`
133
- - `verifyHash(input: string, hashedValue: string, options?: Partial<HashOptions>): boolean`
134
- - `hmac(input: string, key: string, options?: Partial<HashOptions>): string`
121
+ - `defaultPolicy(): Policy`
122
+ - `assertAllowed(policy, action, data): void`
123
+ - `audit(policy, action, data): AuditEvent`
124
+ - `policyLog(policy, logger, level, ...args): void`
135
125
 
136
126
  ## Security Considerations
137
127
 
138
- This package implements best practices for cryptographic operations, but remember that cryptography is complex. For production applications with high security requirements, consider:
128
+ Security is as much about **preventing leaks** as it is about cryptographic correctness. `typesecure` focuses on preventing accidental secret/PII exposure across common boundaries.
129
+
130
+ If you need cryptography for production-grade requirements, prefer well-reviewed primitives and consult a security professional. For production applications with high security requirements, consider:
139
131
 
140
132
  1. Consulting a security professional
141
133
  2. Using specialized security libraries
@@ -162,4 +154,4 @@ MIT © [Arvid Berndtsson](https://github.com/arvid-berndtsson)
162
154
 
163
155
  ## Contributing
164
156
 
165
- Contributions are welcome! Please feel free to submit a Pull Request.
157
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/dist/index.d.mts CHANGED
@@ -1,237 +1,116 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const PasswordStrengthSchema: z.ZodObject<{
4
- score: z.ZodNumber;
5
- feedback: z.ZodObject<{
6
- warning: z.ZodOptional<z.ZodString>;
7
- suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
8
- }, "strip", z.ZodTypeAny, {
9
- warning?: string | undefined;
10
- suggestions?: string[] | undefined;
11
- }, {
12
- warning?: string | undefined;
13
- suggestions?: string[] | undefined;
14
- }>;
15
- isStrong: z.ZodBoolean;
16
- }, "strip", z.ZodTypeAny, {
17
- score: number;
18
- feedback: {
19
- warning?: string | undefined;
20
- suggestions?: string[] | undefined;
21
- };
22
- isStrong: boolean;
23
- }, {
24
- score: number;
25
- feedback: {
26
- warning?: string | undefined;
27
- suggestions?: string[] | undefined;
28
- };
29
- isStrong: boolean;
3
+ type DataClassification = "public" | "pii" | "secret" | "token" | "credential";
4
+ declare const TYPESECURE_SYMBOL: unique symbol;
5
+ type Classified<K extends DataClassification, T> = Readonly<{
6
+ kind: K;
7
+ value: T;
8
+ [TYPESECURE_SYMBOL]: true;
30
9
  }>;
31
- type PasswordStrength = z.infer<typeof PasswordStrengthSchema>;
32
- declare const HashOptionsSchema: z.ZodObject<{
33
- algorithm: z.ZodDefault<z.ZodEnum<["md5", "sha1", "sha256", "sha512", "sha3"]>>;
34
- encoding: z.ZodDefault<z.ZodEnum<["hex", "base64"]>>;
35
- }, "strip", z.ZodTypeAny, {
36
- algorithm: "md5" | "sha1" | "sha256" | "sha512" | "sha3";
37
- encoding: "hex" | "base64";
38
- }, {
39
- algorithm?: "md5" | "sha1" | "sha256" | "sha512" | "sha3" | undefined;
40
- encoding?: "hex" | "base64" | undefined;
41
- }>;
42
- type HashOptions = z.infer<typeof HashOptionsSchema>;
43
- declare const PasswordHashOptionsSchema: z.ZodObject<{
44
- algorithm: z.ZodDefault<z.ZodEnum<["pbkdf2", "argon2", "bcrypt"]>>;
45
- iterations: z.ZodDefault<z.ZodNumber>;
46
- saltLength: z.ZodDefault<z.ZodNumber>;
47
- keyLength: z.ZodDefault<z.ZodNumber>;
48
- }, "strip", z.ZodTypeAny, {
49
- algorithm: "pbkdf2" | "argon2" | "bcrypt";
50
- iterations: number;
51
- saltLength: number;
52
- keyLength: number;
53
- }, {
54
- algorithm?: "pbkdf2" | "argon2" | "bcrypt" | undefined;
55
- iterations?: number | undefined;
56
- saltLength?: number | undefined;
57
- keyLength?: number | undefined;
58
- }>;
59
- type PasswordHashOptions = z.infer<typeof PasswordHashOptionsSchema>;
60
- declare const TimingSafeOptionsSchema: z.ZodObject<{
61
- encoding: z.ZodDefault<z.ZodEnum<["utf8", "hex", "base64"]>>;
62
- }, "strip", z.ZodTypeAny, {
63
- encoding: "hex" | "base64" | "utf8";
64
- }, {
65
- encoding?: "hex" | "base64" | "utf8" | undefined;
66
- }>;
67
- type TimingSafeOptions = z.infer<typeof TimingSafeOptionsSchema>;
68
- declare const EncryptionOptionsSchema: z.ZodObject<{
69
- mode: z.ZodDefault<z.ZodEnum<["aes-cbc", "aes-ctr", "aes-ecb", "aes-gcm"]>>;
70
- padding: z.ZodDefault<z.ZodEnum<["Pkcs7", "NoPadding", "ZeroPadding"]>>;
71
- iv: z.ZodOptional<z.ZodString>;
72
- authTag: z.ZodOptional<z.ZodString>;
73
- aad: z.ZodOptional<z.ZodString>;
74
- }, "strip", z.ZodTypeAny, {
75
- mode: "aes-cbc" | "aes-ctr" | "aes-ecb" | "aes-gcm";
76
- padding: "Pkcs7" | "NoPadding" | "ZeroPadding";
77
- iv?: string | undefined;
78
- authTag?: string | undefined;
79
- aad?: string | undefined;
80
- }, {
81
- mode?: "aes-cbc" | "aes-ctr" | "aes-ecb" | "aes-gcm" | undefined;
82
- padding?: "Pkcs7" | "NoPadding" | "ZeroPadding" | undefined;
83
- iv?: string | undefined;
84
- authTag?: string | undefined;
85
- aad?: string | undefined;
86
- }>;
87
- type EncryptionOptions = z.infer<typeof EncryptionOptionsSchema>;
88
- declare const ConfigSchema: z.ZodObject<{
89
- minimumPasswordLength: z.ZodDefault<z.ZodNumber>;
90
- requireNumbers: z.ZodDefault<z.ZodBoolean>;
91
- requireSymbols: z.ZodDefault<z.ZodBoolean>;
92
- requireUppercase: z.ZodDefault<z.ZodBoolean>;
93
- requireLowercase: z.ZodDefault<z.ZodBoolean>;
94
- }, "strip", z.ZodTypeAny, {
95
- minimumPasswordLength: number;
96
- requireNumbers: boolean;
97
- requireSymbols: boolean;
98
- requireUppercase: boolean;
99
- requireLowercase: boolean;
100
- }, {
101
- minimumPasswordLength?: number | undefined;
102
- requireNumbers?: boolean | undefined;
103
- requireSymbols?: boolean | undefined;
104
- requireUppercase?: boolean | undefined;
105
- requireLowercase?: boolean | undefined;
106
- }>;
107
- type Config = z.infer<typeof ConfigSchema>;
10
+ type PublicString = Classified<"public", string>;
11
+ type PIIString = Classified<"pii", string>;
12
+ type SecretString = Classified<"secret", string>;
13
+ type TokenString = Classified<"token", string>;
14
+ type CredentialString = Classified<"credential", string>;
15
+ declare function isClassified(value: unknown): value is Classified<DataClassification, unknown>;
16
+ declare function classificationOf(value: unknown): DataClassification | undefined;
17
+ /**
18
+ * Intentionally explicit: use this when you need the raw string (e.g. building an HTTP header).
19
+ * Prefer passing classified values to safe sinks/policies instead of revealing early.
20
+ */
21
+ declare function reveal<T>(value: Classified<DataClassification, T>): T;
22
+ declare const PublicStringSchema: z.ZodEffects<z.ZodString, Readonly<{
23
+ kind: "public";
24
+ value: string;
25
+ [TYPESECURE_SYMBOL]: true;
26
+ }>, string>;
27
+ declare const PIIStringSchema: z.ZodEffects<z.ZodString, Readonly<{
28
+ kind: "pii";
29
+ value: string;
30
+ [TYPESECURE_SYMBOL]: true;
31
+ }>, string>;
32
+ declare const SecretStringSchema: z.ZodEffects<z.ZodString, Readonly<{
33
+ kind: "secret";
34
+ value: string;
35
+ [TYPESECURE_SYMBOL]: true;
36
+ }>, string>;
37
+ declare const TokenStringSchema: z.ZodEffects<z.ZodString, Readonly<{
38
+ kind: "token";
39
+ value: string;
40
+ [TYPESECURE_SYMBOL]: true;
41
+ }>, string>;
42
+ declare const CredentialStringSchema: z.ZodEffects<z.ZodString, Readonly<{
43
+ kind: "credential";
44
+ value: string;
45
+ [TYPESECURE_SYMBOL]: true;
46
+ }>, string>;
47
+ declare function publicText(value: string): PublicString;
48
+ declare function piiText(value: string): PIIString;
49
+ declare function secretText(value: string): SecretString;
50
+ declare function token(value: string): TokenString;
51
+ declare function credential(value: string): CredentialString;
108
52
 
109
- /**
110
- * Creates a hash of the input string using the specified algorithm
111
- * @param input - The string to hash
112
- * @param options - Hash options
113
- * @returns The hashed string
114
- */
115
- declare function hash(input: string, options?: Partial<HashOptions>): string;
116
- /**
117
- * Verifies if an input matches a previously hashed value
118
- * @param input - The plain text to verify
119
- * @param hashedValue - The hashed value to compare against
120
- * @param options - Hash options
121
- * @returns True if the input matches the hash, false otherwise
122
- */
123
- declare function verifyHash(input: string, hashedValue: string, options?: Partial<HashOptions>): boolean;
124
- /**
125
- * Creates a HMAC (Hash-based Message Authentication Code) of the input
126
- * @param input - The input message
127
- * @param key - The secret key
128
- * @param options - Hash options
129
- * @returns The HMAC signature
130
- */
131
- declare function hmac(input: string, key: string, options?: Partial<HashOptions>): string;
132
- /**
133
- * Performs a secure password hashing using PBKDF2 (default), Argon2, or bcrypt simulation
134
- * Note: This is a simplified implementation. For production, consider using a specialized library
135
- * @param password - The password to hash
136
- * @param options - Password hash options
137
- * @returns An object containing the hash, salt, and parameters
138
- */
139
- declare function hashPassword(password: string, options?: Partial<PasswordHashOptions>): {
140
- hash: string;
141
- salt: string;
142
- params: PasswordHashOptions;
53
+ type RedactOptions = Readonly<{
54
+ /**
55
+ * If true, redact values for suspicious keys even if they aren't classified.
56
+ * Defaults to true.
57
+ */
58
+ guessByKey?: boolean;
59
+ /**
60
+ * Placeholder format for redacted values.
61
+ * Defaults to "[REDACTED:<kind>]".
62
+ */
63
+ placeholder?: (kind: DataClassification | "unknown") => string;
64
+ /**
65
+ * Max depth to traverse to avoid pathological structures.
66
+ * Defaults to 25.
67
+ */
68
+ maxDepth?: number;
69
+ }>;
70
+ declare function redact<T>(value: T, options?: RedactOptions): T;
71
+ declare function safeJsonStringify(value: unknown, options?: RedactOptions, space?: number): string;
72
+ /**
73
+ * Convenience logger that will redact classified data and suspicious keys.
74
+ * You can pass your own logger implementation (pino, winston, console, etc).
75
+ */
76
+ declare function safeLoggerAdapter(logger: Pick<Console, "info" | "warn" | "error" | "debug" | "log">): {
77
+ info: (...args: unknown[]) => void;
78
+ warn: (...args: unknown[]) => void;
79
+ error: (...args: unknown[]) => void;
80
+ debug: (...args: unknown[]) => void;
81
+ log: (...args: unknown[]) => void;
143
82
  };
144
83
  /**
145
- * Verifies a password against a previously hashed password
146
- * @param password - The password to verify
147
- * @param hash - The previously generated hash
148
- * @param salt - The salt used in the original hash
149
- * @param options - Password hash options (must match those used in hashPassword)
150
- * @returns True if the password matches, false otherwise
151
- */
152
- declare function verifyPassword(password: string, hash: string, salt: string, options?: Partial<PasswordHashOptions>): boolean;
153
- /**
154
- * Performs a constant-time comparison of two strings to prevent timing attacks
155
- * @param a - First string to compare
156
- * @param b - Second string to compare
157
- * @param options - Timing safe comparison options
158
- * @returns True if both strings are equal, false otherwise
159
- */
160
- declare function timingSafeEqual(a: string, b: string, options?: Partial<TimingSafeOptions>): boolean;
161
- /**
162
- * Generates a cryptographically secure random string
163
- * @param length - The length of the random string in bytes
164
- * @param encoding - The encoding to use for the output
165
- * @returns A random string in the specified encoding
84
+ * Helper for cases where you must emit a raw header value.
85
+ * Prefer using the policy layer to validate crossings before revealing.
166
86
  */
167
- declare function generateRandomBytes(length?: number, encoding?: 'hex' | 'base64'): string;
87
+ declare function httpAuthorizationBearer(tokenValue: TokenString): string;
168
88
 
89
+ type PolicyAction = "log" | "network" | "storage" | "analytics";
90
+ type PolicyDecision = Readonly<{
91
+ allowed: boolean;
92
+ reason?: string;
93
+ detectedKinds?: DataClassification[];
94
+ }>;
95
+ type Policy = Readonly<{
96
+ name: string;
97
+ allow: Record<PolicyAction, ReadonlySet<DataClassification>>;
98
+ redactBefore?: ReadonlySet<PolicyAction>;
99
+ redaction?: RedactOptions;
100
+ }>;
101
+ declare function defaultPolicy(): Policy;
102
+ declare function decide(policy: Policy, action: PolicyAction, data: unknown): PolicyDecision;
103
+ declare function assertAllowed(policy: Policy, action: PolicyAction, data: unknown): void;
104
+ type AuditEvent = Readonly<{
105
+ at: number;
106
+ policy: string;
107
+ action: PolicyAction;
108
+ decision: PolicyDecision;
109
+ }>;
110
+ declare function audit(policy: Policy, action: PolicyAction, data: unknown): AuditEvent;
169
111
  /**
170
- * A const enum for security levels, used for warnings
171
- * @public
172
- */
173
- declare enum SecurityLevel {
174
- HIGH = "HIGH",
175
- MEDIUM = "MEDIUM",
176
- LOW = "LOW",
177
- INSECURE = "INSECURE"
178
- }
179
- /**
180
- * Returns the security level of the encryption options
181
- * @param options - The encryption options
182
- * @returns The security level
183
- */
184
- declare function getSecurityLevel(options: EncryptionOptions): SecurityLevel;
185
- /**
186
- * Encrypts the provided text using the specified encryption options
187
- * @param text - The text to encrypt
188
- * @param key - The encryption key
189
- * @param options - Encryption options
190
- * @returns The encrypted text
191
- */
192
- declare function encrypt(text: string, key: string, options?: Partial<EncryptionOptions>): string;
193
- /**
194
- * Decrypts the provided encrypted text using the specified options
195
- * @param encryptedText - The text to decrypt
196
- * @param key - The decryption key
197
- * @param options - Encryption options
198
- * @returns The decrypted text
199
- */
200
- declare function decrypt(encryptedText: string, key: string, options?: Partial<EncryptionOptions>): string;
201
- /**
202
- * Generates a random encryption key
203
- * @param length - Length of the key in bytes
204
- * @returns A random key as a hex string
205
- */
206
- declare function generateKey(length?: number): string;
207
-
208
- /**
209
- * Calculates the entropy of a password in bits
210
- * @param password - The password to calculate entropy for
211
- * @returns The entropy in bits
212
- */
213
- declare function calculatePasswordEntropy(password: string): number;
214
- /**
215
- * Analyzes patterns in the password that might reduce its effective entropy
216
- * @param password - The password to analyze
217
- * @returns The entropy reduction (0 to 1)
218
- */
219
- declare function analyzePasswordPatterns(password: string): {
220
- entropyReduction: number;
221
- patterns: string[];
222
- };
223
- /**
224
- * Checks the strength of a password using both rule-based criteria and entropy
225
- * @param password - The password to check
226
- * @param config - Password configuration options
227
- * @returns A PasswordStrength object containing score and feedback
228
- */
229
- declare function checkPasswordStrength(password: string, config?: Partial<Config>): PasswordStrength;
230
- /**
231
- * Generates a secure random password based on configuration
232
- * @param config - Password configuration options
233
- * @returns A random secure password
112
+ * Safe sink example: log with enforcement + redaction (if configured).
234
113
  */
235
- declare function generateSecurePassword(config?: Partial<Config>): string;
114
+ declare function policyLog(policy: Policy, logger: Pick<Console, "info" | "warn" | "error" | "debug" | "log">, level: keyof Pick<Console, "info" | "warn" | "error" | "debug" | "log">, ...args: unknown[]): void;
236
115
 
237
- export { type Config, ConfigSchema, type EncryptionOptions, EncryptionOptionsSchema, type HashOptions, HashOptionsSchema, type PasswordHashOptions, PasswordHashOptionsSchema, type PasswordStrength, PasswordStrengthSchema, SecurityLevel, type TimingSafeOptions, TimingSafeOptionsSchema, analyzePasswordPatterns, calculatePasswordEntropy, checkPasswordStrength, decrypt, encrypt, generateKey, generateRandomBytes, generateSecurePassword, getSecurityLevel, hash, hashPassword, hmac, timingSafeEqual, verifyHash, verifyPassword };
116
+ export { type AuditEvent, type Classified, type CredentialString, CredentialStringSchema, type DataClassification, type PIIString, PIIStringSchema, type Policy, type PolicyAction, type PolicyDecision, type PublicString, PublicStringSchema, type RedactOptions, type SecretString, SecretStringSchema, type TokenString, TokenStringSchema, assertAllowed, audit, classificationOf, credential, decide, defaultPolicy, httpAuthorizationBearer, isClassified, piiText, policyLog, publicText, redact, reveal, safeJsonStringify, safeLoggerAdapter, secretText, token };