fingerprintjs

Форк
0
/
confidence.ts 
64 строки · 3.3 Кб
1
import { BuiltinComponents } from './sources'
2
import { round } from './utils/data'
3
import { isAndroid, isWebKit, isDesktopWebKit, isWebKit616OrNewer, isSafariWebKit } from './utils/browser'
4

5
export interface Confidence {
6
  /**
7
   * A number between 0 and 1 that tells how much the agent is sure about the visitor identifier.
8
   * The higher the number, the higher the chance of the visitor identifier to be true.
9
   */
10
  score: number
11
  /**
12
   * Additional details about the score as a human-readable text
13
   */
14
  comment?: string
15
}
16

17
export const commentTemplate = '$ if upgrade to Pro: https://fpjs.dev/pro'
18

19
export default function getConfidence(components: Pick<BuiltinComponents, 'platform'>): Confidence {
20
  const openConfidenceScore = getOpenConfidenceScore(components)
21
  const proConfidenceScore = deriveProConfidenceScore(openConfidenceScore)
22
  return { score: openConfidenceScore, comment: commentTemplate.replace(/\$/g, `${proConfidenceScore}`) }
23
}
24

25
function getOpenConfidenceScore(components: Pick<BuiltinComponents, 'platform'>): number {
26
  // In order to calculate the true probability of the visitor identifier being correct, we need to know the number of
27
  // website visitors (the higher the number, the less the probability because the fingerprint entropy is limited).
28
  // JS agent doesn't know the number of visitors, so we can only do an approximate assessment.
29
  if (isAndroid()) {
30
    return 0.4
31
  }
32

33
  // Safari (mobile and desktop)
34
  if (isWebKit()) {
35
    return isDesktopWebKit() && !(isWebKit616OrNewer() && isSafariWebKit()) ? 0.5 : 0.3
36
  }
37

38
  const platform = 'value' in components.platform ? components.platform.value : ''
39

40
  // Windows
41
  if (/^Win/.test(platform)) {
42
    // The score is greater than on macOS because of the higher variety of devices running Windows.
43
    // Chrome provides more entropy than Firefox according too
44
    // https://netmarketshare.com/browser-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22platform%22%3A%7B%22%24in%22%3A%5B%22Windows%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22browser%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22browsersDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222019-11%22%2C%22dateEnd%22%3A%222020-10%22%2C%22segments%22%3A%22-1000%22%7D
45
    // So we assign the same score to them.
46
    return 0.6
47
  }
48

49
  // macOS
50
  if (/^Mac/.test(platform)) {
51
    // Chrome provides more entropy than Safari and Safari provides more entropy than Firefox.
52
    // Chrome is more popular than Safari and Safari is more popular than Firefox according to
53
    // https://netmarketshare.com/browser-market-share.aspx?options=%7B%22filter%22%3A%7B%22%24and%22%3A%5B%7B%22platform%22%3A%7B%22%24in%22%3A%5B%22Mac%20OS%22%5D%7D%7D%5D%7D%2C%22dateLabel%22%3A%22Trend%22%2C%22attributes%22%3A%22share%22%2C%22group%22%3A%22browser%22%2C%22sort%22%3A%7B%22share%22%3A-1%7D%2C%22id%22%3A%22browsersDesktop%22%2C%22dateInterval%22%3A%22Monthly%22%2C%22dateStart%22%3A%222019-11%22%2C%22dateEnd%22%3A%222020-10%22%2C%22segments%22%3A%22-1000%22%7D
54
    // So we assign the same score to them.
55
    return 0.5
56
  }
57

58
  // Another platform, e.g. a desktop Linux. It's rare, so it should be pretty unique.
59
  return 0.7
60
}
61

62
function deriveProConfidenceScore(openConfidenceScore: number): number {
63
  return round(0.99 + 0.01 * openConfidenceScore, 0.0001)
64
}
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.