device-passport 1.0.0 → 1.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/CHANGELOG.md +33 -0
- package/README.md +110 -2
- package/assets/ego-profile-manager.png +0 -0
- package/dist/adapters/index.cjs +19 -0
- package/dist/adapters/index.d.cts +66 -0
- package/dist/adapters/index.d.mts +66 -0
- package/dist/adapters/index.d.ts +66 -0
- package/dist/adapters/index.mjs +3 -0
- package/dist/ego/index.cjs +22 -0
- package/dist/ego/index.d.cts +5 -0
- package/dist/ego/index.d.mts +5 -0
- package/dist/ego/index.d.ts +5 -0
- package/dist/ego/index.mjs +8 -0
- package/dist/evaluator/index.cjs +140 -0
- package/dist/evaluator/index.d.cts +204 -0
- package/dist/evaluator/index.d.mts +204 -0
- package/dist/evaluator/index.d.ts +204 -0
- package/dist/evaluator/index.mjs +119 -0
- package/dist/geo/index.cjs +50 -0
- package/dist/geo/index.d.cts +213 -0
- package/dist/geo/index.d.mts +213 -0
- package/dist/geo/index.d.ts +213 -0
- package/dist/geo/index.mjs +18 -0
- package/dist/index.cjs +110 -3940
- package/dist/index.d.cts +45 -1091
- package/dist/index.d.mts +45 -1091
- package/dist/index.d.ts +45 -1091
- package/dist/index.mjs +11 -3849
- package/dist/shared/device-passport.BGfRcQNh.mjs +565 -0
- package/dist/shared/device-passport.BKtmLzPt.cjs +1266 -0
- package/dist/shared/device-passport.BPQj0qdT.mjs +1238 -0
- package/dist/shared/device-passport.CDS7xrj8.d.ts +469 -0
- package/dist/shared/device-passport.C_F1vBE8.d.cts +79 -0
- package/dist/shared/device-passport.C_F1vBE8.d.mts +79 -0
- package/dist/shared/device-passport.C_F1vBE8.d.ts +79 -0
- package/dist/shared/device-passport.CfLes-lq.d.cts +469 -0
- package/dist/shared/device-passport.Cjxlv8xI.cjs +245 -0
- package/dist/shared/device-passport.CsOWqPIr.d.cts +77 -0
- package/dist/shared/device-passport.CyQtcZeD.mjs +237 -0
- package/dist/shared/device-passport.D7pEnyp2.d.ts +77 -0
- package/dist/shared/device-passport.D9xW6R0B.cjs +1571 -0
- package/dist/shared/device-passport.DirQmSd4.d.cts +47 -0
- package/dist/shared/device-passport.DirQmSd4.d.mts +47 -0
- package/dist/shared/device-passport.DirQmSd4.d.ts +47 -0
- package/dist/shared/device-passport.EK4RX7Xd.cjs +584 -0
- package/dist/shared/device-passport.ZBspe4ZW.d.mts +77 -0
- package/dist/shared/device-passport.dVEqzSEb.d.mts +469 -0
- package/dist/shared/device-passport.gNo82fQ5.mjs +1537 -0
- package/dist/shared/device-passport.kekU28UM.mjs +705 -0
- package/dist/shared/device-passport.qL4tjwc0.cjs +718 -0
- package/dist/storage/index.cjs +10 -0
- package/dist/storage/index.d.cts +97 -0
- package/dist/storage/index.d.mts +97 -0
- package/dist/storage/index.d.ts +97 -0
- package/dist/storage/index.mjs +3 -0
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +397 -0
- package/dist/types/index.d.mts +397 -0
- package/dist/types/index.d.ts +397 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +32 -2
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { DevicePassport } from '../types/index.cjs';
|
|
2
|
+
import '../shared/device-passport.C_F1vBE8.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Contradiction Detection Engine for Device Passport.
|
|
6
|
+
*
|
|
7
|
+
* Evaluates cross-layer integrity across the 4-tuple formal model:
|
|
8
|
+
* P = ⟨H, S, G, C⟩ (Hardware, System, Geo, Client-Hints).
|
|
9
|
+
*
|
|
10
|
+
* Implements deterministic anomaly and anti-fingerprinting rules based on
|
|
11
|
+
* empirical browser telemetry, W3C Client Hints RFCs, and anti-bot heuristic vectors.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type ContradictionSeverity = 'fatal' | 'high' | 'medium' | 'low';
|
|
15
|
+
type ContradictionCategory = 'hardware_system' | 'os_browser' | 'geo_chrono' | 'client_hints' | 'entropy';
|
|
16
|
+
interface Contradiction {
|
|
17
|
+
id: string;
|
|
18
|
+
category: ContradictionCategory;
|
|
19
|
+
severity: ContradictionSeverity;
|
|
20
|
+
description: string;
|
|
21
|
+
fields: string[];
|
|
22
|
+
actual: unknown;
|
|
23
|
+
expected: unknown;
|
|
24
|
+
impactPenalty: number;
|
|
25
|
+
}
|
|
26
|
+
declare const COUNTRY_TIMEZONE_MAP: Record<string, string[]>;
|
|
27
|
+
declare const COUNTRY_PRIMARY_LANGUAGES: Record<string, string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Detect OS vs Browser compatibility contradictions.
|
|
30
|
+
*/
|
|
31
|
+
declare function detectOSBrowserContradictions(passport: DevicePassport): Contradiction[];
|
|
32
|
+
/**
|
|
33
|
+
* Detect Hardware vs System cross-layer contradictions.
|
|
34
|
+
*/
|
|
35
|
+
declare function detectHardwareContradictions(passport: DevicePassport): Contradiction[];
|
|
36
|
+
/**
|
|
37
|
+
* Detect Geographic, Locale, and Chronological (Geo-Chrono) Contradictions.
|
|
38
|
+
*/
|
|
39
|
+
declare function detectGeoChronoContradictions(passport: DevicePassport): Contradiction[];
|
|
40
|
+
/**
|
|
41
|
+
* Detect W3C Client Hints Internal Consistency Contradictions.
|
|
42
|
+
*/
|
|
43
|
+
declare function detectClientHintsContradictions(passport: DevicePassport): Contradiction[];
|
|
44
|
+
/**
|
|
45
|
+
* Master contradiction detection runner across all 4 sub-spaces:
|
|
46
|
+
* P = ⟨H, S, G, C⟩.
|
|
47
|
+
*/
|
|
48
|
+
declare function detectAllContradictions(passport: DevicePassport): Contradiction[];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Shannon Entropy Analyzer for Device Passport HTTP Headers.
|
|
52
|
+
*
|
|
53
|
+
* Grounded in Information Theory (Shannon, 1948: "A Mathematical Theory of Communication"):
|
|
54
|
+
* H(X) = - \sum_{i=1}^{n} P(x_i) \log_2 P(x_i)
|
|
55
|
+
*
|
|
56
|
+
* Evaluates generated header distributions against empirical modern browser baselines
|
|
57
|
+
* to detect:
|
|
58
|
+
* 1. Under-parameterized / Low-entropy signatures (naive scrapers, curl, missing sec-ch headers)
|
|
59
|
+
* 2. Over-parameterized / High-entropy anomalies (random noise injection, spoofing artifacts)
|
|
60
|
+
* 3. Relative Entropy (Kullback-Leibler Divergence) against empirical Chrome/Edge/Safari profiles
|
|
61
|
+
*/
|
|
62
|
+
interface HeaderEntropyProfile {
|
|
63
|
+
characterEntropy: number;
|
|
64
|
+
structuralEntropy: number;
|
|
65
|
+
klDivergence: number;
|
|
66
|
+
totalHeaderBytes: number;
|
|
67
|
+
headerCount: number;
|
|
68
|
+
}
|
|
69
|
+
interface EntropyAnalysisResult {
|
|
70
|
+
entropyScore: number;
|
|
71
|
+
estimatedBits: number;
|
|
72
|
+
klDivergence: number;
|
|
73
|
+
anomaly: 'too_low' | 'too_high' | 'optimal';
|
|
74
|
+
collisionRisk: 'very_low' | 'low' | 'moderate' | 'high';
|
|
75
|
+
verdict: string;
|
|
76
|
+
details: {
|
|
77
|
+
characterEntropy: number;
|
|
78
|
+
structuralEntropy: number;
|
|
79
|
+
baselineEntropy: number;
|
|
80
|
+
deltaFromOptimal: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Empirical baseline frequency distribution of headers in real modern desktop browsers (Chromium 120+).
|
|
85
|
+
* Baseline average entropy is calibrated at 4.45 bits/char.
|
|
86
|
+
*/
|
|
87
|
+
declare const BROWSER_BASELINE_FREQUENCIES: Record<string, number>;
|
|
88
|
+
declare const OPTIMAL_CHAR_ENTROPY_MIN = 4.6;
|
|
89
|
+
declare const OPTIMAL_CHAR_ENTROPY_MAX = 5.6;
|
|
90
|
+
declare const OPTIMAL_ENTROPY_MIN = 4.6;
|
|
91
|
+
declare const OPTIMAL_ENTROPY_MAX = 5.6;
|
|
92
|
+
declare const BASELINE_OPTIMAL_ENTROPY = 5.25;
|
|
93
|
+
declare const MIN_STRUCTURAL_ENTROPY = 3.5;
|
|
94
|
+
/**
|
|
95
|
+
* Calculates fundamental Shannon Information Entropy (in bits) of any string input.
|
|
96
|
+
* H(X) = -\sum_{i=1}^n P(x_i) \log_2 P(x_i)
|
|
97
|
+
*/
|
|
98
|
+
declare function calculateShannonEntropy(data: string): number;
|
|
99
|
+
/**
|
|
100
|
+
* Calculates structural header presence entropy across expected browser header space.
|
|
101
|
+
*/
|
|
102
|
+
declare function calculateStructuralEntropy(headers: Record<string, string>): number;
|
|
103
|
+
/**
|
|
104
|
+
* Calculates Kullback-Leibler (KL) Divergence:
|
|
105
|
+
* D_KL(P || Q) = \sum P(x) * log2(P(x) / Q(x))
|
|
106
|
+
* Measures informational distance between current header distribution and natural browser baseline.
|
|
107
|
+
*/
|
|
108
|
+
declare function calculateKLDivergence(headers: Record<string, string>): number;
|
|
109
|
+
/**
|
|
110
|
+
* Analyzes the entropy of an HTTP header dictionary.
|
|
111
|
+
* Evaluates whether entropy is in the realistic "sweet spot" of real browser traffic.
|
|
112
|
+
*/
|
|
113
|
+
declare function analyzeHeaderEntropy(headers: Record<string, string>): EntropyAnalysisResult;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Academic Coherence Evaluator for Device Passport.
|
|
117
|
+
*
|
|
118
|
+
* Implements the Formal Mathematical Model:
|
|
119
|
+
* P = ⟨H, S, G, C⟩
|
|
120
|
+
*
|
|
121
|
+
* Where:
|
|
122
|
+
* - H ∈ Ω_H: Hardware Sub-space ⟨Screen, CPU, Memory, GPU⟩
|
|
123
|
+
* - S ∈ Ω_S: System Sub-space ⟨OS, Browser, UserAgent⟩
|
|
124
|
+
* - G ∈ Ω_G: Geo-Chrono Sub-space ⟨Country, Timezone, Locale, Languages, Coordinates⟩
|
|
125
|
+
* - C ∈ Ω_C: Client-Hints Sub-space ⟨Sec-CH-UA*, Low & High Entropy Hints⟩
|
|
126
|
+
*
|
|
127
|
+
* The coherence evaluation function Φ(P) maps P into [0, 100%], quantifying
|
|
128
|
+
* cross-subspace plausibility and absence of anti-bot contradiction signatures.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
interface SubspaceEvaluation {
|
|
132
|
+
valid: boolean;
|
|
133
|
+
score: number;
|
|
134
|
+
notes: string[];
|
|
135
|
+
}
|
|
136
|
+
interface MathematicalModelFormalism {
|
|
137
|
+
formalism: string;
|
|
138
|
+
definition: {
|
|
139
|
+
H: string;
|
|
140
|
+
S: string;
|
|
141
|
+
G: string;
|
|
142
|
+
C: string;
|
|
143
|
+
};
|
|
144
|
+
subspaces: {
|
|
145
|
+
H: SubspaceEvaluation;
|
|
146
|
+
S: SubspaceEvaluation;
|
|
147
|
+
G: SubspaceEvaluation;
|
|
148
|
+
C: SubspaceEvaluation;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
interface CoherenceEvaluationResult {
|
|
152
|
+
/** Overall cross-layer coherence score (0 - 100%) */
|
|
153
|
+
coherenceScore: number;
|
|
154
|
+
/** Specific geo-temporal-linguistic alignment score (0 - 100%) */
|
|
155
|
+
geoAlignmentScore: number;
|
|
156
|
+
/** Shannon entropy realistic score (0 - 100%) */
|
|
157
|
+
entropyScore: number;
|
|
158
|
+
/** List of detected contradictions and anomalies */
|
|
159
|
+
contradictions: Contradiction[];
|
|
160
|
+
/** Mathematical formalization of the evaluation state */
|
|
161
|
+
mathematicalModel: MathematicalModelFormalism;
|
|
162
|
+
/** Entropy analysis breakdown */
|
|
163
|
+
entropyAnalysis: EntropyAnalysisResult;
|
|
164
|
+
/** Evaluation summary and grade */
|
|
165
|
+
summary: {
|
|
166
|
+
passed: boolean;
|
|
167
|
+
fatalCount: number;
|
|
168
|
+
warningCount: number;
|
|
169
|
+
grade: 'A+' | 'A' | 'B' | 'C' | 'F';
|
|
170
|
+
verdict: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Calculates Geo-Alignment score between Geographic Country, Timezone, and Accept-Language.
|
|
175
|
+
*/
|
|
176
|
+
declare function evaluateGeoAlignment(passport: DevicePassport): number;
|
|
177
|
+
/**
|
|
178
|
+
* Evaluates the complete internal consistency and coherence of a Device Passport.
|
|
179
|
+
*
|
|
180
|
+
* Implements:
|
|
181
|
+
* Φ: Ω_H × Ω_S × Ω_G × Ω_C → [0, 100%]
|
|
182
|
+
*/
|
|
183
|
+
declare function evaluateCoherence(passport: DevicePassport): CoherenceEvaluationResult;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Academic Evaluation Engine for Device Passport.
|
|
187
|
+
*
|
|
188
|
+
* Implements verification algorithms for the formal model:
|
|
189
|
+
* P = ⟨H, S, G, C⟩
|
|
190
|
+
*
|
|
191
|
+
* Evaluates:
|
|
192
|
+
* 1. Internal Coherence Score (0 - 100%)
|
|
193
|
+
* 2. Geo-Chrono-Linguistic Alignment Score (0 - 100%)
|
|
194
|
+
* 3. Shannon Entropy Analyzer for HTTP Header Distributions
|
|
195
|
+
* 4. Cross-layer Contradiction and Detection Anomaly Detection
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* High-level evaluation entry point for any DevicePassport instance.
|
|
200
|
+
*/
|
|
201
|
+
declare function evaluatePassport(passport: DevicePassport): CoherenceEvaluationResult;
|
|
202
|
+
|
|
203
|
+
export { BASELINE_OPTIMAL_ENTROPY, BROWSER_BASELINE_FREQUENCIES, COUNTRY_PRIMARY_LANGUAGES, COUNTRY_TIMEZONE_MAP, MIN_STRUCTURAL_ENTROPY, OPTIMAL_CHAR_ENTROPY_MAX, OPTIMAL_CHAR_ENTROPY_MIN, OPTIMAL_ENTROPY_MAX, OPTIMAL_ENTROPY_MIN, analyzeHeaderEntropy, calculateKLDivergence, calculateShannonEntropy, calculateStructuralEntropy, detectAllContradictions, detectClientHintsContradictions, detectGeoChronoContradictions, detectHardwareContradictions, detectOSBrowserContradictions, evaluateCoherence, evaluateGeoAlignment, evaluatePassport };
|
|
204
|
+
export type { CoherenceEvaluationResult, Contradiction, ContradictionCategory, ContradictionSeverity, EntropyAnalysisResult, HeaderEntropyProfile, MathematicalModelFormalism, SubspaceEvaluation };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { DevicePassport } from '../types/index.mjs';
|
|
2
|
+
import '../shared/device-passport.C_F1vBE8.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Contradiction Detection Engine for Device Passport.
|
|
6
|
+
*
|
|
7
|
+
* Evaluates cross-layer integrity across the 4-tuple formal model:
|
|
8
|
+
* P = ⟨H, S, G, C⟩ (Hardware, System, Geo, Client-Hints).
|
|
9
|
+
*
|
|
10
|
+
* Implements deterministic anomaly and anti-fingerprinting rules based on
|
|
11
|
+
* empirical browser telemetry, W3C Client Hints RFCs, and anti-bot heuristic vectors.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type ContradictionSeverity = 'fatal' | 'high' | 'medium' | 'low';
|
|
15
|
+
type ContradictionCategory = 'hardware_system' | 'os_browser' | 'geo_chrono' | 'client_hints' | 'entropy';
|
|
16
|
+
interface Contradiction {
|
|
17
|
+
id: string;
|
|
18
|
+
category: ContradictionCategory;
|
|
19
|
+
severity: ContradictionSeverity;
|
|
20
|
+
description: string;
|
|
21
|
+
fields: string[];
|
|
22
|
+
actual: unknown;
|
|
23
|
+
expected: unknown;
|
|
24
|
+
impactPenalty: number;
|
|
25
|
+
}
|
|
26
|
+
declare const COUNTRY_TIMEZONE_MAP: Record<string, string[]>;
|
|
27
|
+
declare const COUNTRY_PRIMARY_LANGUAGES: Record<string, string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Detect OS vs Browser compatibility contradictions.
|
|
30
|
+
*/
|
|
31
|
+
declare function detectOSBrowserContradictions(passport: DevicePassport): Contradiction[];
|
|
32
|
+
/**
|
|
33
|
+
* Detect Hardware vs System cross-layer contradictions.
|
|
34
|
+
*/
|
|
35
|
+
declare function detectHardwareContradictions(passport: DevicePassport): Contradiction[];
|
|
36
|
+
/**
|
|
37
|
+
* Detect Geographic, Locale, and Chronological (Geo-Chrono) Contradictions.
|
|
38
|
+
*/
|
|
39
|
+
declare function detectGeoChronoContradictions(passport: DevicePassport): Contradiction[];
|
|
40
|
+
/**
|
|
41
|
+
* Detect W3C Client Hints Internal Consistency Contradictions.
|
|
42
|
+
*/
|
|
43
|
+
declare function detectClientHintsContradictions(passport: DevicePassport): Contradiction[];
|
|
44
|
+
/**
|
|
45
|
+
* Master contradiction detection runner across all 4 sub-spaces:
|
|
46
|
+
* P = ⟨H, S, G, C⟩.
|
|
47
|
+
*/
|
|
48
|
+
declare function detectAllContradictions(passport: DevicePassport): Contradiction[];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Shannon Entropy Analyzer for Device Passport HTTP Headers.
|
|
52
|
+
*
|
|
53
|
+
* Grounded in Information Theory (Shannon, 1948: "A Mathematical Theory of Communication"):
|
|
54
|
+
* H(X) = - \sum_{i=1}^{n} P(x_i) \log_2 P(x_i)
|
|
55
|
+
*
|
|
56
|
+
* Evaluates generated header distributions against empirical modern browser baselines
|
|
57
|
+
* to detect:
|
|
58
|
+
* 1. Under-parameterized / Low-entropy signatures (naive scrapers, curl, missing sec-ch headers)
|
|
59
|
+
* 2. Over-parameterized / High-entropy anomalies (random noise injection, spoofing artifacts)
|
|
60
|
+
* 3. Relative Entropy (Kullback-Leibler Divergence) against empirical Chrome/Edge/Safari profiles
|
|
61
|
+
*/
|
|
62
|
+
interface HeaderEntropyProfile {
|
|
63
|
+
characterEntropy: number;
|
|
64
|
+
structuralEntropy: number;
|
|
65
|
+
klDivergence: number;
|
|
66
|
+
totalHeaderBytes: number;
|
|
67
|
+
headerCount: number;
|
|
68
|
+
}
|
|
69
|
+
interface EntropyAnalysisResult {
|
|
70
|
+
entropyScore: number;
|
|
71
|
+
estimatedBits: number;
|
|
72
|
+
klDivergence: number;
|
|
73
|
+
anomaly: 'too_low' | 'too_high' | 'optimal';
|
|
74
|
+
collisionRisk: 'very_low' | 'low' | 'moderate' | 'high';
|
|
75
|
+
verdict: string;
|
|
76
|
+
details: {
|
|
77
|
+
characterEntropy: number;
|
|
78
|
+
structuralEntropy: number;
|
|
79
|
+
baselineEntropy: number;
|
|
80
|
+
deltaFromOptimal: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Empirical baseline frequency distribution of headers in real modern desktop browsers (Chromium 120+).
|
|
85
|
+
* Baseline average entropy is calibrated at 4.45 bits/char.
|
|
86
|
+
*/
|
|
87
|
+
declare const BROWSER_BASELINE_FREQUENCIES: Record<string, number>;
|
|
88
|
+
declare const OPTIMAL_CHAR_ENTROPY_MIN = 4.6;
|
|
89
|
+
declare const OPTIMAL_CHAR_ENTROPY_MAX = 5.6;
|
|
90
|
+
declare const OPTIMAL_ENTROPY_MIN = 4.6;
|
|
91
|
+
declare const OPTIMAL_ENTROPY_MAX = 5.6;
|
|
92
|
+
declare const BASELINE_OPTIMAL_ENTROPY = 5.25;
|
|
93
|
+
declare const MIN_STRUCTURAL_ENTROPY = 3.5;
|
|
94
|
+
/**
|
|
95
|
+
* Calculates fundamental Shannon Information Entropy (in bits) of any string input.
|
|
96
|
+
* H(X) = -\sum_{i=1}^n P(x_i) \log_2 P(x_i)
|
|
97
|
+
*/
|
|
98
|
+
declare function calculateShannonEntropy(data: string): number;
|
|
99
|
+
/**
|
|
100
|
+
* Calculates structural header presence entropy across expected browser header space.
|
|
101
|
+
*/
|
|
102
|
+
declare function calculateStructuralEntropy(headers: Record<string, string>): number;
|
|
103
|
+
/**
|
|
104
|
+
* Calculates Kullback-Leibler (KL) Divergence:
|
|
105
|
+
* D_KL(P || Q) = \sum P(x) * log2(P(x) / Q(x))
|
|
106
|
+
* Measures informational distance between current header distribution and natural browser baseline.
|
|
107
|
+
*/
|
|
108
|
+
declare function calculateKLDivergence(headers: Record<string, string>): number;
|
|
109
|
+
/**
|
|
110
|
+
* Analyzes the entropy of an HTTP header dictionary.
|
|
111
|
+
* Evaluates whether entropy is in the realistic "sweet spot" of real browser traffic.
|
|
112
|
+
*/
|
|
113
|
+
declare function analyzeHeaderEntropy(headers: Record<string, string>): EntropyAnalysisResult;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Academic Coherence Evaluator for Device Passport.
|
|
117
|
+
*
|
|
118
|
+
* Implements the Formal Mathematical Model:
|
|
119
|
+
* P = ⟨H, S, G, C⟩
|
|
120
|
+
*
|
|
121
|
+
* Where:
|
|
122
|
+
* - H ∈ Ω_H: Hardware Sub-space ⟨Screen, CPU, Memory, GPU⟩
|
|
123
|
+
* - S ∈ Ω_S: System Sub-space ⟨OS, Browser, UserAgent⟩
|
|
124
|
+
* - G ∈ Ω_G: Geo-Chrono Sub-space ⟨Country, Timezone, Locale, Languages, Coordinates⟩
|
|
125
|
+
* - C ∈ Ω_C: Client-Hints Sub-space ⟨Sec-CH-UA*, Low & High Entropy Hints⟩
|
|
126
|
+
*
|
|
127
|
+
* The coherence evaluation function Φ(P) maps P into [0, 100%], quantifying
|
|
128
|
+
* cross-subspace plausibility and absence of anti-bot contradiction signatures.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
interface SubspaceEvaluation {
|
|
132
|
+
valid: boolean;
|
|
133
|
+
score: number;
|
|
134
|
+
notes: string[];
|
|
135
|
+
}
|
|
136
|
+
interface MathematicalModelFormalism {
|
|
137
|
+
formalism: string;
|
|
138
|
+
definition: {
|
|
139
|
+
H: string;
|
|
140
|
+
S: string;
|
|
141
|
+
G: string;
|
|
142
|
+
C: string;
|
|
143
|
+
};
|
|
144
|
+
subspaces: {
|
|
145
|
+
H: SubspaceEvaluation;
|
|
146
|
+
S: SubspaceEvaluation;
|
|
147
|
+
G: SubspaceEvaluation;
|
|
148
|
+
C: SubspaceEvaluation;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
interface CoherenceEvaluationResult {
|
|
152
|
+
/** Overall cross-layer coherence score (0 - 100%) */
|
|
153
|
+
coherenceScore: number;
|
|
154
|
+
/** Specific geo-temporal-linguistic alignment score (0 - 100%) */
|
|
155
|
+
geoAlignmentScore: number;
|
|
156
|
+
/** Shannon entropy realistic score (0 - 100%) */
|
|
157
|
+
entropyScore: number;
|
|
158
|
+
/** List of detected contradictions and anomalies */
|
|
159
|
+
contradictions: Contradiction[];
|
|
160
|
+
/** Mathematical formalization of the evaluation state */
|
|
161
|
+
mathematicalModel: MathematicalModelFormalism;
|
|
162
|
+
/** Entropy analysis breakdown */
|
|
163
|
+
entropyAnalysis: EntropyAnalysisResult;
|
|
164
|
+
/** Evaluation summary and grade */
|
|
165
|
+
summary: {
|
|
166
|
+
passed: boolean;
|
|
167
|
+
fatalCount: number;
|
|
168
|
+
warningCount: number;
|
|
169
|
+
grade: 'A+' | 'A' | 'B' | 'C' | 'F';
|
|
170
|
+
verdict: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Calculates Geo-Alignment score between Geographic Country, Timezone, and Accept-Language.
|
|
175
|
+
*/
|
|
176
|
+
declare function evaluateGeoAlignment(passport: DevicePassport): number;
|
|
177
|
+
/**
|
|
178
|
+
* Evaluates the complete internal consistency and coherence of a Device Passport.
|
|
179
|
+
*
|
|
180
|
+
* Implements:
|
|
181
|
+
* Φ: Ω_H × Ω_S × Ω_G × Ω_C → [0, 100%]
|
|
182
|
+
*/
|
|
183
|
+
declare function evaluateCoherence(passport: DevicePassport): CoherenceEvaluationResult;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Academic Evaluation Engine for Device Passport.
|
|
187
|
+
*
|
|
188
|
+
* Implements verification algorithms for the formal model:
|
|
189
|
+
* P = ⟨H, S, G, C⟩
|
|
190
|
+
*
|
|
191
|
+
* Evaluates:
|
|
192
|
+
* 1. Internal Coherence Score (0 - 100%)
|
|
193
|
+
* 2. Geo-Chrono-Linguistic Alignment Score (0 - 100%)
|
|
194
|
+
* 3. Shannon Entropy Analyzer for HTTP Header Distributions
|
|
195
|
+
* 4. Cross-layer Contradiction and Detection Anomaly Detection
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* High-level evaluation entry point for any DevicePassport instance.
|
|
200
|
+
*/
|
|
201
|
+
declare function evaluatePassport(passport: DevicePassport): CoherenceEvaluationResult;
|
|
202
|
+
|
|
203
|
+
export { BASELINE_OPTIMAL_ENTROPY, BROWSER_BASELINE_FREQUENCIES, COUNTRY_PRIMARY_LANGUAGES, COUNTRY_TIMEZONE_MAP, MIN_STRUCTURAL_ENTROPY, OPTIMAL_CHAR_ENTROPY_MAX, OPTIMAL_CHAR_ENTROPY_MIN, OPTIMAL_ENTROPY_MAX, OPTIMAL_ENTROPY_MIN, analyzeHeaderEntropy, calculateKLDivergence, calculateShannonEntropy, calculateStructuralEntropy, detectAllContradictions, detectClientHintsContradictions, detectGeoChronoContradictions, detectHardwareContradictions, detectOSBrowserContradictions, evaluateCoherence, evaluateGeoAlignment, evaluatePassport };
|
|
204
|
+
export type { CoherenceEvaluationResult, Contradiction, ContradictionCategory, ContradictionSeverity, EntropyAnalysisResult, HeaderEntropyProfile, MathematicalModelFormalism, SubspaceEvaluation };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { DevicePassport } from '../types/index.js';
|
|
2
|
+
import '../shared/device-passport.C_F1vBE8.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Contradiction Detection Engine for Device Passport.
|
|
6
|
+
*
|
|
7
|
+
* Evaluates cross-layer integrity across the 4-tuple formal model:
|
|
8
|
+
* P = ⟨H, S, G, C⟩ (Hardware, System, Geo, Client-Hints).
|
|
9
|
+
*
|
|
10
|
+
* Implements deterministic anomaly and anti-fingerprinting rules based on
|
|
11
|
+
* empirical browser telemetry, W3C Client Hints RFCs, and anti-bot heuristic vectors.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type ContradictionSeverity = 'fatal' | 'high' | 'medium' | 'low';
|
|
15
|
+
type ContradictionCategory = 'hardware_system' | 'os_browser' | 'geo_chrono' | 'client_hints' | 'entropy';
|
|
16
|
+
interface Contradiction {
|
|
17
|
+
id: string;
|
|
18
|
+
category: ContradictionCategory;
|
|
19
|
+
severity: ContradictionSeverity;
|
|
20
|
+
description: string;
|
|
21
|
+
fields: string[];
|
|
22
|
+
actual: unknown;
|
|
23
|
+
expected: unknown;
|
|
24
|
+
impactPenalty: number;
|
|
25
|
+
}
|
|
26
|
+
declare const COUNTRY_TIMEZONE_MAP: Record<string, string[]>;
|
|
27
|
+
declare const COUNTRY_PRIMARY_LANGUAGES: Record<string, string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Detect OS vs Browser compatibility contradictions.
|
|
30
|
+
*/
|
|
31
|
+
declare function detectOSBrowserContradictions(passport: DevicePassport): Contradiction[];
|
|
32
|
+
/**
|
|
33
|
+
* Detect Hardware vs System cross-layer contradictions.
|
|
34
|
+
*/
|
|
35
|
+
declare function detectHardwareContradictions(passport: DevicePassport): Contradiction[];
|
|
36
|
+
/**
|
|
37
|
+
* Detect Geographic, Locale, and Chronological (Geo-Chrono) Contradictions.
|
|
38
|
+
*/
|
|
39
|
+
declare function detectGeoChronoContradictions(passport: DevicePassport): Contradiction[];
|
|
40
|
+
/**
|
|
41
|
+
* Detect W3C Client Hints Internal Consistency Contradictions.
|
|
42
|
+
*/
|
|
43
|
+
declare function detectClientHintsContradictions(passport: DevicePassport): Contradiction[];
|
|
44
|
+
/**
|
|
45
|
+
* Master contradiction detection runner across all 4 sub-spaces:
|
|
46
|
+
* P = ⟨H, S, G, C⟩.
|
|
47
|
+
*/
|
|
48
|
+
declare function detectAllContradictions(passport: DevicePassport): Contradiction[];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Shannon Entropy Analyzer for Device Passport HTTP Headers.
|
|
52
|
+
*
|
|
53
|
+
* Grounded in Information Theory (Shannon, 1948: "A Mathematical Theory of Communication"):
|
|
54
|
+
* H(X) = - \sum_{i=1}^{n} P(x_i) \log_2 P(x_i)
|
|
55
|
+
*
|
|
56
|
+
* Evaluates generated header distributions against empirical modern browser baselines
|
|
57
|
+
* to detect:
|
|
58
|
+
* 1. Under-parameterized / Low-entropy signatures (naive scrapers, curl, missing sec-ch headers)
|
|
59
|
+
* 2. Over-parameterized / High-entropy anomalies (random noise injection, spoofing artifacts)
|
|
60
|
+
* 3. Relative Entropy (Kullback-Leibler Divergence) against empirical Chrome/Edge/Safari profiles
|
|
61
|
+
*/
|
|
62
|
+
interface HeaderEntropyProfile {
|
|
63
|
+
characterEntropy: number;
|
|
64
|
+
structuralEntropy: number;
|
|
65
|
+
klDivergence: number;
|
|
66
|
+
totalHeaderBytes: number;
|
|
67
|
+
headerCount: number;
|
|
68
|
+
}
|
|
69
|
+
interface EntropyAnalysisResult {
|
|
70
|
+
entropyScore: number;
|
|
71
|
+
estimatedBits: number;
|
|
72
|
+
klDivergence: number;
|
|
73
|
+
anomaly: 'too_low' | 'too_high' | 'optimal';
|
|
74
|
+
collisionRisk: 'very_low' | 'low' | 'moderate' | 'high';
|
|
75
|
+
verdict: string;
|
|
76
|
+
details: {
|
|
77
|
+
characterEntropy: number;
|
|
78
|
+
structuralEntropy: number;
|
|
79
|
+
baselineEntropy: number;
|
|
80
|
+
deltaFromOptimal: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Empirical baseline frequency distribution of headers in real modern desktop browsers (Chromium 120+).
|
|
85
|
+
* Baseline average entropy is calibrated at 4.45 bits/char.
|
|
86
|
+
*/
|
|
87
|
+
declare const BROWSER_BASELINE_FREQUENCIES: Record<string, number>;
|
|
88
|
+
declare const OPTIMAL_CHAR_ENTROPY_MIN = 4.6;
|
|
89
|
+
declare const OPTIMAL_CHAR_ENTROPY_MAX = 5.6;
|
|
90
|
+
declare const OPTIMAL_ENTROPY_MIN = 4.6;
|
|
91
|
+
declare const OPTIMAL_ENTROPY_MAX = 5.6;
|
|
92
|
+
declare const BASELINE_OPTIMAL_ENTROPY = 5.25;
|
|
93
|
+
declare const MIN_STRUCTURAL_ENTROPY = 3.5;
|
|
94
|
+
/**
|
|
95
|
+
* Calculates fundamental Shannon Information Entropy (in bits) of any string input.
|
|
96
|
+
* H(X) = -\sum_{i=1}^n P(x_i) \log_2 P(x_i)
|
|
97
|
+
*/
|
|
98
|
+
declare function calculateShannonEntropy(data: string): number;
|
|
99
|
+
/**
|
|
100
|
+
* Calculates structural header presence entropy across expected browser header space.
|
|
101
|
+
*/
|
|
102
|
+
declare function calculateStructuralEntropy(headers: Record<string, string>): number;
|
|
103
|
+
/**
|
|
104
|
+
* Calculates Kullback-Leibler (KL) Divergence:
|
|
105
|
+
* D_KL(P || Q) = \sum P(x) * log2(P(x) / Q(x))
|
|
106
|
+
* Measures informational distance between current header distribution and natural browser baseline.
|
|
107
|
+
*/
|
|
108
|
+
declare function calculateKLDivergence(headers: Record<string, string>): number;
|
|
109
|
+
/**
|
|
110
|
+
* Analyzes the entropy of an HTTP header dictionary.
|
|
111
|
+
* Evaluates whether entropy is in the realistic "sweet spot" of real browser traffic.
|
|
112
|
+
*/
|
|
113
|
+
declare function analyzeHeaderEntropy(headers: Record<string, string>): EntropyAnalysisResult;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Academic Coherence Evaluator for Device Passport.
|
|
117
|
+
*
|
|
118
|
+
* Implements the Formal Mathematical Model:
|
|
119
|
+
* P = ⟨H, S, G, C⟩
|
|
120
|
+
*
|
|
121
|
+
* Where:
|
|
122
|
+
* - H ∈ Ω_H: Hardware Sub-space ⟨Screen, CPU, Memory, GPU⟩
|
|
123
|
+
* - S ∈ Ω_S: System Sub-space ⟨OS, Browser, UserAgent⟩
|
|
124
|
+
* - G ∈ Ω_G: Geo-Chrono Sub-space ⟨Country, Timezone, Locale, Languages, Coordinates⟩
|
|
125
|
+
* - C ∈ Ω_C: Client-Hints Sub-space ⟨Sec-CH-UA*, Low & High Entropy Hints⟩
|
|
126
|
+
*
|
|
127
|
+
* The coherence evaluation function Φ(P) maps P into [0, 100%], quantifying
|
|
128
|
+
* cross-subspace plausibility and absence of anti-bot contradiction signatures.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
interface SubspaceEvaluation {
|
|
132
|
+
valid: boolean;
|
|
133
|
+
score: number;
|
|
134
|
+
notes: string[];
|
|
135
|
+
}
|
|
136
|
+
interface MathematicalModelFormalism {
|
|
137
|
+
formalism: string;
|
|
138
|
+
definition: {
|
|
139
|
+
H: string;
|
|
140
|
+
S: string;
|
|
141
|
+
G: string;
|
|
142
|
+
C: string;
|
|
143
|
+
};
|
|
144
|
+
subspaces: {
|
|
145
|
+
H: SubspaceEvaluation;
|
|
146
|
+
S: SubspaceEvaluation;
|
|
147
|
+
G: SubspaceEvaluation;
|
|
148
|
+
C: SubspaceEvaluation;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
interface CoherenceEvaluationResult {
|
|
152
|
+
/** Overall cross-layer coherence score (0 - 100%) */
|
|
153
|
+
coherenceScore: number;
|
|
154
|
+
/** Specific geo-temporal-linguistic alignment score (0 - 100%) */
|
|
155
|
+
geoAlignmentScore: number;
|
|
156
|
+
/** Shannon entropy realistic score (0 - 100%) */
|
|
157
|
+
entropyScore: number;
|
|
158
|
+
/** List of detected contradictions and anomalies */
|
|
159
|
+
contradictions: Contradiction[];
|
|
160
|
+
/** Mathematical formalization of the evaluation state */
|
|
161
|
+
mathematicalModel: MathematicalModelFormalism;
|
|
162
|
+
/** Entropy analysis breakdown */
|
|
163
|
+
entropyAnalysis: EntropyAnalysisResult;
|
|
164
|
+
/** Evaluation summary and grade */
|
|
165
|
+
summary: {
|
|
166
|
+
passed: boolean;
|
|
167
|
+
fatalCount: number;
|
|
168
|
+
warningCount: number;
|
|
169
|
+
grade: 'A+' | 'A' | 'B' | 'C' | 'F';
|
|
170
|
+
verdict: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Calculates Geo-Alignment score between Geographic Country, Timezone, and Accept-Language.
|
|
175
|
+
*/
|
|
176
|
+
declare function evaluateGeoAlignment(passport: DevicePassport): number;
|
|
177
|
+
/**
|
|
178
|
+
* Evaluates the complete internal consistency and coherence of a Device Passport.
|
|
179
|
+
*
|
|
180
|
+
* Implements:
|
|
181
|
+
* Φ: Ω_H × Ω_S × Ω_G × Ω_C → [0, 100%]
|
|
182
|
+
*/
|
|
183
|
+
declare function evaluateCoherence(passport: DevicePassport): CoherenceEvaluationResult;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Academic Evaluation Engine for Device Passport.
|
|
187
|
+
*
|
|
188
|
+
* Implements verification algorithms for the formal model:
|
|
189
|
+
* P = ⟨H, S, G, C⟩
|
|
190
|
+
*
|
|
191
|
+
* Evaluates:
|
|
192
|
+
* 1. Internal Coherence Score (0 - 100%)
|
|
193
|
+
* 2. Geo-Chrono-Linguistic Alignment Score (0 - 100%)
|
|
194
|
+
* 3. Shannon Entropy Analyzer for HTTP Header Distributions
|
|
195
|
+
* 4. Cross-layer Contradiction and Detection Anomaly Detection
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* High-level evaluation entry point for any DevicePassport instance.
|
|
200
|
+
*/
|
|
201
|
+
declare function evaluatePassport(passport: DevicePassport): CoherenceEvaluationResult;
|
|
202
|
+
|
|
203
|
+
export { BASELINE_OPTIMAL_ENTROPY, BROWSER_BASELINE_FREQUENCIES, COUNTRY_PRIMARY_LANGUAGES, COUNTRY_TIMEZONE_MAP, MIN_STRUCTURAL_ENTROPY, OPTIMAL_CHAR_ENTROPY_MAX, OPTIMAL_CHAR_ENTROPY_MIN, OPTIMAL_ENTROPY_MAX, OPTIMAL_ENTROPY_MIN, analyzeHeaderEntropy, calculateKLDivergence, calculateShannonEntropy, calculateStructuralEntropy, detectAllContradictions, detectClientHintsContradictions, detectGeoChronoContradictions, detectHardwareContradictions, detectOSBrowserContradictions, evaluateCoherence, evaluateGeoAlignment, evaluatePassport };
|
|
204
|
+
export type { CoherenceEvaluationResult, Contradiction, ContradictionCategory, ContradictionSeverity, EntropyAnalysisResult, HeaderEntropyProfile, MathematicalModelFormalism, SubspaceEvaluation };
|