Browse Source

FEATURE | Fingreprint

pull/18/head
Vitalik 9 months ago
parent
commit
0c4ae669a2
  1. 6
      package-lock.json
  2. 1
      package.json
  3. 4
      src/api/http.service.ts
  4. 28
      src/shared/helpers/fingerprint.helper.ts
  5. 11
      src/shared/helpers/tranposition-cipher.helper.ts

6
package-lock.json generated

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
"events": "^3.3.0",
"ffmpeg-kit-react-native": "^5.1.0",
"jet-tools": "^1.3.0",
"js-base64": "^3.7.6",
"lodash": "^4.17.21",
"mime": "^3.0.0",
"moment": "^2.29.4",
@ -12742,6 +12743,11 @@ @@ -12742,6 +12743,11 @@
"@sideway/pinpoint": "^2.0.0"
}
},
"node_modules/js-base64": {
"version": "3.7.6",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.6.tgz",
"integrity": "sha512-NPrWuHFxFUknr1KqJRDgUQPexQF0uIJWjeT+2KjEePhitQxQEx5EJBG1lVn5/hc8aLycTpXrDOgPQ6Zq+EDiTA=="
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",

1
package.json

@ -42,6 +42,7 @@ @@ -42,6 +42,7 @@
"events": "^3.3.0",
"ffmpeg-kit-react-native": "^5.1.0",
"jet-tools": "^1.3.0",
"js-base64": "^3.7.6",
"lodash": "^4.17.21",
"mime": "^3.0.0",
"moment": "^2.29.4",

4
src/api/http.service.ts

@ -7,6 +7,7 @@ import { authService } from '@/services/domain' @@ -7,6 +7,7 @@ import { authService } from '@/services/domain'
import { SetIsForbidden } from '@/store/shared'
import { simpleDispatch } from '@/store/store-helpers'
import { getErrorCode } from '@/shared/helpers'
import { UserFingerprintGenerator } from '@/shared/helpers/fingerprint.helper'
const store = () => GlobalContainerService.get('store')
@ -23,6 +24,9 @@ axiosInstance.interceptors.request.use((config: any) => { @@ -23,6 +24,9 @@ axiosInstance.interceptors.request.use((config: any) => {
if (token) {
config.headers['authorization'] = `Bearer ${token}`
}
config.headers['x-allow-lang'] =
UserFingerprintGenerator.generateUserFingerprint()
return config
})

28
src/shared/helpers/fingerprint.helper.ts

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
import { Platform } from 'react-native'
import { TranspositionCipher } from './tranposition-cipher.helper'
import DeviceInfo from 'react-native-device-info'
export class UserFingerprintGenerator {
private static exist: string
static generateUserFingerprint(): string {
if (this.exist) return this.exist
const deviceId = DeviceInfo.getDeviceId()
const fingerprint = `deviceId:::${deviceId}|platform:::${
Platform.OS
}|brand:::${DeviceInfo.getBrand()}`
console.log('fingerprint', fingerprint)
const hashedFingerprint = this.hashFunction(fingerprint.trim())
this.exist = hashedFingerprint
return hashedFingerprint
}
private static hashFunction(input: string): string {
return TranspositionCipher.encrypt(input)
}
}

11
src/shared/helpers/tranposition-cipher.helper.ts

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
import { encode, decode } from 'js-base64'
export class TranspositionCipher {
static encrypt(message: string): string {
return encode(message)
}
static decrypt(encryptedMessage: string): string {
return decode(encryptedMessage)
}
}
Loading…
Cancel
Save