Skip to content

feat(lookup): add @txnlab/nfd-sdk/lookup slim subpath export#20

Merged
drichar merged 4 commits into
mainfrom
feat/lookup-subpath-export
May 28, 2026
Merged

feat(lookup): add @txnlab/nfd-sdk/lookup slim subpath export#20
drichar merged 4 commits into
mainfrom
feat/lookup-subpath-export

Conversation

@drichar

@drichar drichar commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a lookup-only entry point at @txnlab/nfd-sdk/lookup exposing an NfdResolver for forward (name → record) and on-chain reverse (address → record) NFD resolution, without bundling the generated typed contract clients or the NFD HTTP API client.

  • New slim entry (src/lookup-entry.ts): NfdResolver with resolve, resolveAddress, resolveAddresses, and mainNet() / testNet() factories. It reads on-chain state through a generic AppClient (created with a minimal inline ARC-56 spec), so the bundle is ~13 KB (lookup.js 4.8 KB + shared util chunk 8.3 KB) vs. the full client's ~320 KB.
  • Shared logic extracted to leaf helpers so the full NfdClient and the slim resolver produce identical records:
    • utils/internal/nfd-record.ts(globalState + boxes) → Nfd parsing
    • utils/internal/registry-box.ts — registry box-name hashing + name-box app ID decode
    • NfdClient behavior is unchanged (refactor only).
  • On-chain reverse lookup: reads the registry's reverse-index box (SHA-256("addr/algo/" + pubkey)), parses concatenated app IDs, and returns the primary (first) NFD. Note this index only holds verified links, so allowUnverified has no effect on this path.
  • Dropped crypto-js (discontinued) in favor of native Web Crypto (globalThis.crypto.subtle) for SHA-256. Box-name helpers are now async; hash output is byte-identical. Removes crypto-js / @types/crypto-js.
  • Build/packaging: vite.config.ts now emits dual entries (index, lookup) for ESM + CJS with matching .d.ts / .d.cts; package.json adds the ./lookup conditional export. publint --strict passes.
  • Declares typescript-eslint as a direct root devDependency so the flat ESLint config resolves reliably.
  • README gains a "Lookup-only entry" section.

This is additive; the existing NfdClient public API and behavior are unchanged.

Test plan

  • pnpm --filter @txnlab/nfd-sdk build succeeds; publint --strict reports "All good!"
  • pnpm --filter @txnlab/nfd-sdk typecheck passes
  • pnpm --filter @txnlab/nfd-sdk test passes (121 tests, incl. 8 new lookup-entry tests)
  • pnpm --filter @txnlab/nfd-sdk lint passes
  • dist/esm/lookup.js + its shared chunk contain no Nfd*Client identifiers, no nfd-contracts-* reference, and no API client functions; lookup.d.ts has no contract-client types
  • Type-resolution smoke test: importing { NfdResolver } from @txnlab/nfd-sdk/lookup resolves correctly via the subpath (bundler resolution)

@drichar drichar force-pushed the feat/lookup-subpath-export branch 2 times, most recently from 637fc4d to 258e9e4 Compare May 28, 2026 06:22
drichar added 4 commits May 28, 2026 03:36
Add an NfdResolver exposed at the @txnlab/nfd-sdk/lookup subpath for
forward (name -> record) and on-chain reverse (address -> record)
lookups. It reads directly from on-chain state via a generic AppClient
and does not bundle the generated typed contract clients or the NFD HTTP
API client, shipping in ~13 KB vs. the full client's ~320 KB.

The shared (globalState + boxes) -> Nfd parsing is extracted into a leaf
helper (utils/internal/nfd-record) and the registry box-name hashing into
utils/internal/registry-box, both reused by the full NfdClient so behavior
is unchanged.

Reverse lookups use the registry's on-chain reverse index, which only
holds verified address links; allowUnverified has no effect there.

Also replace the discontinued crypto-js dependency with native Web Crypto
(globalThis.crypto.subtle) for SHA-256 box-name hashing. The box-name
helpers become async; output is byte-identical, so NfdClient behavior is
unchanged. crypto-js / @types/crypto-js are removed. Declare
typescript-eslint as a direct devDependency so the root eslint flat config
resolves it reliably.
A minimal Node/tsx script demonstrating NfdResolver forward resolution and
on-chain reverse resolution via the slim lookup subpath. Runs against MainNet
(populated on-chain data) and round-trips a verified address back to its NFD.
Hyphens are not allowed in NFD names, so 'your-name.algo' was invalid.
Add a buildNfdRecord unit test exercising box parsing (verified caAlgo,
user-defined, unverified and split fields), view filtering, and the NFD
state matrix - the shared parsing path used by both NfdClient and
NfdResolver. Add a registry-box test asserting getNameBoxName /
getAddressBoxName against known SHA-256 vectors to lock in the
crypto-js -> Web Crypto migration. Raises nfd-record branch coverage from
~5% to ~70% and registry-box to 100%.
@drichar drichar force-pushed the feat/lookup-subpath-export branch from e2fa14e to 2a36897 Compare May 28, 2026 07:38
@drichar drichar merged commit 873c6c3 into main May 28, 2026
1 check passed
txnlab-release-bot Bot added a commit that referenced this pull request May 28, 2026
# [1.1.0](v1.0.0...v1.1.0) (2026-05-28)

### Features

* **lookup:** add @txnlab/nfd-sdk/lookup slim subpath export ([#20](#20)) ([873c6c3](873c6c3))
@txnlab-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@drichar drichar deleted the feat/lookup-subpath-export branch May 28, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant