lexiconDid
uses node:dns/promises
The DID an authority's _lexicon.<authority> DNS record names, if it names one. On a test's network
(TCM_ATPROTO_LOCAL=1), $TCM_LEXICON_DID instead, if it's set: its DNS isn't the test's.
import { isDid, localNetwork } from "#codebase/tcmts/atproto"; import dns from "node:dns/promises"; export async function lexiconDid(authority: string): Promise<string | undefined> { if (localNetwork() && process.env.TCM_LEXICON_DID) return process.env.TCM_LEXICON_DID; const txt = await dns.resolveTxt(`_lexicon.${authority}`).catch(() => [] as string[][]); const dids = new Set( txt .map((t) => t.join("")) .filter((t) => t.startsWith("did=")) .map((t) => t.slice(4)), ); const [did] = dids; return dids.size === 1 && isDid(did!) ? did : undefined; }