systemquery/src/lib/io/hostuuid.mjs

19 lines
638 B
JavaScript
Raw Normal View History

2022-01-08 21:55:18 +00:00
"use strict";
import systeminfo from 'systeminformation';
import hash from '../crypto/hash.mjs';
/**
* Returns what (should) be a reproducible UUID for each host that it runs on.
2022-01-09 00:57:06 +00:00
* @param {number} port The port number the agent will listen on. Optional - useful to disambiguating multiple agents running on the same machine for development purposes.
* @return {string}
2022-01-08 21:55:18 +00:00
*/
2022-01-09 00:57:06 +00:00
export default async function(port) {
2022-01-08 21:55:18 +00:00
let serial = (await systeminfo.system()).serial;
let uuid = await systeminfo.uuid();
return hash("sha256", "base64",
2022-01-09 00:57:06 +00:00
`${port}@${serial}@${uuid.os}@${uuid.hardware}@${uuid.macs.join("#")}`
2022-01-08 21:55:18 +00:00
).replace(/[+/=]/g, "");
}