whoisens-lib
Version:
Whois for ENS (Ethereum Name Service) lookup service
77 lines • 3.19 kB
JavaScript
"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 Registrar extends BaseClass_js_1.default {
constructor(address) {
super();
if (index_js_1.default.getAddressType(address) !== types_js_1.EthAddressType.name)
throw new types_js_1.InvalidEthNameError(address, 'Ethereum name should be provided');
this.address = address;
this.ltd = index_js_1.default.getLTDfromDomain(this.address);
const addressTopLabel = index_js_1.default.getLabelsFromDomain(address).pop();
this.addressHash = index_js_1.default.hash(addressTopLabel);
}
async getOwner() {
await this.init();
const method = 'ownerOf(uint256)';
const methodId = index_js_1.default.getMethodID(method);
const data = `${methodId}${this.addressHash}`;
const result = await json_rpc_js_1.default.getInstance().makeRequest({
to: this.contractAddress,
data
});
const isResult = index_js_1.default.isResult(result.result);
return this.returnResult({
contractAddress: this.contractAddress,
contractMethod: method,
payload: data,
parameters: {
methodId,
addressHash: this.addressHash
},
jsonRCPResult: result,
result: index_js_1.default.normalizeHex(result.result),
resultError: !isResult && new types_js_1.NameIsNotRegisteredError()
});
}
async getExpirationDate() {
await this.init();
const method = 'nameExpires(uint256)';
const methodId = index_js_1.default.getMethodID(method);
const data = [methodId, this.addressHash].join('');
const result = await json_rpc_js_1.default.getInstance().makeRequest({
to: this.contractAddress,
data
});
const timestamp = Number(result.result);
const isResult = index_js_1.default.isResult(timestamp);
return this.returnResult({
contractAddress: this.contractAddress,
contractMethod: method,
payload: data,
parameters: {
methodId,
addressHash: this.addressHash
},
jsonRCPResult: result,
result: timestamp,
resultError: !isResult && new types_js_1.NameIsNotRegisteredError()
});
}
async findContractAddress() {
const ensRoot = new ENSRoot_js_1.default();
return (await ensRoot.getController(this.ltd)).result;
}
async init() {
this.contractAddress = await this.findContractAddress();
}
}
exports.default = Registrar;
//# sourceMappingURL=Registrar.js.map