UNPKG

whoisens-lib

Version:

Whois for ENS (Ethereum Name Service) lookup service

71 lines 2.69 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 { EthAddressType, InvalidEthNameError, NameIsNotRegisteredError } from './types.js'; export default class Registrar extends BaseClass { constructor(address) { super(); if (utils.getAddressType(address) !== EthAddressType.name) throw new InvalidEthNameError(address, 'Ethereum name should be provided'); this.address = address; this.ltd = utils.getLTDfromDomain(this.address); const addressTopLabel = utils.getLabelsFromDomain(address).pop(); this.addressHash = utils.hash(addressTopLabel); } async getOwner() { await this.init(); const method = 'ownerOf(uint256)'; const methodId = utils.getMethodID(method); const data = `${methodId}${this.addressHash}`; const result = await jsonRCP.getInstance().makeRequest({ to: this.contractAddress, data }); const isResult = utils.isResult(result.result); return this.returnResult({ contractAddress: this.contractAddress, contractMethod: method, payload: data, parameters: { methodId, addressHash: this.addressHash }, jsonRCPResult: result, result: utils.normalizeHex(result.result), resultError: !isResult && new NameIsNotRegisteredError() }); } async getExpirationDate() { await this.init(); const method = 'nameExpires(uint256)'; const methodId = utils.getMethodID(method); const data = [methodId, this.addressHash].join(''); const result = await jsonRCP.getInstance().makeRequest({ to: this.contractAddress, data }); const timestamp = Number(result.result); const isResult = utils.isResult(timestamp); return this.returnResult({ contractAddress: this.contractAddress, contractMethod: method, payload: data, parameters: { methodId, addressHash: this.addressHash }, jsonRCPResult: result, result: timestamp, resultError: !isResult && new NameIsNotRegisteredError() }); } async findContractAddress() { const ensRoot = new ENSRoot(); return (await ensRoot.getController(this.ltd)).result; } async init() { this.contractAddress = await this.findContractAddress(); } } //# sourceMappingURL=Registrar.js.map