feat(lookup): add @txnlab/nfd-sdk/lookup slim subpath export#20
Merged
Conversation
637fc4d to
258e9e4
Compare
4 tasks
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%.
e2fa14e to
2a36897
Compare
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))
Contributor
|
🎉 This PR is included in version 1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a lookup-only entry point at
@txnlab/nfd-sdk/lookupexposing anNfdResolverfor forward (name → record) and on-chain reverse (address → record) NFD resolution, without bundling the generated typed contract clients or the NFD HTTP API client.src/lookup-entry.ts):NfdResolverwithresolve,resolveAddress,resolveAddresses, andmainNet()/testNet()factories. It reads on-chain state through a genericAppClient(created with a minimal inline ARC-56 spec), so the bundle is ~13 KB (lookup.js4.8 KB + shared util chunk 8.3 KB) vs. the full client's ~320 KB.NfdClientand the slim resolver produce identical records:utils/internal/nfd-record.ts—(globalState + boxes) → Nfdparsingutils/internal/registry-box.ts— registry box-name hashing + name-box app ID decodeNfdClientbehavior is unchanged (refactor only).SHA-256("addr/algo/" + pubkey)), parses concatenated app IDs, and returns the primary (first) NFD. Note this index only holds verified links, soallowUnverifiedhas no effect on this path.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. Removescrypto-js/@types/crypto-js.vite.config.tsnow emits dual entries (index,lookup) for ESM + CJS with matching.d.ts/.d.cts;package.jsonadds the./lookupconditional export.publint --strictpasses.typescript-eslintas a direct root devDependency so the flat ESLint config resolves reliably.This is additive; the existing
NfdClientpublic API and behavior are unchanged.Test plan
pnpm --filter @txnlab/nfd-sdk buildsucceeds;publint --strictreports "All good!"pnpm --filter @txnlab/nfd-sdk typecheckpassespnpm --filter @txnlab/nfd-sdk testpasses (121 tests, incl. 8 newlookup-entrytests)pnpm --filter @txnlab/nfd-sdk lintpassesdist/esm/lookup.js+ its shared chunk contain noNfd*Clientidentifiers, nonfd-contracts-*reference, and no API client functions;lookup.d.tshas no contract-client types{ NfdResolver }from@txnlab/nfd-sdk/lookupresolves correctly via the subpath (bundler resolution)