UNPKG

@stellar/stellar-sdk

Version:

A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.

839 lines (826 loc) 1.09 MB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.StellarSdk = {})); })(this, (function (exports) { 'use strict'; // src/client.ts async function prepareAxiosResponse(options, res) { const response = { config: options }; response.status = res.status; response.statusText = res.statusText; response.headers = res.headers; if (options.responseType === "stream") { response.data = res.body; return response; } return res[options.responseType || "text"]().then((data) => { if (options.transformResponse) { Array.isArray(options.transformResponse) ? options.transformResponse.map( (fn) => data = fn.call(options, data, res?.headers, res?.status) ) : data = options.transformResponse(data, res?.headers, res?.status); response.data = data; } else { response.data = data; response.data = JSON.parse(data); } }).catch(Object).then(() => response); } async function handleFetch(options, fetchOptions) { let res = null; if ("any" in AbortSignal) { const signals = []; if (options.timeout) { signals.push(AbortSignal.timeout(options.timeout)); } if (options.signal) { signals.push(options.signal); } if (signals.length > 0) { fetchOptions.signal = AbortSignal.any(signals); } } else { if (options.timeout) { fetchOptions.signal = AbortSignal.timeout(options.timeout); } } try { res = await fetch(options.url, fetchOptions); const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok; if (!ok) { return Promise.reject( new AxiosError( `Request failed with status code ${res?.status}`, [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(res?.status / 100) - 4], options, new Request(options.url, fetchOptions), await prepareAxiosResponse(options, res) ) ); } return await prepareAxiosResponse(options, res); } catch (error) { if (error.name === "AbortError" || error.name === "TimeoutError") { const isTimeoutError = error.name === "TimeoutError"; return Promise.reject( isTimeoutError ? new AxiosError( options.timeoutErrorMessage || `timeout of ${options.timeout} ms exceeded`, AxiosError.ECONNABORTED, options, request ) : new CanceledError(null, options) ); } return Promise.reject( new AxiosError( error.message, void 0, options, request, void 0 ) ); } } function buildURL(options) { let url = options.url || ""; if (options.baseURL && options.url) { url = options.url.replace(/^(?!.*\/\/)\/?/, `${options.baseURL}/`); } if (options.params && Object.keys(options.params).length > 0 && options.url) { url += (~options.url.indexOf("?") ? "&" : "?") + (options.paramsSerializer ? options.paramsSerializer(options.params) : new URLSearchParams(options.params)); } return url; } function mergeAxiosOptions(input, defaults) { const merged = { ...defaults, ...input }; if (defaults?.params && input?.params) { merged.params = { ...defaults?.params, ...input?.params }; } if (defaults?.headers && input?.headers) { merged.headers = new Headers(defaults.headers || {}); const headers = new Headers(input.headers || {}); headers.forEach((value, key) => { merged.headers.set(key, value); }); } return merged; } function mergeFetchOptions(input, defaults) { const merged = { ...defaults, ...input }; if (defaults?.headers && input?.headers) { merged.headers = new Headers(defaults.headers || {}); const headers = new Headers(input.headers || {}); headers.forEach((value, key) => { merged.headers.set(key, value); }); } return merged; } function defaultTransformer(data, headers) { const contentType = headers.get("content-type"); if (!contentType) { if (typeof data === "string") { headers.set("content-type", "text/plain"); } else if (data instanceof URLSearchParams) { headers.set("content-type", "application/x-www-form-urlencoded"); } else if (data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) { headers.set("content-type", "application/octet-stream"); } else if (typeof data === "object" && typeof data.append !== "function" && typeof data.text !== "function") { data = JSON.stringify(data); headers.set("content-type", "application/json"); } } else { if (contentType === "application/x-www-form-urlencoded" && !(data instanceof URLSearchParams)) { data = new URLSearchParams(data); } else if (contentType === "application/json" && typeof data === "object") { data = JSON.stringify(data); } } return data; } async function request(configOrUrl, config, defaults, method, interceptors, data) { if (typeof configOrUrl === "string") { config = config || {}; config.url = configOrUrl; } else config = configOrUrl || {}; const options = mergeAxiosOptions(config, defaults || {}); options.fetchOptions = options.fetchOptions || {}; options.timeout = options.timeout || 0; options.headers = new Headers(options.headers || {}); options.transformRequest = options.transformRequest ?? defaultTransformer; data = data || options.data; if (options.transformRequest && data) { Array.isArray(options.transformRequest) ? options.transformRequest.map( (fn) => data = fn.call(options, data, options.headers) ) : data = options.transformRequest(data, options.headers); } options.url = buildURL(options); options.method = method || options.method || "get"; if (interceptors && interceptors.request.handlers.length > 0) { const chain = interceptors.request.handlers.filter( (interceptor) => !interceptor?.runWhen || typeof interceptor.runWhen === "function" && interceptor.runWhen(options) ).flatMap((interceptor) => [interceptor.fulfilled, interceptor.rejected]); let result = options; for (let i = 0, len = chain.length; i < len; i += 2) { const onFulfilled = chain[i]; const onRejected = chain[i + 1]; try { if (onFulfilled) result = onFulfilled(result); } catch (error) { if (onRejected) onRejected?.(error); break; } } } const init = mergeFetchOptions( { method: options.method?.toUpperCase(), body: data, headers: options.headers, credentials: options.withCredentials ? "include" : void 0, signal: options.signal }, options.fetchOptions ); let resp = handleFetch(options, init); if (interceptors && interceptors.response.handlers.length > 0) { const chain = interceptors.response.handlers.flatMap((interceptor) => [ interceptor.fulfilled, interceptor.rejected ]); for (let i = 0, len = chain.length; i < len; i += 2) { resp = resp.then(chain[i], chain[i + 1]); } } return resp; } var AxiosInterceptorManager = class { handlers = []; constructor() { this.handlers = []; } use = (onFulfilled, onRejected, options) => { this.handlers.push({ fulfilled: onFulfilled, rejected: onRejected, runWhen: options?.runWhen }); return this.handlers.length - 1; }; eject = (id) => { if (this.handlers[id]) { this.handlers[id] = null; } }; clear = () => { this.handlers = []; }; }; function createAxiosInstance(defaults) { defaults = defaults || {}; const interceptors = { request: new AxiosInterceptorManager(), response: new AxiosInterceptorManager() }; const axios2 = (url, config) => request(url, config, defaults, void 0, interceptors); axios2.defaults = defaults; axios2.interceptors = interceptors; axios2.getUri = (config) => { const merged = mergeAxiosOptions(config || {}, defaults); return buildURL(merged); }; axios2.request = (config) => request(config, void 0, defaults, void 0, interceptors); ["get", "delete", "head", "options"].forEach((method) => { axios2[method] = (url, config) => request(url, config, defaults, method, interceptors); }); ["post", "put", "patch"].forEach((method) => { axios2[method] = (url, data, config) => request(url, config, defaults, method, interceptors, data); }); ["postForm", "putForm", "patchForm"].forEach((method) => { axios2[method] = (url, data, config) => { config = config || {}; config.headers = new Headers(config.headers || {}); config.headers.set("content-type", "application/x-www-form-urlencoded"); return request( url, config, defaults, method.replace("Form", ""), interceptors, data ); }; }); return axios2; } var AxiosError = class extends Error { config; code; request; response; status; isAxiosError; constructor(message, code, config, request2, response) { super(message); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } else { this.stack = new Error().stack; } this.name = "AxiosError"; this.code = code; this.config = config; this.request = request2; this.response = response; this.isAxiosError = true; } static ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE"; static ERR_BAD_OPTION = "ERR_BAD_OPTION"; static ERR_NETWORK = "ERR_NETWORK"; static ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE"; static ERR_BAD_REQUEST = "ERR_BAD_REQUEST"; static ERR_INVALID_URL = "ERR_INVALID_URL"; static ERR_CANCELED = "ERR_CANCELED"; static ECONNABORTED = "ECONNABORTED"; static ETIMEDOUT = "ETIMEDOUT"; }; var CanceledError = class extends AxiosError { constructor(message, config, request2) { super( !message ? "canceled" : message, AxiosError.ERR_CANCELED, config, request2 ); this.name = "CanceledError"; } }; var axios = createAxiosInstance(); axios.create = (defaults) => createAxiosInstance(defaults); // src/index.ts var src_default = axios; class CancelToken { promise; reason; throwIfRequested() { if (this.reason) { throw new Error(this.reason); } } constructor(executor) { let resolvePromise; this.promise = new Promise((resolve) => { resolvePromise = resolve; }); executor((reason) => { this.reason = reason; resolvePromise(); }); } } const CANCELED_MARKER = /* @__PURE__ */ Symbol.for("@stellar/stellar-sdk.canceled"); function makeCanceledError(reason) { const err = new Error(reason || "Request canceled"); err[CANCELED_MARKER] = true; return err; } class InterceptorManager { handlers = []; use(fulfilled, rejected) { this.handlers.push({ fulfilled, rejected }); return this.handlers.length - 1; } eject(id) { if (this.handlers[id]) { this.handlers[id] = null; } } forEach(fn) { this.handlers.forEach((h) => { if (h !== null) { fn(h); } }); } } function getFormConfig(config) { const formConfig = config || {}; formConfig.headers = new Headers(formConfig.headers || {}); formConfig.headers.set("Content-Type", "application/x-www-form-urlencoded"); return formConfig; } function mergeWithDefaults(defaults, config) { if (!config) return { ...defaults }; const merged = { ...defaults, ...config }; if (defaults?.headers !== void 0 || config.headers !== void 0) { const headers = new Headers(defaults?.headers || {}); new Headers(config.headers || {}).forEach((v, k) => { headers.set(k, v); }); merged.headers = headers; } if (defaults?.params !== void 0 || config.params !== void 0) { merged.params = { ...defaults?.params || {}, ...config.params || {} }; } return merged; } function buildBoundedUrl(config) { let url = config.url || ""; if (config.baseURL && url && !/^https?:\/\//i.test(url)) { url = url.replace(/^\/?/, `${config.baseURL.replace(/\/$/, "")}/`); } if (config.params && Object.keys(config.params).length > 0) { const qs = new URLSearchParams( config.params ).toString(); url += (url.includes("?") ? "&" : "?") + qs; } return url; } function encodeRequestBody(data, headers) { if (data === void 0 || data === null) return void 0; if (typeof data === "string") return data; if (data instanceof URLSearchParams) { if (!headers.has("content-type")) { headers.set("content-type", "application/x-www-form-urlencoded"); } return data; } if (data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) { if (!headers.has("content-type")) { headers.set("content-type", "application/octet-stream"); } return data; } if (typeof FormData !== "undefined" && data instanceof FormData) { return data; } if (!headers.has("content-type")) { headers.set("content-type", "application/json"); } return JSON.stringify(data); } async function readBodyBounded(response, maxContentLength) { if (maxContentLength !== void 0) { const headerLen = response.headers.get("content-length"); if (headerLen && Number(headerLen) > maxContentLength) { throw new Error(`maxContentLength size of ${maxContentLength} exceeded`); } } if (!response.body) return new Uint8Array(0); const reader = response.body.getReader(); const chunks = []; let total = 0; while (true) { const { done, value } = await reader.read(); if (done) break; if (value) { total += value.byteLength; if (maxContentLength !== void 0 && total > maxContentLength) { await reader.cancel(); throw new Error( `maxContentLength size of ${maxContentLength} exceeded` ); } chunks.push(value); } } const out = new Uint8Array(total); let offset = 0; for (const c of chunks) { out.set(c, offset); offset += c.byteLength; } return out; } function createTimeoutSignal(ms) { if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") { return AbortSignal.timeout(ms); } const controller = new AbortController(); setTimeout(() => { const err = new Error("Timeout"); err.name = "TimeoutError"; controller.abort(err); }, ms); return controller.signal; } function composeSignals(signals) { if (signals.length === 0) return void 0; if (signals.length === 1) return signals[0]; if (typeof AbortSignal !== "undefined" && typeof AbortSignal.any === "function") { return AbortSignal.any(signals); } const controller = new AbortController(); for (const s of signals) { if (s.aborted) { controller.abort(s.reason); break; } s.addEventListener("abort", () => controller.abort(s.reason), { once: true }); } return controller.signal; } function canInspectManualRedirects() { return typeof process !== "undefined" && !!process.versions && !!process.versions.node; } function applyRedirectSemantics(init, status) { if (status === 307 || status === 308) return init; const next = { ...init, method: "GET", body: void 0 }; const headers = new Headers(init.headers || {}); headers.delete("content-type"); headers.delete("content-length"); headers.delete("transfer-encoding"); next.headers = headers; return next; } function stripCrossOriginAuth(init, fromUrl, toUrl) { let sameOrigin; try { sameOrigin = new URL(fromUrl).origin === new URL(toUrl).origin; } catch { sameOrigin = false; } if (sameOrigin) return init; const headers = new Headers(init.headers || {}); headers.delete("authorization"); headers.delete("proxy-authorization"); headers.delete("cookie"); return { ...init, headers }; } function buildHttpError(response, config, data) { const err = new Error( `Request failed with status code ${response.status}` ); err.response = { status: response.status, statusText: response.statusText, headers: response.headers, data, config }; return err; } async function boundedFetchAdapter(config) { const { maxRedirects, maxContentLength, timeout } = config; const signals = []; if (timeout && timeout > 0) { signals.push(createTimeoutSignal(timeout)); } const signal = composeSignals(signals); const managedRedirects = maxRedirects !== void 0; const canManage = canInspectManualRedirects(); let redirect; if (!managedRedirects) { redirect = "follow"; } else if (canManage) { redirect = "manual"; } else if (maxRedirects === 0) { redirect = "error"; } else { redirect = "follow"; } const headers = new Headers(config.headers || {}); const body = encodeRequestBody(config.data, headers); let currentInit = { ...config.fetchOptions, method: (config.method || "get").toUpperCase(), headers, body, redirect, ...signal ? { signal } : {} }; let currentUrl = buildBoundedUrl(config); let redirectsRemaining = maxRedirects ?? 0; let response; while (true) { try { response = await fetch(currentUrl, currentInit); } catch (err) { if (err?.name === "TimeoutError") { throw new Error(`timeout of ${config.timeout}ms exceeded`); } throw err; } const isManualRedirectResponse = redirect === "manual" && response.status >= 300 && response.status < 400; if (!isManualRedirectResponse) break; if (redirectsRemaining <= 0) { if (maxRedirects === 0) throw buildHttpError(response, config); throw new Error("Maximum number of redirects exceeded"); } const location = response.headers.get("location"); if (!location) break; const nextUrl = new URL(location, currentUrl).toString(); currentInit = applyRedirectSemantics(currentInit, response.status); currentInit = stripCrossOriginAuth(currentInit, currentUrl, nextUrl); currentUrl = nextUrl; redirectsRemaining -= 1; } if (!response.ok) { let errBody; try { const errBytes = await readBodyBounded(response, maxContentLength); const errText = new TextDecoder().decode(errBytes); try { errBody = JSON.parse(errText); } catch { errBody = errText; } } catch (readErr) { throw readErr; } throw buildHttpError(response, config, errBody); } const bytes = await readBodyBounded(response, maxContentLength); const text = new TextDecoder().decode(bytes); let data = text; try { data = JSON.parse(text); } catch { } return { data, headers: response.headers, config, status: response.status, statusText: response.statusText }; } function createFetchClient(fetchConfig = {}) { const defaults = { ...fetchConfig, headers: fetchConfig.headers || {} }; const axiosStatic = src_default.default ?? src_default; const instance = axiosStatic.create(defaults); const requestInterceptors = new InterceptorManager(); const responseInterceptors = new InterceptorManager(); const httpClient = { interceptors: { request: requestInterceptors, response: responseInterceptors }, defaults: { ...defaults, adapter: (config) => { if (config.maxRedirects !== void 0 || config.maxContentLength !== void 0) { return boundedFetchAdapter(config); } return instance.request(config); } }, create(config) { return createFetchClient({ ...this.defaults, ...config }); }, makeRequest(config) { return new Promise((resolve, reject) => { function processRequest(finalConfig, res, rej) { const adapter = finalConfig.adapter || this.defaults.adapter; if (!adapter) { throw new Error("No adapter available"); } let responsePromise = adapter(finalConfig).then((axiosResponse) => { const httpClientResponse = { data: axiosResponse.data, headers: axiosResponse.headers, config: axiosResponse.config, status: axiosResponse.status, statusText: axiosResponse.statusText }; return httpClientResponse; }); if (responseInterceptors.handlers.length > 0) { const chain = responseInterceptors.handlers.filter( (interceptor) => interceptor !== null ).flatMap((interceptor) => [ interceptor.fulfilled, interceptor.rejected ]); for (let i = 0, len = chain.length; i < len; i += 2) { responsePromise = responsePromise.then( (response) => { const fulfilledInterceptor = chain[i]; if (typeof fulfilledInterceptor === "function") { return fulfilledInterceptor(response); } return response; }, (error) => { const rejectedInterceptor = chain[i + 1]; if (typeof rejectedInterceptor === "function") { return rejectedInterceptor(error); } throw error; } ).then((interceptedResponse) => interceptedResponse); } } responsePromise.then(res).catch(rej); } const abortController = new AbortController(); config.signal = abortController.signal; if (config.cancelToken) { const { cancelToken } = config; cancelToken.promise.then(() => { abortController.abort(); reject(makeCanceledError(cancelToken.reason)); }); } const modifiedConfig = config; if (requestInterceptors.handlers.length > 0) { const chain = requestInterceptors.handlers.filter( (interceptor) => interceptor !== null ).flatMap((interceptor) => [ interceptor.fulfilled, interceptor.rejected ]); let configPromise = Promise.resolve(modifiedConfig); for (let i = 0, len = chain.length; i < len; i += 2) { configPromise = configPromise.then( chain[i], chain[i + 1] ); } configPromise.then((resolvedConfig) => { processRequest.call(this, resolvedConfig, resolve, reject); }).catch(reject); return; } processRequest.call(this, modifiedConfig, resolve, reject); }); }, get(url, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "get" }); }, delete(url, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "delete" }); }, head(url, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "head" }); }, options(url, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "options" }); }, post(url, data, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "post", data }); }, put(url, data, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "put", data }); }, patch(url, data, config) { return this.makeRequest({ ...mergeWithDefaults(this.defaults, config), url, method: "patch", data }); }, postForm(url, data, config) { const formConfig = getFormConfig(config); return this.makeRequest({ ...mergeWithDefaults(this.defaults, formConfig), url, method: "post", data }); }, putForm(url, data, config) { const formConfig = getFormConfig(config); return this.makeRequest({ ...mergeWithDefaults(this.defaults, formConfig), url, method: "put", data }); }, patchForm(url, data, config) { const formConfig = getFormConfig(config); return this.makeRequest({ ...mergeWithDefaults(this.defaults, formConfig), url, method: "patch", data }); }, CancelToken, isCancel: (value) => value instanceof Error && value[CANCELED_MARKER] === true }; return httpClient; } const fetchClient = createFetchClient(); class NetworkError extends Error { /** Response details, received from the Horizon server. */ response; constructor(message, response) { super(message); this.response = response; } /** * Returns the error response sent by the Horizon server. * @returns Response details, received from the Horizon server. */ getResponse() { return this.response; } } class NotFoundError extends NetworkError { } class BadRequestError extends NetworkError { } class BadResponseError extends NetworkError { } function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var xdr$1 = {exports: {}}; /*! For license information please see xdr.js.LICENSE.txt */ var xdr = xdr$1.exports; var hasRequiredXdr; function requireXdr () { if (hasRequiredXdr) return xdr$1.exports; hasRequiredXdr = 1; (function (module, exports) { !function(t,e){module.exports=e();}(xdr,()=>(()=>{var t={348(t,e,r){const n=r(928);t.exports=n;},350(t,e){e.byteLength=function(t){var e=f(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,o=f(t),s=o[0],u=o[1],h=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,u)),a=0,c=u>0?s-4:s;for(r=0;r<c;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],h[a++]=e>>16&255,h[a++]=e>>8&255,h[a++]=255&e;2===u&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,h[a++]=255&e);1===u&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,h[a++]=e>>8&255,h[a++]=255&e);return h},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],s=16383,f=0,u=n-i;f<u;f+=s)o.push(h(t,f,f+s>u?u:f+s));1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"="));return o.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)r[s]=o[s],n[o.charCodeAt(s)]=s;function f(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return -1===r&&(r=e),[r,r===e?0:4-r%4]}function u(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function h(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),i.push(u(n));return i.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;},686(t,e,r){const n=r(350),i=r(947),o="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=u,e.IS=50;const s=2147483647;function f(t){if(t>s)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return c(t)}return h(t,e,r)}function h(t,e,r){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|d(t,e);let n=f(r);const i=n.write(t,e);i!==r&&(n=n.slice(0,i));return n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(J(t,Uint8Array)){const e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return l(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(J(t,ArrayBuffer)||t&&J(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(J(t,SharedArrayBuffer)||t&&J(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return u.from(n,e,r);const i=function(t){if(u.isBuffer(t)){const e=0|g(t.length),r=f(e);return 0===r.length||t.copy(r,0,0,e),r}if(void 0!==t.length)return "number"!=typeof t.length||W(t.length)?f(0):l(t);if("Buffer"===t.type&&Array.isArray(t.data))return l(t.data)}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function a(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function c(t){return a(t),f(t<0?0:0|g(t))}function l(t){const e=t.length<0?0:0|g(t.length),r=f(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,u.prototype),n}function g(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function d(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||J(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&true===arguments[2];if(!n&&0===r)return 0;let i=false;for(;;)switch(e){case "ascii":case "latin1":case "binary":return r;case "utf8":case "utf-8":return H(t).length;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return 2*r;case "hex":return r>>>1;case "base64":return G(t).length;default:if(i)return n?-1:H(t).length;e=(""+e).toLowerCase(),i=true;}}function w(t,e,r){let n=false;if((void 0===e||e<0)&&(e=0),e>this.length)return "";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return "";if((r>>>=0)<=(e>>>=0))return "";for(t||(t="utf8");;)switch(t){case "hex":return L(this,e,r);case "utf8":case "utf-8":return I(this,e,r);case "ascii":return $(this,e,r);case "latin1":case "binary":return T(this,e,r);case "base64":return x(this,e,r);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return R(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=true;}}function y(t,e,r){const n=t[e];t[e]=t[r],t[r]=n;}function m(t,e,r,n,i){if(0===t.length)return -1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),W(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return -1;r=t.length-1;}else if(r<0){if(!i)return -1;r=0;}if("string"==typeof e&&(e=u.from(e,n)),u.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,i){let o,s=1,f=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return -1;s=2,f/=2,u/=2,r/=2;}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){let n=-1;for(o=r;o<f;o++)if(h(t,o)===h(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*s}else -1!==n&&(o-=o-n),n=-1;}else for(r+u>f&&(r=f-u),o=r;o>=0;o--){let r=true;for(let n=0;n<u;n++)if(h(t,o+n)!==h(e,n)){r=false;break}if(r)return o}return -1}function _(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let s;for(n>o/2&&(n=o/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(W(n))return s;t[r+s]=n;}return s}function E(t,e,r,n){return Y(H(e,t.length-r),t,r,n)}function B(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function v(t,e,r,n){return Y(G(e),t,r,n)}function A(t,e,r,n){return Y(function(t,e){let r,n,i;const o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function x(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function I(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,s=e>239?4:e>223?3:e>191?2:1;if(i+s<=r){let r,n,f,u;switch(s){case 1:e<128&&(o=e);break;case 2:r=t[i+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(o=u));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=t[i+1],n=t[i+2],f=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&f)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&f,u>65535&&u<1114112&&(o=u));}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s;}return function(t){const e=t.length;if(e<=U)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=U));return r}(n)}u.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return false}}(),u.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(u.prototype,"parent",{enumerable:true,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:true,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,r){return h(t,e,r)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,r){return function(t,e,r){return a(t),t<=0?f(t):void 0!==e?"string"==typeof r?f(t).fill(e,r):f(t).fill(e):f(t)}(t,e,r)},u.allocUnsafe=function(t){return c(t)},u.allocUnsafeSlow=function(t){return c(t)},u.isBuffer=function(t){return null!=t&&true===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(J(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),J(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "latin1":case "binary":case "base64":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return true;default:return false}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=u.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(J(e,Uint8Array))i+e.length>n.length?(u.isBuffer(e)||(e=u.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else {if(!u.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i);}i+=e.length;}return n},u.byteLength=d,u.prototype._isBuffer=true,u.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)y(this,e,e+1);return this},u.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},u.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},u.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?I(this,0,t):w.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){let t="";const r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},o&&(u.prototype[o]=u.prototype.inspect),u.prototype.compare=function(t,e,r,n,i){if(J(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return -1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0);const f=Math.min(o,s),h=this.slice(n,i),a=t.slice(e,r);for(let t=0;t<f;++t)if(h[t]!==a[t]){o=h[t],s=a[t];break}return o<s?-1:s<o?1:0},u.prototype.includes=function(t,e,r){return -1!==this.indexOf(t,e,r)},u.prototype.indexOf=function(t,e,r){return m(this,t,e,r,true)},u.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,false)},u.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else {if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0);}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=false;for(;;)switch(n){case "hex":return _(this,t,e,r);case "utf8":case "utf-8":return E(this,t,e,r);case "ascii":case "latin1":case "binary":return B(this,t,e,r);case "base64":return v(this,t,e,r);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return A(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=true;}},u.prototype.toJSON=function(){return {type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const U=4096;function $(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function T(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function L(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function R(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function O(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function D(t,e,r,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function N(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function S(t,e,r,n,i){j(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function V(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function M(t,e,r,n,o){return e=+e,r>>>=0,o||V(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function F(t,e,r,n,o){return e=+e,r>>>=0,o||V(t,0,r,8),i.write(t,e,r,n,52,8),r+8}u.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,u.prototype),n},u.prototype.readUintLE=u.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},u.prototype.readUint8=u.prototype.readUInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),this[t]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readBigUInt64LE=Z(function(t){k(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),u.prototype.readBigUInt64BE=Z(function(t){k(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return (BigInt(n)<<BigInt(32))+BigInt(i)}),u.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},u.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},u.prototype.readInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){t>>>=0,e||O(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){t>>>=0,e||O(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readBigInt64LE=Z(function(t){k(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return (BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)}),u.prototype.readBigInt64BE=Z(function(t){k(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return (BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)}),u.prototype.readFloatLE=function(t,e){return t>>>=0,e||O(t,4,this.length),i.read(this,t,true,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||O(t,4,this.length),i.read(this,t,false,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||O(t,8,this.length),i.read(this,t,true,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||O(t,8,this.length),i.read(this,t,false,52,8)},u.prototype.writeUintLE=u.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){D(this,t,e,r,Math.pow(2,8*r)-1,0);}let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){D(this,t,e,r,Math.pow(2,8*r)-1,0);}let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},u.prototype.writeUint8=u.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,1,255,0),this[e]=255&t,e+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeBigUInt64LE=Z(function(t,e=0){return N(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeBigUInt64BE=Z(function(t,e=0){return S(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);D(this,t,e,r,n-1,-n);}let i=0,o=1,s=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===s&&0!==this[e+i-1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);D(this,t,e,r,n-1,-n);}let i=r-1,o=1,s=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===s&&0!==this[e+i+1]&&(s=1),this[e+i]=(t/o|0)-s&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeBigInt64LE=Z(function(t,e=0){return N(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeBigInt64BE=Z(function(t,e=0){return S(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),u.prototype.writeFloatLE=function(t,e,r){return M(this,t,e,true,r)},u.prototype.writeFloatBE=function(t,e,r){return M(this,t,e,false,r)},u.prototype.writeDoubleLE=function(t,e,r){return F(this,t,e,true,r)},u.prototype.writeDoubleBE=function(t,e,r){return F(this,t,e,false,r)},u.prototype.copy=function(t,e,r,n){if(!u.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,t