/** * @file AT Protocol handle resolver * @description Resolves AT Protocol handles to DIDs using DNS TXT records */ import dns from "node:dns"; import process from "node:process"; const DOT = "."; /** * The AT Protocol DNS TXT record prefix * @see https://atproto.com/specs/handle#dns-txt-method */ const at_prefix = "_atproto"; /** * Callback function for DNS TXT record resolution * @param {NodeJS.ErrnoException | null} err - Error object if resolution failed, null otherwise * @param {string[][]} addresses - Array of TXT record values returned from DNS lookup * @throws {NodeJS.ErrnoException} Throws the error if DNS resolution fails */ function resolveCb(err: NodeJS.ErrnoException | null, addresses: string[][]) { if (err) { throw err; } const address = addresses[0][0]; console.info(address); } const input = process.argv; if (input.length !== 3) { throw new Error("Please provide a handle to resolve."); } const host = input.pop(); /** * Get the did record that corresponds to an internet handle * see https://atproto.com/specs/handle#dns-txt-method */ dns.resolveTxt(at_prefix + DOT + host, resolveCb);