From 49664879ddf34d597e8a032dba22cb6feae5e10b Mon Sep 17 00:00:00 2001 From: zaneli Date: Wed, 30 Jul 2014 12:12:40 +0900 Subject: [PATCH] Add definitions for fingerprintjs --- CONTRIBUTORS.md | 1 + fingerprintjs/fingerprint-tests.ts | 53 ++++++++++++++++ fingerprintjs/fingerprint.d.ts | 99 ++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 fingerprintjs/fingerprint-tests.ts create mode 100644 fingerprintjs/fingerprint.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 35e2980f7b..38519a81a7 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -82,6 +82,7 @@ All definitions files include a header with the author and editors, so at some p * [File API: Directories and System](http://www.w3.org/TR/file-system-api/) (by [Kon](http://phyzkit.net/)) * [File API: Writer](http://www.w3.org/TR/file-writer-api/) (by [Kon](http://phyzkit.net/)) * [Finch](https://github.com/stoodder/finchjs) (by [David Sichau](https://github.com/DavidSichau/)) +* [fingerprintjs](https://github.com/Valve/fingerprintjs) (by [Shunsuke Ohtani](https://github.com/zaneli)) * [Finite State Machine](https://github.com/jakesgordon/javascript-state-machine) (by [Boris Yankov](https://github.com/borisyankov)) * [Firebase](https://www.firebase.com/docs/javascript/firebase) (by [Vincent Bortone](https://github.com/vbortone)) * [Firefox](https://developer.mozilla.org/en-US/docs/Web/API) (by [vvakame](https://github.com/vvakame)) diff --git a/fingerprintjs/fingerprint-tests.ts b/fingerprintjs/fingerprint-tests.ts new file mode 100644 index 0000000000..8b07898709 --- /dev/null +++ b/fingerprintjs/fingerprint-tests.ts @@ -0,0 +1,53 @@ +/// + +function test_no_option() { + var fingerprint = new Fingerprint().get(); +} + +function test_set_canvas_enabled() { + var fingerprint = new Fingerprint({canvas: true}).get(); +} + +function test_set_screen_resolution_enabled() { + var fingerprint = new Fingerprint({screen_resolution: true}).get(); +} + +function test_set_ie_activex_enabled() { + var fingerprint = new Fingerprint({ie_activex: true}).get(); +} + +function test_set_hasher_in_option() { + var my_hasher = (value: string, seed: number) => { return value.length % seed; }; + var fingerprint = new Fingerprint({hasher: my_hasher}).get(); + + var fingerprint = new Fingerprint({hasher: (value, seed) => { return value.length % seed; }}).get(); +} + +function test_set_hasher_in_constructor() { + var my_hasher = (value: string, seed: number) => { return value.length % seed; }; + var fingerprint = new Fingerprint(my_hasher).get(); + + var fingerprint = new Fingerprint((value, seed) => { return value.length % seed; }).get(); +} + +function test_call_methods() { + var f = new Fingerprint(); + f.murmurhash3_32_gc("abcde", 123); + if (f.hasLocalStorage()) { + alert("LocalStorage"); + } + if (f.hasSessionStorage()) { + alert("SessionStorage"); + } + if (f.isCanvasSupported()) { + alert("CanvasSupported"); + } + if (f.isIE()) { + alert("IE"); + } + f.getPluginsString(); + f.getRegularPluginsString(); + f.getIEPluginsString(); + f.getScreenResolution(); + f.getCanvasFingerprint(); +} diff --git a/fingerprintjs/fingerprint.d.ts b/fingerprintjs/fingerprint.d.ts new file mode 100644 index 0000000000..f472b04894 --- /dev/null +++ b/fingerprintjs/fingerprint.d.ts @@ -0,0 +1,99 @@ +// Type definitions for fingerprintjs 0.5.4 +// Project: https://github.com/Valve/fingerprintjs +// Definitions by: Shunsuke Ohtani +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module FingerprintJs { + + interface FingerprintStatic { + /** + * Create Fingerprint object. + */ + new(hasher: (key: string, seed: number) => number): Fingerprint; + new(option: FingerprintOption): Fingerprint; + new(): Fingerprint; + } + + interface Fingerprint { + /** + * Generate fingerprint number. + */ + get(): number; + + /** + * Generate fingerprint number using Murmur hashing. + * @param key ASCII only + * @param seed Positive integer only + */ + murmurhash3_32_gc(key: string, seed: number): number; + + /** + * Check whether or not the browser has local storage. + */ + hasLocalStorage(): boolean; + + /** + * Check whether or not the browser has session storage. + */ + hasSessionStorage(): boolean; + + /** + * Check whether or not the browser supports canvas. + */ + isCanvasSupported(): boolean; + + /** + * Check whether or not the browser is IE. + */ + isIE(): boolean; + + /** + * Get plugins string. + */ + getPluginsString(): string; + + /** + * Get plugins string from navigator plugins. + */ + getRegularPluginsString(): string; + + /** + * Get plugins string from ActiveXObject. + */ + getIEPluginsString(): string; + + /** + * Get screen height and width. + */ + getScreenResolution(): number[]; + + /** + * Get canvas data url string. + */ + getCanvasFingerprint(): string; + } + + interface FingerprintOption { + /** + * If you want to use canvas fingerprinting, set true. + */ + canvas?: boolean; + + /** + * If you want to use the screen resolution in calculating the fingerprint, set true. + */ + screen_resolution?: boolean; + + /** + * If you want to query the IE plugins info to further diversify the fingerprinting process, set true. + */ + ie_activex?: boolean; + + /** + * If you want to use custom hashing function, set function. + */ + hasher?: (key: string, seed: number) => number; + } +} + +declare var Fingerprint: FingerprintJs.FingerprintStatic;