From d03bd796d63b0c17aea457acd61353e62da21632 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 12 Feb 2019 22:24:18 +0100 Subject: Added unique fingerprint function (although it's not working) --- public/scripts/encryption.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'public/scripts/encryption.js') diff --git a/public/scripts/encryption.js b/public/scripts/encryption.js index fc5665b..4e3eeb4 100644 --- a/public/scripts/encryption.js +++ b/public/scripts/encryption.js @@ -8,6 +8,8 @@ const Dexie = require('dexie'); const moment = require('moment'); const crypto = require('crypto'); +const jsSHA = require("jssha"); +const fingerprint = require('fingerprintjs2'); const openpgp = require('openpgp'); const swal = require('sweetalert'); @@ -247,6 +249,21 @@ async function getPeerPublicKey(peerId) { }); } +/** + * Gets the unique fingerprint of the user + * @param passphrase + * @returns {Promise} + */ +async function getUniqueFingerprint(passphrase) { + return await fingerprint.get(components => { + const passphraseHash = new Buffer(crypto.createHmac('SHA256', passphrase).update(passphrase).digest('hex')).toString('HEX'); + const userFingerprint = fingerprint.x64hash128(components.map(pair => pair.value).join(), 31); + console.log(passphraseHash + " - " + userFingerprint); + console.log(new Buffer(crypto.createHmac('SHA256', userFingerprint + passphraseHash).update(userFingerprint + passphraseHash).digest('hex')).toString('HEX')); + return new Buffer(crypto.createHmac('SHA256', userFingerprint + passphraseHash).update(userFingerprint + passphraseHash).digest('hex')).toString('HEX'); + }) +} + /** * Returns user id of a public key * @param publicKey @@ -279,4 +296,5 @@ exports.getMsgs = getMessages; exports.store = storePeerPublicKey; exports.get = getPeerPublicKey; exports.getId = getPublicKeyUserId; +exports.getFingerprint = getUniqueFingerprint; exports.reset = reset; -- cgit v1.2.3