diff --git a/apps/main-app/src/lib/dns-verify.ts b/apps/main-app/src/lib/dns-verify.ts index db62236..7e60f3d 100644 --- a/apps/main-app/src/lib/dns-verify.ts +++ b/apps/main-app/src/lib/dns-verify.ts @@ -158,14 +158,8 @@ async function authoritativeResolveTxt(domain: string): Promise { const records: string[][] = [] for (const answer of response.answers ?? []) { if (answer.type === 'TXT' && 'data' in answer) { - const data = answer.data as Buffer | Buffer[] | string | string[] - if (Array.isArray(data)) { - records.push(data.map((d) => (Buffer.isBuffer(d) ? d.toString('utf-8') : String(d)))) - } else if (Buffer.isBuffer(data)) { - records.push([data.toString('utf-8')]) - } else { - records.push([String(data)]) - } + const chunks = Array.isArray(answer.data) ? answer.data : [answer.data] + records.push(chunks.map((d) => (Buffer.isBuffer(d) ? d.toString('utf-8') : String(d)))) } } return records @@ -212,7 +206,7 @@ export const verifyDomainOwnership = async (domain: string, expectedDid: string) const foundTxtValues = records.map((r) => r.join('')) console.log(`[DNS Verify] Found TXT records:`, foundTxtValues) - if (foundTxtValues.find((v) => v === expectedDid)) { + if (foundTxtValues.some((v) => v === expectedDid)) { console.log(`[DNS Verify] ✓ TXT record matches`) const extras = foundTxtValues.filter((v) => v !== expectedDid) const warning = @@ -229,11 +223,12 @@ export const verifyDomainOwnership = async (domain: string, expectedDid: string) error: `TXT record at ${txtDomain} does not match expected DID. Expected: ${expectedDid}`, found: { txt: foundTxtValues }, } - } catch (err: any) { - console.log(`[DNS Verify] ✗ TXT lookup error:`, err.message) + } catch (err) { + const message = err instanceof Error ? err.message : String(err) + console.log(`[DNS Verify] ✗ TXT lookup error:`, message) return { verified: false, - error: `DNS lookup failed: ${err.message}`, + error: `DNS lookup failed: ${message}`, found: { txt: [] }, } } @@ -266,11 +261,12 @@ export const verifyCNAME = async (domain: string, expectedHash: string): Promise error: `CNAME for ${domain} points to ${foundCname}, expected ${expectedTarget}`, found: { cname: foundCname }, } - } catch (err: any) { - console.log(`[DNS Verify] ✗ CNAME lookup error:`, err.message) + } catch (err) { + const message = err instanceof Error ? err.message : String(err) + console.log(`[DNS Verify] ✗ CNAME lookup error:`, message) return { verified: false, - error: `DNS lookup failed: ${err.message}`, + error: `DNS lookup failed: ${message}`, found: { cname: '' }, } } diff --git a/apps/main-app/src/routes/xrpc.ts b/apps/main-app/src/routes/xrpc.ts index dee6445..f97ab92 100644 --- a/apps/main-app/src/routes/xrpc.ts +++ b/apps/main-app/src/routes/xrpc.ts @@ -112,19 +112,17 @@ const mapSiteDomains = ( domain: string verified?: boolean }>, -) => { +): PlaceWispV2SiteGetDomains.SiteDomain[] => { return mappedDomains - .map((entry) => ({ - domain: entry.domain, - kind: entry.type, - status: - entry.type === 'wisp' - ? ('verified' as const) - : entry.verified - ? ('verified' as const) - : ('pendingVerification' as const), - verified: entry.type === 'wisp' ? true : Boolean(entry.verified), - })) + .map((entry) => { + const verified = entry.type === 'wisp' || Boolean(entry.verified) + return { + domain: entry.domain, + kind: entry.type, + status: verified ? ('verified' as const) : ('pendingVerification' as const), + verified, + } + }) .sort((a, b) => a.domain.localeCompare(b.domain)) } @@ -491,11 +489,7 @@ const deleteSiteForDid = async (did: DidString, input: { siteRkey: string }) => const mappedDomains = await getDomainsBySite(did, siteRkey) - const unmappedDomains: Array<{ - domain: string - kind: 'wisp' | 'custom' - status: 'pendingVerification' | 'verified' - }> = [] + const unmappedDomains: PlaceWispV2SiteDelete.UnmappedDomain[] = [] for (const mapped of mappedDomains as Array<{ type: 'wisp' | 'custom' @@ -505,11 +499,7 @@ const deleteSiteForDid = async (did: DidString, input: { siteRkey: string }) => }>) { if (mapped.type === 'wisp') { await updateWispDomainSite(mapped.domain, null) - unmappedDomains.push({ - domain: mapped.domain, - kind: 'wisp', - status: 'verified', - }) + unmappedDomains.push({ domain: mapped.domain, kind: 'wisp', status: 'verified' }) continue } @@ -640,9 +630,9 @@ export const xrpcRoutes = () => { const [wispDomains, customDomains] = await Promise.all([getAllWispDomains(did), getCustomDomainsByDid(did)]) - const domains = [ + const domains: PlaceWispV2DomainGetList.DomainSummary[] = [ ...wispDomains.map((entry: { domain: string; rkey: string | null }) => ({ - domain: entry.domain as string, + domain: entry.domain, kind: 'wisp' as const, status: 'verified' as const, verified: true, @@ -654,14 +644,17 @@ export const xrpcRoutes = () => { verified: boolean rkey: string | null last_verified_at?: number | string | null - }) => ({ - domain: entry.domain as string, - kind: 'custom' as const, - status: entry.verified ? ('verified' as const) : ('pendingVerification' as const), - verified: Boolean(entry.verified), - siteRkey: entry.rkey ?? undefined, - lastCheckedAt: toIsoFromEpoch(entry.last_verified_at), - }), + }) => { + const verified = Boolean(entry.verified) + return { + domain: entry.domain, + kind: 'custom' as const, + status: verified ? ('verified' as const) : ('pendingVerification' as const), + verified, + siteRkey: entry.rkey ?? undefined, + lastCheckedAt: toIsoFromEpoch(entry.last_verified_at), + } + }, ), ].sort((a, b) => a.domain.localeCompare(b.domain))