@devshub198211/devguard 2.0.2 → 2.0.3

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/dist/auth.d.cts DELETED
@@ -1,245 +0,0 @@
1
- interface JWTPayload {
2
- sub?: string;
3
- iss?: string;
4
- aud?: string | string[];
5
- exp?: number;
6
- iat?: number;
7
- nbf?: number;
8
- jti?: string;
9
- [key: string]: any;
10
- }
11
- interface VerifyResult {
12
- valid: boolean;
13
- payload?: JWTPayload;
14
- error?: string;
15
- }
16
- interface JWKSKey {
17
- kty: string;
18
- kid?: string;
19
- use?: string;
20
- alg?: string;
21
- n?: string;
22
- e?: string;
23
- }
24
- declare function decodeJWT(token: string): {
25
- header: any;
26
- payload: JWTPayload;
27
- sig: string;
28
- signingInput: string;
29
- } | null;
30
- declare function signHMAC(payload: JWTPayload, secret: string, algorithm?: "HS256" | "HS512"): string;
31
- declare function verifyHMAC(token: string, secret: string, expectedAlg?: "HS256" | "HS512"): VerifyResult;
32
- declare function fetchJWKS(jwksUri: string): Promise<JWKSKey[]>;
33
- /** Expose cache management for long-running servers */
34
- declare const jwksCacheUtils: {
35
- prune: () => number;
36
- size: () => number;
37
- destroy: () => void;
38
- };
39
- declare function verifyRS256(token: string, jwksUri: string): Promise<VerifyResult>;
40
- declare class RevocationList {
41
- private revoked;
42
- revoke(jti: string): void;
43
- isRevoked(jti?: string): boolean;
44
- revokedCount(): number;
45
- prune(maxAgeMs?: number): number;
46
- exportJSON(): string;
47
- importJSON(json: string): void;
48
- }
49
- interface AnomalyReport {
50
- score: number;
51
- warnings: string[];
52
- level: "safe" | "suspicious" | "dangerous";
53
- }
54
- declare function detectAnomalies(payload: JWTPayload, ctx?: {
55
- expectedIss?: string;
56
- expectedAud?: string;
57
- }): AnomalyReport;
58
- declare class JWTVerifier {
59
- private opts;
60
- private revocation;
61
- constructor(opts: {
62
- secret?: string;
63
- jwksUri?: string;
64
- expectedIss?: string;
65
- expectedAud?: string;
66
- expectedAlg?: "HS256" | "HS512";
67
- });
68
- verify(token: string): Promise<VerifyResult & {
69
- anomalies?: AnomalyReport;
70
- }>;
71
- revoke(jti: string): void;
72
- getRevocationList(): RevocationList;
73
- }
74
-
75
- /**
76
- * bot-fence v2.1 — Behavioral fingerprinting to distinguish humans from bots/AI agents.
77
- * Signals: UA analysis, header entropy, timing, mouse/keyboard patterns, TLS fingerprint.
78
- * Includes: rate-limit-per-IP, challenge system, whitelist/blacklist, IP normalization.
79
- * No external dependencies.
80
- */
81
- interface RequestFingerprint {
82
- userAgent?: string;
83
- ip?: string;
84
- headers?: Record<string, string | string[] | undefined>;
85
- timingMs?: number;
86
- acceptLanguage?: string;
87
- acceptEncoding?: string;
88
- referer?: string;
89
- origin?: string;
90
- mouseEvents?: number;
91
- keystrokeIntervals?: number[];
92
- scrollEvents?: number;
93
- touchEvents?: number;
94
- }
95
- interface BotScore {
96
- score: number;
97
- verdict: "human" | "likely_human" | "suspicious" | "bot";
98
- signals: Array<{
99
- signal: string;
100
- weight: number;
101
- matched: boolean;
102
- }>;
103
- recommendation: "allow" | "challenge" | "block";
104
- }
105
- declare function scoreRequest(fp: RequestFingerprint): BotScore;
106
- declare class IPRateLimiter {
107
- private maxRequests;
108
- private windowMs;
109
- private blockDurationMs;
110
- private windows;
111
- private blocked;
112
- private checkCount;
113
- constructor(maxRequests?: number, windowMs?: number, blockDurationMs?: number);
114
- check(ip: string): {
115
- allowed: boolean;
116
- remaining: number;
117
- retryAfterMs?: number;
118
- };
119
- /** Prune stale windows and expired blocks to prevent memory growth */
120
- prune(): void;
121
- }
122
- interface MiddlewareOptions {
123
- blockThreshold?: number;
124
- challengeThreshold?: number;
125
- whitelist?: string[];
126
- blacklist?: string[];
127
- rateLimiter?: IPRateLimiter;
128
- onBlock?: (fp: RequestFingerprint, score: BotScore) => void;
129
- }
130
- declare function createMiddleware(opts?: MiddlewareOptions): (req: any, res: any, next: any) => any;
131
-
132
- interface RPConfig {
133
- rpId: string;
134
- rpName: string;
135
- origin: string;
136
- }
137
- interface RegistrationOptions {
138
- challenge: string;
139
- rp: {
140
- id: string;
141
- name: string;
142
- };
143
- user: {
144
- id: string;
145
- name: string;
146
- displayName: string;
147
- };
148
- pubKeyCredParams: Array<{
149
- type: "public-key";
150
- alg: number;
151
- }>;
152
- timeout: number;
153
- attestation: "none" | "direct";
154
- authenticatorSelection?: {
155
- userVerification?: "required" | "preferred" | "discouraged";
156
- residentKey?: "required" | "preferred" | "discouraged";
157
- };
158
- }
159
- interface AuthenticationOptions {
160
- challenge: string;
161
- rpId: string;
162
- timeout: number;
163
- userVerification: "required" | "preferred" | "discouraged";
164
- allowCredentials?: Array<{
165
- type: "public-key";
166
- id: string;
167
- }>;
168
- }
169
- interface StoredCredential {
170
- credentialId: string;
171
- publicKeyPem: string;
172
- publicKeyAlg: number;
173
- userId: string;
174
- userHandle: string;
175
- signCount: number;
176
- createdAt: number;
177
- lastUsedAt: number;
178
- aaguid?: string;
179
- transports?: string[];
180
- }
181
- interface VerificationResult {
182
- verified: boolean;
183
- credential?: StoredCredential;
184
- error?: string;
185
- }
186
- declare class ChallengeStore {
187
- private challenges;
188
- create(ttlMs?: number): string;
189
- consume(challenge: string): boolean;
190
- private _prune;
191
- /** Get the number of active challenges */
192
- size(): number;
193
- }
194
- declare class CredentialStore {
195
- private creds;
196
- private byUser;
197
- save(cred: StoredCredential): void;
198
- get(credentialId: string): StoredCredential | undefined;
199
- getByUser(userId: string): StoredCredential[];
200
- update(credentialId: string, patch: Partial<StoredCredential>): void;
201
- delete(credentialId: string): void;
202
- exportJSON(): string;
203
- importJSON(json: string): void;
204
- }
205
- declare function generateRegistrationOptions(opts: {
206
- rpId: string;
207
- rpName: string;
208
- userId: string;
209
- userName: string;
210
- userDisplayName?: string;
211
- challengeStore?: ChallengeStore;
212
- }): RegistrationOptions;
213
- declare function verifyRegistration(opts: {
214
- response: {
215
- clientDataJSON: string;
216
- attestationObject: string;
217
- };
218
- expectedChallenge: string;
219
- expectedOrigin: string;
220
- expectedRpId: string;
221
- userId: string;
222
- challengeStore?: ChallengeStore;
223
- }): Promise<VerificationResult>;
224
- declare function generateAuthenticationOptions(opts: {
225
- rpId: string;
226
- challengeStore?: ChallengeStore;
227
- allowCredentialIds?: string[];
228
- userVerification?: "required" | "preferred" | "discouraged";
229
- }): AuthenticationOptions;
230
- declare function verifyAuthentication(opts: {
231
- response: {
232
- credentialId: string;
233
- clientDataJSON: string;
234
- authenticatorData: string;
235
- signature: string;
236
- userHandle?: string;
237
- };
238
- expectedChallenge: string;
239
- expectedOrigin: string;
240
- expectedRpId: string;
241
- storedCredential: StoredCredential;
242
- requireUserVerification?: boolean;
243
- }): Promise<VerificationResult>;
244
-
245
- export { type AnomalyReport, type AuthenticationOptions, type BotScore, ChallengeStore, CredentialStore, IPRateLimiter, type JWKSKey, type JWTPayload, JWTVerifier, type MiddlewareOptions, type RPConfig, type RegistrationOptions, type RequestFingerprint, RevocationList, type StoredCredential, type VerificationResult, type VerifyResult, createMiddleware, decodeJWT, detectAnomalies, fetchJWKS, generateAuthenticationOptions, generateRegistrationOptions, jwksCacheUtils, scoreRequest, signHMAC, verifyAuthentication, verifyHMAC, verifyRS256, verifyRegistration };