Skip to content

[BUG] v3 / v5 do not produce RFC 4122 name-based UUIDs (hex text of the digest is used as the bytes) #52

Closed

Description

@trackoor

Description

uuid.v5(name, namespace) and uuid.v3(name, namespace) are deterministic, but the returned values differ from every other RFC 4122 implementation. In src/v35.ts:

bytes = stringToBytes(
  hashfunc(bytesToString(bytes.buffer as ArrayBuffer)),
) as any;

hashfunc is hex_sha1 / hex_md5, which returns the digest as a lowercase hex string, and stringToBytes then converts each hex character to its ASCII code instead of decoding the hex bytes (so the UUID bytes 36 65 31 63 ... are the ASCII text "6e1c..."). In addition, bytesToString turns the 16 namespace bytes into a Latin-1 string and hex_sha1 / hex_md5 UTF-8 encodes that string again, so any namespace byte >= 0x80 is hashed as two UTF-8 bytes instead of one raw byte.

Expected Behavior

For "www.example.com" in the DNS namespace (6ba7b810-9dad-11d1-80b4-00c04fd430c8), RFC 4122 Appendix B, the uuid npm package, and Python's uuid.uuid5 / uuid.uuid3 produce:

  • v5: 2ed6657d-e927-568b-95e1-2665a8aea6a2
  • v3: 5df41881-3aed-3515-88a7-2f4a814cf09e

Actual Behavior

  • v5: 36653163-3630-5538-b731-646230306266
  • v3: 30633233-3762-3465-b333-303237346338

Steps to Reproduce

  1. Install react-native-uuid@2.0.4.
  2. Run uuid.v5("www.example.com", uuid.DNS) and uuid.v3("www.example.com", uuid.DNS).
  3. Compare the output with uuid or RFC 4122 test vectors.

Environment

  • Node.js version: v26.13.0
  • npm version: 11.20.0
  • OS: Linux x86_64
  • Package version: 2.0.4 (and master at 4c793f6)

Code Example

const uuid = require("react-native-uuid").default;

console.log(uuid.v5("www.example.com", uuid.DNS));
// Actual:   36653163-3630-5538-b731-646230306266
// Expected: 2ed6657d-e927-568b-95e1-2665a8aea6a2

console.log(uuid.v3("www.example.com", uuid.DNS));
// Actual:   30633233-3762-3465-b333-303237346338
// Expected: 5df41881-3aed-3515-88a7-2f4a814cf09e

Stack Trace / Error Message

N/A (wrong return value, no exception thrown)

Additional Context

#18 previously reported this symptom (v5("orderId", "f87ff660-ef24-47a6-b9a8-d64545dd6a4e") returning 31306430-6633-5136-b061-636236373634) and was closed without a fix; 2.0.4 still returns that value.

Credit: https://ucsbplse.github.io/

Activity

  1. eugenehp commented on Nov 15, 2026

    @eugenehp
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions