1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14 | function verb(n) { return function (v) { return step([n, v]); }; }
|
15 | function step(op) {
|
16 | if (f) throw new TypeError("Generator is already executing.");
|
17 | while (_) try {
|
18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19 | if (y = 0, t) op = [op[0] & 2, t.value];
|
20 | switch (op[0]) {
|
21 | case 0: case 1: t = op; break;
|
22 | case 4: _.label++; return { value: op[1], done: false };
|
23 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
24 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25 | default:
|
26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30 | if (t[2]) _.ops.pop();
|
31 | _.trys.pop(); continue;
|
32 | }
|
33 | op = body.call(thisArg, _);
|
34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36 | }
|
37 | };
|
38 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
39 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
40 | };
|
41 | var __importStar = (this && this.__importStar) || function (mod) {
|
42 | if (mod && mod.__esModule) return mod;
|
43 | var result = {};
|
44 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
45 | result["default"] = mod;
|
46 | return result;
|
47 | };
|
48 | Object.defineProperty(exports, "__esModule", { value: true });
|
49 | var ens_1 = __importDefault(require("./ens"));
|
50 | var zns_1 = __importDefault(require("./zns"));
|
51 | var cns_1 = __importDefault(require("./cns"));
|
52 | var unstoppableAPI_1 = __importDefault(require("./unstoppableAPI"));
|
53 | var types_1 = require("./types");
|
54 | var resolutionError_1 = __importStar(require("./resolutionError"));
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | var Resolution = (function () {
|
65 | |
66 |
|
67 |
|
68 |
|
69 | function Resolution(_a) {
|
70 | var _b = (_a === void 0 ? {} : _a).blockchain, blockchain = _b === void 0 ? true : _b;
|
71 | this.blockchain = !!blockchain;
|
72 | if (blockchain) {
|
73 | if (blockchain == true) {
|
74 | blockchain = {};
|
75 | }
|
76 | if (blockchain.ens === undefined) {
|
77 | blockchain.ens = true;
|
78 | }
|
79 | if (blockchain.zns === undefined) {
|
80 | blockchain.zns = true;
|
81 | }
|
82 | if (blockchain.cns == undefined) {
|
83 | blockchain.cns = true;
|
84 | }
|
85 | if (blockchain.ens) {
|
86 | this.ens = new ens_1.default(blockchain.ens);
|
87 | }
|
88 | if (blockchain.zns) {
|
89 | this.zns = new zns_1.default(blockchain.zns);
|
90 | }
|
91 | if (blockchain.cns) {
|
92 | this.cns = new cns_1.default(blockchain.cns);
|
93 | }
|
94 | }
|
95 | else {
|
96 | this.api = new unstoppableAPI_1.default();
|
97 | }
|
98 | }
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | Resolution.prototype.resolve = function (domain) {
|
106 | return __awaiter(this, void 0, void 0, function () {
|
107 | var method, result;
|
108 | return __generator(this, function (_a) {
|
109 | switch (_a.label) {
|
110 | case 0:
|
111 | method = this.getNamingMethodOrThrow(domain);
|
112 | return [4 , method.resolve(domain)];
|
113 | case 1:
|
114 | result = _a.sent();
|
115 | return [2 , result || types_1.UnclaimedDomainResponse];
|
116 | }
|
117 | });
|
118 | });
|
119 | };
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | Resolution.prototype.address = function (domain, currencyTicker) {
|
128 | return __awaiter(this, void 0, void 0, function () {
|
129 | var error_1;
|
130 | return __generator(this, function (_a) {
|
131 | switch (_a.label) {
|
132 | case 0:
|
133 | _a.trys.push([0, 2, , 3]);
|
134 | return [4 , this.addressOrThrow(domain, currencyTicker)];
|
135 | case 1: return [2 , _a.sent()];
|
136 | case 2:
|
137 | error_1 = _a.sent();
|
138 | if (error_1 instanceof resolutionError_1.default) {
|
139 | return [2 , null];
|
140 | }
|
141 | else {
|
142 | throw error_1;
|
143 | }
|
144 | return [3 , 3];
|
145 | case 3: return [2 ];
|
146 | }
|
147 | });
|
148 | });
|
149 | };
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | Resolution.prototype.ipfsHash = function (domain) {
|
157 | return __awaiter(this, void 0, void 0, function () {
|
158 | return __generator(this, function (_a) {
|
159 | switch (_a.label) {
|
160 | case 0: return [4 , this.getNamingMethodOrThrow(domain).record(domain, 'ipfs.html.value')];
|
161 | case 1: return [2 , _a.sent()];
|
162 | }
|
163 | });
|
164 | });
|
165 | };
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | Resolution.prototype.ipfsRedirect = function (domain) {
|
173 | return __awaiter(this, void 0, void 0, function () {
|
174 | return __generator(this, function (_a) {
|
175 | switch (_a.label) {
|
176 | case 0: return [4 , this.getNamingMethodOrThrow(domain).record(domain, 'ipfs.redirect_domain.value')];
|
177 | case 1: return [2 , _a.sent()];
|
178 | }
|
179 | });
|
180 | });
|
181 | };
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | Resolution.prototype.email = function (domain) {
|
189 | return __awaiter(this, void 0, void 0, function () {
|
190 | return __generator(this, function (_a) {
|
191 | switch (_a.label) {
|
192 | case 0: return [4 , this.getNamingMethodOrThrow(domain).record(domain, 'whois.email.value')];
|
193 | case 1: return [2 , _a.sent()];
|
194 | }
|
195 | });
|
196 | });
|
197 | };
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | Resolution.prototype.addressOrThrow = function (domain, currencyTicker) {
|
208 | return __awaiter(this, void 0, void 0, function () {
|
209 | var method;
|
210 | return __generator(this, function (_a) {
|
211 | switch (_a.label) {
|
212 | case 0:
|
213 | method = this.getNamingMethodOrThrow(domain);
|
214 | return [4 , method.address(domain, currencyTicker)];
|
215 | case 1: return [2 , _a.sent()];
|
216 | }
|
217 | });
|
218 | });
|
219 | };
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 | Resolution.prototype.owner = function (domain) {
|
226 | return __awaiter(this, void 0, void 0, function () {
|
227 | var method;
|
228 | return __generator(this, function (_a) {
|
229 | switch (_a.label) {
|
230 | case 0:
|
231 | method = this.getNamingMethod(domain);
|
232 | return [4 , method.owner(domain)];
|
233 | case 1: return [2 , (_a.sent()) || null];
|
234 | }
|
235 | });
|
236 | });
|
237 | };
|
238 | |
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 | Resolution.prototype.reverse = function (address, currencyTicker) {
|
246 | return __awaiter(this, void 0, void 0, function () {
|
247 | return __generator(this, function (_a) {
|
248 | switch (_a.label) {
|
249 | case 0: return [4 , this.ens.reverse(address, currencyTicker)];
|
250 | case 1: return [2 , _a.sent()];
|
251 | }
|
252 | });
|
253 | });
|
254 | };
|
255 | |
256 |
|
257 |
|
258 |
|
259 |
|
260 | Resolution.prototype.namehash = function (domain) {
|
261 | var method = this.getNamingMethod(domain);
|
262 | if (!method)
|
263 | throw new resolutionError_1.default(resolutionError_1.ResolutionErrorCode.UnsupportedDomain, {
|
264 | domain: domain,
|
265 | });
|
266 | return method.namehash(domain);
|
267 | };
|
268 | |
269 |
|
270 |
|
271 |
|
272 | Resolution.prototype.isSupportedDomain = function (domain) {
|
273 | return !!this.getNamingMethod(domain);
|
274 | };
|
275 | |
276 |
|
277 |
|
278 |
|
279 | Resolution.prototype.isSupportedDomainInNetwork = function (domain) {
|
280 | var method = this.getNamingMethod(domain);
|
281 | return method && method.isSupportedNetwork();
|
282 | };
|
283 | |
284 |
|
285 |
|
286 |
|
287 | Resolution.prototype.getNamingMethod = function (domain) {
|
288 | var methods = this.blockchain
|
289 | ? [this.ens, this.zns, this.cns]
|
290 | : [this.api];
|
291 | var method = methods.find(function (method) { return method && method.isSupportedDomain(domain); });
|
292 | return method;
|
293 | };
|
294 | Resolution.prototype.getNamingMethodOrThrow = function (domain) {
|
295 | var method = this.getNamingMethod(domain);
|
296 | if (!method)
|
297 | throw new resolutionError_1.default(resolutionError_1.ResolutionErrorCode.UnsupportedDomain, {
|
298 | domain: domain,
|
299 | });
|
300 | return method;
|
301 | };
|
302 | return Resolution;
|
303 | }());
|
304 | exports.Resolution = Resolution;
|
305 | exports.default = Resolution;
|