Skip to content

fix(issuer-registry): keep the issuer data and registry private - #148

Merged
Shinrai merged 4 commits into
nextfrom
fix/private-issuer-registry
Nov 29, 2026
Merged

Shinrai merged 4 commits into
nextfrom
fix/private-issuer-registry

Conversation

@cldmv-bot

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

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

👥 Contributors

Add tests that pin down what the issuer registry must not hand out:
no _registry Map or _-prefixed members, no swappable UUID._registryInstance,
frozen copies from getIssuer/getByCategory/getIssuerInfo, copies from
export() and import(), no JSON module behind the issuer data, a frozen
ISSUER_CATEGORIES, range checks on reserveFutureRFCBlock and import()
without the test-only FUTURE_RFC_* constants, and a dist/ that loads in
plain Node.
Three problems with how the issuer registry held its data:

1. src/data/issuers.json was loaded as a JSON module. That object is cached
   and shared, so any code importing the same file got the same mutable
   object and could change the issuer data before IssuerRegistry read it.
2. The entries lived in a public _registry Map, next to public
   _initializeReservedIDs/_loadIssuersFromFile and _validate* helpers.
   Anyone holding the registry (UUID.getRegistry() hands it out) could
   .set()/.delete() entries and skip the checks in registerCategoryA,
   registerCategoryB and reserveFutureRFCBlock. Returned entries were the
   stored objects themselves, so changing one changed the registry.
3. JSON import attributes need Node 18.20, 20.10 or 22+, below the
   engines.node floor of >=16.12.0 (src/ under the uuid-dev condition
   can't parse there).

The issuer data is now a deep-frozen, unexported constant in
issuer-registry.mjs and src/data/issuers.json is gone. The entries are in
a #registry field and the helpers are #private methods. getIssuer,
getByCategory and UUID.getIssuerInfo return frozen copies (with their own
Date objects), getByCategory returns a frozen array, and export()/import()
copy their data instead of sharing it.

Fixed along the way: reserveFutureRFCBlock and getStats read
ISSUER_CATEGORIES.FUTURE_RFC_START/END, which don't exist, so the
Future RFC range check never fired and available.futureRFC was always 0.
They now use RFC_EXPANSION_START/END (512-1023). import() validates each
entry against its category's range and builds the new map before
swapping it in, so a refused import leaves the registry as it was.
getRegistry() caches one promise, so concurrent first calls share one
instance.

No longer public:
- IssuerRegistry#_registry, _initializeReservedIDs, _loadIssuersFromFile,
  _validateIssuerID, _validateCategoryAID, _validateCategoryBID,
  _isReservedRange
- UUID._registryInstance (the shared registry can't be read or replaced
  except through UUID.getRegistry())
- writes to ISSUER_CATEGORIES: it's frozen, so assigning to it throws
- writes to returned entries and lists: they're frozen and throw
- src/data/issuers.json (never in "files", but importable from a checkout)

import() now throws for an entry whose ID is outside 0-1023, outside its
category's range, has a category other than "Category A", "Category B" or
"Future RFC", or isn't an object. It used to store anything.
@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 29, 2026
Add tests for ratified entries, the ones that ship with the package (the
reserved IDs 0, 1 and 404 and the bundled Category A and B issuers):
a ratified flag on returned entries, export() and getStats(); register*
and reserveFutureRFCBlock refusing ratified IDs; no remove or reset
method; import() refusing a payload that changes or replaces a ratified
entry or marks a runtime ID ratified, naming the ID and leaving the
registry as it was; and import() keeping the ratified entries a payload
leaves out while replacing the runtime ones.

The old "preserving immutable reserved IDs" test expected import() to
skip a changed reserved ID silently; it now expects the import to fail.
Ratified entries are the ones that ship with the package: the reserved
IDs 0, 1 and 404 and every issuer in the bundled registry data. Entries
added at runtime through registerCategoryA, registerCategoryB or
reserveFutureRFCBlock aren't ratified.

New rules:
- Every entry carries a ratified flag: true for the shipped entries,
  false for runtime ones. It shows on the frozen copies from getIssuer,
  getByCategory and UUID.getIssuerInfo, and on the entries export()
  writes. getStats() gains a ratified count.
- register* refuse a ratified ID (as a duplicate, or out of range for
  0 and 1). reserveFutureRFCBlock can't reach one: every ratified ID is
  below the 512-1023 Future RFC range. The registry has no method that
  removes or resets entries.
- import() keeps every ratified entry and replaces the runtime entries
  only. Before, it kept the reserved IDs but dropped everything else,
  the bundled issuers 2 and 256 included.
- A payload may leave ratified entries out or carry them exactly as
  export() wrote them, with or without the ratified flag. A payload
  that changes or replaces a ratified entry is refused with
  "Issuer ID N is ratified and can't be changed by import()". Before,
  a changed reserved ID was skipped silently.
- A payload that marks a runtime ID ratified is refused too. Imported
  entries are stored with ratified: false.
- A refused import leaves the registry unchanged.
@Shinrai
Shinrai merged commit f43e7fc into next Nov 29, 2026
34 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/private-issuer-registry branch November 29, 2026 05:57
Shinrai added a commit that referenced this pull request Nov 29, 2026
## 🚀 What's Changed

### 💥 Breaking Changes
_No breaking changes_

### ✨ Features
_No new features_

### 🐛 Bug Fixes
_No bug fixes_

### 📦 Dependencies
_No dependency updates_

### 🔧 Other Changes
- docs: note the restored Node.js floor in the v3.0.0 changelog (#149)
(dd7b8d2)
- docs: cover #147 and #148 in the v3.0.0 changelog (#149) (8877bcc)



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

- @Shinrai

</details>
cldmv-bot Bot added a commit that referenced this pull request Nov 30, 2026
# `@cldmv/uuid` v3.0.0 Changelog

**Release Date**: November 2026
**Release Type**: Major
**Branch**: `release/3.0.0`

---

## Overview

v3.0.0 switches the CommonJS entry to the generic `index.cjs` shim used across the CLDMV libraries. `require("@cldmv/uuid")` now returns the module object, the same exports `import` gives, instead of the `UUID` class with properties attached.

There are two breaking changes. The `require()` shape changes, which only affects code that treats the result as the `UUID` class, and the deprecated `@cldmv/uuid/main` alias is removed ([#154](#154)). ESM `import` is unchanged, and so is every `UUID` method. The release also closes off the issuer registry: its bundled data and its entries are now private, and the registry won't let a ratified entry change ([#148](#148)). `dist/` is now built one file per module instead of as tsup bundles, so the code the subpaths share ships once ([#152](#152)).

---

## 💥 Breaking Changes

### `require("@cldmv/uuid")` returns the module object ([#141](#141), fixes [#140](#140))

The ESM entry exports two distinct values, the `UUID` class (also exported as `uuid` and `default`) and `ISSUER_CATEGORIES`, so the shim hands back the module object:

```javascript
const uuid = require("@cldmv/uuid");
// => { __esModule, default: UUID, UUID, uuid, ISSUER_CATEGORIES }

const { UUID } = require("@cldmv/uuid");
UUID.TB();
```

- `new (require(x))()` becomes `new (require(x).UUID)()`, or `const { UUID } = require(x)`.
- Statics called on the result, such as `require(x).v4()`, `require(x).NIL` and `require(x).DNS`, move to the class: `require(x).UUID.v4()`, `UUID.NIL`, `UUID.DNS`.
- `require(x).UUID`, `require(x).uuid` and destructuring keep working.
- `require(x).default` and `require(x).ISSUER_CATEGORIES` are newly available.

`src/index.cjs` is now the generic shim used by the other CLDMV libraries: the Node version guard, then `require("./index.mjs")`. With one distinct exported value it returns that value with `.default` and every export name attached; with several, as here, it returns the module object untouched. The build still copies it unchanged to `dist/index.cjs`. The CJS test expects the module object and checks that the statics are no longer top-level keys.

The first cut of the shim in [#141](#141) returned the single value or the module object without the `.default` and name aliases for the single-value case. [#147](#147) syncs `src/index.cjs` with the corrected template. Nothing changes for uuid, since its entry has two distinct values and `require()` still gives the module object, and the CJS test now also asserts that `UUID` isn't decorated with `.default` or `ISSUER_CATEGORIES`.

### The deprecated `@cldmv/uuid/main` alias is removed ([#154](#154))

`@cldmv/uuid/main` has been a deprecated alias of the package root since v1.3.0, with a one-time `DeprecationWarning` (`CLDMV_UUID_MAIN`), and was kept until the next major. The `./main` export, `src/main.mjs` and its declaration are gone, so importing `@cldmv/uuid/main` now fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Import `@cldmv/uuid` instead; it exports the same objects. With the alias gone nothing in the package has import-time side effects, so `package.json` sets `"sideEffects": false`.

---

## 🐛 Bug Fixes

### The issuer data and registry are private, and ratified entries can't change ([#148](#148))

The bundled Category A and B issuer data and the registry's entries could be reached and changed from outside the registry. Now:

- The bundled data is a frozen constant inside `issuer-registry.mjs`, no longer a separate `src/data/issuers.json` import, and the registry keeps its entries in a private field.
- Everything the registry returns is a frozen copy, or a fresh copy for `export()`, so `UUID.getIssuerInfo()` hands back a read-only object. `ISSUER_CATEGORIES` is frozen too.
- The shared registry instance lives in module scope instead of `UUID._registryInstance`, and concurrent first calls to `UUID.getRegistry()` share one instance.
- The reserved IDs (0, 1 and 404) and the bundled Category A and B issuers are ratified: entries carry `ratified: true` and nothing can change, replace or remove them. Entries added at runtime carry `ratified: false`. `import()` throws if it would alter a ratified entry or mark an entry ratified; an export from before the flag existed still imports when its ratified entries match.

If you were mutating a returned issuer object or reading `UUID._registryInstance`, that no longer works. Registering and looking up issuers through the public API is unchanged.

### The package loads on its stated Node.js floor again ([#148](#148))

v2.1.0 loaded the issuer data with `import issuers from "../data/issuers.json" with { type: "json" }`. The `with` form of import attributes needs Node.js 18.20, or 20.10 on the 20 line, so on the older versions `engines.node` (`>=16.12.0`) still allowed, importing the package failed with a `SyntaxError`. With the data inlined there is no JSON import left, and the built `dist/` loads and runs on Node.js 16.12.0. The `engines.node` floor of `>=16.12.0` is unchanged and now holds.

---

## 🔧 Build

### `dist/` mirrors `src/`, one minified file per module ([#152](#152), fixes [#138](#138))

The tsup build made a separate bundle for each export (`.`, `./main`, `./rng`, `./bytes`, `./hash` and `./entropy`), so the code they share was copied into several files. An app that imported more than one subpath loaded it more than once. `scripts/build.mjs` now runs esbuild over every `src/**/*.mjs` file with `bundle: false` and the `node16` target. Each module is minified on its own with names kept and written to the same path under `dist/`, so `UUID` and every helper exist once. The `@cldmv/uuid/rng`, `/bytes` and `/hash` imports are left as written, so a browser bundler still picks the browser variants through the exports map. `src/index.cjs` is still copied verbatim.

The `exports` map, the entry points and what each subpath exports are unchanged. The tarball now holds one `.mjs` file per source module, and the `.map` files are still left out by `files`.

## 🔧 CI & tooling

- `ci.yml` adopts the CLDMV/.github v4.46.0 concurrency block, so superseded runs on `next`, `hotfixes` and feature branches are cancelled ([#142](#142), fixes [#139](#139)).

## 📚 Documentation

- **NEW:** [docs/changelog/v3/v3.0.0.md](https://github.com/CLDMV/uuid/blob/v3.0.0/docs/changelog/v3/v3.0.0.md): this changelog.
- README: the CommonJS requirements note and example show the module object.
- README What's New promoted to v3.0.0.

## 🔧 Dependencies

- **CLDMV dev tools** ([#145](#145), [#150](#150)): `@cldmv/vitest-runner` 1.5.6 → 1.11.5, `@cldmv/configs` 1.4.0 → 1.5.1 and `@cldmv/fix-headers` 2.2.4 → 2.6.2, plus `npm update` for the rest. `fix-headers` 2.6.1 restamped the file headers, which now write `@Filename` without a leading slash, and `dependabot.yml` takes the npm groups from the CLDMV/.github v4.47.0 template. Development only; nothing changes for consumers.
- `esbuild` added and `tsup` removed ([#152](#152)).

---

## Upgrade notes

- `require("@cldmv/uuid")` no longer returns the `UUID` class. Use `const { UUID } = require("@cldmv/uuid")`, and call statics on `UUID` (`UUID.v4()`, `UUID.NIL`, `UUID.DNS`).
- `require(x).UUID`, `.uuid` and destructuring work as before; `.default` and `.ISSUER_CATEGORIES` are new.
- `@cldmv/uuid/main` is gone. Import `@cldmv/uuid` instead, which exports the same objects.
- ESM `import` from `@cldmv/uuid` and its other subpaths is unchanged.
- On Node.js 16.12 to 18.19 (and 20.0 to 20.9), the package loads again; v2.1.0 failed there.



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

- @Shinrai

</details>

---

<!-- coverage-start -->

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

| Metric | Coverage |
|--------|----------|
| Statements | 100.0% |
| Branches   | 100.0% |
| Functions  | 100.0% |
| Lines      | 100.0% |

*Avg: **100.0%** · `3fdb25a` · 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