devicer.js 1.0.3 → 1.0.5
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/package.json +1 -1
- package/src/libs/confidence.js +21 -8
- package/src/libs/confidence.ts +25 -10
- package/tests/confidence.test.ts +13 -15
- package/tests/data.test.ts +6 -6
package/package.json
CHANGED
package/src/libs/confidence.js
CHANGED
|
@@ -2,28 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateConfidence = void 0;
|
|
4
4
|
const tlsh_1 = require("./tlsh");
|
|
5
|
-
function
|
|
6
|
-
// Calculate the hash for each user data
|
|
7
|
-
const hash1 = (0, tlsh_1.getHash)(JSON.stringify(data1));
|
|
8
|
-
const hash2 = (0, tlsh_1.getHash)(JSON.stringify(data2));
|
|
9
|
-
// Compare the hashes to get their difference
|
|
10
|
-
const differenceScore = (0, tlsh_1.compareHashes)(hash1, hash2);
|
|
11
|
-
// Compare how many fields are the same in both datasets
|
|
5
|
+
function compareDataSets(data1, data2) {
|
|
12
6
|
let fields = 0;
|
|
13
7
|
let matches = 0;
|
|
14
8
|
for (const key in data1) {
|
|
15
9
|
if (data1[key] !== undefined && data2[key] !== undefined) {
|
|
16
10
|
fields++;
|
|
11
|
+
if (typeof data1[key] == "object") {
|
|
12
|
+
const subData = compareDataSets(data1[key], data2[key]);
|
|
13
|
+
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
14
|
+
matches += subData[1];
|
|
15
|
+
}
|
|
17
16
|
if (data1[key] == data2[key]) {
|
|
18
17
|
matches++;
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
}
|
|
21
|
+
return [fields, matches];
|
|
22
|
+
}
|
|
23
|
+
function calculateConfidence(data1, data2) {
|
|
24
|
+
// Compare how many fields are the same in both datasets
|
|
25
|
+
const [fields, matches] = compareDataSets(data1, data2);
|
|
26
|
+
if (fields === 0 || matches === 0) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
// Calculate the hash for each user data
|
|
30
|
+
const hash1 = (0, tlsh_1.getHash)(JSON.stringify(data1));
|
|
31
|
+
const hash2 = (0, tlsh_1.getHash)(JSON.stringify(data2));
|
|
32
|
+
// Compare the hashes to get their difference
|
|
33
|
+
const differenceScore = (0, tlsh_1.compareHashes)(hash1, hash2);
|
|
22
34
|
const inverseMatchScore = 1 - (matches / fields);
|
|
23
35
|
const x = (differenceScore / 1.5) * inverseMatchScore;
|
|
24
36
|
if (inverseMatchScore === 0 || differenceScore === 0) {
|
|
25
37
|
return 100;
|
|
26
38
|
}
|
|
27
|
-
|
|
39
|
+
const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
|
|
40
|
+
return confidenceScore;
|
|
28
41
|
}
|
|
29
42
|
exports.calculateConfidence = calculateConfidence;
|
package/src/libs/confidence.ts
CHANGED
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
import { getHash, compareHashes } from "./tlsh";
|
|
2
2
|
import { FPDataSet } from "../types/data";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
// Calculate the hash for each user data
|
|
6
|
-
const hash1 = getHash(JSON.stringify(data1));
|
|
7
|
-
const hash2 = getHash(JSON.stringify(data2));
|
|
8
|
-
|
|
9
|
-
// Compare the hashes to get their difference
|
|
10
|
-
const differenceScore = compareHashes(hash1, hash2);
|
|
11
|
-
|
|
12
|
-
// Compare how many fields are the same in both datasets
|
|
4
|
+
function compareDataSets(data1: FPDataSet, data2: FPDataSet): [number, number] {
|
|
13
5
|
let fields = 0;
|
|
14
6
|
let matches = 0;
|
|
15
7
|
for (const key in data1) {
|
|
16
8
|
if (data1[key] !== undefined && data2[key] !== undefined) {
|
|
17
9
|
fields++;
|
|
10
|
+
if (typeof data1[key] == "object") {
|
|
11
|
+
const subData = compareDataSets(data1[key] as FPDataSet, data2[key] as FPDataSet);
|
|
12
|
+
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
13
|
+
matches += subData[1];
|
|
14
|
+
}
|
|
18
15
|
if (data1[key] == data2[key]) {
|
|
19
16
|
matches++;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
}
|
|
20
|
+
return [fields, matches];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function calculateConfidence(data1: FPDataSet, data2: FPDataSet): number {
|
|
24
|
+
// Compare how many fields are the same in both datasets
|
|
25
|
+
const [fields, matches] = compareDataSets(data1, data2);
|
|
26
|
+
|
|
27
|
+
if (fields === 0 || matches === 0) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Calculate the hash for each user data
|
|
32
|
+
const hash1 = getHash(JSON.stringify(data1));
|
|
33
|
+
const hash2 = getHash(JSON.stringify(data2));
|
|
34
|
+
|
|
35
|
+
// Compare the hashes to get their difference
|
|
36
|
+
const differenceScore = compareHashes(hash1, hash2);
|
|
23
37
|
|
|
24
38
|
const inverseMatchScore = 1 - (matches / fields);
|
|
25
39
|
const x = (differenceScore / 1.5) * inverseMatchScore
|
|
26
40
|
if (inverseMatchScore === 0 || differenceScore === 0) {
|
|
27
41
|
return 100;
|
|
28
42
|
}
|
|
29
|
-
|
|
43
|
+
const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
|
|
44
|
+
return confidenceScore;
|
|
30
45
|
}
|
package/tests/confidence.test.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { it, describe, expect } from 'vitest';
|
|
2
2
|
import { FPUserDataSet } from '../src/types/data';
|
|
3
|
-
import { getHash } from '../src/libs/tlsh';
|
|
4
3
|
import { calculateConfidence } from '../src/libs/confidence';
|
|
5
4
|
import { randomString } from './tlsh.test';
|
|
6
5
|
|
|
@@ -21,9 +20,9 @@ const sampleData1: FPUserDataSet = {
|
|
|
21
20
|
ip: '157.185.170.244',
|
|
22
21
|
languages: ['en-US', 'en'],
|
|
23
22
|
plugins: ['Chrome PDF Viewer', 'Shockwave Flash'],
|
|
24
|
-
canvasHash:
|
|
25
|
-
audioHash:
|
|
26
|
-
webglHash:
|
|
23
|
+
canvasHash: randomString(524),
|
|
24
|
+
audioHash: randomString(524),
|
|
25
|
+
webglHash: randomString(524)
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
const sampleData2: FPUserDataSet = {
|
|
@@ -43,9 +42,9 @@ const sampleData2: FPUserDataSet = {
|
|
|
43
42
|
ip: '178.238.11.6',
|
|
44
43
|
languages: ['en-GB', 'en'],
|
|
45
44
|
plugins: ['Chrome PDF Viewer', 'Shockwave Flash'],
|
|
46
|
-
canvasHash:
|
|
47
|
-
audioHash:
|
|
48
|
-
webglHash:
|
|
45
|
+
canvasHash: randomString(524),
|
|
46
|
+
audioHash: randomString(524),
|
|
47
|
+
webglHash: randomString(524)
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
describe('Confidence Calculation', () => {
|
|
@@ -85,15 +84,14 @@ describe('Confidence Calculation', () => {
|
|
|
85
84
|
const partialData: FPUserDataSet = {
|
|
86
85
|
...sampleData1,
|
|
87
86
|
hardware: {
|
|
88
|
-
|
|
89
|
-
gpu: 'Intel HD Graphics'
|
|
90
|
-
|
|
91
|
-
screen: {
|
|
92
|
-
...sampleData1.screen,
|
|
93
|
-
width: 1280, // Different screen width
|
|
94
|
-
height: 720 // Different screen height
|
|
87
|
+
cpu: 'Pentium 4',
|
|
88
|
+
gpu: 'Intel HD Graphics',
|
|
89
|
+
ram: 4096
|
|
95
90
|
},
|
|
96
|
-
timezone: 'Europe/London',
|
|
91
|
+
timezone: 'Europe/London',
|
|
92
|
+
ip: '178.238.11.6',
|
|
93
|
+
languages: ['en-GB', 'en'],
|
|
94
|
+
userAgent: 'Mozilla/5.0 (compatible; Konqueror/2.2.2-3; Linux)'
|
|
97
95
|
};
|
|
98
96
|
const confidence = calculateConfidence(sampleData1, partialData);
|
|
99
97
|
console.log('Confidence for partially similar data:', confidence);
|
package/tests/data.test.ts
CHANGED
|
@@ -20,9 +20,9 @@ const sampleData1: FPUserDataSet = {
|
|
|
20
20
|
ip: '157.185.170.244',
|
|
21
21
|
languages: ['en-US', 'en'],
|
|
22
22
|
plugins: ['Chrome PDF Viewer', 'Shockwave Flash'],
|
|
23
|
-
canvasHash:
|
|
24
|
-
audioHash:
|
|
25
|
-
webglHash:
|
|
23
|
+
canvasHash: randomString(524),
|
|
24
|
+
audioHash: randomString(524),
|
|
25
|
+
webglHash: randomString(524)
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const sampleData2: FPUserDataSet = {
|
|
@@ -42,9 +42,9 @@ const sampleData2: FPUserDataSet = {
|
|
|
42
42
|
ip: '178.238.11.6',
|
|
43
43
|
languages: ['en-GB', 'en'],
|
|
44
44
|
plugins: ['Chrome PDF Viewer', 'Shockwave Flash'],
|
|
45
|
-
canvasHash:
|
|
46
|
-
audioHash:
|
|
47
|
-
webglHash:
|
|
45
|
+
canvasHash: randomString(524),
|
|
46
|
+
audioHash: randomString(524),
|
|
47
|
+
webglHash: randomString(524)
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
describe('User Data Fingerprinting', () => {
|