@thumbmarkjs/thumbmarkjs 0.20.6 → 1.0.0-rc.1
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 +43 -45
- package/dist/thumbmark.cjs.js +1 -1
- package/dist/thumbmark.cjs.js.map +1 -1
- package/dist/thumbmark.esm.d.ts +107 -16
- package/dist/thumbmark.esm.js +1 -1
- package/dist/thumbmark.esm.js.map +1 -1
- package/dist/thumbmark.umd.js +1 -1
- package/dist/thumbmark.umd.js.map +1 -1
- package/package.json +7 -2
- package/src/components/audio/{audio.ts → index.ts} +11 -8
- package/src/components/canvas/{canvas.ts → index.ts} +12 -8
- package/src/components/fonts/{fonts.ts → index.ts} +10 -5
- package/src/components/hardware/{hardware.ts → index.ts} +3 -5
- package/src/components/locales/{locales.ts → index.ts} +2 -4
- package/src/components/math/index.ts +28 -0
- package/src/components/permissions/{permissions.ts → index.ts} +29 -37
- package/src/components/plugins/{plugins.ts → index.ts} +2 -4
- package/src/components/screen/{screen.ts → index.ts} +2 -4
- package/src/components/system/{system.ts → index.ts} +2 -5
- package/src/components/webgl/{webgl.ts → index.ts} +3 -5
- package/src/factory.ts +40 -29
- package/src/functions/filterComponents.ts +42 -0
- package/src/functions/functions.test.ts +39 -0
- package/src/functions/index.ts +262 -0
- package/src/functions/legacy_functions.ts +54 -0
- package/src/index.ts +13 -4
- package/src/{fingerprint/options.ts → options.ts} +20 -12
- package/src/thumbmark.ts +41 -0
- package/src/{declarations.d.ts → types/global.d.ts} +1 -1
- package/src/utils/raceAll.ts +0 -2
- package/src/components/index.ts +0 -17
- package/src/components/math/math.ts +0 -39
- package/src/fingerprint/functions.test.ts +0 -34
- package/src/fingerprint/functions.ts +0 -118
- /package/src/components/canvas/{canvas.test.ts → index.test.ts} +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {componentInterface} from '../factory'
|
|
2
|
-
import {filterFingerprintData} from './functions'
|
|
3
|
-
|
|
4
|
-
const test_components: componentInterface = {
|
|
5
|
-
'one': '1',
|
|
6
|
-
'two': 2,
|
|
7
|
-
'three': {'a': true, 'b': false}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe('component filtering tests', () => {
|
|
11
|
-
test("excluding top level works", () => {
|
|
12
|
-
expect(filterFingerprintData(test_components, ['one'], [])).toMatchObject({
|
|
13
|
-
'two': 2, 'three': {'a': true, 'b': false}
|
|
14
|
-
})
|
|
15
|
-
});
|
|
16
|
-
test("including top level works", () => {
|
|
17
|
-
expect(filterFingerprintData(test_components, [], ['one', 'two'])).toMatchObject({
|
|
18
|
-
'one': '1', 'two': 2
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
test("excluding low-level works", () => {
|
|
22
|
-
expect(filterFingerprintData(test_components, ['two', 'three.a'], [])).toMatchObject({
|
|
23
|
-
'one': '1',
|
|
24
|
-
'three': {'b': false}
|
|
25
|
-
})
|
|
26
|
-
});
|
|
27
|
-
test("including low-level works", () => {
|
|
28
|
-
expect(filterFingerprintData(test_components, [], ['one', 'three.b'])).toMatchObject({
|
|
29
|
-
'one': '1',
|
|
30
|
-
'three': {'b': false}
|
|
31
|
-
})
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import {componentInterface, getComponentPromises, timeoutInstance} from '../factory'
|
|
2
|
-
import {hash} from '../utils/hash'
|
|
3
|
-
import {raceAll, raceAllPerformance} from '../utils/raceAll'
|
|
4
|
-
import {options} from './options'
|
|
5
|
-
import * as packageJson from '../../package.json'
|
|
6
|
-
|
|
7
|
-
export function getVersion(): string {
|
|
8
|
-
return packageJson.version
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function getFingerprintData(): Promise<componentInterface> {
|
|
12
|
-
try {
|
|
13
|
-
const promiseMap: Record<string, Promise<componentInterface>> = getComponentPromises()
|
|
14
|
-
const keys: string[] = Object.keys(promiseMap)
|
|
15
|
-
const promises: Promise<componentInterface>[] = Object.values(promiseMap)
|
|
16
|
-
const resolvedValues: (componentInterface | undefined)[] = await raceAll(promises, options?.timeout || 1000, timeoutInstance);
|
|
17
|
-
const validValues: componentInterface[] = resolvedValues.filter((value): value is componentInterface => value !== undefined);
|
|
18
|
-
const resolvedComponents: Record<string, componentInterface> = {};
|
|
19
|
-
validValues.forEach((value, index) => {
|
|
20
|
-
resolvedComponents[keys[index]] = value
|
|
21
|
-
})
|
|
22
|
-
return filterFingerprintData(resolvedComponents, options.exclude || [], options.include || [], "")
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw error
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This function filters the fingerprint data based on the exclude and include list
|
|
31
|
-
* @param {componentInterface} obj - components objects from main componentInterface
|
|
32
|
-
* @param {string[]} excludeList - elements to exclude from components objects (e.g : 'canvas', 'system.browser')
|
|
33
|
-
* @param {string[]} includeList - elements to only include from components objects (e.g : 'canvas', 'system.browser')
|
|
34
|
-
* @param {string} path - auto-increment path iterating on key objects from components objects
|
|
35
|
-
* @returns {componentInterface} result - returns the final object before hashing in order to get fingerprint
|
|
36
|
-
*/
|
|
37
|
-
export function filterFingerprintData(obj: componentInterface, excludeList: string[], includeList: string[], path: string = ""): componentInterface {
|
|
38
|
-
const result: componentInterface = {};
|
|
39
|
-
|
|
40
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
41
|
-
const currentPath = path + key + ".";
|
|
42
|
-
|
|
43
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
44
|
-
const filtered = filterFingerprintData(value, excludeList, includeList, currentPath);
|
|
45
|
-
if (Object.keys(filtered).length > 0) {
|
|
46
|
-
result[key] = filtered;
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
const isExcluded = excludeList.some(exclusion => currentPath.startsWith(exclusion));
|
|
50
|
-
const isIncluded = includeList.some(inclusion => currentPath.startsWith(inclusion));
|
|
51
|
-
|
|
52
|
-
if (!isExcluded || isIncluded) {
|
|
53
|
-
result[key] = value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function getFingerprint(includeData?: false): Promise<string>
|
|
62
|
-
export async function getFingerprint(includeData: true): Promise<{ hash: string, data: componentInterface }>
|
|
63
|
-
export async function getFingerprint(includeData?: boolean): Promise<string | { hash: string, data: componentInterface }> {
|
|
64
|
-
try {
|
|
65
|
-
const fingerprintData = await getFingerprintData()
|
|
66
|
-
const thisHash = hash(JSON.stringify(fingerprintData))
|
|
67
|
-
if (Math.random() < 0.00001 && options.logging) logFingerprintData(thisHash, fingerprintData)
|
|
68
|
-
if (includeData) {
|
|
69
|
-
return { hash: thisHash.toString(), data: fingerprintData}
|
|
70
|
-
} else {
|
|
71
|
-
return thisHash.toString()
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
throw error
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function getFingerprintPerformance() {
|
|
79
|
-
try {
|
|
80
|
-
const promiseMap = getComponentPromises()
|
|
81
|
-
const keys = Object.keys(promiseMap)
|
|
82
|
-
const promises = Object.values(promiseMap)
|
|
83
|
-
const resolvedValues = await raceAllPerformance(promises, options?.timeout || 1000, timeoutInstance )
|
|
84
|
-
const resolvedComponents: { [key: string]: any } = {
|
|
85
|
-
elapsed: {}
|
|
86
|
-
}
|
|
87
|
-
resolvedValues.forEach((value, index) => {
|
|
88
|
-
resolvedComponents[keys[index]] = value.value
|
|
89
|
-
resolvedComponents["elapsed"][keys[index]] = value.elapsed
|
|
90
|
-
});
|
|
91
|
-
return resolvedComponents
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
throw error
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Function to log the fingerprint data
|
|
99
|
-
async function logFingerprintData(thisHash: string, fingerprintData: componentInterface) {
|
|
100
|
-
const url = 'https://logging.thumbmarkjs.com/v1/log'
|
|
101
|
-
const payload = {
|
|
102
|
-
thumbmark: thisHash,
|
|
103
|
-
components: fingerprintData,
|
|
104
|
-
version: getVersion()
|
|
105
|
-
};
|
|
106
|
-
if (!sessionStorage.getItem("_tmjs_l")) {
|
|
107
|
-
sessionStorage.setItem("_tmjs_l", "1")
|
|
108
|
-
try {
|
|
109
|
-
await fetch(url, {
|
|
110
|
-
method: 'POST',
|
|
111
|
-
headers: {
|
|
112
|
-
'Content-Type': 'application/json'
|
|
113
|
-
},
|
|
114
|
-
body: JSON.stringify(payload)
|
|
115
|
-
});
|
|
116
|
-
} catch { } // do nothing
|
|
117
|
-
}
|
|
118
|
-
}
|
|
File without changes
|