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.
51 lines • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMachineId = getMachineId;
exports.getMachineIdSync = getMachineIdSync;
const crypto_1 = require("crypto");
const util_1 = require("util");
const binding = (() => {
try {
return require('../build/Release/native_machine_id.node');
}
catch (outerError) {
try {
return require('../build/Debug/native_machine_id.node');
}
catch {
throw outerError;
}
}
})();
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