Skip to content

feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests#2

Closed
skydudie wants to merge 9 commits intomasterfrom
Add-Alidns-as-a-resolver
Closed

feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests#2
skydudie wants to merge 9 commits intomasterfrom
Add-Alidns-as-a-resolver

Conversation

@skydudie
Copy link
Copy Markdown

@skydudie skydudie commented Apr 2, 2026

This pull request refactors DNS resolver logic by modularizing and expanding support for multiple public DNS-over-HTTPS providers. It introduces dedicated resolver functions for Google, Cloudflare, and AliDNS, updates the default resolver chain to include all three, and improves test coverage for these resolvers. Additionally, minor improvements were made to parsing and documentation.

DNS Resolver Refactoring and Expansion:

  • Added separate resolver implementations for Google, Cloudflare, and AliDNS in the new src/util/dns-resolvers directory, each encapsulating the logic for querying their respective public DNS-over-HTTPS endpoints. [1] [2] [3]
  • Updated the default resolver chain in index.ts to use the new resolver functions, now supporting Google, Cloudflare, and AliDNS by default.
  • Exported all DNS resolver utilities from a new src/util/dns-resolvers/index.ts barrel file for easier imports. [1] [2]

Testing Improvements:

  • Added comprehensive tests for each DNS resolver to verify correct request construction and response handling, using MSW for HTTP mocking.
  • Updated existing tests to use the new resolver functions instead of inlined resolver implementations. [1] [2] [3]

Minor Improvements:

  • Improved parsing logic in parseOpenAttestationRecord to better handle missing type tokens.
  • Enhanced documentation for several functions, clarifying parameter usage and expected behavior. [1] [2]
  • Changed fallback logic for custom resolvers from || to ?? for better handling of falsy values. [1] [2]

These changes make the DNS resolution logic more modular, robust, and easier to extend or test.

Reference

The implementation is based off the PR made in the Open-Attestation DNS Prove repo: https://github.com/Open-Attestation/dnsprove/pull/61/changes#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80

@skydudie skydudie self-assigned this Apr 2, 2026
@skydudie skydudie added the enhancement New feature or request label Apr 2, 2026
Copy link
Copy Markdown

@rejin-r rejin-r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !! Much cleaner implementations. Thanks @skydudie 💯
Left some minor comments :)

import type { CustomDnsResolver, IDNSQueryResponse } from "../..";

export const aliDnsResolver: CustomDnsResolver = async (domain) => {
const url = new URL("https://dns.alidns.com/resolve");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can prolly add in a check on Domain existence just in case anyone passes empty string

if (!domain) {
    throw new Error("Domain is required");
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const aliDnsResolver: CustomDnsResolver = async (domain) => {
const url = new URL("https://dns.alidns.com/resolve");
url.searchParams.set("name", domain);
url.searchParams.set("type", "16");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can maybe extract that 16 number to a variable with a clear name on what that is? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new Error(`Ali DNS request failed: HTTP ${res.status}`);
}

return res.json() as Promise<IDNSQueryResponse>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance the res.json() would fail?

Suggested change
return res.json() as Promise<IDNSQueryResponse>;
let data;
try {
data = await res.json();
} catch {
throw new Error("Failed to parse DNS response JSON");
}
return data as IDNSQueryResponse;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.searchParams.set("name", domain);
url.searchParams.set("type", "TXT");

const res = await fetch(url, { method: "GET" });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method GET is the default. You can remove it :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skydudie skydudie closed this Apr 17, 2026
@skydudie
Copy link
Copy Markdown
Author

Merged upstream: TradeTrust#30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants