Does uuid v1 have browser compatibility issues?

I checked the information and learned that uuid version1 is generated based on timestamp and MAC address. Is there any browser compatibility problem? For example, some browsers cannot obtain the MAC address.

I’m now using an npm package called uuid in a javaScript project.

I am using the v4 version now, but there is a possibility of duplication, and I hope that a version of the uuid generation algorithm can be replaced.

This is my code:

import { v1 as uuidv1 } from 'uuid'; 
const uuid = () => {
  return uuidv1()
}

>Solution :

That’s not possible. It’s not possible to read a system’s interface mac address from a browser. At least not with the standard API. That would be a privacy nightmare.

Check the implementation of uuid (or whatever package you intend to use) and you’ll see they won’t be using a MAC address for their version 1 UUIDs – simply because it’s not possible to obtain such information from a browser.

Wikipedia states that:

Version-1 UUIDs are generated from a time and a node ID (usually the MAC address)

(emphasis mine)

So the node ID is usually a mac address. Although wikipedia is not the authoritative source for generating UUIDs I think we can safely assume that’s the case (with the node ID being usually the mac address).

Looking at the source code of uuid package:

  // node and clockseq need to be initialized to random values if they're not
  // specified.  We do this lazily to minimize issues related to insufficient
  // system entropy.  See #189
  if (node == null || clockseq == null) {
    const seedBytes = options.random || (options.rng || rng)();

    if (node == null) {
      // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
      node = _nodeId = [
        seedBytes[0] | 0x01,
        seedBytes[1],
        seedBytes[2],
        seedBytes[3],
        seedBytes[4],
        seedBytes[5],
      ];
    }

  // later in the source code ...

  // `node`
  for (let n = 0; n < 6; ++n) {
    b[i + n] = node[n];
  }

We can see that uuid package simply uses a random value for the mac address instead.

Leave a Reply