@surbee/cipher 0.1.0 → 0.2.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.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @surbee/cipher
2
+
3
+ AI-powered survey response validation — detect bots, fraud, AI-generated text,
4
+ and low-quality responses. Score a response anywhere you collect it, not just
5
+ inside Surbee.
6
+
7
+ ```bash
8
+ pnpm add @surbee/cipher
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { Cipher } from '@surbee/cipher';
15
+
16
+ const cipher = new Cipher({
17
+ apiKey: process.env.CIPHER_API_KEY, // cipher_sk_...
18
+ tier: 4, // 1–5, higher = more checks
19
+ });
20
+
21
+ const result = await cipher.validate({
22
+ responses: [
23
+ { question: 'Would you recommend us?', answer: 'Yes' },
24
+ ],
25
+ behavioralMetrics: tracker.getMetrics(), // optional
26
+ deviceInfo: tracker.getDeviceInfo(), // optional
27
+ });
28
+
29
+ result.score; // 0–1 (higher = better quality)
30
+ result.recommendation; // 'keep' | 'review' | 'discard'
31
+ result.flags; // names of checks that fired
32
+ ```
33
+
34
+ ## Offline mode (tiers 1–2)
35
+
36
+ Tiers 1 and 2 run fully on-device — no API key, no network. Only the offline
37
+ checks for the tier are evaluated (AI-powered checks stay server-side).
38
+
39
+ ```ts
40
+ const cipher = new Cipher({ tier: 2, offline: true }); // no apiKey needed
41
+
42
+ const result = cipher.validateSync({
43
+ responses: [{ question: 'Rate us', answer: '4', questionType: 'rating' }],
44
+ deviceInfo: tracker.getDeviceInfo(),
45
+ });
46
+ ```
47
+
48
+ The decision engine combines failed checks with a noisy-OR, so a single
49
+ high-confidence signal (a webdriver flag, straight-lining) is enough to flag a
50
+ response — it is never averaged away by the checks that passed.
51
+
52
+ ## Tiers
53
+
54
+ | Tier | Name | Mode | Notes |
55
+ | ---- | -------- | ---------------- | --------------------------------------- |
56
+ | 1 | Basic | offline, free | Behavioral heuristics |
57
+ | 2 | Standard | offline, free | + device fingerprinting / automation |
58
+ | 3 | Enhanced | online | + AI content quality |
59
+ | 4 | Advanced | online | + network + semantic analysis |
60
+ | 5 | Maximum | online | + cross-respondent fraud-ring detection |
61
+
62
+ ## API
63
+
64
+ - `new Cipher(config)` — `{ apiKey?, tier?, thresholds?, offline?, debug?, endpoint? }`
65
+ - `validate(input)` — score one response (local when `offline`, else via API)
66
+ - `validateSync(input)` — synchronous, on-device scoring
67
+ - `validateBatch({ submissions, crossAnalysis? })` — score many at once
68
+ - `getTierInfo(tier?)` / `getAllTiers()` — tier metadata and check lists
69
+ - `estimateCost(responses?)` — per-tier cost estimate (0 for tiers 1–2)
70
+ - `checkStatus()` — verify an API key and remaining credits
71
+
72
+ Individual checks are importable for custom pipelines:
73
+
74
+ ```ts
75
+ import { checkWebDriverDetected, checkStraightLining } from '@surbee/cipher/checks';
76
+ ```
77
+
78
+ ## Result shape
79
+
80
+ ```ts
81
+ {
82
+ score: number, // 0–1
83
+ passed: boolean,
84
+ recommendation: 'keep' | 'review' | 'discard',
85
+ confidence: number, // 0–1
86
+ flags: string[], // human-readable names of failed checks
87
+ summary: { verdict, issues, positives, suggestion },
88
+ checks: CheckResult[], // per-check breakdown
89
+ meta: { tier, processingTimeMs, checksRun, checksPassed, requestId, timestamp },
90
+ }
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT
@@ -0,0 +1,215 @@
1
+ import { R as ResponseInput, S as SurveyContext, h as CheckResult, e as BehavioralMetrics, D as DeviceInfo } from '../types-C8t_T3bP.mjs';
2
+
3
+ /**
4
+ * Timing-based checks
5
+ *
6
+ * Analyzes response timing patterns to detect bots and low-effort responses.
7
+ * All checks in this file are offline (no API required).
8
+ */
9
+
10
+ /**
11
+ * Check: Impossibly Fast
12
+ *
13
+ * Detects responses that were submitted faster than humanly possible.
14
+ * Based on reading speed + minimum typing time.
15
+ */
16
+ declare function checkImpossiblyFast(responses: ResponseInput[], context?: SurveyContext): CheckResult;
17
+ /**
18
+ * Check: Rapid Completion
19
+ *
20
+ * Simpler check for overall survey completion speed.
21
+ * Flags if completed in less than 20% of expected time.
22
+ */
23
+ declare function checkRapidCompletion(responses: ResponseInput[], context?: SurveyContext): CheckResult;
24
+ /**
25
+ * Check: Uniform Timing
26
+ *
27
+ * Detects robotic behavior where response times are suspiciously consistent.
28
+ * Humans have natural variation in response times.
29
+ */
30
+ declare function checkUniformTiming(responses: ResponseInput[], metrics?: BehavioralMetrics): CheckResult;
31
+ /**
32
+ * Check: Suspicious Pauses
33
+ *
34
+ * Detects unusual gaps in activity that might indicate:
35
+ * - Looking up answers
36
+ * - Bot waiting for external input
37
+ * - Copy-pasting from other sources
38
+ */
39
+ declare function checkSuspiciousPauses(metrics?: BehavioralMetrics): CheckResult;
40
+ /**
41
+ * Run all timing checks
42
+ */
43
+ declare function runTimingChecks(responses: ResponseInput[], metrics?: BehavioralMetrics, context?: SurveyContext): CheckResult[];
44
+
45
+ /**
46
+ * Behavioral checks
47
+ *
48
+ * Analyzes mouse, keyboard, and interaction patterns to detect bots.
49
+ * All checks in this file are offline (no API required).
50
+ */
51
+
52
+ /**
53
+ * Check: Low Interaction
54
+ *
55
+ * Detects minimal mouse/keyboard activity relative to survey duration.
56
+ * Bots often have very few interaction events.
57
+ */
58
+ declare function checkLowInteraction(metrics?: BehavioralMetrics): CheckResult;
59
+ /**
60
+ * Check: Excessive Paste
61
+ *
62
+ * Detects heavy copy-paste behavior which might indicate:
63
+ * - AI-generated content being pasted
64
+ * - Copying from other sources
65
+ * - Bot automation
66
+ */
67
+ declare function checkExcessivePaste(metrics?: BehavioralMetrics): CheckResult;
68
+ /**
69
+ * Check: Pointer Velocity Spikes
70
+ *
71
+ * Detects unnatural mouse movement patterns:
72
+ * - Teleporting (instant jumps)
73
+ * - Perfectly linear movement
74
+ * - Inhuman speeds
75
+ */
76
+ declare function checkPointerSpikes(metrics?: BehavioralMetrics): CheckResult;
77
+ /**
78
+ * Check: Robotic Typing
79
+ *
80
+ * Detects uniform keystroke timing that suggests automation.
81
+ * Humans have natural variation in typing rhythm.
82
+ */
83
+ declare function checkRoboticTyping(metrics?: BehavioralMetrics): CheckResult;
84
+ /**
85
+ * Check: Mouse Teleporting
86
+ *
87
+ * Detects large instant mouse jumps that are physically impossible.
88
+ */
89
+ declare function checkMouseTeleporting(metrics?: BehavioralMetrics): CheckResult;
90
+ /**
91
+ * Check: No Corrections
92
+ *
93
+ * Detects perfect typing with no backspaces or corrections.
94
+ * Humans naturally make typos and correct them.
95
+ */
96
+ declare function checkNoCorrections(metrics?: BehavioralMetrics): CheckResult;
97
+ /**
98
+ * Check: Hover Behavior
99
+ *
100
+ * Analyzes mouse hover patterns before clicks.
101
+ * Humans typically hover before clicking; bots often don't.
102
+ */
103
+ declare function checkHoverBehavior(metrics?: BehavioralMetrics): CheckResult;
104
+ /**
105
+ * Check: Scroll Patterns
106
+ *
107
+ * Analyzes scrolling behavior for signs of automation.
108
+ */
109
+ declare function checkScrollPatterns(metrics?: BehavioralMetrics): CheckResult;
110
+ /**
111
+ * Check: Mouse Acceleration
112
+ *
113
+ * Analyzes natural mouse acceleration patterns.
114
+ * Real mice have gradual acceleration/deceleration.
115
+ */
116
+ declare function checkMouseAcceleration(metrics?: BehavioralMetrics): CheckResult;
117
+ /**
118
+ * Run all behavioral checks
119
+ */
120
+ declare function runBehavioralChecks(metrics?: BehavioralMetrics): CheckResult[];
121
+
122
+ /**
123
+ * Content-based checks
124
+ *
125
+ * Analyzes response content for quality and patterns.
126
+ * All checks in this file are offline (no API required).
127
+ */
128
+
129
+ /**
130
+ * Check: Minimal Effort
131
+ *
132
+ * Detects very short or low-quality text responses.
133
+ */
134
+ declare function checkMinimalEffort(responses: ResponseInput[]): CheckResult;
135
+ /**
136
+ * Check: Straight-Lining
137
+ *
138
+ * Detects selecting the same option repeatedly in multiple choice questions.
139
+ */
140
+ declare function checkStraightLining(responses: ResponseInput[]): CheckResult;
141
+ /**
142
+ * Check: Excessive Tab Switching
143
+ *
144
+ * Detects frequent tab/window changes which might indicate:
145
+ * - Looking up answers
146
+ * - Using AI to generate responses
147
+ * - Distracted/inattentive respondent
148
+ */
149
+ declare function checkExcessiveTabSwitching(metrics?: BehavioralMetrics): CheckResult;
150
+ /**
151
+ * Check: Window Focus Loss
152
+ *
153
+ * Detects extended periods where the survey was not in focus.
154
+ */
155
+ declare function checkWindowFocusLoss(metrics?: BehavioralMetrics): CheckResult;
156
+ /**
157
+ * Run all content checks
158
+ */
159
+ declare function runContentChecks(responses: ResponseInput[], metrics?: BehavioralMetrics): CheckResult[];
160
+
161
+ /**
162
+ * Device-based checks
163
+ *
164
+ * Analyzes device fingerprint and browser characteristics to detect bots.
165
+ * All checks in this file are offline (no API required).
166
+ */
167
+
168
+ /**
169
+ * Check: WebDriver Detection
170
+ *
171
+ * Detects Selenium/automation tools via navigator.webdriver flag.
172
+ */
173
+ declare function checkWebDriverDetected(device?: DeviceInfo): CheckResult;
174
+ /**
175
+ * Check: Automation Detection
176
+ *
177
+ * Detects headless browsers and automation frameworks.
178
+ */
179
+ declare function checkAutomationDetected(device?: DeviceInfo): CheckResult;
180
+ /**
181
+ * Check: Missing Plugins
182
+ *
183
+ * Bots often have zero browser plugins, which is unusual for real browsers.
184
+ */
185
+ declare function checkNoPlugins(device?: DeviceInfo): CheckResult;
186
+ /**
187
+ * Check: Suspicious User Agent
188
+ *
189
+ * Detects bot-like user agent strings.
190
+ */
191
+ declare function checkSuspiciousUserAgent(device?: DeviceInfo): CheckResult;
192
+ /**
193
+ * Check: Device Fingerprint Mismatch
194
+ *
195
+ * Detects inconsistent device characteristics that suggest spoofing.
196
+ */
197
+ declare function checkDeviceFingerprintMismatch(device?: DeviceInfo): CheckResult;
198
+ /**
199
+ * Check: Screen Anomaly
200
+ *
201
+ * Detects impossible or suspicious screen dimensions.
202
+ */
203
+ declare function checkScreenAnomaly(device?: DeviceInfo): CheckResult;
204
+ /**
205
+ * Check: Timezone Validation
206
+ *
207
+ * Validates timezone consistency between browser and behavior.
208
+ */
209
+ declare function checkTimezoneValidation(device?: DeviceInfo): CheckResult;
210
+ /**
211
+ * Run all device checks
212
+ */
213
+ declare function runDeviceChecks(device?: DeviceInfo): CheckResult[];
214
+
215
+ export { CheckResult, checkAutomationDetected, checkDeviceFingerprintMismatch, checkExcessivePaste, checkExcessiveTabSwitching, checkHoverBehavior, checkImpossiblyFast, checkLowInteraction, checkMinimalEffort, checkMouseAcceleration, checkMouseTeleporting, checkNoCorrections, checkNoPlugins, checkPointerSpikes, checkRapidCompletion, checkRoboticTyping, checkScreenAnomaly, checkScrollPatterns, checkStraightLining, checkSuspiciousPauses, checkSuspiciousUserAgent, checkTimezoneValidation, checkUniformTiming, checkWebDriverDetected, checkWindowFocusLoss, runBehavioralChecks, runContentChecks, runDeviceChecks, runTimingChecks };
@@ -0,0 +1,215 @@
1
+ import { R as ResponseInput, S as SurveyContext, h as CheckResult, e as BehavioralMetrics, D as DeviceInfo } from '../types-C8t_T3bP.js';
2
+
3
+ /**
4
+ * Timing-based checks
5
+ *
6
+ * Analyzes response timing patterns to detect bots and low-effort responses.
7
+ * All checks in this file are offline (no API required).
8
+ */
9
+
10
+ /**
11
+ * Check: Impossibly Fast
12
+ *
13
+ * Detects responses that were submitted faster than humanly possible.
14
+ * Based on reading speed + minimum typing time.
15
+ */
16
+ declare function checkImpossiblyFast(responses: ResponseInput[], context?: SurveyContext): CheckResult;
17
+ /**
18
+ * Check: Rapid Completion
19
+ *
20
+ * Simpler check for overall survey completion speed.
21
+ * Flags if completed in less than 20% of expected time.
22
+ */
23
+ declare function checkRapidCompletion(responses: ResponseInput[], context?: SurveyContext): CheckResult;
24
+ /**
25
+ * Check: Uniform Timing
26
+ *
27
+ * Detects robotic behavior where response times are suspiciously consistent.
28
+ * Humans have natural variation in response times.
29
+ */
30
+ declare function checkUniformTiming(responses: ResponseInput[], metrics?: BehavioralMetrics): CheckResult;
31
+ /**
32
+ * Check: Suspicious Pauses
33
+ *
34
+ * Detects unusual gaps in activity that might indicate:
35
+ * - Looking up answers
36
+ * - Bot waiting for external input
37
+ * - Copy-pasting from other sources
38
+ */
39
+ declare function checkSuspiciousPauses(metrics?: BehavioralMetrics): CheckResult;
40
+ /**
41
+ * Run all timing checks
42
+ */
43
+ declare function runTimingChecks(responses: ResponseInput[], metrics?: BehavioralMetrics, context?: SurveyContext): CheckResult[];
44
+
45
+ /**
46
+ * Behavioral checks
47
+ *
48
+ * Analyzes mouse, keyboard, and interaction patterns to detect bots.
49
+ * All checks in this file are offline (no API required).
50
+ */
51
+
52
+ /**
53
+ * Check: Low Interaction
54
+ *
55
+ * Detects minimal mouse/keyboard activity relative to survey duration.
56
+ * Bots often have very few interaction events.
57
+ */
58
+ declare function checkLowInteraction(metrics?: BehavioralMetrics): CheckResult;
59
+ /**
60
+ * Check: Excessive Paste
61
+ *
62
+ * Detects heavy copy-paste behavior which might indicate:
63
+ * - AI-generated content being pasted
64
+ * - Copying from other sources
65
+ * - Bot automation
66
+ */
67
+ declare function checkExcessivePaste(metrics?: BehavioralMetrics): CheckResult;
68
+ /**
69
+ * Check: Pointer Velocity Spikes
70
+ *
71
+ * Detects unnatural mouse movement patterns:
72
+ * - Teleporting (instant jumps)
73
+ * - Perfectly linear movement
74
+ * - Inhuman speeds
75
+ */
76
+ declare function checkPointerSpikes(metrics?: BehavioralMetrics): CheckResult;
77
+ /**
78
+ * Check: Robotic Typing
79
+ *
80
+ * Detects uniform keystroke timing that suggests automation.
81
+ * Humans have natural variation in typing rhythm.
82
+ */
83
+ declare function checkRoboticTyping(metrics?: BehavioralMetrics): CheckResult;
84
+ /**
85
+ * Check: Mouse Teleporting
86
+ *
87
+ * Detects large instant mouse jumps that are physically impossible.
88
+ */
89
+ declare function checkMouseTeleporting(metrics?: BehavioralMetrics): CheckResult;
90
+ /**
91
+ * Check: No Corrections
92
+ *
93
+ * Detects perfect typing with no backspaces or corrections.
94
+ * Humans naturally make typos and correct them.
95
+ */
96
+ declare function checkNoCorrections(metrics?: BehavioralMetrics): CheckResult;
97
+ /**
98
+ * Check: Hover Behavior
99
+ *
100
+ * Analyzes mouse hover patterns before clicks.
101
+ * Humans typically hover before clicking; bots often don't.
102
+ */
103
+ declare function checkHoverBehavior(metrics?: BehavioralMetrics): CheckResult;
104
+ /**
105
+ * Check: Scroll Patterns
106
+ *
107
+ * Analyzes scrolling behavior for signs of automation.
108
+ */
109
+ declare function checkScrollPatterns(metrics?: BehavioralMetrics): CheckResult;
110
+ /**
111
+ * Check: Mouse Acceleration
112
+ *
113
+ * Analyzes natural mouse acceleration patterns.
114
+ * Real mice have gradual acceleration/deceleration.
115
+ */
116
+ declare function checkMouseAcceleration(metrics?: BehavioralMetrics): CheckResult;
117
+ /**
118
+ * Run all behavioral checks
119
+ */
120
+ declare function runBehavioralChecks(metrics?: BehavioralMetrics): CheckResult[];
121
+
122
+ /**
123
+ * Content-based checks
124
+ *
125
+ * Analyzes response content for quality and patterns.
126
+ * All checks in this file are offline (no API required).
127
+ */
128
+
129
+ /**
130
+ * Check: Minimal Effort
131
+ *
132
+ * Detects very short or low-quality text responses.
133
+ */
134
+ declare function checkMinimalEffort(responses: ResponseInput[]): CheckResult;
135
+ /**
136
+ * Check: Straight-Lining
137
+ *
138
+ * Detects selecting the same option repeatedly in multiple choice questions.
139
+ */
140
+ declare function checkStraightLining(responses: ResponseInput[]): CheckResult;
141
+ /**
142
+ * Check: Excessive Tab Switching
143
+ *
144
+ * Detects frequent tab/window changes which might indicate:
145
+ * - Looking up answers
146
+ * - Using AI to generate responses
147
+ * - Distracted/inattentive respondent
148
+ */
149
+ declare function checkExcessiveTabSwitching(metrics?: BehavioralMetrics): CheckResult;
150
+ /**
151
+ * Check: Window Focus Loss
152
+ *
153
+ * Detects extended periods where the survey was not in focus.
154
+ */
155
+ declare function checkWindowFocusLoss(metrics?: BehavioralMetrics): CheckResult;
156
+ /**
157
+ * Run all content checks
158
+ */
159
+ declare function runContentChecks(responses: ResponseInput[], metrics?: BehavioralMetrics): CheckResult[];
160
+
161
+ /**
162
+ * Device-based checks
163
+ *
164
+ * Analyzes device fingerprint and browser characteristics to detect bots.
165
+ * All checks in this file are offline (no API required).
166
+ */
167
+
168
+ /**
169
+ * Check: WebDriver Detection
170
+ *
171
+ * Detects Selenium/automation tools via navigator.webdriver flag.
172
+ */
173
+ declare function checkWebDriverDetected(device?: DeviceInfo): CheckResult;
174
+ /**
175
+ * Check: Automation Detection
176
+ *
177
+ * Detects headless browsers and automation frameworks.
178
+ */
179
+ declare function checkAutomationDetected(device?: DeviceInfo): CheckResult;
180
+ /**
181
+ * Check: Missing Plugins
182
+ *
183
+ * Bots often have zero browser plugins, which is unusual for real browsers.
184
+ */
185
+ declare function checkNoPlugins(device?: DeviceInfo): CheckResult;
186
+ /**
187
+ * Check: Suspicious User Agent
188
+ *
189
+ * Detects bot-like user agent strings.
190
+ */
191
+ declare function checkSuspiciousUserAgent(device?: DeviceInfo): CheckResult;
192
+ /**
193
+ * Check: Device Fingerprint Mismatch
194
+ *
195
+ * Detects inconsistent device characteristics that suggest spoofing.
196
+ */
197
+ declare function checkDeviceFingerprintMismatch(device?: DeviceInfo): CheckResult;
198
+ /**
199
+ * Check: Screen Anomaly
200
+ *
201
+ * Detects impossible or suspicious screen dimensions.
202
+ */
203
+ declare function checkScreenAnomaly(device?: DeviceInfo): CheckResult;
204
+ /**
205
+ * Check: Timezone Validation
206
+ *
207
+ * Validates timezone consistency between browser and behavior.
208
+ */
209
+ declare function checkTimezoneValidation(device?: DeviceInfo): CheckResult;
210
+ /**
211
+ * Run all device checks
212
+ */
213
+ declare function runDeviceChecks(device?: DeviceInfo): CheckResult[];
214
+
215
+ export { CheckResult, checkAutomationDetected, checkDeviceFingerprintMismatch, checkExcessivePaste, checkExcessiveTabSwitching, checkHoverBehavior, checkImpossiblyFast, checkLowInteraction, checkMinimalEffort, checkMouseAcceleration, checkMouseTeleporting, checkNoCorrections, checkNoPlugins, checkPointerSpikes, checkRapidCompletion, checkRoboticTyping, checkScreenAnomaly, checkScrollPatterns, checkStraightLining, checkSuspiciousPauses, checkSuspiciousUserAgent, checkTimezoneValidation, checkUniformTiming, checkWebDriverDetected, checkWindowFocusLoss, runBehavioralChecks, runContentChecks, runDeviceChecks, runTimingChecks };