Skip to content

fix: accept UUID strings and instances in validate and validateDetailed - #120

Merged
Shinrai merged 1 commit into
nextfrom
fix/validate-detailed-119
Nov 25, 2026
Merged

Shinrai merged 1 commit into
nextfrom
fix/validate-detailed-119

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

UUID.validate() and UUID.validateDetailed() now take a UUID string (dashed or not, any case), a UUID instance or the 16 bytes. Before this, validateDetailed passed a string straight to toHex and threw ERR_INVALID_ARG_TYPE. Malformed input gets a clear error, and there's a regression test covering TA/TB/IA and timestamp/issuer v1–6 IDs plus an RFC ID.

Resolves #119

validateDetailed passed a string straight to toHex, which threw
ERR_INVALID_ARG_TYPE. Both methods now take a UUID string (dashed or
not, any case), a UUID instance or the 16 bytes, and validateDetailed
rejects other input with the same clear error as validate.

Fixes #119
@cldmv-bot cldmv-bot Bot added ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure labels Nov 25, 2026
@Shinrai
Shinrai merged commit 677a026 into next Nov 25, 2026
34 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/validate-detailed-119 branch November 25, 2026 06:17
cldmv-bot Bot added a commit that referenced this pull request Nov 25, 2026
# `@cldmv/uuid` v2.0.1 Changelog

**Release Date**: November 2026
**Release Type**: Patch
**Branch**: `release/2.0.1`

---

## Overview

v2.0.1 fixes how the library describes and generates UUIDs.

- `UUID.validate()` and `UUID.validateDetailed()` take a UUID string or a `UUID` instance; `validateDetailed()` threw a `TypeError` on a string.
- `getInfo()`, `validate()` and `validateDetailed()` describe every UUID, RFC or custom, with the same fields. They used to read the custom-variant bit positions on RFC ids too, which gave RFC ids made-up subvariants, versions and issuer categories.
- RFC version 1, 6 and 7 ids report the timestamp they hold, and `UUID.compare()` sorts them by time alongside TA and TB ids.
- `UUID.v1()` and `UUID.v6()` wrote the wrong timestamp into every id. They now match the RFC 9562 test vectors.

Generated TA, TB and IA ids and their timestamps are unchanged. Code that reads the validator report or `getInfo()` should check the upgrade notes: a few fields were renamed or now return `null`.

---

## 🐛 Bug Fixes

### `validate()` and `validateDetailed()` accept strings and instances ([#120](#120), fixes [#119](#119))

Both methods only took the 16 raw bytes. Given a string, `validate()` threw `UUID must be a 16-byte buffer`, and `validateDetailed()` handed the string to the hex encoder and threw `TypeError [ERR_INVALID_ARG_TYPE] … at toHex`. Both now take a UUID string (with or without dashes, either case), a `UUID` instance or 16 bytes. A string that isn't 32 hex digits throws `Invalid UUID string`.

### Every UUID gets the same detail fields (fixes [#123](#123))

The variant is bits 64-66: RFC 4122/9562 ids are `10x`, custom ids are `111`. The detail methods read bits 67-68 (subvariant), 75-78 (version) and 79-88 (issuer ID) on every id, but those fields only exist under `111`. An RFC v4 id came back with `version: 14`, `issuerID: 276` and `issuerCategory: "Category B (Open Source Contributors)"`.

One decoder now describes every id, and a field the id's variant doesn't define is `null`:

- `getInfo()` returns `uuid`, `isUUID`, `isCLDMV`, `variant`, `variantFamily`, `subvariant`, `version`, `fullVersion`, `variantIdentifier`, `issuerID`, `issuerCategory`, `timestamp`, `timestampUnit`, `date`, `isIssuerVariant` and `isTimestampVariant` for every id. `version` is bits 75-78 on a CLDMV id and the RFC version (bits 48-51) on an RFC id. `isCLDMV`, `variantFamily`, `fullVersion`, `timestampUnit` and `date` are new.
- `isUUID()` returned `false` for every RFC id: it only checked for variant `111`. It now means a well-formed UUID (RFC versions 1-8, Nil, Max and CLDMV ids), and the new `isCLDMV()` tells CLDMV ids apart. `variantFamily` is `"CLDMV"`, `"RFC 4122/9562"`, `"Microsoft"` or `"NCS"`.
- `getInfo().variant` is the family's number: 7 for CLDMV (prefix `111`), 2 for RFC (prefix `10`), 6 for Microsoft, 0 for NCS. It used to be the raw bits 64-66, which read 4 or 5 on an RFC id depending on a data bit; `getVariant()` still returns the raw bits.
- `fullVersion` is `variant.subvariant.version` as numbers, 0 for a part the id doesn't have: `"7.0.6"` for TB, `"7.1.1"` for IA, `"2.0.4"` for RFC v4, `"2.0.0"` for Nil, `"6.0.0"` for Microsoft.
- RFC v1 and v6 (100-ns intervals) and v7 (milliseconds) ids report their timestamp on the Unix epoch. `getTimestamp()` and `getTimestampBigInt()` cover them, the new `getTimestampUnit()` gives the unit, and `UUID.compare()` puts them in time order with TA and TB ids.
- The RFC Nil and Max ids are RFC ids. Max (all ones) used to read as a custom id with reserved subvariant `11`.
- `getIssuerID()` and `getIssuerCategory()` return `null` for every id that isn't an Issuer Variant.
- `validate()` `fields` are the `getInfo()` fields plus the raw timestamp bit fields, named after the spec: `timestampLayout`, `timestampSign`, `timestampSegmentA` (bits 1-63), `timestampContinuation` (bits 69-74) and `timestampMagnitude`. `validateDetailed()`'s `bitLayout` and `entropy` sections also have the same keys for every id.
- The entropy section counts the real random bits: 49 for TA/TB, 109 for IA, 122 for RFC v4, 74 for RFC v7, `null` where there is no random field. It used to report 109 for everything and count timestamp bits as entropy.
- Issuer categories have one name everywhere (`"Category A (Well-Recognized Tech Entities)"`). Issuer IDs 512-1023 get the future RFC range warning again; the check compared against constants that didn't exist. Issuer 404's report no longer says Category B.
- Valid RFC ids no longer get the warning `Not a valid UUID`.

### `UUID.v1()` and `UUID.v6()` write RFC 9562 timestamps (fixes [#124](#124))

`v1()` wrote `time_hi` from the wrong bits, `v6()` laid the time field out 4 bits off, and both computed the 60-bit count of 100-ns intervals as a JavaScript number past 2^53, which drops low bits. Every v1 and v6 id the library generated held the wrong time; a 2023 id decoded as the year 4896 in any RFC parser. Both now compute the time as a bigint and produce the RFC 9562 test vectors byte for byte.

## 🧪 Tests

- `validate()` and `validateDetailed()` on TA, TB and IA ids, timestamp and issuer ids of versions 1-6, an RFC id and malformed input, each as a string, bytes and an instance ([#120](#120)).
- New `tests/uuid-detail-fields.test.vitest.mjs`: the RFC 9562 v1, v6 and v7 test vectors, every RFC version, Nil, Max, a Microsoft id and every custom kind through `getInfo()`, the getters, `validate()` and `validateDetailed()`, the same key set for every id, `UUID.compare()` across RFC and custom ids, and v6 order across a 2^48 tick boundary.

## 📚 Documentation

- **NEW:** [UUID detail reference](https://cldmv.github.io/uuid/) ([Markdown version](https://github.com/CLDMV/uuid/blob/master/docs/reference/uuid-details.md)): what every detail method returns for each RFC version, the Nil, Max and Microsoft ids, and each kind of CLDMV id. Both are generated from the library (`npm run docs:build` for the page, published to GitHub Pages on each release; `npm run docs:details` for the Markdown), and a test fails when the Markdown falls out of date.
- **NEW:** [docs/changelog/v2/v2.0.1.md](https://github.com/CLDMV/uuid/blob/v2.0.1/docs/changelog/v2/v2.0.1.md): this changelog.
- README: `getInfo()` field table for custom and RFC ids, `getTimestamp()` / `getTimestampUnit()` for RFC ids, `UUID.compare()` with RFC ids, a `validate()` / `validateDetailed()` section, and `isUUID()` in place of a `isCustomUUID()` that never existed.
- README What's New promoted to v2.0.1.

---

## Upgrade notes

- Calls that passed bytes to `validate()` / `validateDetailed()` work as before; strings and instances now work too.
- **Validator fields renamed:** `timestampLower63` is `timestampSegmentA`, `actualTimestamp` is `timestamp`, `reservedBit69` and `categoryValidation` are gone (bit 69 is in `timestampContinuation`), and `issuerCategory` uses the long names.
- **`isUUID()` is `true` for RFC ids.** Code that used it to mean "one of the TA, TB or IA ids" should call `isCLDMV()`. `getInfo().variant` is now 2 for every RFC id, where it was the raw 4 or 5.
- **`null` for fields an id doesn't have:** `getIssuerID()`, `getIssuerCategory()` and `getInfo()`'s `subvariant`, `issuerID` and `issuerCategory` on RFC ids; missing keys in the validator sections are now present as `null`.
- **RFC timestamps:** `getTimestamp()` returns a value for RFC v1, v6 and v7 ids where it returned `null`. Code that used a non-null timestamp to mean "TA or TB" should check `isTimestampVariant()` instead. `UUID.compare()` now sorts those RFC ids by time instead of after all timestamp ids.
- **v1 and v6 ids generated by earlier versions** hold the wrong time and can't be corrected from the id alone. Generate new ones if anything reads their time.



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>

---

<!-- coverage-start -->

![coverage](https://img.shields.io/badge/coverage-98.1%25-brightgreen?style=for-the-badge&logo=vitest&logoColor=white)

| Metric | Coverage |
|--------|----------|
| Statements | 98.4% |
| Branches   | 98.0% |
| Functions  | 97.8% |
| Lines      | 98.4% |

*Avg: **98.1%** · `e2b8acd` · Node lts/**

<!-- coverage-end -->

<!-- co-authors -->

Co-authored-by: Shinrai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant