()
| 7 | let cachedId: string | undefined; |
| 8 | |
| 9 | export const machineId = () => { |
| 10 | if (cachedId) { |
| 11 | return cachedId; |
| 12 | } |
| 13 | |
| 14 | try { |
| 15 | const id = machineIdSync(); |
| 16 | const hash = createHash("shake256", { |
| 17 | outputLength: 8, |
| 18 | }) |
| 19 | .update(id) |
| 20 | .digest("hex"); |
| 21 | |
| 22 | cachedId = hash; |
| 23 | |
| 24 | return hash; |
| 25 | } catch (e) { |
| 26 | log("Failed to get machine ID. Defaulting to random string.", { error: e }); |
| 27 | |
| 28 | const str = Math.random().toString(36).substring(8); |
| 29 | cachedId = str; |
| 30 | |
| 31 | return str; |
| 32 | } |
| 33 | }; |