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O,KAAK,YAAY,GACrB,MAAM,GAAS,KAAK,mBAAmB,KACvC,MAAM,GAAa,EAAS,KAAK,KACjC,MAAM,GAAY,EAAQ,IAC/B,EAGF,OAAO,QAAU","file":"/npm/ethjs-xns@0.0.3/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ethjs-xns@0.0.3/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// External Deps\nconst Eth = require('ethjs-query')\nconst EthContract = require('ethjs-contract')\nconst namehash = require('eth-ens-namehash')\n\n// ABIs\nconst registryAbi = require('./abis/registry.json')\nconst resolverAbi = require('./abis/resolver.json')\n\n// Map network to known ENS registries\nconst networkMap = require('./lib/network-map.json')\nconst emptyHash =\n  '0x0000000000000000000000000000000000000000000000000000000000000000'\nconst emptyAddr = '0x0000000000000000000000000000000000000000'\n\nconst NotFoundError = new Error('ENS name not defined.')\nconst BadCharacterError = new Error('Illegal Character for ENS.')\n\nclass Ens {\n  constructor(opts = {}) {\n    const { provider, network } = opts\n    console.log(\n      '🚀 ~ file: index.js ~ line 22 ~ Ens ~ constructor ~ network',\n      network\n    )\n    let { registryAddress } = opts\n\n    // Validations\n    if (!provider) {\n      throw new Error('The EthJsENS Constructor requires a provider.')\n    }\n\n    // Requires EITHER a network or a registryAddress\n    if (!network && !registryAddress) {\n      throw new Error(\n        'The EthJsENS Constructor requires a network or registry address.'\n      )\n    }\n\n    this.provider = provider\n    this.eth = new Eth(this.provider)\n    this.contract = new EthContract(this.eth)\n    this.namehash = namehash\n\n    // Link to Registry\n    this.Registry = this.contract(registryAbi)\n    if (!registryAddress && network) {\n      registryAddress = '0x' + networkMap[network]['registry']\n      console.log(\n        '🚀 ~ file: index.js ~ line 45 ~ Ens ~ constructor ~ registryAddress',\n        registryAddress\n      )\n    }\n    this.registry = this.Registry.at(registryAddress)\n\n    // Create Resolver class\n    this.Resolver = this.contract(resolverAbi)\n  }\n\n  lookup(name = '') {\n    console.log('🚀 ~ file: index.js ~ line 61 ~ Ens ~ lookup ~ name', name)\n    try {\n      return this.getNamehash(name).then((node) => {\n        console.log(\n          '🚀 ~ file: index.js ~ line 63 ~ Ens ~ returnthis.getNamehash ~ node',\n          node\n        )\n        if (node === emptyHash) {\n          console.log('NOTFOUNDERROR-EMPTYHASH')\n          return Promise.reject(NotFoundError)\n        }\n        console.log('resolveAddressForNode')\n        return this.resolveAddressForNode(node)\n      })\n    } catch (e) {\n      console.log(\n        '🚀 ~ file: index.js ~ line 63 ~ Ens ~ returnthis.getNamehash ~ e',\n        e\n      )\n      throw e\n    }\n  }\n\n  getNamehash(name) {\n    try {\n      return Promise.resolve(namehash(name))\n    } catch (e) {\n      return Promise.reject(BadCharacterError)\n    }\n  }\n\n  getOwner(name = '') {\n    return this.getNamehash(name).then((node) => this.getOwnerForNode(node))\n  }\n\n  getOwnerForNode(node) {\n    if (node === emptyHash) {\n      return Promise.reject(NotFoundError)\n    }\n    return this.registry.owner(node).then((result) => {\n      const ownerAddress = result[0]\n      if (ownerAddress === emptyAddr) {\n        throw NotFoundError\n      }\n\n      return ownerAddress\n    })\n  }\n\n  getResolver(name = '') {\n    return this.getNamehash(name).then((node) => this.getResolverForNode(node))\n  }\n\n  getResolverAddress(name = '') {\n    return this.getNamehash(name).then((node) =>\n      this.getResolverAddressForNode(node)\n    )\n  }\n\n  getResolverForNode(node) {\n    if (!node.startsWith('0x')) {\n      node = `0x${node}`\n    }\n\n    return this.getResolverAddressForNode(node).then((resolverAddress) => {\n      console.log(\n        '🚀 ~ file: index.js ~ line 116 ~ Ens ~ returnthis.getResolverAddressForNode ~ resolverAddress',\n        resolverAddress\n      )\n      return this.Resolver.at(resolverAddress)\n    })\n  }\n\n  getResolverAddressForNode(node) {\n    console.log('CHECKING getResolverAddressForNode', node)\n    try {\n      return this.registry.resolver(node).then((result) => {\n        console.log(\n          '🚀 ~ file: index.js ~ line 128 ~ Ens ~ returnthis.registry.resolver ~ result',\n          result\n        )\n        const resolverAddress = result[0]\n        console.log(\n          '🚀 ~ file: index.js ~ line 123 ~ Ens ~ returnthis.registry.resolver ~ resolverAddress',\n          resolverAddress\n        )\n        if (resolverAddress === emptyAddr) {\n          console.log('NOTFOUNDERROR')\n          throw NotFoundError\n        }\n        return resolverAddress\n      })\n    } catch (e) {\n      console.error(\n        '🚀 ~ file: index.js ~ line 128 ~ Ens ~ returnthis.registry.resolver ~ e',\n        e\n      )\n      throw e\n    }\n  }\n\n  resolveAddressForNode(node) {\n    console.log('CHECKING resolveAddressForNode')\n    return this.getResolverForNode(node)\n      .then((resolver) => {\n        console.log(\n          '🚀 ~ file: index.js ~ line 130 ~ Ens ~ .then ~ resolver',\n          resolver\n        )\n\n        return resolver.addr(node, 60)\n      })\n      .then((result) => {\n        console.log(\n          '🚀 ~ file: index.js ~ line 150 ~ Ens ~ .then ~ result',\n          result\n        )\n        return result[0]\n      })\n  }\n\n  reverse(address) {\n    if (!address) {\n      return Promise.reject(\n        new Error('Must supply an address to reverse lookup.')\n      )\n    }\n\n    if (address.startsWith('0x')) {\n      address = address.slice(2)\n    } else if (address.startsWith('xdc')) {\n      address = address.slice(3)\n    }\n\n\n    const name = `${address.toLowerCase()}.addr.reverse`\n    const node = namehash(name)\n    return this.getNamehash(name)\n      .then((node) => this.getResolverForNode(node))\n      .then((resolver) => resolver.name(node))\n      .then((results) => results[0])\n  }\n}\n\nmodule.exports = Ens\n"]}