UNPKG

whoisens-lib

Version:

Whois for ENS (Ethereum Name Service) lookup service

77 lines 3.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_js_1 = __importDefault(require("../utils/index.js")); const json_rpc_js_1 = __importDefault(require("../utils/json-rpc.js")); const ENSRoot_js_1 = __importDefault(require("./ENSRoot.js")); const BaseClass_js_1 = __importDefault(require("./BaseClass.js")); const types_js_1 = require("./types.js"); class Resolver extends BaseClass_js_1.default { constructor(address) { super(); this.ltd = index_js_1.default.getLTDfromDomain(address); this.address = address; this.addressNode = index_js_1.default.node(this.address); } async getAddress() { await this.init(); if (!index_js_1.default.isResult(this.contractAddress)) throw new types_js_1.ResolverNotSetError(); const method = 'addr(bytes32)'; const methodId = index_js_1.default.getMethodID(method); const addressNode = index_js_1.default.remove0x(this.addressNode); const data = [methodId, addressNode].join(''); const result = await json_rpc_js_1.default.getInstance().makeRequest({ to: this.contractAddress, data }); return this.returnResult({ contractAddress: this.contractAddress, contractMethod: method, payload: data, parameters: { methodId, addressNode }, jsonRCPResult: result, result: index_js_1.default.normalizeHex(result.result), data: { resolveType: types_js_1.ResolveType.forward } }); } async getContentHash() { await this.init(); const method = 'contenthash(bytes32)'; const methodId = index_js_1.default.getMethodID(method); const addressNode = index_js_1.default.remove0x(this.addressNode); const data = [methodId, addressNode].join(''); const result = await json_rpc_js_1.default.getInstance().makeRequest({ to: this.contractAddress, data }); const contentHash = index_js_1.default.decodeContentHash(result.result); return this.returnResult({ contractAddress: this.contractAddress, contractMethod: method, payload: data, parameters: { methodId, addressNode }, jsonRCPResult: result, result: contentHash && index_js_1.default.getContentHashAsURL(contentHash) }); } async findContractAddress() { const ensRoot = new ENSRoot_js_1.default(); return (await ensRoot.getResolver(this.address)).result; } async init() { this.contractAddress = await this.findContractAddress(); } } exports.default = Resolver; //# sourceMappingURL=Resolver.js.map