{"version":3,"file":"universal-resolver.cjs","sources":["../../../../src/resolver/did/universal-resolver.js"],"sourcesContent":["import { NoDIDError } from '../../modules/abstract/did/errors';\nimport { Resolver, WILDCARD } from '../generic';\nimport jsonFetch from '../../utils/json-fetch';\n\n/**\n * Resolves `DID`s with wildcard method: `did:*:`.\n */\nexport default class UniversalResolver extends Resolver {\n  prefix = 'did';\n\n  method = WILDCARD;\n\n  /**\n   * Create an adapter to a\n   * [universal-resolver](https://github.com/decentralized-identity/universal-resolver) instance. The\n   * adapter has type\n   * [DIDResolver](https://github.com/decentralized-identity/did-resolver/blob/02bdaf1687151bb934b10093042e576ed54b229c/src/resolver.ts#L73).\n   * @constructor\n   * @param {string} url - address of an instance of universal-resolver.\n   */\n  constructor(url) {\n    super();\n    this.url = new URL(url);\n\n    // Remove trailing slash if any and append the string `/1.0/identifiers/`\n    this.idUrl = `${url.replace(/\\/$/, '')}/1.0/identifiers/`;\n  }\n\n  /**\n   * Fetch the DID from the universal resolver.\n   * @param {string} did - A full DID (with method, like did:uport:2nQtiQG....)\n   * @returns {Promise<object>}\n   */\n  async resolve(did) {\n    const hashIndex = did.indexOf('#');\n    const encodedDid = encodeURIComponent(\n      hashIndex === -1 ? did : did.slice(0, hashIndex).trim(),\n    );\n    try {\n      const resp = await jsonFetch(`${this.idUrl}${encodedDid}`, {\n        headers: {\n          Accept:\n            'application/ld+json;profile=\"https://w3id.org/did-resolution\"',\n        },\n      });\n\n      // Sometimes didDocument doesnt exist, if so return data as document\n      return resp.didDocument || resp;\n    } catch (error) {\n      if (error.statusCode === 404) {\n        throw new NoDIDError(did);\n      }\n\n      throw error;\n    }\n  }\n}\n"],"names":["Resolver","WILDCARD","jsonFetch","NoDIDError"],"mappings":";;;;;;;;;;;;;;;;AAIA;AACA;AACA;AACe,MAAM,iBAAiB,SAASA,yBAAQ,CAAC;AACxD,EAAE,MAAM,GAAG,KAAK;;AAEhB,EAAE,MAAM,GAAGC,+BAAQ;;AAEnB;AACA;AACA;AACA;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