devicer.js 1.0.3 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devicer.js",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Open-Source Digital Fingerprinting Middleware",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -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 calculateConfidence(data1, data2) {
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) {
@@ -1,25 +1,35 @@
1
1
  import { getHash, compareHashes } from "./tlsh";
2
2
  import { FPDataSet } from "../types/data";
3
3
 
4
- export function calculateConfidence(data1: FPDataSet, data2: FPDataSet): number {
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