devicer.js 1.0.7 → 1.0.9
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 +1 -1
- package/src/libs/confidence.js +32 -2
- package/src/libs/confidence.ts +39 -2
package/package.json
CHANGED
package/src/libs/confidence.js
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateConfidence = void 0;
|
|
4
4
|
const tlsh_1 = require("./tlsh");
|
|
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
|
+
}
|
|
5
30
|
function compareDatasets(data1, data2) {
|
|
6
31
|
let fields = 0;
|
|
7
32
|
let matches = 0;
|
|
@@ -14,6 +39,11 @@ function compareDatasets(data1, data2) {
|
|
|
14
39
|
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
15
40
|
matches += subData[1];
|
|
16
41
|
}
|
|
42
|
+
else if (Array.isArray(data1[key]) && Array.isArray(data2[key])) {
|
|
43
|
+
const subData = compareArrays(data1[key], data2[key]);
|
|
44
|
+
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
45
|
+
matches += subData[1];
|
|
46
|
+
}
|
|
17
47
|
if (data1[key] == data2[key]) {
|
|
18
48
|
matches++;
|
|
19
49
|
}
|
|
@@ -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 * 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.
|
|
70
|
+
const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.3 * x)));
|
|
41
71
|
return confidenceScore;
|
|
42
72
|
}
|
|
43
73
|
exports.calculateConfidence = calculateConfidence;
|
package/src/libs/confidence.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
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
|
+
}
|
|
16
|
+
|
|
17
|
+
else if (
|
|
18
|
+
(typeof arr1[i] == "object" && arr1[i]) &&
|
|
19
|
+
(typeof arr2[i] == "object" && arr2[i])
|
|
20
|
+
) {
|
|
21
|
+
const subData = compareDatasets(arr1[i] as FPDataSet, arr2[i] as FPDataSet);
|
|
22
|
+
fields += subData[0] - 1; // Subtract 1 for the index itself
|
|
23
|
+
matches += subData[1];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (arr1[i] === arr2[i]) {
|
|
27
|
+
matches++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [fields, matches];
|
|
32
|
+
}
|
|
33
|
+
|
|
4
34
|
function compareDatasets(data1: FPDataSet, data2: FPDataSet): [number, number] {
|
|
5
35
|
let fields = 0;
|
|
6
36
|
let matches = 0;
|
|
@@ -15,6 +45,13 @@ function compareDatasets(data1: FPDataSet, data2: FPDataSet): [number, number] {
|
|
|
15
45
|
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
16
46
|
matches += subData[1];
|
|
17
47
|
}
|
|
48
|
+
|
|
49
|
+
else if (Array.isArray(data1[key]) && Array.isArray(data2[key])) {
|
|
50
|
+
const subData = compareArrays(data1[key], data2[key]);
|
|
51
|
+
fields += subData[0] - 1; // Subtract 1 for the key itself
|
|
52
|
+
matches += subData[1];
|
|
53
|
+
}
|
|
54
|
+
|
|
18
55
|
if (data1[key] == data2[key]) {
|
|
19
56
|
matches++;
|
|
20
57
|
}
|
|
@@ -39,10 +76,10 @@ export function calculateConfidence(data1: FPDataSet, data2: FPDataSet): number
|
|
|
39
76
|
const differenceScore = compareHashes(hash1, hash2);
|
|
40
77
|
|
|
41
78
|
const inverseMatchScore = 1 - (matches / fields);
|
|
42
|
-
const x = differenceScore * inverseMatchScore
|
|
79
|
+
const x = 1.3 * differenceScore * inverseMatchScore
|
|
43
80
|
if (inverseMatchScore === 0 || differenceScore === 0) {
|
|
44
81
|
return 100;
|
|
45
82
|
}
|
|
46
|
-
const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.
|
|
83
|
+
const confidenceScore = 100 / (1 + Math.E ** (-4.5 + (0.3 * x)));
|
|
47
84
|
return confidenceScore;
|
|
48
85
|
}
|