UNPKG

whoisens-lib

Version:

Whois for ENS (Ethereum Name Service) lookup service

71 lines 2.5 kB
import utils from '../utils/index.js'; import jsonRCP from '../utils/json-rpc.js'; import ENSRoot from './ENSRoot.js'; import BaseClass from './BaseClass.js'; import { ResolverNotSetError, ResolveType } from './types.js'; export default class Resolver extends BaseClass { constructor(address) { super(); this.ltd = utils.getLTDfromDomain(address); this.address = address; this.addressNode = utils.node(this.address); } async getAddress() { await this.init(); if (!utils.isResult(this.contractAddress)) throw new ResolverNotSetError(); const method = 'addr(bytes32)'; const methodId = utils.getMethodID(method); const addressNode = utils.remove0x(this.addressNode); const data = [methodId, addressNode].join(''); const result = await jsonRCP.getInstance().makeRequest({ to: this.contractAddress, data }); return this.returnResult({ contractAddress: this.contractAddress, contractMethod: method, payload: data, parameters: { methodId, addressNode }, jsonRCPResult: result, result: utils.normalizeHex(result.result), data: { resolveType: ResolveType.forward } }); } async getContentHash() { await this.init(); const method = 'contenthash(bytes32)'; const methodId = utils.getMethodID(method); const addressNode = utils.remove0x(this.addressNode); const data = [methodId, addressNode].join(''); const result = await jsonRCP.getInstance().makeRequest({ to: this.contractAddress, data }); const contentHash = utils.decodeContentHash(result.result); return this.returnResult({ contractAddress: this.contractAddress, contractMethod: method, payload: data, parameters: { methodId, addressNode }, jsonRCPResult: result, result: contentHash && utils.getContentHashAsURL(contentHash) }); } async findContractAddress() { const ensRoot = new ENSRoot(); return (await ensRoot.getResolver(this.address)).result; } async init() { this.contractAddress = await this.findContractAddress(); } } //# sourceMappingURL=Resolver.js.map