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ers-web@1.0.0/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ethers-workers-web@1.0.0/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n    return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n    function verb(n) { return function (v) { return step([n, v]); }; }\n    function step(op) {\n        if (f) throw new TypeError(\"Generator is already executing.\");\n        while (_) try {\n            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;\n            if (y = 0, t) op = [op[0] & 2, t.value];\n            switch (op[0]) {\n                case 0: case 1: t = op; break;\n                case 4: _.label++; return { value: op[1], done: false };\n                case 5: _.label++; y = op[1]; op = [0]; continue;\n                case 7: op = _.ops.pop(); _.trys.pop(); continue;\n                default:\n                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n                    if (t[2]) _.ops.pop();\n                    _.trys.pop(); continue;\n            }\n            op = body.call(thisArg, _);\n        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n    }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.poll = exports.fetchJson = exports._fetchData = void 0;\nvar base64_1 = require(\"@ethersproject/base64\");\nvar bytes_1 = require(\"@ethersproject/bytes\");\nvar properties_1 = require(\"@ethersproject/properties\");\nvar strings_1 = require(\"@ethersproject/strings\");\nvar logger_1 = require(\"@ethersproject/logger\");\nvar _version_1 = require(\"./_version\");\nvar logger = new logger_1.Logger(_version_1.version);\nvar geturl_1 = require(\"./geturl\");\nfunction staller(duration) {\n    return new Promise(function (resolve) {\n        setTimeout(resolve, duration);\n    });\n}\nfunction bodyify(value, type) {\n    if (value == null) {\n        return null;\n    }\n    if (typeof (value) === \"string\") {\n        return value;\n    }\n    if ((0, bytes_1.isBytesLike)(value)) {\n        if (type && (type.split(\"/\")[0] === \"text\" || type.split(\";\")[0].trim() === \"application/json\")) {\n            try {\n                return (0, strings_1.toUtf8String)(value);\n            }\n            catch (error) { }\n            ;\n        }\n        return (0, bytes_1.hexlify)(value);\n    }\n    return value;\n}\n// This API is still a work in progress; the future changes will likely be:\n// - ConnectionInfo => FetchDataRequest<T = any>\n// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }\n//   - If string => text/plain, Uint8Array => application/octet-stream (if content-type unspecified)\n// - FetchDataRequest.processFunc = (body: Uint8Array, response: FetchDataResponse) => T\n// For this reason, it should be considered internal until the API is finalized\nfunction _fetchData(connection, body, processFunc) {\n    // How many times to retry in the event of a throttle\n    var attemptLimit = (typeof (connection) === \"object\" && connection.throttleLimit != null) ? connection.throttleLimit : 12;\n    logger.assertArgument((attemptLimit > 0 && (attemptLimit % 1) === 0), \"invalid connection throttle limit\", \"connection.throttleLimit\", attemptLimit);\n    var throttleCallback = ((typeof (connection) === \"object\") ? connection.throttleCallback : null);\n    var throttleSlotInterval = ((typeof (connection) === \"object\" && typeof (connection.throttleSlotInterval) === \"number\") ? connection.throttleSlotInterval : 100);\n    logger.assertArgument((throttleSlotInterval > 0 && (throttleSlotInterval % 1) === 0), \"invalid connection throttle slot interval\", \"connection.throttleSlotInterval\", throttleSlotInterval);\n    var headers = {};\n    var url = null;\n    // @TODO: Allow ConnectionInfo to override some of these values\n    var options = {\n        method: \"GET\",\n    };\n    var allow304 = false;\n    var timeout = 2 * 60 * 1000;\n    if (typeof (connection) === \"string\") {\n        url = connection;\n    }\n    else if (typeof (connection) === \"object\") {\n        if (connection == null || connection.url == null) {\n            logger.throwArgumentError(\"missing URL\", \"connection.url\", connection);\n        }\n        url = connection.url;\n        if (typeof (connection.timeout) === \"number\" && connection.timeout > 0) {\n            timeout = connection.timeout;\n        }\n        if (connection.headers) {\n            for (var key in connection.headers) {\n                headers[key.toLowerCase()] = { key: key, value: String(connection.headers[key]) };\n                if ([\"if-none-match\", \"if-modified-since\"].indexOf(key.toLowerCase()) >= 0) {\n                    allow304 = true;\n                }\n            }\n        }\n        options.allowGzip = !!connection.allowGzip;\n        if (connection.user != null && connection.password != null) {\n            if (url.substring(0, 6) !== \"https:\" && connection.allowInsecureAuthentication !== true) {\n                logger.throwError(\"basic authentication requires a secure https url\", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: \"url\", url: url, user: connection.user, password: \"[REDACTED]\" });\n            }\n            var authorization = connection.user + \":\" + connection.password;\n            headers[\"authorization\"] = {\n                key: \"Authorization\",\n                value: \"Basic \" + (0, base64_1.encode)((0, strings_1.toUtf8Bytes)(authorization))\n            };\n        }\n    }\n    var reData = new RegExp(\"^data:([a-z0-9-]+/[a-z0-9-]+);base64,(.*)$\", \"i\");\n    var dataMatch = ((url) ? url.match(reData) : null);\n    if (dataMatch) {\n        try {\n            var response = {\n                statusCode: 200,\n                statusMessage: \"OK\",\n                headers: { \"content-type\": dataMatch[1] },\n                body: (0, base64_1.decode)(dataMatch[2])\n            };\n            var result = response.body;\n            if (processFunc) {\n                result = processFunc(response.body, response);\n            }\n            return Promise.resolve(result);\n        }\n        catch (error) {\n            logger.throwError(\"processing response error\", logger_1.Logger.errors.SERVER_ERROR, {\n                body: bodyify(dataMatch[1], dataMatch[2]),\n                error: error,\n                requestBody: null,\n                requestMethod: \"GET\",\n                url: url\n            });\n        }\n    }\n    if (body) {\n        options.method = \"POST\";\n        options.body = body;\n        if (headers[\"content-type\"] == null) {\n            headers[\"content-type\"] = { key: \"Content-Type\", value: \"application/octet-stream\" };\n        }\n        if (headers[\"content-length\"] == null) {\n            headers[\"content-length\"] = { key: \"Content-Length\", value: String(body.length) };\n        }\n    }\n    var flatHeaders = {};\n    Object.keys(headers).forEach(function (key) {\n        var header = headers[key];\n        flatHeaders[header.key] = header.value;\n    });\n    options.headers = flatHeaders;\n    var runningTimeout = (function () {\n        var timer = null;\n        var promise = new Promise(function (resolve, reject) {\n            if (timeout) {\n                timer = setTimeout(function () {\n                    if (timer == null) {\n                        return;\n                    }\n                    timer = null;\n                    reject(logger.makeError(\"timeout\", logger_1.Logger.errors.TIMEOUT, {\n                        requestBody: bodyify(options.body, flatHeaders[\"content-type\"]),\n                        requestMethod: options.method,\n                        timeout: timeout,\n                        url: url\n                    }));\n                }, timeout);\n            }\n        });\n        var cancel = function () {\n            if (timer == null) {\n                return;\n            }\n            clearTimeout(timer);\n            timer = null;\n        };\n        return { promise: promise, cancel: cancel };\n    })();\n    var runningFetch = (function () {\n        return __awaiter(this, void 0, void 0, function () {\n            var attempt, response, location_1, tryAgain, stall, retryAfter, error_1, body_1, result, error_2, tryAgain, timeout_1;\n            return __generator(this, function (_a) {\n                switch (_a.label) {\n                    case 0:\n                        attempt = 0;\n                        _a.label = 1;\n                    case 1:\n                        if (!(attempt < attemptLimit)) return [3 /*break*/, 20];\n                        response = null;\n                        _a.label = 2;\n                    case 2:\n                        _a.trys.push([2, 9, , 10]);\n                        return [4 /*yield*/, (0, geturl_1.getUrl)(url, options)];\n                    case 3:\n                        response = _a.sent();\n                        if (!(attempt < attemptLimit)) return [3 /*break*/, 8];\n                        if (!(response.statusCode === 301 || response.statusCode === 302)) return [3 /*break*/, 4];\n                        location_1 = response.headers.location || \"\";\n                        if (options.method === \"GET\" && location_1.match(/^https:/)) {\n                            url = response.headers.location;\n                            return [3 /*break*/, 19];\n                        }\n                        return [3 /*break*/, 8];\n                    case 4:\n                        if (!(response.statusCode === 429)) return [3 /*break*/, 8];\n                        tryAgain = true;\n                        if (!throttleCallback) return [3 /*break*/, 6];\n                        return [4 /*yield*/, throttleCallback(attempt, url)];\n                    case 5:\n                        tryAgain = _a.sent();\n                        _a.label = 6;\n                    case 6:\n                        if (!tryAgain) return [3 /*break*/, 8];\n                        stall = 0;\n                        retryAfter = response.headers[\"retry-after\"];\n                        if (typeof (retryAfter) === \"string\" && retryAfter.match(/^[1-9][0-9]*$/)) {\n                            stall = parseInt(retryAfter) * 1000;\n                        }\n                        else {\n                            stall = throttleSlotInterval * parseInt(String(Math.random() * Math.pow(2, attempt)));\n                        }\n                        //console.log(\"Stalling 429\");\n                        return [4 /*yield*/, staller(stall)];\n                    case 7:\n                        //console.log(\"Stalling 429\");\n                        _a.sent();\n                        return [3 /*break*/, 19];\n                    case 8: return [3 /*break*/, 10];\n                    case 9:\n                        error_1 = _a.sent();\n                        response = error_1.response;\n                        if (response == null) {\n                            runningTimeout.cancel();\n                            logger.throwError(\"missing response\", logger_1.Logger.errors.SERVER_ERROR, {\n                                requestBody: bodyify(options.body, flatHeaders[\"content-type\"]),\n                                requestMethod: options.method,\n                                serverError: error_1,\n                                url: url\n                            });\n                        }\n                        return [3 /*break*/, 10];\n                    case 10:\n                        body_1 = response.body;\n                        if (allow304 && response.statusCode === 304) {\n                            body_1 = null;\n                        }\n                        else if (response.statusCode < 200 || response.statusCode >= 300) {\n                            runningTimeout.cancel();\n                            logger.throwError(\"bad response\", logger_1.Logger.errors.SERVER_ERROR, {\n                                status: response.statusCode,\n                                headers: response.headers,\n                                body: bodyify(body_1, ((response.headers) ? response.headers[\"content-type\"] : null)),\n                                requestBody: bodyify(options.body, flatHeaders[\"content-type\"]),\n                                requestMethod: options.method,\n                                url: url\n                            });\n                        }\n                        if (!processFunc) return [3 /*break*/, 18];\n                        _a.label = 11;\n                    case 11:\n                        _a.trys.push([11, 13, , 18]);\n                        return [4 /*yield*/, processFunc(body_1, response)];\n                    case 12:\n                        result = _a.sent();\n                        runningTimeout.cancel();\n                        return [2 /*return*/, result];\n                    case 13:\n                        error_2 = _a.sent();\n                        if (!(error_2.throttleRetry && attempt < attemptLimit)) return [3 /*break*/, 17];\n                        tryAgain = true;\n                        if (!throttleCallback) return [3 /*break*/, 15];\n                        return [4 /*yield*/, throttleCallback(attempt, url)];\n                    case 14:\n                        tryAgain = _a.sent();\n                        _a.label = 15;\n                    case 15:\n                        if (!tryAgain) return [3 /*break*/, 17];\n                        timeout_1 = throttleSlotInterval * parseInt(String(Math.random() * Math.pow(2, attempt)));\n                        //console.log(\"Stalling callback\");\n                        return [4 /*yield*/, staller(timeout_1)];\n                    case 16:\n                        //console.log(\"Stalling callback\");\n                        _a.sent();\n                        return [3 /*break*/, 19];\n                    case 17:\n                        runningTimeout.cancel();\n                        logger.throwError(\"processing response error\", logger_1.Logger.errors.SERVER_ERROR, {\n                            body: bodyify(body_1, ((response.headers) ? response.headers[\"content-type\"] : null)),\n                            error: error_2,\n                            requestBody: bodyify(options.body, flatHeaders[\"content-type\"]),\n                            requestMethod: options.method,\n                            url: url\n                        });\n                        return [3 /*break*/, 18];\n                    case 18:\n                        runningTimeout.cancel();\n                        // If we had a processFunc, it either returned a T or threw above.\n                        // The \"body\" is now a Uint8Array.\n                        return [2 /*return*/, body_1];\n                    case 19:\n                        attempt++;\n                        return [3 /*break*/, 1];\n                    case 20: return [2 /*return*/, logger.throwError(\"failed response\", logger_1.Logger.errors.SERVER_ERROR, {\n                            requestBody: bodyify(options.body, flatHeaders[\"content-type\"]),\n                            requestMethod: options.method,\n                            url: url\n                        })];\n                }\n            });\n        });\n    })();\n    return Promise.race([runningTimeout.promise, runningFetch]);\n}\nexports._fetchData = _fetchData;\nfunction fetchJson(connection, json, processFunc) {\n    var processJsonFunc = function (value, response) {\n        var result = null;\n        if (value != null) {\n            try {\n                result = JSON.parse((0, strings_1.toUtf8String)(value));\n            }\n            catch (error) {\n                logger.throwError(\"invalid JSON\", logger_1.Logger.errors.SERVER_ERROR, {\n                    body: value,\n                    error: error\n                });\n            }\n        }\n        if (processFunc) {\n            result = processFunc(result, response);\n        }\n        return result;\n    };\n    // If we have json to send, we must\n    // - add content-type of application/json (unless already overridden)\n    // - convert the json to bytes\n    var body = null;\n    if (json != null) {\n        body = (0, strings_1.toUtf8Bytes)(json);\n        // Create a connection with the content-type set for JSON\n        var updated = (typeof (connection) === \"string\") ? ({ url: connection }) : (0, properties_1.shallowCopy)(connection);\n        if (updated.headers) {\n            var hasContentType = (Object.keys(updated.headers).filter(function (k) { return (k.toLowerCase() === \"content-type\"); }).length) !== 0;\n            if (!hasContentType) {\n                updated.headers = (0, properties_1.shallowCopy)(updated.headers);\n                updated.headers[\"content-type\"] = \"application/json\";\n            }\n        }\n        else {\n            updated.headers = { \"content-type\": \"application/json\" };\n        }\n        connection = updated;\n    }\n    return _fetchData(connection, body, processJsonFunc);\n}\nexports.fetchJson = fetchJson;\nfunction poll(func, options) {\n    if (!options) {\n        options = {};\n    }\n    options = (0, properties_1.shallowCopy)(options);\n    if (options.floor == null) {\n        options.floor = 0;\n    }\n    if (options.ceiling == null) {\n        options.ceiling = 10000;\n    }\n    if (options.interval == null) {\n        options.interval = 250;\n    }\n    return new Promise(function (resolve, reject) {\n        var timer = null;\n        var done = false;\n        // Returns true if cancel was successful. Unsuccessful cancel means we're already done.\n        var cancel = function () {\n            if (done) {\n                return false;\n            }\n            done = true;\n            if (timer) {\n                clearTimeout(timer);\n            }\n            return true;\n        };\n        if (options.timeout) {\n            timer = setTimeout(function () {\n                if (cancel()) {\n                    reject(new Error(\"timeout\"));\n                }\n            }, options.timeout);\n        }\n        var retryLimit = options.retryLimit;\n        var attempt = 0;\n        function check() {\n            return func().then(function (result) {\n                // If we have a result, or are allowed null then we're done\n                if (result !== undefined) {\n                    if (cancel()) {\n                        resolve(result);\n                    }\n                }\n                else if (options.oncePoll) {\n                    options.oncePoll.once(\"poll\", check);\n                }\n                else if (options.onceBlock) {\n                    options.onceBlock.once(\"block\", check);\n                    // Otherwise, exponential back-off (up to 10s) our next request\n                }\n                else if (!done) {\n                    attempt++;\n                    if (attempt > retryLimit) {\n                        if (cancel()) {\n                            reject(new Error(\"retry limit reached\"));\n                        }\n                        return;\n                    }\n                    var timeout = options.interval * parseInt(String(Math.random() * Math.pow(2, attempt)));\n                    if (timeout < options.floor) {\n                        timeout = options.floor;\n                    }\n                    if (timeout > options.ceiling) {\n                        timeout = options.ceiling;\n                    }\n                    setTimeout(check, timeout);\n                }\n                return null;\n            }, function (error) {\n                if (cancel()) {\n                    reject(error);\n                }\n            });\n        }\n        check();\n    });\n}\nexports.poll = poll;\n"]}