devicer.js 1.0.6 → 1.0.8

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.6",
3
+ "version": "1.0.8",
4
4
  "description": "Open-Source Digital Fingerprinting Middleware",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -2,7 +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 compareDataSets(data1, data2) {
5
+ function compareArrays(arr1, arr2) {
6
+ let fields = 0;
7
+ let matches = 0;
8
+ const maxLength = Math.max(arr1.length, arr2.length);
9
+ for (let i = 0; i < maxLength; i++) {
10
+ if (arr1[i] !== undefined && arr2[i] !== undefined) {
11
+ fields++;
12
+ if (Array.isArray(arr1[i]) && Array.isArray(arr2[i])) {
13
+ const subData = compareArrays(arr1[i], arr2[i]);
14
+ fields += subData[0] - 1; // Subtract 1 for the index itself
15
+ matches += subData[1];
16
+ }
17
+ else if ((typeof arr1[i] == "object" && arr1[i]) &&
18
+ (typeof arr2[i] == "object" && arr2[i])) {
19
+ const subData = compareDatasets(arr1[i], arr2[i]);
20
+ fields += subData[0] - 1; // Subtract 1 for the index itself
21
+ matches += subData[1];
22
+ }
23
+ else if (arr1[i] === arr2[i]) {
24
+ matches++;
25
+ }
26
+ }
27
+ }
28
+ return [fields, matches];
29
+ }
30
+ function compareDatasets(data1, data2) {
6
31
  let fields = 0;
7
32
  let matches = 0;
8
33
  for (const key in data1) {
@@ -10,7 +35,12 @@ function compareDataSets(data1, data2) {
10
35
  fields++;
11
36
  if ((typeof data1[key] == "object" && data1[key]) &&
12
37
  (typeof data2[key] == "object" && data2[key])) {
13
- const subData = compareDataSets(data1[key], data2[key]);
38
+ const subData = compareDatasets(data1[key], data2[key]);
39
+ fields += subData[0] - 1; // Subtract 1 for the key itself
40
+ matches += subData[1];
41
+ }
42
+ else if (Array.isArray(data1[key]) && Array.isArray(data2[key])) {
43
+ const subData = compareArrays(data1[key], data2[key]);
14
44
  fields += subData[0] - 1; // Subtract 1 for the key itself
15
45
  matches += subData[1];
16
46
  }
@@ -23,7 +53,7 @@ function compareDataSets(data1, data2) {
23
53
  }
24
54
  function calculateConfidence(data1, data2) {
25
55
  // Compare how many fields are the same in both datasets
26
- const [fields, matches] = compareDataSets(data1, data2);
56
+ const [fields, matches] = compareDatasets(data1, data2);
27
57
  if (fields === 0 || matches === 0) {
28
58
  return 0;
29
59
  }
@@ -33,11 +63,11 @@ function calculateConfidence(data1, data2) {
33
63
  // Compare the hashes to get their difference
34
64
  const differenceScore = (0, tlsh_1.compareHashes)(hash1, hash2);
35
65
  const inverseMatchScore = 1 - (matches / fields);
36
- const x = (differenceScore / 1.5) * inverseMatchScore;
66
+ const x = 1.3 * differenceScore * inverseMatchScore;
37
67
  if (inverseMatchScore === 0 || differenceScore === 0) {
38
68
  return 100;
39
69
  }
40
- const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
70
+ const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.3 * x)));
41
71
  return confidenceScore;
42
72
  }
43
73
  exports.calculateConfidence = calculateConfidence;
@@ -1,6 +1,32 @@
1
1
  import { getHash, compareHashes } from "./tlsh";
2
2
  import { FPDataSet } from "../types/data";
3
3
 
4
+ function compareArrays(arr1: any[], arr2: any[]): [number, number] {
5
+ let fields = 0;
6
+ let matches = 0;
7
+ const maxLength = Math.max(arr1.length, arr2.length);
8
+ for (let i = 0; i < maxLength; i++) {
9
+ if (arr1[i] !== undefined && arr2[i] !== undefined) {
10
+ fields++;
11
+ if (Array.isArray(arr1[i]) && Array.isArray(arr2[i])) {
12
+ const subData = compareArrays(arr1[i], arr2[i]);
13
+ fields += subData[0] - 1; // Subtract 1 for the index itself
14
+ matches += subData[1];
15
+ } else if (
16
+ (typeof arr1[i] == "object" && arr1[i]) &&
17
+ (typeof arr2[i] == "object" && arr2[i])
18
+ ) {
19
+ const subData = compareDatasets(arr1[i] as FPDataSet, arr2[i] as FPDataSet);
20
+ fields += subData[0] - 1; // Subtract 1 for the index itself
21
+ matches += subData[1];
22
+ } else if (arr1[i] === arr2[i]) {
23
+ matches++;
24
+ }
25
+ }
26
+ }
27
+ return [fields, matches];
28
+ }
29
+
4
30
  function compareDatasets(data1: FPDataSet, data2: FPDataSet): [number, number] {
5
31
  let fields = 0;
6
32
  let matches = 0;
@@ -15,6 +41,13 @@ function compareDatasets(data1: FPDataSet, data2: FPDataSet): [number, number] {
15
41
  fields += subData[0] - 1; // Subtract 1 for the key itself
16
42
  matches += subData[1];
17
43
  }
44
+
45
+ else if (Array.isArray(data1[key]) && Array.isArray(data2[key])) {
46
+ const subData = compareArrays(data1[key], data2[key]);
47
+ fields += subData[0] - 1; // Subtract 1 for the key itself
48
+ matches += subData[1];
49
+ }
50
+
18
51
  if (data1[key] == data2[key]) {
19
52
  matches++;
20
53
  }
@@ -39,10 +72,10 @@ export function calculateConfidence(data1: FPDataSet, data2: FPDataSet): number
39
72
  const differenceScore = compareHashes(hash1, hash2);
40
73
 
41
74
  const inverseMatchScore = 1 - (matches / fields);
42
- const x = (differenceScore / 1.5) * inverseMatchScore
75
+ const x = 1.3 * differenceScore * inverseMatchScore
43
76
  if (inverseMatchScore === 0 || differenceScore === 0) {
44
77
  return 100;
45
78
  }
46
- const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.25 * x)));
79
+ const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.3 * x)));
47
80
  return confidenceScore;
48
81
  }