devicer.js 1.0.5 → 1.0.6

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.5",
3
+ "version": "1.0.6",
4
4
  "description": "Open-Source Digital Fingerprinting Middleware",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -8,7 +8,8 @@ function compareDataSets(data1, data2) {
8
8
  for (const key in data1) {
9
9
  if (data1[key] !== undefined && data2[key] !== undefined) {
10
10
  fields++;
11
- if (typeof data1[key] == "object") {
11
+ if ((typeof data1[key] == "object" && data1[key]) &&
12
+ (typeof data2[key] == "object" && data2[key])) {
12
13
  const subData = compareDataSets(data1[key], data2[key]);
13
14
  fields += subData[0] - 1; // Subtract 1 for the key itself
14
15
  matches += subData[1];
@@ -1,14 +1,17 @@
1
1
  import { getHash, compareHashes } from "./tlsh";
2
2
  import { FPDataSet } from "../types/data";
3
3
 
4
- function compareDataSets(data1: FPDataSet, data2: FPDataSet): [number, number] {
4
+ function compareDatasets(data1: FPDataSet, data2: FPDataSet): [number, number] {
5
5
  let fields = 0;
6
6
  let matches = 0;
7
7
  for (const key in data1) {
8
8
  if (data1[key] !== undefined && data2[key] !== undefined) {
9
9
  fields++;
10
- if (typeof data1[key] == "object") {
11
- const subData = compareDataSets(data1[key] as FPDataSet, data2[key] as FPDataSet);
10
+ if (
11
+ (typeof data1[key] == "object" && data1[key]) &&
12
+ (typeof data2[key] == "object" && data2[key])
13
+ ) {
14
+ const subData = compareDatasets(data1[key] as FPDataSet, data2[key] as FPDataSet);
12
15
  fields += subData[0] - 1; // Subtract 1 for the key itself
13
16
  matches += subData[1];
14
17
  }
@@ -22,7 +25,7 @@ function compareDataSets(data1: FPDataSet, data2: FPDataSet): [number, number] {
22
25
 
23
26
  export function calculateConfidence(data1: FPDataSet, data2: FPDataSet): number {
24
27
  // Compare how many fields are the same in both datasets
25
- const [fields, matches] = compareDataSets(data1, data2);
28
+ const [fields, matches] = compareDatasets(data1, data2);
26
29
 
27
30
  if (fields === 0 || matches === 0) {
28
31
  return 0;
@@ -98,4 +98,15 @@ describe('Confidence Calculation', () => {
98
98
  expect(confidence).toBeGreaterThan(10);
99
99
  expect(confidence).toBeLessThan(95);
100
100
  });
101
+
102
+ it('should handle empty datasets and nonetypes gracefully', () => {
103
+ const incompleteData = {
104
+ ...sampleData1,
105
+ hardware: {},
106
+ screen: null
107
+ };
108
+ const confidence = calculateConfidence(sampleData1, incompleteData);
109
+ expect(confidence).toBeGreaterThan(0); // Expecting some confidence even with missing data
110
+ expect(confidence).toBeLessThan(100); // Not identical, so confidence should not be 100
111
+ });
101
112
  });