Would this library support generating namespaced UUIDs without a namespace?
See original GitHub issueIs your feature request related to a problem? Please describe.
I am working with some other microservices implemented in Java, their acceptance tests use UUIDs which are generated from string names, and no namespaces, using this library: docs, source.
Describe the solution you’d like
I think it would be possible to include a similar option, which omits the namespace if it is not given.
Describe alternatives you’ve considered
I am considering just using the URL namespace, but i was hoping to raise as little eyebrows as possible for future workers who have to read my code. Tests are like documentation after all, and I was hoping to reflect the logic as closely as possible as the Java side.
It is also possible to give { length: 16 }
as the argument instead of a uuid string, which achieves the desired result, but would be preferable to just give null as the argument, or something along those lines.
Additional context
Here is the logic which i was hoping to get from this library, in Java code (please forgive me, i couldnt get a job doing nodejs in my city):
@Override
public UUID generate(byte[] nameBytes)
{
byte[] digest;
synchronized (_digester) {
_digester.reset();
if (_namespace != null) {
_digester.update(UUIDUtil.asByteArray(_namespace));
}
_digester.update(nameBytes);
digest = _digester.digest();
}
return UUIDUtil.constructUUID(_type, digest);
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I came across this when trying to implement the Yggdrasil protocol for Minecraft; if you really need to generate the same UUID as
UUID.nameUUIDFromBytes(bytes)
in Java does, here is a hack to trick the library into doing this:It’s a hack anyway (so pin the npm package version), and I really hope we can achieve this in an easier way.
@alexanderankin yes, this is totally expected. The two different UUIDs you are generating with the JAVA library are:
where
NIL
are just 16 0-bytes.