import { DidCache } from '../types.js' import { BaseResolver } from './base-resolver.js' import { timed } from './util.js' export class DidPlcResolver extends BaseResolver { constructor( public plcUrl: string, public timeout: number, public cache?: DidCache, ) { super(cache) } async resolveNoCheck(did: string): Promise { return timed(this.timeout, async (signal) => { const url = new URL(`/${encodeURIComponent(did)}`, this.plcUrl) const res = await fetch(url, { redirect: 'error', headers: { accept: 'application/did+ld+json,application/json' }, signal, }) // Positively not found, versus due to e.g. network error if (res.status === 404) return null if (!res.ok) { throw Object.assign(new Error(res.statusText), { status: res.status }) } return res.json() }) } }