UNPKG

mini-id

Version:

A lightweight and customizable unique ID generator with zero collisions.

19 lines (18 loc) 662 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMachineId = getMachineId; const crypto_1 = require("crypto"); const os_1 = require("os"); /** * Generate a machine ID based on network MAC address. */ function getMachineId() { const interfaces = (0, os_1.networkInterfaces)(); const macs = Object.values(interfaces) .flat() .filter((details) => details?.mac && details.mac !== "00:00:00:00:00:00") .map((details) => details.mac) .join(""); const hash = (0, crypto_1.createHash)("sha256").update(macs).digest(); return hash.slice(0, 4); // Use first 4 bytes for machine ID }