feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests#2
Closed
feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests#2
Conversation
rejin-r
approved these changes
Apr 2, 2026
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| export const aliDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const url = new URL("https://dns.alidns.com/resolve"); |
There was a problem hiding this comment.
Can prolly add in a check on Domain existence just in case anyone passes empty string
if (!domain) {
throw new Error("Domain is required");
}
| 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"); |
There was a problem hiding this comment.
Can maybe extract that 16 number to a variable with a clear name on what that is? :)
| throw new Error(`Ali DNS request failed: HTTP ${res.status}`); | ||
| } | ||
|
|
||
| return res.json() as Promise<IDNSQueryResponse>; |
There was a problem hiding this comment.
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; |
| url.searchParams.set("name", domain); | ||
| url.searchParams.set("type", "TXT"); | ||
|
|
||
| const res = await fetch(url, { method: "GET" }); |
There was a problem hiding this comment.
method GET is the default. You can remove it :)
…hod specification
Author
|
Merged upstream: TradeTrust#30 |
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.

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:
src/util/dns-resolversdirectory, each encapsulating the logic for querying their respective public DNS-over-HTTPS endpoints. [1] [2] [3]index.tsto use the new resolver functions, now supporting Google, Cloudflare, and AliDNS by default.src/util/dns-resolvers/index.tsbarrel file for easier imports. [1] [2]Testing Improvements:
Minor Improvements:
parseOpenAttestationRecordto better handle missing type tokens.||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