devicer.js 1.0.13 → 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.
@@ -1,106 +0,0 @@
1
- import { it, describe, expect } from 'vitest';
2
- import { FPUserDataSet } from '../src/types/data';
3
- import { getHash, compareHashes } from '../src/libs/tlsh';
4
- import { randomString } from './tlsh.test';
5
-
6
- const sampleData1: FPUserDataSet = {
7
- fonts: ['Arial', 'Verdana'],
8
- hardware: {
9
- cpu: 'Intel Core i7',
10
- gpu: 'NVIDIA GTX 1080',
11
- ram: 16384 // in MB
12
- },
13
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
14
- screen: {
15
- width: 1920,
16
- height: 1080,
17
- colorDepth: 24
18
- },
19
- timezone: 'America/New_York',
20
- ip: '157.185.170.244',
21
- languages: ['en-US', 'en'],
22
- plugins: ['Chrome PDF Viewer', 'Shockwave Flash'],
23
- canvasHash: randomString(524),
24
- audioHash: randomString(524),
25
- webglHash: randomString(524)
26
- };
27
-
28
- const sampleData2: FPUserDataSet = {
29
- fonts: ['Arial', 'Verdana'],
30
- hardware: {
31
- cpu: 'Pentium 4',
32
- gpu: 'Intel HD Graphics',
33
- ram: 4096 // in MB
34
- },
35
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
36
- screen: {
37
- width: 1280,
38
- height: 720,
39
- colorDepth: 24
40
- },
41
- timezone: 'Europe/London',
42
- ip: '178.238.11.6',
43
- languages: ['en-GB', 'en'],
44
- plugins: ['Chrome PDF Viewer', 'Shockwave Flash'],
45
- canvasHash: randomString(524),
46
- audioHash: randomString(524),
47
- webglHash: randomString(524)
48
- };
49
-
50
- describe('User Data Fingerprinting', () => {
51
- it('should generate a hash for user data', () => {
52
- const hash = getHash(JSON.stringify(sampleData1));
53
- expect(typeof hash).toBe('string');
54
- expect(hash.length).toBeGreaterThan(0);
55
- });
56
-
57
- it('should generate the same hash for identical user data', () => {
58
- const hash1 = getHash(JSON.stringify(sampleData1));
59
- const hash2 = getHash(JSON.stringify(sampleData1));
60
- expect(hash1).toBe(hash2);
61
- });
62
-
63
- it('should generate different hashes for different user data', () => {
64
- const hash1 = getHash(JSON.stringify(sampleData1));
65
- const hash2 = getHash(JSON.stringify(sampleData2));
66
- expect(hash1).not.toBe(hash2);
67
- });
68
-
69
- it('should compare hashes of identical user data and return 0 distance', () => {
70
- const hash1 = getHash(JSON.stringify(sampleData1));
71
- const hash2 = getHash(JSON.stringify(sampleData1));
72
- const distance = compareHashes(hash1, hash2);
73
- expect(distance).toBe(0);
74
- });
75
-
76
- it('should compare hashes of different user data and return a positive distance', () => {
77
- const hash1 = getHash(JSON.stringify(sampleData1));
78
- const hash2 = getHash(JSON.stringify(sampleData2));
79
- const distance = compareHashes(hash1, hash2);
80
- console.log('Distance between hashes:', distance);
81
- expect(distance).toBeGreaterThan(0);
82
- });
83
-
84
- it('should compare similar user data and return a small distance', () => {
85
- const modifiedData = { ...sampleData1, hardware: { ...sampleData1.hardware, ram: 8192 } }; // Slightly modified
86
- const hash1 = getHash(JSON.stringify(sampleData1));
87
- const hash2 = getHash(JSON.stringify(modifiedData));
88
- const distance = compareHashes(hash1, hash2);
89
- console.log('Distance between hashes:', distance);
90
- expect(distance).toBeGreaterThan(0);
91
- expect(distance).toBeLessThan(140); // Assuming small changes yield small distances
92
- });
93
-
94
- it('should compare very different user data and return a large distance', () => {
95
- const hash1 = getHash(JSON.stringify(sampleData1));
96
- const hash2 = getHash(JSON.stringify(sampleData2));
97
- const distance = compareHashes(hash1, hash2);
98
- console.log('Distance between hashes:', distance);
99
- expect(distance).toBeGreaterThan(80); // Assuming significant differences yield larger distances
100
- });
101
-
102
- it('should handle invalid hash input gracefully', () => {
103
- expect(() => compareHashes('invalidhash', 'anotherinvalid')).toThrow();
104
- });
105
- });
106
- // This test suite verifies the functionality of user data fingerprinting using the TLSH hashing algorithm.
File without changes