80
81
let machineId: Promise<string>;
82
>
export async function getMachineId(errorLogger: (error: Error) => void): Promise<string> {
id.ts
83
>
if (!machineId) {
84
>
machineId = (async () => {
85
>
const id = await getMacMachineId(errorLogger);
86
>
87
>
return id || uuid.generateUuid(); // fallback, generate a UUID
88
>
})();
89
>
}
90
>
91
>
return machineId;
92
>
}
93
94
>
async function getMacMachineId(errorLogger: (error: Error) => void): Promise<string | undefined> {
id.ts
95
>
try {
96
>
const crypto = await import('crypto');
97
>
const macAddress = getMac();
98
>
return crypto.createHash('sha256').update(macAddress, 'utf8').digest('hex');
99
>
} catch (err) {
100
errorLogger(err);
101
return undefined;
102
}
104
105
const SQM_KEY: string = 'Software\\Microsoft\\SQMClient';