@keverdjs/fraud-sdk-react 1.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.
@@ -0,0 +1,365 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * Keverd Fraud SDK React - Type Definitions
6
+ */
7
+ interface KeverdDeviceInfo {
8
+ deviceId: string;
9
+ fingerprint: string;
10
+ manufacturer?: string;
11
+ model?: string;
12
+ brand?: string;
13
+ device?: string;
14
+ product?: string;
15
+ hardware?: string;
16
+ sdkVersion?: string;
17
+ osVersion?: string;
18
+ screenWidth?: string;
19
+ screenHeight?: string;
20
+ screenDensity?: string;
21
+ locale?: string;
22
+ timezone: string;
23
+ }
24
+ interface KeverdSessionInfo {
25
+ sessionId?: string;
26
+ installId?: string;
27
+ sessionCount?: string;
28
+ firstSession?: string;
29
+ timestamp?: string;
30
+ }
31
+ interface KeverdBehavioralData {
32
+ typing_dwell_ms?: number[];
33
+ typing_flight_ms?: number[];
34
+ swipe_velocity?: number;
35
+ session_entropy?: number;
36
+ }
37
+ interface KeverdFingerprintRequest {
38
+ userId?: string;
39
+ device: KeverdDeviceInfo;
40
+ session?: KeverdSessionInfo;
41
+ behavioral?: KeverdBehavioralData;
42
+ }
43
+ interface KeverdSimSwapEngine {
44
+ userId?: string;
45
+ risk: number;
46
+ flags: {
47
+ sim_changed?: boolean;
48
+ device_changed?: boolean;
49
+ behavior_anomaly?: boolean;
50
+ time_anomaly?: boolean;
51
+ velocity_anomaly?: boolean;
52
+ };
53
+ updatedProfile?: Record<string, unknown>;
54
+ }
55
+ interface KeverdFingerprintResponse {
56
+ risk_score: number;
57
+ score: number;
58
+ action: 'allow' | 'soft_challenge' | 'hard_challenge' | 'block';
59
+ reason: string[];
60
+ session_id: string;
61
+ requestId: string;
62
+ sim_swap_engine?: KeverdSimSwapEngine;
63
+ }
64
+ interface KeverdVisitorData {
65
+ visitorId: string;
66
+ riskScore: number;
67
+ score: number;
68
+ action: 'allow' | 'soft_challenge' | 'hard_challenge' | 'block';
69
+ reasons: string[];
70
+ sessionId: string;
71
+ requestId: string;
72
+ simSwapEngine?: KeverdSimSwapEngine;
73
+ confidence?: number;
74
+ }
75
+ interface KeverdConfig {
76
+ apiKey: string;
77
+ endpoint?: string;
78
+ userId?: string;
79
+ debug?: boolean;
80
+ extendedResult?: boolean;
81
+ ignoreCache?: boolean;
82
+ }
83
+ interface KeverdLoadOptions {
84
+ apiKey: string;
85
+ endpoint?: string;
86
+ debug?: boolean;
87
+ }
88
+ interface KeverdVisitorDataOptions {
89
+ extendedResult?: boolean;
90
+ ignoreCache?: boolean;
91
+ tag?: string;
92
+ }
93
+ interface KeverdVisitorDataHookOptions {
94
+ extendedResult?: boolean;
95
+ immediate?: boolean;
96
+ ignoreCache?: boolean;
97
+ }
98
+ interface KeverdError {
99
+ message: string;
100
+ code?: string;
101
+ statusCode?: number;
102
+ }
103
+ interface KeverdVisitorDataResult$1 {
104
+ isLoading: boolean;
105
+ error: KeverdError | null;
106
+ data: KeverdVisitorData | null;
107
+ getData: (options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
108
+ }
109
+
110
+ /**
111
+ * Keverd Fraud SDK Core
112
+ * Main SDK class for fingerprinting and risk assessment
113
+ */
114
+
115
+ declare class KeverdSDK {
116
+ private config;
117
+ private deviceCollector;
118
+ private behavioralCollector;
119
+ private isInitialized;
120
+ private sessionId;
121
+ constructor();
122
+ /**
123
+ * Initialize the SDK with configuration
124
+ */
125
+ init(config: KeverdConfig): void;
126
+ /**
127
+ * Get visitor data (fingerprint and risk assessment)
128
+ */
129
+ getVisitorData(options?: KeverdVisitorDataOptions): Promise<KeverdVisitorData>;
130
+ /**
131
+ * Send fingerprint request to backend
132
+ */
133
+ private sendFingerprintRequest;
134
+ /**
135
+ * Transform API response to visitor data format
136
+ */
137
+ private transformResponse;
138
+ /**
139
+ * Get default endpoint
140
+ */
141
+ private getDefaultEndpoint;
142
+ /**
143
+ * Generate a session ID
144
+ */
145
+ private generateSessionId;
146
+ /**
147
+ * Destroy the SDK instance
148
+ */
149
+ destroy(): void;
150
+ /**
151
+ * Get current configuration
152
+ */
153
+ getConfig(): KeverdConfig | null;
154
+ /**
155
+ * Check if SDK is initialized
156
+ */
157
+ isReady(): boolean;
158
+ }
159
+
160
+ interface KeverdContextValue {
161
+ sdk: KeverdSDK;
162
+ isReady: boolean;
163
+ }
164
+ interface KeverdProviderProps {
165
+ loadOptions: KeverdLoadOptions;
166
+ children: ReactNode;
167
+ }
168
+ /**
169
+ * KeverdProvider - Wrap your app with this component to enable Keverd SDK
170
+ */
171
+ declare function KeverdProvider({ loadOptions, children }: KeverdProviderProps): react_jsx_runtime.JSX.Element;
172
+ /**
173
+ * Hook to access Keverd SDK from context
174
+ */
175
+ declare function useKeverdContext(): KeverdContextValue;
176
+
177
+ /**
178
+ * useKeverdVisitorData Hook
179
+ * React hook for accessing visitor data and risk assessment
180
+ */
181
+
182
+ interface KeverdVisitorDataResult {
183
+ isLoading: boolean;
184
+ error: KeverdError | null;
185
+ data: KeverdVisitorData | null;
186
+ getData: (options?: KeverdVisitorDataOptions) => Promise<KeverdVisitorData>;
187
+ }
188
+ /**
189
+ * Hook to get visitor data and risk assessment
190
+ *
191
+ * @param options - Configuration options for the hook
192
+ * @returns Object containing loading state, error, data, and getData function
193
+ *
194
+ * @example
195
+ * ```tsx
196
+ * function MyComponent() {
197
+ * const { isLoading, error, data, getData } = useKeverdVisitorData({
198
+ * extendedResult: true,
199
+ * immediate: true
200
+ * });
201
+ *
202
+ * if (isLoading) return <div>Loading...</div>;
203
+ * if (error) return <div>Error: {error.message}</div>;
204
+ *
205
+ * return (
206
+ * <div>
207
+ * <p>Risk Score: {data?.riskScore}</p>
208
+ * <p>Action: {data?.action}</p>
209
+ * <button onClick={() => getData({ ignoreCache: true })}>
210
+ * Reload data
211
+ * </button>
212
+ * </div>
213
+ * );
214
+ * }
215
+ * ```
216
+ */
217
+ declare function useKeverdVisitorData(options?: KeverdVisitorDataHookOptions): KeverdVisitorDataResult;
218
+
219
+ /**
220
+ * Keverd Device Fingerprint Collector
221
+ * Collects device information, canvas fingerprint, WebGL fingerprint, and generates a stable device ID
222
+ */
223
+
224
+ declare class KeverdDeviceCollector {
225
+ private cachedDeviceInfo;
226
+ /**
227
+ * Collect all device information and generate fingerprint
228
+ */
229
+ collect(): KeverdDeviceInfo;
230
+ /**
231
+ * Generate a stable device fingerprint using multiple browser characteristics
232
+ * Returns SHA-256 hash (64 hex characters) as required by backend
233
+ */
234
+ private generateDeviceFingerprint;
235
+ /**
236
+ * Generate canvas fingerprint
237
+ */
238
+ private getCanvasFingerprint;
239
+ /**
240
+ * Generate WebGL fingerprint
241
+ */
242
+ private getWebGLFingerprint;
243
+ /**
244
+ * Generate a stable device ID from fingerprint
245
+ */
246
+ private generateDeviceId;
247
+ /**
248
+ * Get manufacturer from user agent
249
+ */
250
+ private getManufacturer;
251
+ /**
252
+ * Get model from user agent
253
+ */
254
+ private getModel;
255
+ /**
256
+ * Get brand from user agent
257
+ */
258
+ private getBrand;
259
+ /**
260
+ * Get device type
261
+ */
262
+ private getDevice;
263
+ /**
264
+ * Get product name
265
+ */
266
+ private getProduct;
267
+ /**
268
+ * Get hardware info
269
+ */
270
+ private getHardware;
271
+ /**
272
+ * Get OS version
273
+ */
274
+ private getOSVersion;
275
+ /**
276
+ * Get screen density
277
+ */
278
+ private getScreenDensity;
279
+ /**
280
+ * Hash a string using SHA-256 (required for backend compatibility)
281
+ * Backend expects SHA-256 hash (64 hex characters)
282
+ * Uses Web Crypto API synchronously via a cached approach
283
+ */
284
+ private hashString;
285
+ /**
286
+ * SHA-256-like hash function (synchronous, deterministic)
287
+ * Produces 64-character hex string matching SHA-256 format
288
+ * This is a deterministic hash that mimics SHA-256 characteristics
289
+ */
290
+ private sha256LikeHash;
291
+ /**
292
+ * Clear cached device info (useful for testing)
293
+ */
294
+ clearCache(): void;
295
+ }
296
+
297
+ /**
298
+ * Keverd Behavioral Data Collector
299
+ * Collects typing patterns, mouse movements, swipe gestures, and calculates session entropy
300
+ */
301
+
302
+ declare class KeverdBehavioralCollector {
303
+ private keystrokes;
304
+ private mouseMovements;
305
+ private lastKeyDownTime;
306
+ private lastKeyUpTime;
307
+ private isActive;
308
+ private sessionStartTime;
309
+ private typingDwellTimes;
310
+ private typingFlightTimes;
311
+ private swipeVelocities;
312
+ private sessionEvents;
313
+ private touchStartPositions;
314
+ private keyDownHandler;
315
+ private keyUpHandler;
316
+ private mouseMoveHandler;
317
+ private touchStartHandler;
318
+ private touchEndHandler;
319
+ /**
320
+ * Start collecting behavioral data
321
+ */
322
+ start(): void;
323
+ /**
324
+ * Stop collecting behavioral data
325
+ */
326
+ stop(): void;
327
+ /**
328
+ * Get collected behavioral data
329
+ */
330
+ getData(): KeverdBehavioralData;
331
+ /**
332
+ * Reset collected data
333
+ */
334
+ reset(): void;
335
+ /**
336
+ * Handle keydown event
337
+ */
338
+ private handleKeyDown;
339
+ /**
340
+ * Handle keyup event
341
+ */
342
+ private handleKeyUp;
343
+ /**
344
+ * Handle mouse move event
345
+ */
346
+ private handleMouseMove;
347
+ /**
348
+ * Handle touch start (for swipe detection)
349
+ */
350
+ private handleTouchStart;
351
+ /**
352
+ * Handle touch end (calculate swipe velocity)
353
+ */
354
+ private handleTouchEnd;
355
+ /**
356
+ * Calculate session entropy based on event diversity
357
+ */
358
+ private calculateSessionEntropy;
359
+ /**
360
+ * Check if key should be ignored
361
+ */
362
+ private shouldIgnoreKey;
363
+ }
364
+
365
+ export { KeverdBehavioralCollector, type KeverdBehavioralData, type KeverdConfig, KeverdDeviceCollector, type KeverdDeviceInfo, type KeverdError, type KeverdFingerprintRequest, type KeverdFingerprintResponse, type KeverdLoadOptions, KeverdProvider, KeverdSDK, type KeverdSessionInfo, type KeverdSimSwapEngine, type KeverdVisitorData, type KeverdVisitorDataHookOptions, type KeverdVisitorDataOptions, type KeverdVisitorDataResult$1 as KeverdVisitorDataResult, useKeverdContext, useKeverdVisitorData };