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 +91 -99
- package/dist/index.d.mts +105 -226
- package/dist/index.d.ts +105 -226
- package/dist/index.js +200 -663
- package/dist/index.mjs +185 -638
- package/package.json +37 -35
package/README.md
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
# typesecure
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
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
|
-
###
|
|
43
|
+
### Classification-first data handling
|
|
33
44
|
|
|
34
45
|
```typescript
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
###
|
|
77
|
+
### Express / Next.js examples
|
|
60
78
|
|
|
61
79
|
```typescript
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
###
|
|
104
|
+
### Classification
|
|
117
105
|
|
|
118
|
-
- `
|
|
119
|
-
- `
|
|
120
|
-
- `
|
|
121
|
-
- `
|
|
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
|
-
###
|
|
113
|
+
### Redaction
|
|
124
114
|
|
|
125
|
-
- `
|
|
126
|
-
- `
|
|
127
|
-
- `
|
|
128
|
-
- `generateRandomBytes(length?: number, encoding?: 'hex' | 'base64'): string`
|
|
115
|
+
- `redact(value): value` (deep traversal)
|
|
116
|
+
- `safeJsonStringify(value): string`
|
|
117
|
+
- `safeLoggerAdapter(consoleLike)`
|
|
129
118
|
|
|
130
|
-
###
|
|
119
|
+
### Policy
|
|
131
120
|
|
|
132
|
-
- `
|
|
133
|
-
- `
|
|
134
|
-
- `
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
declare const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
declare
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
*
|
|
146
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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 };
|