1 import init from './dnssec_prover_wasm.js';
2 import * as wasm from './dnssec_prover_wasm.js';
5 * Asynchronously resolves a given domain and type using the provided DoH endpoint, then verifies
6 * the returned DNSSEC data and ultimately returns a JSON-encoded list of validated records.
8 export async function lookup_doh(domain, ty, doh_endpoint) {
11 if (!domain.endsWith(".")) domain += ".";
12 if (ty.toLowerCase() == "txt") {
14 } else if (ty.toLowerCase() == "tlsa") {
16 } else if (ty.toLowerCase() == "a") {
18 } else if (ty.toLowerCase() == "aaaa") {
21 if (typeof(ty) == "number") {
22 var builder = wasm.init_proof_builder(domain, ty);
23 if (builder == null) {
24 return "{\"error\":\"Bad domain\"}";
26 var queries_pending = 0;
28 send_next_query = async function() {
29 var query = wasm.get_next_query(builder);
32 var b64 = btoa(String.fromCodePoint(...query));
33 var b64url = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
35 var resp = await fetch(doh_endpoint + "?dns=" + b64url,
36 {headers: {"accept": "application/dns-message"}});
37 if (!resp.ok) { throw "Query returned HTTP " + resp.status; }
38 var array = await resp.arrayBuffer();
39 var buf = new Uint8Array(array);
40 wasm.process_query_response(builder, buf);
43 return "{\"error\":\"DoH Query failed: " + e + "\"}";
45 return await send_next_query();
46 } else if (queries_pending == 0) {
47 var proof = wasm.get_unverified_proof(builder);
49 var result = wasm.verify_byte_stream(proof);
50 return JSON.stringify(JSON.parse(result), null, 1);
52 return "{\"error\":\"Failed to build proof\"}";
56 return await send_next_query();
59 return "{\"error\":\"Unsupported Type\"}";