Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case 1:
address = _b.sent();
_b.label = 2;
case 2:
address = this.formatter.address(address);
reverseName = address.substring(2).toLowerCase() + ".addr.reverse";
return [4 /*yield*/, this._getResolver(reverseName)];
case 3:
resolverAddress = _b.sent();
if (!resolverAddress) {
return [2 /*return*/, null];
}
_a = bytes_1.arrayify;
return [4 /*yield*/, this.call({
to: resolverAddress,
data: ("0x691f3431" + hash_1.namehash(reverseName).substring(2))
})];
case 4:
bytes = _a.apply(void 0, [_b.sent()]);
// Strip off the dynamic string pointer (0x20)
if (bytes.length < 32 || !bignumber_1.BigNumber.from(bytes.slice(0, 32)).eq(32)) {
return [2 /*return*/, null];
}
bytes = bytes.slice(32);
// Not a length-prefixed string
if (bytes.length < 32) {
return [2 /*return*/, null];
}
length = bignumber_1.BigNumber.from(bytes.slice(0, 32)).toNumber();
bytes = bytes.slice(32);
// Length longer than available data
if (length > bytes.length) {
_c.label = 2;
case 2:
// If it is already an address, nothing to resolve
try {
return [2 /*return*/, Promise.resolve(this.formatter.address(name))];
}
catch (error) { }
return [4 /*yield*/, this._getResolver(name)];
case 3:
resolverAddress = _c.sent();
if (!resolverAddress) {
return [2 /*return*/, null];
}
transaction = {
to: resolverAddress,
data: ("0x3b3b57de" + hash_1.namehash(name).substring(2))
};
_b = (_a = this.formatter).callAddress;
return [4 /*yield*/, this.call(transaction)];
case 4: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
}
});
});
return __awaiter(this, void 0, void 0, function* () {
// Get the resolver from the blockchain
const network = yield this.getNetwork();
// No ENS...
if (!network.ensAddress) {
logger.throwError("network does not support ENS", Logger.errors.UNSUPPORTED_OPERATION, { operation: "ENS", network: network.name });
}
// keccak256("resolver(bytes32)")
const transaction = {
to: network.ensAddress,
data: ("0x0178b8bf" + namehash(name).substring(2))
};
return this.formatter.callAddress(yield this.call(transaction));
});
}
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, this.getNetwork()];
case 1:
network = _c.sent();
// No ENS...
if (!network.ensAddress) {
logger.throwError("network does not support ENS", logger_1.Logger.errors.UNSUPPORTED_OPERATION, { operation: "ENS", network: network.name });
}
transaction = {
to: network.ensAddress,
data: ("0x0178b8bf" + hash_1.namehash(name).substring(2))
};
_b = (_a = this.formatter).callAddress;
return [4 /*yield*/, this.call(transaction)];
case 2: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
}
});
});
name = yield name;
}
// If it is already an address, nothing to resolve
try {
return Promise.resolve(this.formatter.address(name));
}
catch (error) { }
// Get the addr from the resovler
const resolverAddress = yield this._getResolver(name);
if (!resolverAddress) {
return null;
}
// keccak256("addr(bytes32)")
const transaction = {
to: resolverAddress,
data: ("0x3b3b57de" + namehash(name).substring(2))
};
return this.formatter.callAddress(yield this.call(transaction));
});
}