UNPKG

native-machine-id

Version:

Native retrieval of a unique desktop machine ID without admin privileges or child processes. Faster and more reliable alternative to node-machine-id.

43 lines 1.43 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMachineId = getMachineId; exports.getMachineIdSync = getMachineIdSync; const bindings_1 = __importDefault(require("bindings")); const crypto_1 = require("crypto"); const util_1 = require("util"); const binding = (0, bindings_1.default)('native_machine_id'); function getMachineIdFromBindingSync() { try { return binding.getMachineIdSync() || undefined; } catch { return undefined; } } async function getMachineIdFromBindingAsync() { try { const deviceId = (await (0, util_1.promisify)(binding.getMachineIdAsync)()) || undefined; return deviceId; } catch { return undefined; } } async function getMachineId({ raw = false, } = {}) { const machineId = await getMachineIdFromBindingAsync(); if (!machineId || raw === true) { return machineId; } return (0, crypto_1.createHash)('sha256').update(machineId).digest('hex'); } function getMachineIdSync({ raw = false } = {}) { const machineId = getMachineIdFromBindingSync(); if (!machineId || raw === true) { return machineId; } return (0, crypto_1.createHash)('sha256').update(machineId).digest('hex'); } //# sourceMappingURL=index.js.map