amethysta
Version:
Smart Contract Validator
942 lines (911 loc) • 64.7 kB
JavaScript
(function(root, factory) {
(typeof module === 'object' && module.exports) ? module.exports = factory(): root.IpfsPublicGatewayChecker = factory()
}(typeof self !== 'undefined' ? self : this, function() {
var IpfsPublicGatewayChecker = (() => {
var bt = Object.create;
var st = Object.defineProperty;
var xt = Object.getOwnPropertyDescriptor;
var Tt = Object.getOwnPropertyNames;
var Rt = Object.getPrototypeOf,
Et = Object.prototype.hasOwnProperty;
var At = a => st(a, "__esModule", {
value: !0
});
var St = (a, t) => () => (t || a((t = {
exports: {}
}).exports, t), t.exports);
var Ct = (a, t, i) => {
if (t && typeof t == "object" || typeof t == "function")
for (let o of Tt(t)) !Et.call(a, o) && o !== "default" && st(a, o, {
get: () => t[o],
enumerable: !(i = xt(t, o)) || i.enumerable
});
return a
},
Lt = a => Ct(At(st(a != null ? bt(Rt(a)) : {}, "default", a && a.__esModule && "default" in a ? {
get: () => a.default,
enumerable: !0
} : {
value: a,
enumerable: !0
})), a);
var mt = St((V, it) => {
(function(a) {
"use strict";
function t(i) {
var o = i && i.Promise || a.Promise,
p = i && i.XMLHttpRequest || a.XMLHttpRequest;
return function() {
var w = Object.create(a, {
fetch: {
value: void 0,
writable: !0
}
});
return function(g, h) {
typeof V == "object" && typeof it != "undefined" ? h(V) : typeof define == "function" && define.amd ? define(["exports"], h) : h(g.WHATWGFetch = {})
}(this, function(g) {
"use strict";
var h = typeof w != "undefined" && w || typeof self != "undefined" && self || typeof h != "undefined" && h,
v = {
searchParams: "URLSearchParams" in h,
iterable: "Symbol" in h && "iterator" in Symbol,
blob: "FileReader" in h && "Blob" in h && function() {
try {
return new Blob, !0
} catch (e) {
return !1
}
}(),
formData: "FormData" in h,
arrayBuffer: "ArrayBuffer" in h
};
function Q(e) {
return e && DataView.prototype.isPrototypeOf(e)
}
if (v.arrayBuffer) var T = ["[object Int8Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Int16Array]", "[object Uint16Array]", "[object Int32Array]", "[object Uint32Array]", "[object Float32Array]", "[object Float64Array]"],
H = ArrayBuffer.isView || function(e) {
return e && T.indexOf(Object.prototype.toString.call(e)) > -1
};
function R(e) {
if (typeof e != "string" && (e = String(e)), /[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e) || e === "") throw new TypeError("Invalid character in header field name");
return e.toLowerCase()
}
function O(e) {
return typeof e != "string" && (e = String(e)), e
}
function n(e) {
var r = {
next: function() {
var c = e.shift();
return {
done: c === void 0,
value: c
}
}
};
return v.iterable && (r[Symbol.iterator] = function() {
return r
}), r
}
function l(e) {
this.map = {}, e instanceof l ? e.forEach(function(r, c) {
this.append(c, r)
}, this) : Array.isArray(e) ? e.forEach(function(r) {
this.append(r[0], r[1])
}, this) : e && Object.getOwnPropertyNames(e).forEach(function(r) {
this.append(r, e[r])
}, this)
}
l.prototype.append = function(e, r) {
e = R(e), r = O(r);
var c = this.map[e];
this.map[e] = c ? c + ", " + r : r
}, l.prototype.delete = function(e) {
delete this.map[R(e)]
}, l.prototype.get = function(e) {
return e = R(e), this.has(e) ? this.map[e] : null
}, l.prototype.has = function(e) {
return this.map.hasOwnProperty(R(e))
}, l.prototype.set = function(e, r) {
this.map[R(e)] = O(r)
}, l.prototype.forEach = function(e, r) {
for (var c in this.map) this.map.hasOwnProperty(c) && e.call(r, this.map[c], c, this)
}, l.prototype.keys = function() {
var e = [];
return this.forEach(function(r, c) {
e.push(c)
}), n(e)
}, l.prototype.values = function() {
var e = [];
return this.forEach(function(r) {
e.push(r)
}), n(e)
}, l.prototype.entries = function() {
var e = [];
return this.forEach(function(r, c) {
e.push([c, r])
}), n(e)
}, v.iterable && (l.prototype[Symbol.iterator] = l.prototype.entries);
function u(e) {
if (e.bodyUsed) return o.reject(new TypeError("Already read"));
e.bodyUsed = !0
}
function _(e) {
return new o(function(r, c) {
e.onload = function() {
r(e.result)
}, e.onerror = function() {
c(e.error)
}
})
}
function d(e) {
var r = new FileReader,
c = _(r);
return r.readAsArrayBuffer(e), c
}
function S(e) {
var r = new FileReader,
c = _(r);
return r.readAsText(e), c
}
function f(e) {
for (var r = new Uint8Array(e), c = new Array(r.length), y = 0; y < r.length; y++) c[y] = String.fromCharCode(r[y]);
return c.join("")
}
function G(e) {
if (e.slice) return e.slice(0);
var r = new Uint8Array(e.byteLength);
return r.set(new Uint8Array(e)), r.buffer
}
function M() {
return this.bodyUsed = !1, this._initBody = function(e) {
this.bodyUsed = this.bodyUsed, this._bodyInit = e, e ? typeof e == "string" ? this._bodyText = e : v.blob && Blob.prototype.isPrototypeOf(e) ? this._bodyBlob = e : v.formData && FormData.prototype.isPrototypeOf(e) ? this._bodyFormData = e : v.searchParams && URLSearchParams.prototype.isPrototypeOf(e) ? this._bodyText = e.toString() : v.arrayBuffer && v.blob && Q(e) ? (this._bodyArrayBuffer = G(e.buffer), this._bodyInit = new Blob([this._bodyArrayBuffer])) : v.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(e) || H(e)) ? this._bodyArrayBuffer = G(e) : this._bodyText = e = Object.prototype.toString.call(e) : this._bodyText = "", this.headers.get("content-type") || (typeof e == "string" ? this.headers.set("content-type", "text/plain;charset=UTF-8") : this._bodyBlob && this._bodyBlob.type ? this.headers.set("content-type", this._bodyBlob.type) : v.searchParams && URLSearchParams.prototype.isPrototypeOf(e) && this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8"))
}, v.blob && (this.blob = function() {
var e = u(this);
if (e) return e;
if (this._bodyBlob) return o.resolve(this._bodyBlob);
if (this._bodyArrayBuffer) return o.resolve(new Blob([this._bodyArrayBuffer]));
if (this._bodyFormData) throw new Error("could not read FormData body as blob");
return o.resolve(new Blob([this._bodyText]))
}, this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
var e = u(this);
return e || (ArrayBuffer.isView(this._bodyArrayBuffer) ? o.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset, this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength)) : o.resolve(this._bodyArrayBuffer))
} else return this.blob().then(d)
}), this.text = function() {
var e = u(this);
if (e) return e;
if (this._bodyBlob) return S(this._bodyBlob);
if (this._bodyArrayBuffer) return o.resolve(f(this._bodyArrayBuffer));
if (this._bodyFormData) throw new Error("could not read FormData body as text");
return o.resolve(this._bodyText)
}, v.formData && (this.formData = function() {
return this.text().then(B)
}), this.json = function() {
return this.text().then(JSON.parse)
}, this
}
var et = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
function s(e) {
var r = e.toUpperCase();
return et.indexOf(r) > -1 ? r : e
}
function C(e, r) {
if (!(this instanceof C)) throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
r = r || {};
var c = r.body;
if (e instanceof C) {
if (e.bodyUsed) throw new TypeError("Already read");
this.url = e.url, this.credentials = e.credentials, r.headers || (this.headers = new l(e.headers)), this.method = e.method, this.mode = e.mode, this.signal = e.signal, !c && e._bodyInit != null && (c = e._bodyInit, e.bodyUsed = !0)
} else this.url = String(e);
if (this.credentials = r.credentials || this.credentials || "same-origin", (r.headers || !this.headers) && (this.headers = new l(r.headers)), this.method = s(r.method || this.method || "GET"), this.mode = r.mode || this.mode || null, this.signal = r.signal || this.signal, this.referrer = null, (this.method === "GET" || this.method === "HEAD") && c) throw new TypeError("Body not allowed for GET or HEAD requests");
if (this._initBody(c), (this.method === "GET" || this.method === "HEAD") && (r.cache === "no-store" || r.cache === "no-cache")) {
var y = /([?&])_=[^&]*/;
if (y.test(this.url)) this.url = this.url.replace(y, "$1_=" + new Date().getTime());
else {
var k = /\?/;
this.url += (k.test(this.url) ? "&" : "?") + "_=" + new Date().getTime()
}
}
}
C.prototype.clone = function() {
return new C(this, {
body: this._bodyInit
})
};
function B(e) {
var r = new FormData;
return e.trim().split("&").forEach(function(c) {
if (c) {
var y = c.split("="),
k = y.shift().replace(/\+/g, " "),
m = y.join("=").replace(/\+/g, " ");
r.append(decodeURIComponent(k), decodeURIComponent(m))
}
}), r
}
function z(e) {
var r = new l,
c = e.replace(/\r?\n[\t ]+/g, " ");
return c.split("\r").map(function(y) {
return y.indexOf(`
`) === 0 ? y.substr(1, y.length) : y
}).forEach(function(y) {
var k = y.split(":"),
m = k.shift().trim();
if (m) {
var Z = k.join(":").trim();
r.append(m, Z)
}
}), r
}
M.call(C.prototype);
function b(e, r) {
if (!(this instanceof b)) throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
r || (r = {}), this.type = "default", this.status = r.status === void 0 ? 200 : r.status, this.ok = this.status >= 200 && this.status < 300, this.statusText = "statusText" in r ? r.statusText : "", this.headers = new l(r.headers), this.url = r.url || "", this._initBody(e)
}
M.call(b.prototype), b.prototype.clone = function() {
return new b(this._bodyInit, {
status: this.status,
statusText: this.statusText,
headers: new l(this.headers),
url: this.url
})
}, b.error = function() {
var e = new b(null, {
status: 0,
statusText: ""
});
return e.type = "error", e
};
var X = [301, 302, 303, 307, 308];
b.redirect = function(e, r) {
if (X.indexOf(r) === -1) throw new RangeError("Invalid status code");
return new b(null, {
status: r,
headers: {
location: e
}
})
}, g.DOMException = h.DOMException;
try {
new g.DOMException
} catch (e) {
g.DOMException = function(r, c) {
this.message = r, this.name = c;
var y = Error(r);
this.stack = y.stack
}, g.DOMException.prototype = Object.create(Error.prototype), g.DOMException.prototype.constructor = g.DOMException
}
function q(e, r) {
return new o(function(c, y) {
var k = new C(e, r);
if (k.signal && k.signal.aborted) return y(new g.DOMException("Aborted", "AbortError"));
var m = new p;
function Z() {
m.abort()
}
m.onload = function() {
var E = {
status: m.status,
statusText: m.statusText,
headers: z(m.getAllResponseHeaders() || "")
};
E.url = "responseURL" in m ? m.responseURL : E.headers.get("X-Request-URL");
var Y = "response" in m ? m.response : m.responseText;
setTimeout(function() {
c(new b(Y, E))
}, 0)
}, m.onerror = function() {
setTimeout(function() {
y(new TypeError("Network request failed"))
}, 0)
}, m.ontimeout = function() {
setTimeout(function() {
y(new TypeError("Network request failed"))
}, 0)
}, m.onabort = function() {
setTimeout(function() {
y(new g.DOMException("Aborted", "AbortError"))
}, 0)
};
function _t(E) {
try {
return E === "" && h.location.href ? h.location.href : E
} catch (Y) {
return E
}
}
m.open(k.method, _t(k.url), !0), k.credentials === "include" ? m.withCredentials = !0 : k.credentials === "omit" && (m.withCredentials = !1), "responseType" in m && (v.blob ? m.responseType = "blob" : v.arrayBuffer && k.headers.get("Content-Type") && k.headers.get("Content-Type").indexOf("application/octet-stream") !== -1 && (m.responseType = "arraybuffer")), r && typeof r.headers == "object" && !(r.headers instanceof l) ? Object.getOwnPropertyNames(r.headers).forEach(function(E) {
m.setRequestHeader(E, O(r.headers[E]))
}) : k.headers.forEach(function(E, Y) {
m.setRequestHeader(Y, E)
}), k.signal && (k.signal.addEventListener("abort", Z), m.onreadystatechange = function() {
m.readyState === 4 && k.signal.removeEventListener("abort", Z)
}), m.send(typeof k._bodyInit == "undefined" ? null : k._bodyInit)
})
}
q.polyfill = !0, h.fetch || (h.fetch = q, h.Headers = l, h.Request = C, h.Response = b), g.Headers = l, g.Request = C, g.Response = b, g.fetch = q, Object.defineProperty(g, "__esModule", {
value: !0
})
}), {
fetch: w.fetch,
Headers: w.Headers,
Request: w.Request,
Response: w.Response,
DOMException: w.DOMException
}
}()
}
typeof define == "function" && define.amd ? define(function() {
return t
}) : typeof V == "object" ? it.exports = t : a.fetchPonyfill = t
})(typeof globalThis != "undefined" ? globalThis : typeof self != "undefined" ? self : typeof globalThis != "undefined" ? globalThis : V)
});
function It() {
var a = Object.create(null);
a.ftp = 21, a.file = 0, a.gopher = 70, a.http = 80, a.https = 443, a.ws = 80, a.wss = 443;
var t = Object.create(null);
t["%2e"] = ".", t[".%2e"] = "..", t["%2e."] = "..", t["%2e%2e"] = "..";
function i(n) {
return a[n] !== void 0
}
function o() {
H.call(this), this._isInvalid = !0
}
function p(n) {
return n == "" && o.call(this), n.toLowerCase()
}
function w(n) {
var l = n.charCodeAt(0);
return l > 32 && l < 127 && [34, 35, 60, 62, 63, 96].indexOf(l) == -1 ? n : encodeURIComponent(n)
}
function g(n) {
var l = n.charCodeAt(0);
return l > 32 && l < 127 && [34, 35, 60, 62, 96].indexOf(l) == -1 ? n : encodeURIComponent(n)
}
var h = void 0,
v = /[a-zA-Z]/,
Q = /[a-zA-Z0-9\+\-\.]/;
function T(n, l, u) {
function _(r) {
et.push(r)
}
var d = l || "scheme start",
S = 0,
f = "",
G = !1,
M = !1,
et = [];
t: for (;
(n[S - 1] != h || S == 0) && !this._isInvalid;) {
var s = n[S];
switch (d) {
case "scheme start":
if (s && v.test(s)) f += s.toLowerCase(), d = "scheme";
else if (l) {
_("Invalid scheme.");
break t
} else {
f = "", d = "no scheme";
continue
}
break;
case "scheme":
if (s && Q.test(s)) f += s.toLowerCase();
else if (s == ":") {
if (this._scheme = f, f = "", l) break t;
i(this._scheme) && (this._isRelative = !0), this._scheme == "file" ? d = "relative" : this._isRelative && u && u._scheme == this._scheme ? d = "relative or authority" : this._isRelative ? d = "authority first slash" : d = "scheme data"
} else if (l) {
if (h == s) break t;
_("Code point not allowed in scheme: " + s);
break t
} else {
f = "", S = 0, d = "no scheme";
continue
}
break;
case "scheme data":
s == "?" ? (this._query = "?", d = "query") : s == "#" ? (this._fragment = "#", d = "fragment") : h != s && s != " " && s != `
` && s != "\r" && (this._schemeData += w(s));
break;
case "no scheme":
if (!u || !i(u._scheme)) _("Missing scheme."), o.call(this);
else {
d = "relative";
continue
}
break;
case "relative or authority":
if (s == "/" && n[S + 1] == "/") d = "authority ignore slashes";
else {
_("Expected /, got: " + s), d = "relative";
continue
}
break;
case "relative":
if (this._isRelative = !0, this._scheme != "file" && (this._scheme = u._scheme), h == s) {
this._host = u._host, this._port = u._port, this._path = u._path.slice(), this._query = u._query, this._username = u._username, this._password = u._password;
break t
} else if (s == "/" || s == "\\") s == "\\" && _("\\ is an invalid code point."), d = "relative slash";
else if (s == "?") this._host = u._host, this._port = u._port, this._path = u._path.slice(), this._query = "?", this._username = u._username, this._password = u._password, d = "query";
else if (s == "#") this._host = u._host, this._port = u._port, this._path = u._path.slice(), this._query = u._query, this._fragment = "#", this._username = u._username, this._password = u._password, d = "fragment";
else {
var C = n[S + 1],
B = n[S + 2];
(this._scheme != "file" || !v.test(s) || C != ":" && C != "|" || h != B && B != "/" && B != "\\" && B != "?" && B != "#") && (this._host = u._host, this._port = u._port, this._username = u._username, this._password = u._password, this._path = u._path.slice(), this._path.pop()), d = "relative path";
continue
}
break;
case "relative slash":
if (s == "/" || s == "\\") s == "\\" && _("\\ is an invalid code point."), this._scheme == "file" ? d = "file host" : d = "authority ignore slashes";
else {
this._scheme != "file" && (this._host = u._host, this._port = u._port, this._username = u._username, this._password = u._password), d = "relative path";
continue
}
break;
case "authority first slash":
if (s == "/") d = "authority second slash";
else {
_("Expected '/', got: " + s), d = "authority ignore slashes";
continue
}
break;
case "authority second slash":
if (d = "authority ignore slashes", s != "/") {
_("Expected '/', got: " + s);
continue
}
break;
case "authority ignore slashes":
if (s != "/" && s != "\\") {
d = "authority";
continue
} else _("Expected authority, got: " + s);
break;
case "authority":
if (s == "@") {
G && (_("@ already seen."), f += "%40"), G = !0;
for (var z = 0; z < f.length; z++) {
var b = f[z];
if (b == " " || b == `
` || b == "\r") {
_("Invalid whitespace in authority.");
continue
}
if (b == ":" && this._password === null) {
this._password = "";
continue
}
var X = w(b);
this._password !== null ? this._password += X : this._username += X
}
f = ""
} else if (h == s || s == "/" || s == "\\" || s == "?" || s == "#") {
S -= f.length, f = "", d = "host";
continue
} else f += s;
break;
case "file host":
if (h == s || s == "/" || s == "\\" || s == "?" || s == "#") {
f.length == 2 && v.test(f[0]) && (f[1] == ":" || f[1] == "|") ? d = "relative path" : (f.length == 0 || (this._host = p.call(this, f), f = ""), d = "relative path start");
continue
} else s == " " || s == `
` || s == "\r" ? _("Invalid whitespace in file host.") : f += s;
break;
case "host":
case "hostname":
if (s == ":" && !M) {
if (this._host = p.call(this, f), f = "", d = "port", l == "hostname") break t
} else if (h == s || s == "/" || s == "\\" || s == "?" || s == "#") {
if (this._host = p.call(this, f), f = "", d = "relative path start", l) break t;
continue
} else s != " " && s != `
` && s != "\r" ? (s == "[" ? M = !0 : s == "]" && (M = !1), f += s) : _("Invalid code point in host/hostname: " + s);
break;
case "port":
if (/[0-9]/.test(s)) f += s;
else if (h == s || s == "/" || s == "\\" || s == "?" || s == "#" || l) {
if (f != "") {
var q = parseInt(f, 10);
q != a[this._scheme] && (this._port = q + ""), f = ""
}
if (l) break t;
d = "relative path start";
continue
} else s == " " || s == `
` || s == "\r" ? _("Invalid code point in port: " + s) : o.call(this);
break;
case "relative path start":
if (s == "\\" && _("'\\' not allowed in path."), d = "relative path", s != "/" && s != "\\") continue;
break;
case "relative path":
if (h == s || s == "/" || s == "\\" || !l && (s == "?" || s == "#")) {
s == "\\" && _("\\ not allowed in relative path.");
var e;
(e = t[f.toLowerCase()]) && (f = e), f == ".." ? (this._path.pop(), s != "/" && s != "\\" && this._path.push("")) : f == "." && s != "/" && s != "\\" ? this._path.push("") : f != "." && (this._scheme == "file" && this._path.length == 0 && f.length == 2 && v.test(f[0]) && f[1] == "|" && (f = f[0] + ":"), this._path.push(f)), f = "", s == "?" ? (this._query = "?", d = "query") : s == "#" && (this._fragment = "#", d = "fragment")
} else s != " " && s != `
` && s != "\r" && (f += w(s));
break;
case "query":
!l && s == "#" ? (this._fragment = "#", d = "fragment") : h != s && s != " " && s != `
` && s != "\r" && (this._query += g(s));
break;
case "fragment":
h != s && s != " " && s != `
` && s != "\r" && (this._fragment += s);
break
}
S++
}
}
function H() {
this._scheme = "", this._schemeData = "", this._username = "", this._password = null, this._host = "", this._port = "", this._path = [], this._query = "", this._fragment = "", this._isInvalid = !1, this._isRelative = !1
}
function R(n, l) {
l !== void 0 && !(l instanceof R) && (l = new R(String(l))), n = String(n), this._url = n, H.call(this);
var u = n.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, "");
T.call(this, u, null, l)
}
R.prototype = {
toString: function() {
return this.href
},
get href() {
if (this._isInvalid) return this._url;
var n = "";
return (this._username != "" || this._password != null) && (n = this._username + (this._password != null ? ":" + this._password : "") + "@"), this.protocol + (this._isRelative ? "//" + n + this.host : "") + this.pathname + this._query + this._fragment
},
set href(n) {
H.call(this), T.call(this, n)
},
get protocol() {
return this._scheme + ":"
},
set protocol(n) {
this._isInvalid || T.call(this, n + ":", "scheme start")
},
get host() {
return this._isInvalid ? "" : this._port ? this._host + ":" + this._port : this._host
},
set host(n) {
this._isInvalid || !this._isRelative || T.call(this, n, "host")
},
get hostname() {
return this._host
},
set hostname(n) {
this._isInvalid || !this._isRelative || T.call(this, n, "hostname")
},
get port() {
return this._port
},
set port(n) {
this._isInvalid || !this._isRelative || T.call(this, n, "port")
},
get pathname() {
return this._isInvalid ? "" : this._isRelative ? "/" + this._path.join("/") : this._schemeData
},
set pathname(n) {
this._isInvalid || !this._isRelative || (this._path = [], T.call(this, n, "relative path start"))
},
get search() {
return this._isInvalid || !this._query || this._query == "?" ? "" : this._query
},
set search(n) {
this._isInvalid || !this._isRelative || (this._query = "?", n[0] == "?" && (n = n.slice(1)), T.call(this, n, "query"))
},
get hash() {
return this._isInvalid || !this._fragment || this._fragment == "#" ? "" : this._fragment
},
set hash(n) {
this._isInvalid || (this._fragment = "#", n[0] == "#" && (n = n.slice(1)), T.call(this, n, "fragment"))
},
get origin() {
var n;
if (this._isInvalid || !this._scheme) return "";
switch (this._scheme) {
case "data":
case "file":
case "javascript":
case "mailto":
return "null"
}
return n = this.host, n ? this._scheme + "://" + n : ""
}
};
var O = self.URL;
return O && (R.createObjectURL = function(n) {
return O.createObjectURL.apply(O, arguments)
}, R.revokeObjectURL = function(n) {
O.revokeObjectURL(n)
}), R
}
var L = It();
var gt = Lt(mt());
var A;
(function(h) {
h.empty = "", h.pending = "\u{1F551}", h.successful = "\u2705", h.caution = "\u26A0\uFE0F", h.failed = "\u274C", h.global = "\u{1F30D}", h.asterisk = "*"
})(A || (A = {}));
var U = class {
constructor(t = "div", i = void 0, o = A.pending) {
let p = document.createElement(t);
this.element = p, i != null && (this.className = i), this.textContent = o
}
static fromElement(t) {
let i = new U("div");
return i.element = t, i
}
asterisk() {
this.textContent = A.asterisk
}
lose() {
this.textContent = A.failed
}
win(t) {
if (t != null) {
this.textContent = A.empty;
let i = document.createElement("a");
i.href = t, i.target = "_blank", i.textContent = A.successful, this.element.title = t, this.element.appendChild(i)
} else this.textContent = A.successful
}
global() {
this.textContent = A.global
}
err() {
this.textContent = A.caution
}
empty() {
this.textContent = A.empty
}
get style() {
return this.element.style
}
append(t) {
return t instanceof U && (t = t.element), this.element.append(t)
}
get classList() {
return this.element.classList
}
set title(t) {
this.element.title = t
}
set className(t) {
this.element.className = t
}
set textContent(t) {
this.element.textContent = t
}
};
var I = class {
constructor(t, ...i) {
this.parent = t;
this.tag = new U(...i)
}
};
var rt = class extends I {
constructor(t, ...i) {
super(t, ...i);
this.parent = t;
this._className = "Not-set";
this._tagName = "Not-set"
}
get className() {
return this._className
}
get tagName() {
return this._tagName
}
check() {}
checked() {}
onerror() {
this.tag.err()
}
};
var $ = "bafybeifx7yeb55armcsxwwitkymga5xf53dxiarykms3ygqic223w5sk3m",
N = "bafybeibwzifw52ttrkqlikfzext5akxu7lz4xiwjgwzmqcpdzmp3n5vnbe",
yt = "Hello from IPFS Gateway Checker";
var x = class {
constructor(t) {
this.namespace = t
}
log(t, ...i) {
let [o, ...p] = i, w = this.namespace != null ? `${this.namespace}.${t}: ` : "";
console[t](`${w}${o}`, ...p)
}
debug(...t) {
this.log("debug", ...t)
}
info(...t) {
this.log("info", ...t)
}
warn(...t) {
this.log("warn", ...t)
}
error(...t) {
this.log("error", ...t)
}
};
var {
fetch: Dt
} = (0, gt.default)(), ot = new x("Cors"), nt = class extends rt {
constructor(t) {
super(t, "div", "Cors");
this.parent = t;
this._className = "Cors";
this._tagName = "div"
}
async check() {
let t = Date.now(),
o = `${this.parent.gateway.replace(":hash",$)}?now=${t}#x-ipfs-companion-no-redirect`;
try {
let p = await Dt(o),
{
status: w
} = p,
g = await p.text();
if (this.tag.title = `Response code: ${w}`, yt === g.trim()) this.tag.asterisk(), this.parent.tag.classList.add("cors");
else throw ot.debug("The response text did not match the expected string"), this.onerror(), new Error(`URL '${o} does not support CORS`)
} catch (p) {
throw ot.error(p), this.onerror(), p
}
}
checked() {
ot.warn("Not implemented yet")
}
onerror() {
this.tag.empty()
}
};
var at = window.IpfsHttpClient({
host: "ipfs.io",
port: 443,
protocol: "https"
});
window.client = at;
var F = class {
constructor({
tokensPerInterval: t,
interval: i,
stopped: o
}) {
if (this.tokensPerInterval = t, this._isStopped = o, typeof i == "string") switch (i) {
case "sec":
case "second": {
this.interval = 1e3;
break
}
case "min":
case "minute": {
this.interval = 1e3 * 60;
break
}
case "hr":
case "hour": {
this.interval = 1e3 * 60 * 60;
break
}
case "day": {
this.interval = 1e3 * 60 * 60 * 24;
break
}
default:
throw new Error("Invalid interval " + i)
} else this.interval = i;
this.tokensRemovedAt = [], this.awaitingRestart = new Set
}
dripTokens() {
throw new Error("dripTokens() not implemented")
}
getDelayForTokens() {
throw new Error("getDelayForTokens() not implemented")
}
getTokens() {
return this.dripTokens(), Math.floor(this.tokens)
}
tryRemoveTokens(t) {
return this.dripTokens(), t > this.tokens ? !1 : (this.tokens -= t, this.tokensRemovedAt.push([Date.now(), t]), !0)
}
async awaitTokens(t = 1) {
this._isStopped && await new Promise(o => this.awaitingRestart.add(o));
let i = this.getDelayForTokens(t);
return i === 0 ? Math.floor(this.tokens) : (await new Promise(o => setTimeout(() => o(), i)), this.awaitTokens(t))
}
reset() {
this.awaitingRestart.forEach(t => t())
}
stop(t = !0) {
this._isStopped = !0, t && this.tryRemoveTokens(this.getTokens())
}
start() {
this._isStopped = !1
}
get isStopped() {
return this._isStopped
}
};
var W = class extends F {
constructor({
bucketSize: t,
tokensPerInterval: i,
interval: o,
stopped: p = !1
}) {
super({
tokensPerInterval: i,
interval: o,
stopped: p
});
this.bucketSize = t, this.tokens = p ? 0 : this.bucketSize, this.tokensRemovedAt = p ? [0] : [Date.now()]
}
dripTokens() {
if (this._isStopped) return;
let t = Date.now(),
i = this.tokensRemovedAt[0],
o = Math.max(t - i, 0);
this.tokensRemovedAt = [t];
let p = o * (this.tokensPerInterval / this.interval);
return this.tokens = Math.min(this.tokens + p, this.bucketSize), Math.floor(this.tokens)
}
getDelayForTokens(t = 1) {
if (t > this.bucketSize) throw new Error(`Cannot supply ${t} tokens at once (max is bucketSize = ${this.bucketSize}`);
this.dripTokens();
let i = t - this.tokens;
if (i <= 0) return 0;
if (!this._isStopped) return Math.ceil(i * (this.interval / this.tokensPerInterval))
}
reset() {
this._isStopped = !1, this.tokens = this.bucketSize, this.tokensRemovedAt = [Date.now()], super.reset()
}
};
var j = new x("Flag"),
P = class extends I {
constructor(t, i) {
super(t, "div", "Flag");
this.parent = t;
this.hostname = i
}
async check() {
let t = !0;
try {
let i = localStorage.getItem(this.hostname);
if (i != null) {
let o = JSON.parse(i),
p = Date.now(),
w = o.time,
g = p - w,
h = 7 * 24 * 60 * 60 * 1e3;
g < h && (t = !1, this.onResponse(o))
}
} catch (i) {
throw j.error(`error while getting savedSTR for ${this.hostname}`, i), this.onError(), i
}
if (t) {
this.startLimiters();
let i = await this.waitForAvailableEndpoint();
await this.dnsRequest(i)
}
}
startLimiters() {
P.googleLimiter.isStopped === !0 && P.googleLimiter.start(), P.cloudFlareLimiter.isStopped === !0 && P.cloudFlareLimiter.start()
}
async waitForAvailableEndpoint() {
let t = await Promise.race([P.googleLimiter.awaitTokens(1).then(() => P.googleLimiter.tryRemoveTokens(1)).then(i => {
if (i) return `https://dns.google/resolve?name=${this.hostname}&type=A`
}), P.cloudFlareLimiter.awaitTokens(1).then(() => P.cloudFlareLimiter.tryRemoveTokens(1)).then(i => {
if (i) return `https://cloudflare-dns.com/dns-query?name=${this.hostname}&type=A`
})]);
return t ?? (j.info("we awaited tokens, but could not retrieve any.. restarting dnsRequest"), await this.waitForAvailableEndpoint())
}
async dnsRequest(t) {
try {
let o = await (await fetch(t, {
method: "GET",
headers: {
Accept: "application/dns-json"
}
})).json();
await this.handleDnsQueryResponse(o)
} catch (i) {