blinktrade
Version:
BlinkTrade client for node.js
53 lines (45 loc) • 1.56 kB
JavaScript
/**
* BlinkTradeJS SDK
* (c) 2016-present BlinkTrade, Inc.
*
* This file is part of BlinkTradeJS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @flow
*/
/* eslint-disable operator-assignment */
/* eslint-disable no-plusplus */
/* eslint-disable import/prefer-default-export */
import macaddress from 'macaddress-secure';
export function getMac(callback: Function): void {
macaddress.all((err, all) => {
const hashCode = (str) => {
let hash = 0;
if (str.length === 0) return hash;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) - hash) + str.charCodeAt(i);
hash = hash & hash; // Convert to 32bit integer
}
return hash;
};
let macAddresses = '';
Object.keys(all).forEach(iface => {
macAddresses += all[iface].mac;
});
let fingerPrint = hashCode(macAddresses);
if (fingerPrint < 0) {
fingerPrint *= -1;
}
callback(fingerPrint);
});
}