devicer.js 1.0.4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devicer.js",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Open-Source Digital Fingerprinting Middleware",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -21,18 +21,22 @@ function compareDataSets(data1, data2) {
21
21
  return [fields, matches];
22
22
  }
23
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
+ }
24
29
  // Calculate the hash for each user data
25
30
  const hash1 = (0, tlsh_1.getHash)(JSON.stringify(data1));
26
31
  const hash2 = (0, tlsh_1.getHash)(JSON.stringify(data2));
27
32
  // Compare the hashes to get their difference
28
33
  const differenceScore = (0, tlsh_1.compareHashes)(hash1, hash2);
29
- // Compare how many fields are the same in both datasets
30
- const [fields, matches] = compareDataSets(data1, data2);
31
34
  const inverseMatchScore = 1 - (matches / fields);
32
35
  const x = (differenceScore / 1.5) * inverseMatchScore;
33
36
  if (inverseMatchScore === 0 || differenceScore === 0) {
34
37
  return 100;
35
38
  }
36
- return 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
39
+ const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
40
+ return confidenceScore;
37
41
  }
38
42
  exports.calculateConfidence = calculateConfidence;
@@ -21,6 +21,13 @@ function compareDataSets(data1: FPDataSet, data2: FPDataSet): [number, number] {
21
21
  }
22
22
 
23
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
+
24
31
  // Calculate the hash for each user data
25
32
  const hash1 = getHash(JSON.stringify(data1));
26
33
  const hash2 = getHash(JSON.stringify(data2));
@@ -28,13 +35,11 @@ export function calculateConfidence(data1: FPDataSet, data2: FPDataSet): number
28
35
  // Compare the hashes to get their difference
29
36
  const differenceScore = compareHashes(hash1, hash2);
30
37
 
31
- // Compare how many fields are the same in both datasets
32
- const [fields, matches] = compareDataSets(data1, data2);
33
-
34
38
  const inverseMatchScore = 1 - (matches / fields);
35
39
  const x = (differenceScore / 1.5) * inverseMatchScore
36
40
  if (inverseMatchScore === 0 || differenceScore === 0) {
37
41
  return 100;
38
42
  }
39
- return 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
43
+ const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
44
+ return confidenceScore;
40
45
  }
@@ -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: getHash(randomString(524)),
25
- audioHash: getHash(randomString(524)),
26
- webglHash: getHash(randomString(524))
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: getHash(randomString(524)),
47
- audioHash: getHash(randomString(524)),
48
- webglHash: getHash(randomString(524))
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
- ...sampleData1.hardware,
89
- gpu: 'Intel HD Graphics' // Different GPU
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', // Different timezone
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);
@@ -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: getHash(randomString(524)),
24
- audioHash: getHash(randomString(524)),
25
- webglHash: getHash(randomString(524))
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: getHash(randomString(524)),
46
- audioHash: getHash(randomString(524)),
47
- webglHash: getHash(randomString(524))
45
+ canvasHash: randomString(524),
46
+ audioHash: randomString(524),
47
+ webglHash: randomString(524)
48
48
  };
49
49
 
50
50
  describe('User Data Fingerprinting', () => {