@versini/ui-fingerprint 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Arno Versini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @versini/ui-fingerprint
2
+
3
+ This package provides a simple way to fingerprint a user's browser and device.
@@ -0,0 +1,77 @@
1
+ type BrowserFP = { browser: string };
2
+
3
+ type VideoCardFP = {
4
+ vendor: string;
5
+ vendorUnmasked: string;
6
+ renderer: string;
7
+ rendererUnmasked: string;
8
+ version: string;
9
+ shadingLanguageVersion: string;
10
+ };
11
+
12
+ type HardwareFP = {
13
+ hardware: {
14
+ videocard: VideoCardFP;
15
+ architecture: number;
16
+ deviceMemory: string;
17
+ jsHeapSizeLimit: number;
18
+ };
19
+ };
20
+
21
+ type CanvasFP = {
22
+ canvas: {
23
+ data: string;
24
+ };
25
+ };
26
+
27
+ type AudioFP = {
28
+ audio: {
29
+ sampleHash: string;
30
+ oscillator: string;
31
+ maxChannels: number;
32
+ channelCountMode: string;
33
+ };
34
+ };
35
+
36
+ type SystemFP = {
37
+ system: {
38
+ platform: string;
39
+ cookieEnabled: boolean;
40
+ productSub: string;
41
+ product: string;
42
+ };
43
+ };
44
+
45
+ type LocalesFP = {
46
+ locales: {
47
+ languages: string;
48
+ timezone: string;
49
+ };
50
+ };
51
+
52
+ type ScreenFP = {
53
+ screen: {
54
+ colorDepth: number;
55
+ pixelDepth: number;
56
+ isTouchScreen: boolean;
57
+ maxTouchPoints: number;
58
+ mediaMatches: string[];
59
+ };
60
+ };
61
+
62
+ type FontsFP = string[];
63
+
64
+ type FingerprintData = [
65
+ AudioFP,
66
+ BrowserFP,
67
+ CanvasFP,
68
+ FontsFP,
69
+ HardwareFP,
70
+ LocalesFP,
71
+ ScreenFP,
72
+ SystemFP
73
+ ];
74
+ declare const getFingerprintData: (debug: boolean) => Promise<FingerprintData>;
75
+ declare const getFingerprintHash: (debug: boolean) => Promise<string>;
76
+
77
+ export { getFingerprintData, getFingerprintHash };
package/dist/index.js ADDED
@@ -0,0 +1,361 @@
1
+ /*!
2
+ @versini/ui-fingerprint v0.0.0
3
+ © 2024 gizmette.com
4
+ */
5
+ try {
6
+ window.__VERSINI_UI_FINGERPRINT__ || (window.__VERSINI_UI_FINGERPRINT__ = {
7
+ version: "0.0.0",
8
+ buildTime: "07/18/2024 08:42 AM EDT",
9
+ homepage: "https://github.com/aversini/ui-components",
10
+ license: "MIT"
11
+ });
12
+ } catch {
13
+ }
14
+ const D = (t) => Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join(""), v = async (t) => {
15
+ if (t === "")
16
+ return "";
17
+ const e = new TextEncoder().encode(t), o = await crypto.subtle.digest("SHA-256", e);
18
+ return Array.from(new Uint8Array(o)).map((c) => c.toString(16).padStart(2, "0")).join("");
19
+ };
20
+ function S(t, n) {
21
+ return new Promise((e) => setTimeout(e, t, n));
22
+ }
23
+ async function T(t, n, e = 50) {
24
+ var a, c, d;
25
+ const o = document;
26
+ for (; !o.body; )
27
+ await S(e);
28
+ const r = o.createElement("iframe");
29
+ try {
30
+ for (await new Promise((m, y) => {
31
+ let g = !1;
32
+ const f = () => {
33
+ g = !0, m();
34
+ }, p = (s) => {
35
+ g = !0, y(s);
36
+ };
37
+ r.onload = f, r.onerror = p;
38
+ const { style: u } = r;
39
+ u.setProperty("display", "block", "important"), u.position = "absolute", u.top = "0", u.left = "0", u.visibility = "hidden", r.src = "about:blank", o.body.appendChild(r);
40
+ const i = () => {
41
+ var s, l;
42
+ g || (((l = (s = r.contentWindow) == null ? void 0 : s.document) == null ? void 0 : l.readyState) === "complete" ? f() : setTimeout(i, 10));
43
+ };
44
+ i();
45
+ }); !((c = (a = r.contentWindow) == null ? void 0 : a.document) != null && c.body); )
46
+ await S(e);
47
+ return await t(r, r.contentWindow);
48
+ } finally {
49
+ (d = r.parentNode) == null || d.removeChild(r);
50
+ }
51
+ }
52
+ const x = {
53
+ audio: {
54
+ sampleHash: "",
55
+ oscillator: "",
56
+ maxChannels: 0,
57
+ channelCountMode: ""
58
+ }
59
+ }, H = async (t) => new Promise((n) => {
60
+ try {
61
+ const e = new window.OfflineAudioContext(1, 5e3, 44100), o = e.createBufferSource(), r = e.createOscillator();
62
+ r.frequency.value = 1e3;
63
+ const a = e.createDynamicsCompressor();
64
+ a.threshold.value = -50, a.knee.value = 40, a.ratio.value = 12, a.attack.value = 0, a.release.value = 0.2, r.connect(a), a.connect(e.destination), r.start(), e.startRendering(), e.oncomplete = (c) => {
65
+ const d = c.renderedBuffer.getChannelData(0);
66
+ r.disconnect(), a.disconnect(), n({
67
+ audio: {
68
+ sampleHash: D(d),
69
+ oscillator: r.type,
70
+ maxChannels: e.destination.maxChannelCount,
71
+ channelCountMode: o.channelCountMode
72
+ }
73
+ });
74
+ };
75
+ } catch (e) {
76
+ t && console.error("Error creating audio fingerprint:", e), n({
77
+ audio: {
78
+ sampleHash: "",
79
+ oscillator: "",
80
+ maxChannels: 0,
81
+ channelCountMode: ""
82
+ }
83
+ });
84
+ }
85
+ }), E = { browser: "" }, P = async (t) => typeof navigator > "u" ? E : { browser: navigator.userAgent }, C = {
86
+ canvas: {
87
+ data: ""
88
+ }
89
+ }, R = async (t) => {
90
+ try {
91
+ const o = Array.from(
92
+ { length: 3 },
93
+ () => _(300, 30)
94
+ ), r = N(o, 300, 30);
95
+ return {
96
+ canvas: {
97
+ data: (await v(r.data.toString())).toString()
98
+ }
99
+ };
100
+ } catch (o) {
101
+ return t && (console.error("Error creating canvas fingerprint"), console.info(o)), C;
102
+ }
103
+ }, _ = (t, n) => {
104
+ const e = document.createElement("canvas"), o = e.getContext("2d");
105
+ if (!o)
106
+ return new ImageData(1, 1);
107
+ e.width = t, e.height = n;
108
+ const r = o.createLinearGradient(0, 0, e.width, e.height);
109
+ r.addColorStop(0, "red"), r.addColorStop(1 / 6, "orange"), r.addColorStop(2 / 6, "yellow"), r.addColorStop(3 / 6, "green"), r.addColorStop(4 / 6, "blue"), r.addColorStop(5 / 6, "indigo"), r.addColorStop(1, "violet"), o.fillStyle = r, o.fillRect(0, 0, e.width, e.height);
110
+ const a = "mmMwWLliI0O&1 - Les sanglots longs des violons de l'automne blessent mon coeur d'une langueur monotone";
111
+ return o.font = "26.321px Arial", o.fillStyle = "black", o.fillText(a, -5, 15), o.fillStyle = "rgba(0, 0, 255, 0.5)", o.fillText(a, -3.3, 17.7), o.beginPath(), o.moveTo(0, 0), o.lineTo(e.width * 2 / 7, e.height), o.strokeStyle = "white", o.lineWidth = 2, o.stroke(), o.getImageData(0, 0, e.width, e.height);
112
+ }, F = (t) => {
113
+ if (t.length === 0)
114
+ return 0;
115
+ const n = {};
116
+ for (const o of t)
117
+ n[o] = (n[o] || 0) + 1;
118
+ let e = t[0];
119
+ for (const o in n)
120
+ n[o] > n[e] && (e = parseInt(o, 10));
121
+ return e;
122
+ }, N = (t, n, e) => {
123
+ const o = [];
124
+ for (let c = 0; c < t[0].data.length; c++) {
125
+ const d = [];
126
+ for (let m = 0; m < t.length; m++)
127
+ d.push(t[m].data[c]);
128
+ o.push(F(d));
129
+ }
130
+ const r = o, a = new Uint8ClampedArray(r);
131
+ return new ImageData(a, n, e);
132
+ }, G = [], L = "mmMwWLliI0O&1", k = "48px", h = ["monospace", "sans-serif", "serif"], w = [
133
+ "sans-serif-thin",
134
+ "ARNO PRO",
135
+ "Agency FB",
136
+ "Arabic Typesetting",
137
+ "Arial Unicode MS",
138
+ "AvantGarde Bk BT",
139
+ "BankGothic Md BT",
140
+ "Bitstream Vera Sans Mono",
141
+ "Calibri",
142
+ "Century",
143
+ "Century Gothic",
144
+ "Clarendon",
145
+ "EUROSTILE",
146
+ "Franklin Gothic",
147
+ "GOTHAM",
148
+ "Gill Sans",
149
+ "Helvetica Neue",
150
+ "Letter Gothic",
151
+ "Menlo",
152
+ "MS Outlook",
153
+ "MS Reference Specialty",
154
+ "MS UI Gothic",
155
+ "MT Extra",
156
+ "MYRIAD PRO",
157
+ "Marlett",
158
+ "Microsoft Uighur",
159
+ "Minion Pro",
160
+ "Monotype Corsiva",
161
+ "PMingLiU",
162
+ "Pristina",
163
+ "SCRIPTINA",
164
+ "SimHei",
165
+ "Small Fonts",
166
+ "Staccato222 BT",
167
+ "TRAJAN PRO",
168
+ "Univers CE 55 Medium",
169
+ "ZWAdobeF"
170
+ ], O = async (t) => T(async (n, { document: e }) => {
171
+ const o = e.body;
172
+ o.style.fontSize = k;
173
+ const r = e.createElement("div");
174
+ r.style.setProperty("visibility", "hidden", "important");
175
+ const a = {}, c = {}, d = (i) => {
176
+ const s = e.createElement("span"), { style: l } = s;
177
+ return l.position = "absolute", l.top = "0", l.left = "0", l.fontFamily = i, s.textContent = L, r.appendChild(s), s;
178
+ }, m = (i, s) => d(`'${i}',${s}`), y = () => h.map(d), g = () => {
179
+ const i = {};
180
+ for (const s of w)
181
+ i[s] = h.map(
182
+ (l) => m(s, l)
183
+ );
184
+ return i;
185
+ }, f = (i) => h.some(
186
+ (s, l) => i[l].offsetWidth !== a[s] || i[l].offsetHeight !== c[s]
187
+ ), p = y(), u = g();
188
+ o.appendChild(r);
189
+ for (let i = 0; i < h.length; i++)
190
+ a[h[i]] = p[i].offsetWidth, c[h[i]] = p[i].offsetHeight;
191
+ return w.filter((i) => f(u[i]));
192
+ }), A = {
193
+ vendor: "",
194
+ vendorUnmasked: "",
195
+ renderer: "",
196
+ rendererUnmasked: "",
197
+ version: "",
198
+ shadingLanguageVersion: ""
199
+ }, M = {
200
+ hardware: {
201
+ videocard: A,
202
+ architecture: 0,
203
+ deviceMemory: "undefined",
204
+ jsHeapSizeLimit: 0
205
+ }
206
+ };
207
+ function U() {
208
+ const t = document.createElement("canvas"), n = t.getContext("webgl") ?? t.getContext("experimental-webgl");
209
+ if (n && "getParameter" in n) {
210
+ const e = n.getExtension("WEBGL_debug_renderer_info");
211
+ return {
212
+ vendor: (n.getParameter(n.VENDOR) || "").toString(),
213
+ vendorUnmasked: e ? (n.getParameter(e.UNMASKED_VENDOR_WEBGL) || "").toString() : "",
214
+ renderer: (n.getParameter(n.RENDERER) || "").toString(),
215
+ rendererUnmasked: e ? (n.getParameter(e.UNMASKED_RENDERER_WEBGL) || "").toString() : "",
216
+ version: (n.getParameter(n.VERSION) || "").toString(),
217
+ shadingLanguageVersion: (n.getParameter(n.SHADING_LANGUAGE_VERSION) || "").toString()
218
+ };
219
+ }
220
+ return A;
221
+ }
222
+ function B() {
223
+ const t = new Float32Array(1), n = new Uint8Array(t.buffer);
224
+ return t[0] = 1 / 0, t[0] = t[0] - t[0], n[3];
225
+ }
226
+ const W = () => navigator.deviceMemory || 0, V = () => window.performance && window.performance.memory || {
227
+ jsHeapSizeLimit: 0
228
+ }, z = async (t) => new Promise((n) => {
229
+ try {
230
+ const e = W(), o = V();
231
+ n({
232
+ hardware: {
233
+ videocard: U(),
234
+ architecture: B(),
235
+ deviceMemory: e.toString() || "undefined",
236
+ jsHeapSizeLimit: o.jsHeapSizeLimit || 0
237
+ }
238
+ });
239
+ } catch (e) {
240
+ t && (console.error("Error getting hardware data"), console.info(e)), n(M);
241
+ }
242
+ }), j = {
243
+ locales: {
244
+ languages: "",
245
+ timezone: ""
246
+ }
247
+ }, $ = async (t) => new Promise((n) => {
248
+ n({
249
+ locales: {
250
+ languages: navigator.language,
251
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
252
+ }
253
+ });
254
+ }), b = {
255
+ screen: {
256
+ colorDepth: 0,
257
+ pixelDepth: 0,
258
+ isTouchScreen: !1,
259
+ maxTouchPoints: 0,
260
+ mediaMatches: []
261
+ }
262
+ }, q = async (t) => new Promise((n) => {
263
+ try {
264
+ const e = window.screen, o = {
265
+ screen: {
266
+ colorDepth: e.colorDepth,
267
+ pixelDepth: e.pixelDepth,
268
+ isTouchScreen: navigator.maxTouchPoints > 0,
269
+ maxTouchPoints: navigator.maxTouchPoints,
270
+ mediaMatches: J()
271
+ }
272
+ };
273
+ n(o);
274
+ } catch (e) {
275
+ t && (console.error("Error creating screen fingerprint"), console.info(e)), n(b);
276
+ }
277
+ });
278
+ function J() {
279
+ const t = [], n = {
280
+ "prefers-contrast": [
281
+ "high",
282
+ "more",
283
+ "low",
284
+ "less",
285
+ "forced",
286
+ "no-preference"
287
+ ],
288
+ "any-hover": ["hover", "none"],
289
+ "any-pointer": ["none", "coarse", "fine"],
290
+ pointer: ["none", "coarse", "fine"],
291
+ hover: ["hover", "none"],
292
+ update: ["fast", "slow"],
293
+ "inverted-colors": ["inverted", "none"],
294
+ "prefers-reduced-motion": ["reduce", "no-preference"],
295
+ "prefers-reduced-transparency": ["reduce", "no-preference"],
296
+ scripting: ["none", "initial-only", "enabled"],
297
+ "forced-colors": ["active", "none"],
298
+ "color-gamut": ["srgb", "p3", "rec2020"]
299
+ };
300
+ return Object.keys(n).forEach((e) => {
301
+ n[e].forEach((o) => {
302
+ matchMedia(`(${e}: ${o})`).matches && t.push(`${e}: ${o}`);
303
+ });
304
+ }), t;
305
+ }
306
+ const K = async (t) => {
307
+ try {
308
+ return {
309
+ system: {
310
+ platform: navigator.platform,
311
+ cookieEnabled: navigator.cookieEnabled,
312
+ productSub: navigator.productSub,
313
+ product: navigator.product
314
+ }
315
+ };
316
+ } catch (n) {
317
+ return t && (console.error("Error getting system data"), console.info(n)), I;
318
+ }
319
+ }, I = {
320
+ system: {
321
+ platform: "",
322
+ cookieEnabled: !1,
323
+ productSub: "",
324
+ product: ""
325
+ }
326
+ }, Z = async (t) => {
327
+ try {
328
+ return Promise.all([
329
+ H(t),
330
+ P(),
331
+ R(t),
332
+ O(),
333
+ z(t),
334
+ $(),
335
+ q(t),
336
+ K(t)
337
+ ]);
338
+ } catch {
339
+ return [
340
+ x,
341
+ E,
342
+ C,
343
+ G,
344
+ M,
345
+ j,
346
+ b,
347
+ I
348
+ ];
349
+ }
350
+ }, Q = async (t) => {
351
+ try {
352
+ const n = await Z(t);
353
+ return await v(JSON.stringify(n));
354
+ } catch (n) {
355
+ return t && (console.error("Error getting fingerprint hash"), console.info(n)), "";
356
+ }
357
+ };
358
+ export {
359
+ Z as getFingerprintData,
360
+ Q as getFingerprintHash
361
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@versini/ui-fingerprint",
3
+ "version": "0.0.0",
4
+ "license": "MIT",
5
+ "author": "Arno Versini",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "homepage": "https://github.com/aversini/ui-components",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git@github.com:aversini/ui-components.git"
13
+ },
14
+ "type": "module",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build:check": "tsc",
22
+ "build:js": "vite build",
23
+ "build:types": "tsup",
24
+ "build": "npm-run-all --serial clean build:check build:js build:types",
25
+ "clean": "rimraf dist tmp",
26
+ "dev:js": "vite build --watch --mode development",
27
+ "dev:types": "tsup --watch src",
28
+ "dev": "npm-run-all clean --parallel dev:js dev:types",
29
+ "lint": "biome lint src",
30
+ "start": "static-server dist --port 5173",
31
+ "stats:pr": "bundlesize -c bundlesize.config.js -p \"$npm_package_version\" -o tmp/stats.json --silent",
32
+ "stats:release": "bundlesize -c bundlesize.config.js -p \"$npm_package_version\" -o stats/stats.json --silent",
33
+ "stats:report": "bundlesize -c bundlesize.config.js --type report -o tmp/pr-stats.md --silent",
34
+ "stats": "bundlesize -c bundlesize.config.js -p \"$npm_package_version\"",
35
+ "test:watch": "vitest",
36
+ "test": "vitest run"
37
+ },
38
+ "gitHead": "30d5e3f729226c417a7554eeb2dad57909d54e47"
39
+ }