Skip to content

Own the library surface instead of shipping one by accident - #15

Merged
MastaP merged 1 commit into
mainfrom
feat/library-surface
Oct 27, 2026
Merged

MastaP merged 1 commit into
mainfrom
feat/library-surface

Conversation

@MastaP

@MastaP MastaP commented Oct 27, 2026

Copy link
Copy Markdown
Member

Closes #14.

src/lib/index.ts was a blanket export * over all seven lib modules, wired into
the exports map since the first commit and shipped in 0.2.0. It published 43
names — TIMESTAMP_RECIPIENT_ENCODED, errorMessage,
createUnicityCertificateVerifier and certifyMintTransaction among them — with
nothing recording which were meant to be stable. Adding a symbol to any module
widened the public API and renaming one broke consumers, neither producing a diff
that looked like an API change.

Two entry points

entry modules Node builtins
@unicitylabs/proof-cli/verify 80 none
@unicitylabs/proof-cli 137 node:crypto, from uuid under the Node condition

Verification needs no gateway, no API key and no filesystem, and /verify now
cannot reach one: no aggregator client, no JSON-RPC transport, no node: import
anywhere in its graph. The package root adds stamping. Both files list every name
they export.

Getting there took two moves:

  • TimestampClient.ts keeps stamping. describeToken, verificationFailure,
    verify and the result types move to TimestampVerification.ts, which does not
    import AggregatorClient.
  • loadTrustBase moves to src/config.ts with INetworkSelection, leaving
    src/lib/ free of filesystem access. resolveNetwork takes a parsed
    trustBase instead of a path and is synchronous.

No CLI behaviour changes: TIMESTAMP_TAG, the token type, the payload format and
every command and flag are untouched.

Guards

tests/unit/PublicApiTest.ts imports the package by name in a child process, so
it sees what a consumer sees through the exports map. It pins both export lists
and the exported types, asserts a deep import is refused, and walks each built
module graph. Every guard was checked against the drift it exists to catch:

drift introduced caught by
node:crypto added to src/lib/TimestampPayload.ts no Node builtin in this package
/verify re-exports stamp gateway out of /verify, and the name list
export * added back to src/verify.ts lists every name instead of a barrel
exports map target points at a missing file ships both entry points
a name silently dropped from src/verify.ts publishes exactly the offline names

Breaking, deliberately

Narrowing removes names 0.2.0 exported: TIMESTAMP_BURN_REASON,
TIMESTAMP_RECIPIENT_ENCODED, createUnicityCertificateVerifier, errorMessage,
NO_PAYLOAD_MESSAGE, DEFAULT_POLL_INTERVAL_MS, certifyMintTransaction,
TrustBaseSource, ITrustBaseChoice and loadTrustBase. All stay available
inside the package. No version bump here — releasing is a separate decision.

The build now removes lib/ before compiling, so the deleted barrel stops
shipping from working trees that built before its removal.

Verified: npm run lint, npm run build:check, and npm test (154 passed, 5
skipped — the network suite, which needs a key). npm pack --dry-run confirms
both entry points and their declarations ship and the old barrel does not. The
README examples were run against tests/fixtures/testnet2-signed.cbor.

`src/lib/index.ts` was a blanket `export *` over all seven lib modules, wired
into the `exports` map since the first commit. It published 43 names, internals
among them: adding a symbol to any module widened the public API and renaming one
broke consumers, neither producing a diff that looked like an API change.
Importing anything also pulled in the aggregator client, so verification — which
needs no gateway, no API key and no filesystem — could not be used without them.

Two explicit entry points replace it. `@unicitylabs/proof-cli/verify` carries
offline verification: 80 modules, no transport, no `node:` import. The package
root adds stamping. Both list every name they export.

Making the verification entry point independent of the gateway:

- `TimestampClient.ts` keeps stamping; `describeToken`, `verificationFailure`,
  `verify` and the result types move to `TimestampVerification.ts`, which does
  not import `AggregatorClient`.
- `loadTrustBase` moves to `src/config.ts` along with `INetworkSelection`,
  leaving `src/lib/` free of filesystem access. `resolveNetwork` takes a parsed
  `trustBase` instead of a path, and is now synchronous.

`PublicApiTest` pins both export lists, asserts a deep import is refused, and
walks each built module graph: no module in this package may import from `node:`,
and nothing reachable from `/verify` may be the aggregator client or its
transport. Each guard was confirmed to fail on the drift it exists to catch.

The build now removes `lib/` before compiling, so the deleted barrel stops
shipping from working trees that built before its removal.

Narrowing drops names 0.2.0 exported: `TIMESTAMP_BURN_REASON`,
`TIMESTAMP_RECIPIENT_ENCODED`, `createUnicityCertificateVerifier`,
`errorMessage`, `NO_PAYLOAD_MESSAGE`, `DEFAULT_POLL_INTERVAL_MS`,
`certifyMintTransaction`, `TrustBaseSource`, `ITrustBaseChoice` and
`loadTrustBase`. All remain available inside the package.

Refs #14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T15:14:35.022545Z 5ad8d08 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MastaP
MastaP merged commit 527e58b into main Oct 27, 2026
2 checks passed
@MastaP
MastaP deleted the feat/library-surface branch October 27, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Own the library surface: the package already exports one by accident

1 participant