Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

A quick method to derive the ATProto PLC from a domain using Cloudflare's 1.1.1.1 service.

Use as an API with val.town's usual URL structure: eg. https://api.val.town/v1/run/byjp.atproto?args=%5B%22byjp.me%22%5D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { fetch } from "https://esm.town/v/std/fetch";
export const atproto = async (domain) => {
const atRecord = `_atproto.${domain}`;
const res = await fetch(
`https://1.1.1.1/dns-query?name=${atRecord}&type=TXT`,
{
headers: { "Accept": "application/dns-json" },
},
);
if (res.status !== 200) {
throw `Cloudflare not responding (${res.status}): ${res.body}`;
}
const data = await res.json();
return data.Answer
?.find((ans) => ans.name === atRecord && ans.data.substr(0, 5) === `"did=`)
?.data?.slice(5, -1);
};
October 23, 2023