devicer.js 1.0.2 → 1.0.4
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 +1 -1
- package/package.json +1 -1
- package/src/libs/confidence.js +16 -7
- package/src/libs/confidence.ts +19 -9
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ FP-Devicer is a digital fingerprinting middleware library designed for ease of u
|
|
|
5
5
|
|
|
6
6
|
Importing and using the library to compare fingerprints between users is as simple as collecting some user data and running the calculateConfidence function.
|
|
7
7
|
```javascript
|
|
8
|
-
import { FPUserDataSet as UserData, calculateConfidence } from "
|
|
8
|
+
import { FPUserDataSet as UserData, calculateConfidence } from "devicer.js";
|
|
9
9
|
|
|
10
10
|
const user1: UserData = {
|
|
11
11
|
// Collected data goes here
|
package/package.json
CHANGED
package/src/libs/confidence.js
CHANGED
|
@@ -2,23 +2,32 @@
|
|
|
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
|
+
// Calculate the hash for each user data
|
|
25
|
+
const hash1 = (0, tlsh_1.getHash)(JSON.stringify(data1));
|
|
26
|
+
const hash2 = (0, tlsh_1.getHash)(JSON.stringify(data2));
|
|
27
|
+
// Compare the hashes to get their difference
|
|
28
|
+
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);
|
|
22
31
|
const inverseMatchScore = 1 - (matches / fields);
|
|
23
32
|
const x = (differenceScore / 1.5) * inverseMatchScore;
|
|
24
33
|
if (inverseMatchScore === 0 || differenceScore === 0) {
|
package/src/libs/confidence.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
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
|
+
// Calculate the hash for each user data
|
|
25
|
+
const hash1 = getHash(JSON.stringify(data1));
|
|
26
|
+
const hash2 = getHash(JSON.stringify(data2));
|
|
27
|
+
|
|
28
|
+
// Compare the hashes to get their difference
|
|
29
|
+
const differenceScore = compareHashes(hash1, hash2);
|
|
30
|
+
|
|
31
|
+
// Compare how many fields are the same in both datasets
|
|
32
|
+
const [fields, matches] = compareDataSets(data1, data2);
|
|
23
33
|
|
|
24
34
|
const inverseMatchScore = 1 - (matches / fields);
|
|
25
35
|
const x = (differenceScore / 1.5) * inverseMatchScore
|