import { DIDResolutionOptions, DIDResolutionResult, DIDResolver, ParsedDID, Resolvable } from 'did-resolver' import request from 'axios' const DEREFERENCE_PATH = '/1.0/dereference/' export function getResolver(url: string): Record { const resolver = new ZXCDidResolver(url) return resolver.build() } export class ZXCDidResolver { private web_did_resolver_url: string constructor(url: string) { this.web_did_resolver_url = url } async resolve( _did: string, parsed: ParsedDID, // eslint-disable-next-line @typescript-eslint/no-unused-vars _unused: Resolvable, _options: DIDResolutionOptions ): Promise { const url = this.web_did_resolver_url + DEREFERENCE_PATH + encodeURIComponent(parsed.didUrl) const didReponse = await request .get(url) .then((res: any) => { return res.data }) .catch((err: any) => { return { didResolutionMetadata: { error: 'notFound', message: err.toString(), // This is not in spec, nut may be helpful }, didDocumentMetadata: {}, didDocument: null, } }) return didReponse } build(): Record { return { zxc: this.resolve.bind(this) } } }