danakt / uuid-by-string

Generates the RFC-4122 Name-Based UUID
MIT License
66 stars 12 forks source link

RFC-4122 doesn't specify UUID v3 and v5 without a namespace #35

Open OSA413 opened 3 months ago

OSA413 commented 3 months ago

I've just found out that the generation of UUIDs without a namespace are not standard, all other implementations found online and in other programming languages requires providing a namespace and a name.

The specification explicitly says to use a namespace during generation:

"o  Compute the hash of the name space ID concatenated with the name."

Currently your library concatenates an empty array that results in using just the data of the provided name for hashing without any data of the namespace: https://github.com/danakt/uuid-by-string/blob/master/src/index.js#L35

Should you specify in the documentation about library's non-standard function?

Another solution would be using a nil UUID as namespace in cases when user provides no namespace (but that will break current tests that check the generation of UUID without a namespace).

OSA413 commented 2 months ago

The fix turned out to be easy, I actually think that it was a bug because it actually needed to be 16, not 0:

https://github.com/danakt/uuid-by-string/blob/master/src/index.js#L4

Anyway, here's the PR: https://github.com/danakt/uuid-by-string/pull/36