@cloudglides/veil 1.0.0 → 1.0.2

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.
Files changed (58) hide show
  1. package/README.md +190 -0
  2. package/dist/index.d.ts +103 -0
  3. package/dist/index.js +999 -0
  4. package/dist/veil_core.js +370 -0
  5. package/dist/veil_core_bg.wasm +0 -0
  6. package/package.json +24 -10
  7. package/.envrc +0 -1
  8. package/.github/workflows/build-on-tag.yml +0 -75
  9. package/example/index.html +0 -226
  10. package/flake.nix +0 -68
  11. package/scripts/patch-wasm.js +0 -12
  12. package/src/cpu.ts +0 -67
  13. package/src/entropy/adblock.ts +0 -16
  14. package/src/entropy/approximate.ts +0 -8
  15. package/src/entropy/audio.ts +0 -17
  16. package/src/entropy/battery.ts +0 -10
  17. package/src/entropy/browser.ts +0 -7
  18. package/src/entropy/canvas.ts +0 -17
  19. package/src/entropy/complexity.ts +0 -13
  20. package/src/entropy/connection.ts +0 -14
  21. package/src/entropy/distribution.ts +0 -8
  22. package/src/entropy/fonts.ts +0 -4
  23. package/src/entropy/hardware.ts +0 -10
  24. package/src/entropy/language.ts +0 -14
  25. package/src/entropy/os.ts +0 -12
  26. package/src/entropy/osVersion.ts +0 -6
  27. package/src/entropy/performance.ts +0 -14
  28. package/src/entropy/permissions.ts +0 -15
  29. package/src/entropy/plugins.ts +0 -14
  30. package/src/entropy/preferences.ts +0 -12
  31. package/src/entropy/probabilistic.ts +0 -20
  32. package/src/entropy/screen.ts +0 -12
  33. package/src/entropy/screenInfo.ts +0 -8
  34. package/src/entropy/spectral.ts +0 -8
  35. package/src/entropy/statistical.ts +0 -15
  36. package/src/entropy/storage.ts +0 -22
  37. package/src/entropy/timezone.ts +0 -10
  38. package/src/entropy/userAgent.ts +0 -16
  39. package/src/entropy/webFeatures.ts +0 -21
  40. package/src/entropy/webgl.ts +0 -11
  41. package/src/gpu.ts +0 -132
  42. package/src/index.test.ts +0 -26
  43. package/src/index.ts +0 -198
  44. package/src/normalize/index.ts +0 -31
  45. package/src/probability.ts +0 -11
  46. package/src/scoring.ts +0 -106
  47. package/src/seeded-rng.ts +0 -14
  48. package/src/types/index.ts +0 -11
  49. package/src/types.ts +0 -47
  50. package/src/veil_core.d.ts +0 -4
  51. package/src/wasm-loader.ts +0 -14
  52. package/tsconfig.json +0 -12
  53. package/tsup.config.ts +0 -35
  54. package/veil-core/Cargo.lock +0 -114
  55. package/veil-core/Cargo.toml +0 -12
  56. package/veil-core/src/entropy.rs +0 -132
  57. package/veil-core/src/lib.rs +0 -90
  58. package/vitest.config.ts +0 -15
@@ -0,0 +1,370 @@
1
+ let wasm;
2
+
3
+ let cachedFloat64ArrayMemory0 = null;
4
+ function getFloat64ArrayMemory0() {
5
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
6
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
7
+ }
8
+ return cachedFloat64ArrayMemory0;
9
+ }
10
+
11
+ function getStringFromWasm0(ptr, len) {
12
+ ptr = ptr >>> 0;
13
+ return decodeText(ptr, len);
14
+ }
15
+
16
+ let cachedUint8ArrayMemory0 = null;
17
+ function getUint8ArrayMemory0() {
18
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
19
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
20
+ }
21
+ return cachedUint8ArrayMemory0;
22
+ }
23
+
24
+ function passArray8ToWasm0(arg, malloc) {
25
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
26
+ getUint8ArrayMemory0().set(arg, ptr / 1);
27
+ WASM_VECTOR_LEN = arg.length;
28
+ return ptr;
29
+ }
30
+
31
+ function passArrayF64ToWasm0(arg, malloc) {
32
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
33
+ getFloat64ArrayMemory0().set(arg, ptr / 8);
34
+ WASM_VECTOR_LEN = arg.length;
35
+ return ptr;
36
+ }
37
+
38
+ function passStringToWasm0(arg, malloc, realloc) {
39
+ if (realloc === undefined) {
40
+ const buf = cachedTextEncoder.encode(arg);
41
+ const ptr = malloc(buf.length, 1) >>> 0;
42
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
43
+ WASM_VECTOR_LEN = buf.length;
44
+ return ptr;
45
+ }
46
+
47
+ let len = arg.length;
48
+ let ptr = malloc(len, 1) >>> 0;
49
+
50
+ const mem = getUint8ArrayMemory0();
51
+
52
+ let offset = 0;
53
+
54
+ for (; offset < len; offset++) {
55
+ const code = arg.charCodeAt(offset);
56
+ if (code > 0x7F) break;
57
+ mem[ptr + offset] = code;
58
+ }
59
+ if (offset !== len) {
60
+ if (offset !== 0) {
61
+ arg = arg.slice(offset);
62
+ }
63
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
64
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
65
+ const ret = cachedTextEncoder.encodeInto(arg, view);
66
+
67
+ offset += ret.written;
68
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
69
+ }
70
+
71
+ WASM_VECTOR_LEN = offset;
72
+ return ptr;
73
+ }
74
+
75
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
76
+ cachedTextDecoder.decode();
77
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
78
+ let numBytesDecoded = 0;
79
+ function decodeText(ptr, len) {
80
+ numBytesDecoded += len;
81
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
82
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
83
+ cachedTextDecoder.decode();
84
+ numBytesDecoded = len;
85
+ }
86
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
87
+ }
88
+
89
+ const cachedTextEncoder = new TextEncoder();
90
+
91
+ if (!('encodeInto' in cachedTextEncoder)) {
92
+ cachedTextEncoder.encodeInto = function (arg, view) {
93
+ const buf = cachedTextEncoder.encode(arg);
94
+ view.set(buf);
95
+ return {
96
+ read: arg.length,
97
+ written: buf.length
98
+ };
99
+ }
100
+ }
101
+
102
+ let WASM_VECTOR_LEN = 0;
103
+
104
+ /**
105
+ * @param {Float64Array} samples
106
+ * @param {number} m
107
+ * @returns {number}
108
+ */
109
+ export function approx_entropy(samples, m) {
110
+ const ptr0 = passArrayF64ToWasm0(samples, wasm.__wbindgen_malloc);
111
+ const len0 = WASM_VECTOR_LEN;
112
+ const ret = wasm.approx_entropy(ptr0, len0, m);
113
+ return ret;
114
+ }
115
+
116
+ /**
117
+ * @param {Float64Array} v1
118
+ * @param {Float64Array} v2
119
+ * @returns {number}
120
+ */
121
+ export function cosine_similarity(v1, v2) {
122
+ const ptr0 = passArrayF64ToWasm0(v1, wasm.__wbindgen_malloc);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ const ptr1 = passArrayF64ToWasm0(v2, wasm.__wbindgen_malloc);
125
+ const len1 = WASM_VECTOR_LEN;
126
+ const ret = wasm.cosine_similarity(ptr0, len0, ptr1, len1);
127
+ return ret;
128
+ }
129
+
130
+ /**
131
+ * @param {string} s
132
+ * @returns {string}
133
+ */
134
+ export function fnv_hash(s) {
135
+ let deferred2_0;
136
+ let deferred2_1;
137
+ try {
138
+ const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
139
+ const len0 = WASM_VECTOR_LEN;
140
+ const ret = wasm.fnv_hash(ptr0, len0);
141
+ deferred2_0 = ret[0];
142
+ deferred2_1 = ret[1];
143
+ return getStringFromWasm0(ret[0], ret[1]);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @param {string} s
151
+ * @returns {number}
152
+ */
153
+ export function kolmogorov_complexity(s) {
154
+ const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
155
+ const len0 = WASM_VECTOR_LEN;
156
+ const ret = wasm.kolmogorov_complexity(ptr0, len0);
157
+ return ret;
158
+ }
159
+
160
+ /**
161
+ * @param {Float64Array} values
162
+ * @returns {number}
163
+ */
164
+ export function ks_test(values) {
165
+ const ptr0 = passArrayF64ToWasm0(values, wasm.__wbindgen_malloc);
166
+ const len0 = WASM_VECTOR_LEN;
167
+ const ret = wasm.ks_test(ptr0, len0);
168
+ return ret;
169
+ }
170
+
171
+ /**
172
+ * @param {string} s1
173
+ * @param {string} s2
174
+ * @returns {number}
175
+ */
176
+ export function levenshtein_distance(s1, s2) {
177
+ const ptr0 = passStringToWasm0(s1, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
178
+ const len0 = WASM_VECTOR_LEN;
179
+ const ptr1 = passStringToWasm0(s2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ const len1 = WASM_VECTOR_LEN;
181
+ const ret = wasm.levenshtein_distance(ptr0, len0, ptr1, len1);
182
+ return ret >>> 0;
183
+ }
184
+
185
+ /**
186
+ * @param {Uint8Array} data
187
+ * @returns {number}
188
+ */
189
+ export function lz_complexity(data) {
190
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
191
+ const len0 = WASM_VECTOR_LEN;
192
+ const ret = wasm.lz_complexity(ptr0, len0);
193
+ return ret >>> 0;
194
+ }
195
+
196
+ /**
197
+ * @param {string} s
198
+ * @returns {string}
199
+ */
200
+ export function murmur_hash(s) {
201
+ let deferred2_0;
202
+ let deferred2_1;
203
+ try {
204
+ const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
205
+ const len0 = WASM_VECTOR_LEN;
206
+ const ret = wasm.murmur_hash(ptr0, len0);
207
+ deferred2_0 = ret[0];
208
+ deferred2_1 = ret[1];
209
+ return getStringFromWasm0(ret[0], ret[1]);
210
+ } finally {
211
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
212
+ }
213
+ }
214
+
215
+ /**
216
+ * @param {Float64Array} samples
217
+ * @param {number} m
218
+ * @param {number} r
219
+ * @returns {number}
220
+ */
221
+ export function sample_ent(samples, m, r) {
222
+ const ptr0 = passArrayF64ToWasm0(samples, wasm.__wbindgen_malloc);
223
+ const len0 = WASM_VECTOR_LEN;
224
+ const ret = wasm.sample_ent(ptr0, len0, m, r);
225
+ return ret;
226
+ }
227
+
228
+ /**
229
+ * @param {string} s
230
+ * @returns {number}
231
+ */
232
+ export function shannon_entropy(s) {
233
+ const ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
234
+ const len0 = WASM_VECTOR_LEN;
235
+ const ret = wasm.shannon_entropy(ptr0, len0);
236
+ return ret;
237
+ }
238
+
239
+ /**
240
+ * @param {string} s1
241
+ * @param {string} s2
242
+ * @returns {number}
243
+ */
244
+ export function similarity_score(s1, s2) {
245
+ const ptr0 = passStringToWasm0(s1, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
246
+ const len0 = WASM_VECTOR_LEN;
247
+ const ptr1 = passStringToWasm0(s2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
248
+ const len1 = WASM_VECTOR_LEN;
249
+ const ret = wasm.similarity_score(ptr0, len0, ptr1, len1);
250
+ return ret;
251
+ }
252
+
253
+ /**
254
+ * @param {Float64Array} samples
255
+ * @returns {number}
256
+ */
257
+ export function spectral(samples) {
258
+ const ptr0 = passArrayF64ToWasm0(samples, wasm.__wbindgen_malloc);
259
+ const len0 = WASM_VECTOR_LEN;
260
+ const ret = wasm.spectral(ptr0, len0);
261
+ return ret;
262
+ }
263
+
264
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
265
+
266
+ async function __wbg_load(module, imports) {
267
+ if (typeof Response === 'function' && module instanceof Response) {
268
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
269
+ try {
270
+ return await WebAssembly.instantiateStreaming(module, imports);
271
+ } catch (e) {
272
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
273
+
274
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
275
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
276
+
277
+ } else {
278
+ throw e;
279
+ }
280
+ }
281
+ }
282
+
283
+ const bytes = await module.arrayBuffer();
284
+ return await WebAssembly.instantiate(bytes, imports);
285
+ } else {
286
+ const instance = await WebAssembly.instantiate(module, imports);
287
+
288
+ if (instance instanceof WebAssembly.Instance) {
289
+ return { instance, module };
290
+ } else {
291
+ return instance;
292
+ }
293
+ }
294
+ }
295
+
296
+ function __wbg_get_imports() {
297
+ const imports = {};
298
+ imports.wbg = {};
299
+ imports.wbg.__wbindgen_init_externref_table = function() {
300
+ const table = wasm.__wbindgen_externrefs;
301
+ const offset = table.grow(4);
302
+ table.set(0, undefined);
303
+ table.set(offset + 0, undefined);
304
+ table.set(offset + 1, null);
305
+ table.set(offset + 2, true);
306
+ table.set(offset + 3, false);
307
+ };
308
+
309
+ return imports;
310
+ }
311
+
312
+ function __wbg_finalize_init(instance, module) {
313
+ wasm = instance.exports;
314
+ __wbg_init.__wbindgen_wasm_module = module;
315
+ cachedFloat64ArrayMemory0 = null;
316
+ cachedUint8ArrayMemory0 = null;
317
+
318
+
319
+ wasm.__wbindgen_start();
320
+ return wasm;
321
+ }
322
+
323
+ function initSync(module) {
324
+ if (wasm !== undefined) return wasm;
325
+
326
+
327
+ if (typeof module !== 'undefined') {
328
+ if (Object.getPrototypeOf(module) === Object.prototype) {
329
+ ({module} = module)
330
+ } else {
331
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
332
+ }
333
+ }
334
+
335
+ const imports = __wbg_get_imports();
336
+ if (!(module instanceof WebAssembly.Module)) {
337
+ module = new WebAssembly.Module(module);
338
+ }
339
+ const instance = new WebAssembly.Instance(module, imports);
340
+ return __wbg_finalize_init(instance, module);
341
+ }
342
+
343
+ async function __wbg_init(module_or_path) {
344
+ if (wasm !== undefined) return wasm;
345
+
346
+
347
+ if (typeof module_or_path !== 'undefined') {
348
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
349
+ ({module_or_path} = module_or_path)
350
+ } else {
351
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
352
+ }
353
+ }
354
+
355
+ if (typeof module_or_path === 'undefined') {
356
+ module_or_path = new URL('veil_core_bg.wasm', import.meta.url).href;
357
+ }
358
+ const imports = __wbg_get_imports();
359
+
360
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
361
+ module_or_path = fetch(module_or_path);
362
+ }
363
+
364
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
365
+
366
+ return __wbg_finalize_init(instance, module);
367
+ }
368
+
369
+ export { initSync };
370
+ export default __wbg_init;
Binary file
package/package.json CHANGED
@@ -1,21 +1,25 @@
1
1
  {
2
2
  "name": "@cloudglides/veil",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Math-based deterministic browser fingerprinting library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
- "exports": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
8
13
  "type": "module",
9
14
  "publishConfig": {
10
15
  "access": "public"
11
16
  },
12
- "scripts": {
13
- "build": "tsup",
14
- "dev": "tsup --watch",
15
- "build:wasm": "wasm-pack build veil-core --target web",
16
- "test": "vitest",
17
- "test:ui": "vitest --ui"
18
- },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "workspaces": [
21
+ "example"
22
+ ],
19
23
  "devDependencies": {
20
24
  "@vitest/ui": "^1.0.0",
21
25
  "eslint": "^9.39.2",
@@ -27,5 +31,15 @@
27
31
  "vite-plugin-top-level-await": "^1.6.0",
28
32
  "vite-plugin-wasm": "^3.5.0",
29
33
  "vitest": "^1.0.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "build:all": "node scripts/build.js",
38
+ "build:example": "pnpm -C example build",
39
+ "dev": "tsup --watch",
40
+ "build:wasm": "wasm-pack build veil-core --target web",
41
+ "test": "vitest",
42
+ "test:ui": "vitest --ui",
43
+ "example:dev": "pnpm -C example dev"
30
44
  }
31
- }
45
+ }
package/.envrc DELETED
@@ -1 +0,0 @@
1
- use flake
@@ -1,75 +0,0 @@
1
- name: Build on Tag
2
- on:
3
- push:
4
- tags:
5
- - 'v*'
6
-
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
- permissions:
11
- contents: write # For creating releases
12
- steps:
13
- - uses: actions/checkout@v4
14
- with:
15
- fetch-depth: 0
16
-
17
- - uses: pnpm/action-setup@v2
18
- with:
19
- version: 8
20
-
21
- - uses: actions/setup-node@v4
22
- with:
23
- node-version: '20'
24
- cache: 'pnpm'
25
- registry-url: 'https://registry.npmjs.org'
26
-
27
- - uses: dtolnay/rust-toolchain@stable
28
-
29
- - name: Install wasm-pack
30
- run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
31
-
32
- - name: Extract version from tag
33
- id: version
34
- run: |
35
- VERSION=${GITHUB_REF#refs/tags/v}
36
- echo "version=$VERSION" >> $GITHUB_OUTPUT
37
-
38
- - name: Update package.json version
39
- run: |
40
- VERSION="${{ steps.version.outputs.version }}"
41
- pnpm exec jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp
42
- mv package.json.tmp package.json
43
-
44
- - name: Install dependencies
45
- run: pnpm install
46
-
47
- - name: Build WASM
48
- run: pnpm run build:wasm
49
-
50
- - name: Build
51
- run: pnpm run build
52
-
53
- - name: Publish to npm
54
- run: npm publish
55
- env:
56
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
57
-
58
- - name: Get commit history
59
- id: commits
60
- run: |
61
- PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
62
- COMMITS=$(git log $PREV_TAG..HEAD --oneline --no-decorate)
63
- {
64
- echo "commit_log<<EOF"
65
- echo "$COMMITS"
66
- echo "EOF"
67
- } >> $GITHUB_OUTPUT
68
-
69
- - name: Create GitHub Release
70
- uses: softprops/action-gh-release@v1
71
- with:
72
- body: ${{ steps.commits.outputs.commit_log }}
73
- generate_release_notes: true
74
- env:
75
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}