Finished fingerprint functionality on frontend

This commit is contained in:
z0ccc 2021-09-28 17:44:21 -04:00
parent e4c7448b0b
commit 64e30bc855
2 changed files with 62 additions and 7 deletions

View file

@ -1,19 +1,40 @@
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
import { useState } from 'react'; import { useState, useEffect } from 'react';
import Block from './Block'; import Block from './Block';
import Table from './Table'; import Table from './Table';
import getHash from '../utils/fingerprint'; import {
getSignature,
postSignature,
getHash,
getFingerprint,
} from '../utils/fingerprint';
const FingerprintBlock = ({ workerData }) => { const FingerprintBlock = ({ workerData }) => {
const [signature, setSignature] = useState(); const [signature, setSignature] = useState();
useEffect(() => {
if (signature) {
postSignature(hash, signature);
} else {
console.log(signature);
getSignature(hash, setSignature);
}
}, [signature]);
const hash = getHash(workerData); const hash = getHash(workerData);
return ( return (
<Block> <Block>
<h1>Fingerprint</h1> <h1>Fingerprint</h1>
<div className="boxWrap"> <>
<div className="hash">{hash}</div> {signature ? (
</div> <Table data={getFingerprint(signature, hash)} />
) : (
<div className="boxWrap">
<div className="hash">{hash}</div>
</div>
)}
</>
<p> <p>
<b>Explanation:</b> This is a unique identifier that can be used to <b>Explanation:</b> This is a unique identifier that can be used to
follow you around the web. Even if you clear cookies, change your IP or follow you around the web. Even if you clear cookies, change your IP or
@ -21,7 +42,7 @@ const FingerprintBlock = ({ workerData }) => {
reload the page in private mode to test it out. reload the page in private mode to test it out.
</p> </p>
{signature ? ( {signature ? (
<p>Success! Reload browser.</p> <p>Success! Reload page.</p>
) : ( ) : (
<form onSubmit={(e) => setSignature(e.target[0].value)}> <form onSubmit={(e) => setSignature(e.target[0].value)}>
<input <input

View file

@ -1,5 +1,39 @@
import axios from 'axios';
import md5 from 'crypto-js/md5'; import md5 from 'crypto-js/md5';
export { getSignature, postSignature, getHash, getFingerprint };
const getSignature = (hash, setSignature) => {
console.log('1');
axios
.get(`https://api.vytal.io/fingerprint/?hash=${hash}`)
.then((response) => {
console.log(response.data[response.data.length - 1]);
if (response.data.length !== 0) {
setSignature(response.data[response.data.length - 1].name);
}
});
};
const postSignature = (hash, signature) => {
axios.post('https://api.vytal.io/fingerprint/', {
name: signature,
hash,
});
};
const getHash = (data) => md5(JSON.stringify(data)).toString(); const getHash = (data) => md5(JSON.stringify(data)).toString();
export default getHash; const getFingerprint = (signature, hash) => [
{
key: 'Signature',
value: signature,
issues: [],
},
{
key: 'Hash',
value: hash,
issues: [],
},
];