UNPKG

@borderlessdev/filecoin-storage-sdk

Version:

Comprehensive Filecoin storage SDK with Synapse integration. Simplifies decentralized file storage on Filecoin with wallet management, upload/download, and IPFS pinning.

2 lines 535 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FilecoinStorageSDK={})}(this,function(e){"use strict";const t="6.15.0";function n(e,t,n){const r=t.split("|").map(e=>e.trim());for(let n=0;n<r.length;n++)switch(t){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof e===t)return}const i=new Error(`invalid value for type ${t}`);throw i.code="INVALID_ARGUMENT",i.argument=`value.${n}`,i.value=e,i}async function r(e){const t=Object.keys(e);return(await Promise.all(t.map(t=>Promise.resolve(e[t])))).reduce((e,n,r)=>(e[t[r]]=n,e),{})}function i(e,t,r){for(let i in t){let a=t[i];const s=r?r[i]:null;s&&n(a,s,i),Object.defineProperty(e,i,{enumerable:!0,value:a,writable:!1})}}function a(e,t){if(null==e)return"null";if(null==t&&(t=new Set),"object"==typeof e){if(t.has(e))return"[Circular]";t.add(e)}if(Array.isArray(e))return"[ "+e.map(e=>a(e,t)).join(", ")+" ]";if(e instanceof Uint8Array){const t="0123456789abcdef";let n="0x";for(let r=0;r<e.length;r++)n+=t[e[r]>>4],n+=t[15&e[r]];return n}if("object"==typeof e&&"function"==typeof e.toJSON)return a(e.toJSON(),t);switch(typeof e){case"boolean":case"number":case"symbol":return e.toString();case"bigint":return BigInt(e).toString();case"string":return JSON.stringify(e);case"object":{const n=Object.keys(e);return n.sort(),"{ "+n.map(n=>`${a(n,t)}: ${a(e[n],t)}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function s(e,t){return e&&e.code===t}function o(e){return s(e,"CALL_EXCEPTION")}function l(e,n,r){let s,o=e;{const i=[];if(r){if("message"in r||"code"in r||"name"in r)throw new Error(`value will overwrite populated values: ${a(r)}`);for(const e in r){if("shortMessage"===e)continue;const t=r[e];i.push(e+"="+a(t))}}i.push(`code=${n}`),i.push(`version=${t}`),i.length&&(e+=" ("+i.join(", ")+")")}switch(n){case"INVALID_ARGUMENT":s=new TypeError(e);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":s=new RangeError(e);break;default:s=new Error(e)}return i(s,{code:n}),r&&Object.assign(s,r),null==s.shortMessage&&i(s,{shortMessage:o}),s}function u(e,t,n,r){if(!e)throw l(t,n,r)}function c(e,t,n,r){u(e,t,"INVALID_ARGUMENT",{argument:n,value:r})}function d(e,t,n){null==n&&(n=""),n&&(n=": "+n),u(e>=t,"missing argument"+n,"MISSING_ARGUMENT",{count:e,expectedCount:t}),u(e<=t,"too many arguments"+n,"UNEXPECTED_ARGUMENT",{count:e,expectedCount:t})}const p=["NFD","NFC","NFKD","NFKC"].reduce((e,t)=>{try{if("test"!=="test".normalize(t))throw new Error("bad");if("NFD"===t){const e=String.fromCharCode(233).normalize("NFD");if(e!==String.fromCharCode(101,769))throw new Error("broken")}e.push(t)}catch(e){}return e},[]);function h(e){u(p.indexOf(e)>=0,"platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:e}})}function y(e,t,n){if(null==n&&(n=""),e!==t){let e=n,t="new";n&&(e+=".",t+=" "+n),u(!1,`private constructor; use ${e}from* methods`,"UNSUPPORTED_OPERATION",{operation:t})}}function f(e,t,n){if(e instanceof Uint8Array)return n?new Uint8Array(e):e;if("string"==typeof e&&e.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)){const t=new Uint8Array((e.length-2)/2);let n=2;for(let r=0;r<t.length;r++)t[r]=parseInt(e.substring(n,n+2),16),n+=2;return t}c(!1,"invalid BytesLike value",t||"value",e)}function m(e,t){return f(e,t,!1)}function g(e,t){return f(e,t,!0)}function w(e,t){return!("string"!=typeof e||!e.match(/^0x[0-9A-Fa-f]*$/))&&(("number"!=typeof t||e.length===2+2*t)&&(!0!==t||e.length%2==0))}function v(e){return w(e,!0)||e instanceof Uint8Array}const b="0123456789abcdef";function A(e){const t=m(e);let n="0x";for(let e=0;e<t.length;e++){const r=t[e];n+=b[(240&r)>>4]+b[15&r]}return n}function T(e){return"0x"+e.map(e=>A(e).substring(2)).join("")}function P(e){return w(e,!0)?(e.length-2)/2:m(e).length}function S(e,t,n){const r=m(e);return null!=n&&n>r.length&&u(!1,"cannot slice beyond data bounds","BUFFER_OVERRUN",{buffer:r,length:r.length,offset:n}),A(r.slice(null==t?0:t,null==n?r.length:n))}function E(e,t,n){const r=m(e);u(t>=r.length,"padding exceeds data length","BUFFER_OVERRUN",{buffer:new Uint8Array(r),length:t,offset:t+1});const i=new Uint8Array(t);return i.fill(0),n?i.set(r,t-r.length):i.set(r,0),A(i)}function I(e,t){return E(e,t,!0)}const C=BigInt(0),x=BigInt(1),k=9007199254740991;function N(e,t){const n=O(e,"value"),r=BigInt(F(t,"width"));if(u(n>>r===C,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:e}),n>>r-x){return-((~n&(x<<r)-x)+x)}return n}function R(e,t){let n=B(e,"value");const r=BigInt(F(t,"width")),i=x<<r-x;if(n<C){n=-n,u(n<=i,"too low","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e});return(~n&(x<<r)-x)+x}return u(n<i,"too high","NUMERIC_FAULT",{operation:"toTwos",fault:"overflow",value:e}),n}function D(e,t){const n=O(e,"value"),r=BigInt(F(t,"bits"));return n&(x<<r)-x}function B(e,t){switch(typeof e){case"bigint":return e;case"number":return c(Number.isInteger(e),"underflow",t||"value",e),c(e>=-k&&e<=k,"overflow",t||"value",e),BigInt(e);case"string":try{if(""===e)throw new Error("empty string");return"-"===e[0]&&"-"!==e[1]?-BigInt(e.substring(1)):BigInt(e)}catch(n){c(!1,`invalid BigNumberish string: ${n.message}`,t||"value",e)}}c(!1,"invalid BigNumberish value",t||"value",e)}function O(e,t){const n=B(e,t);return u(n>=C,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:e}),n}const U="0123456789abcdef";function M(e){if(e instanceof Uint8Array){let t="0x0";for(const n of e)t+=U[n>>4],t+=U[15&n];return BigInt(t)}return B(e)}function F(e,t){switch(typeof e){case"bigint":return c(e>=-k&&e<=k,"overflow",t||"value",e),Number(e);case"number":return c(Number.isInteger(e),"underflow",t||"value",e),c(e>=-k&&e<=k,"overflow",t||"value",e),e;case"string":try{if(""===e)throw new Error("empty string");return F(BigInt(e),t)}catch(n){c(!1,`invalid numeric string: ${n.message}`,t||"value",e)}}c(!1,"invalid numeric value",t||"value",e)}function L(e,t){let n=O(e,"value").toString(16);if(null==t)n.length%2&&(n="0"+n);else{const r=F(t,"width");for(u(2*r>=n.length,`value exceeds width (${r} bytes)`,"NUMERIC_FAULT",{operation:"toBeHex",fault:"overflow",value:e});n.length<2*r;)n="0"+n}return"0x"+n}function _(e){const t=O(e,"value");if(t===C)return new Uint8Array([]);let n=t.toString(16);n.length%2&&(n="0"+n);const r=new Uint8Array(n.length/2);for(let e=0;e<r.length;e++){const t=2*e;r[e]=parseInt(n.substring(t,t+2),16)}return r}function G(e){let t=A(v(e)?e:_(e)).substring(2);for(;t.startsWith("0");)t=t.substring(1);return""===t&&(t="0"),"0x"+t}const z="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";let V=null;function H(e){if(null==V){V={};for(let e=0;e<58;e++)V[z[e]]=BigInt(e)}const t=V[e];return c(null!=t,"invalid base58 value","letter",e),t}const j=BigInt(0),Q=BigInt(58);function K(e){const t=m(e);let n=M(t),r="";for(;n;)r=z[Number(n%Q)]+r,n/=Q;for(let e=0;e<t.length&&!t[e];e++)r=z[0]+r;return r}class ${filter;emitter;#e;constructor(e,t,n){this.#e=t,i(this,{emitter:e,filter:n})}async removeListener(){null!=this.#e&&await this.emitter.off(this.filter,this.#e)}}function W(e,t,n,r,i){if("BAD_PREFIX"===e||"UNEXPECTED_CONTINUE"===e){let e=0;for(let r=t+1;r<n.length&&n[r]>>6==2;r++)e++;return e}return"OVERRUN"===e?n.length-t-1:0}const J=Object.freeze({error:function(e,t,n,r,i){c(!1,`invalid codepoint at offset ${t}; ${e}`,"bytes",n)},ignore:W,replace:function(e,t,n,r,i){return"OVERLONG"===e?(c("number"==typeof i,"invalid bad code point for replacement","badCodepoint",i),r.push(i),0):(r.push(65533),W(e,t,n))}});function q(e,t){c("string"==typeof e,"invalid string value","str",e),null!=t&&(h(t),e=e.normalize(t));let n=[];for(let t=0;t<e.length;t++){const r=e.charCodeAt(t);if(r<128)n.push(r);else if(r<2048)n.push(r>>6|192),n.push(63&r|128);else if(55296==(64512&r)){t++;const i=e.charCodeAt(t);c(t<e.length&&56320==(64512&i),"invalid surrogate pair","str",e);const a=65536+((1023&r)<<10)+(1023&i);n.push(a>>18|240),n.push(a>>12&63|128),n.push(a>>6&63|128),n.push(63&a|128)}else n.push(r>>12|224),n.push(r>>6&63|128),n.push(63&r|128)}return new Uint8Array(n)}function Z(e,t){return n=function(e,t){null==t&&(t=J.error);const n=m(e,"bytes"),r=[];let i=0;for(;i<n.length;){const e=n[i++];if(!(e>>7)){r.push(e);continue}let a=null,s=null;if(192==(224&e))a=1,s=127;else if(224==(240&e))a=2,s=2047;else{if(240!=(248&e)){i+=t(128==(192&e)?"UNEXPECTED_CONTINUE":"BAD_PREFIX",i-1,n,r);continue}a=3,s=65535}if(i-1+a>=n.length){i+=t("OVERRUN",i-1,n,r);continue}let o=e&(1<<8-a-1)-1;for(let e=0;e<a;e++){let e=n[i];if(128!=(192&e)){i+=t("MISSING_CONTINUE",i,n,r),o=null;break}o=o<<6|63&e,i++}null!==o&&(o>1114111?i+=t("OUT_OF_RANGE",i-1-a,n,r,o):o>=55296&&o<=57343?i+=t("UTF16_SURROGATE",i-1-a,n,r,o):o<=s?i+=t("OVERLONG",i-1-a,n,r,o):r.push(o))}return r}(e,t),n.map(e=>e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10&1023),56320+(1023&e)))).join("");var n}function Y(e){return async function(t,n){u(null==n||!n.cancelled,"request cancelled before sending","CANCELLED");const r=t.url.split(":")[0].toLowerCase();u("http"===r||"https"===r,`unsupported protocol ${r}`,"UNSUPPORTED_OPERATION",{info:{protocol:r},operation:"request"}),u("https"===r||!t.credentials||t.allowInsecureAuthentication,"insecure authorized connections unsupported","UNSUPPORTED_OPERATION",{operation:"request"});let i=null;const a=new AbortController,s=setTimeout(()=>{i=l("request timeout","TIMEOUT"),a.abort()},t.timeout);n&&n.addListener(()=>{i=l("request cancelled","CANCELLED"),a.abort()});const o=Object.assign({},e,{method:t.method,headers:new Headers(Array.from(t)),body:t.body||void 0,signal:a.signal});let c;try{c=await fetch(t.url,o)}catch(e){if(clearTimeout(s),i)throw i;throw e}clearTimeout(s);const d={};c.headers.forEach((e,t)=>{d[t.toLowerCase()]=e});const p=await c.arrayBuffer(),h=null==p?null:new Uint8Array(p);return{statusCode:c.status,statusMessage:c.statusText,headers:d,body:h}}}let X=Y();const ee=new RegExp("^data:([^;:]*)?(;base64)?,(.*)$","i"),te=new RegExp("^ipfs://(ipfs/)?(.*)$","i");let ne=!1;async function re(e,t){try{const t=e.match(ee);if(!t)throw new Error("invalid data");return new ce(200,"OK",{"content-type":t[1]||"text/plain"},t[2]?function(e){e=atob(e);const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return m(t)}(t[3]):q(t[3].replace(/%([0-9a-f][0-9a-f])/gi,(e,t)=>String.fromCharCode(parseInt(t,16)))))}catch(t){return new ce(599,"BAD REQUEST (invalid data: URI)",{},null,new ue(e))}}function ie(e){return async function(t,n){try{const n=t.match(te);if(!n)throw new Error("invalid link");return new ue(`${e}${n[2]}`)}catch(e){return new ce(599,"BAD REQUEST (invalid IPFS URI)",{},null,new ue(t))}}}const ae={data:re,ipfs:ie("https://gateway.ipfs.io/ipfs/")},se=new WeakMap;class oe{#t;#n;constructor(e){this.#t=[],this.#n=!1,se.set(e,()=>{if(!this.#n){this.#n=!0;for(const e of this.#t)setTimeout(()=>{e()},0);this.#t=[]}})}addListener(e){u(!this.#n,"singal already cancelled","UNSUPPORTED_OPERATION",{operation:"fetchCancelSignal.addCancelListener"}),this.#t.push(e)}get cancelled(){return this.#n}checkSignal(){u(!this.cancelled,"cancelled","CANCELLED",{})}}function le(e){if(null==e)throw new Error("missing signal; should not happen");return e.checkSignal(),e}class ue{#r;#i;#a;#s;#o;#l;#u;#c;#d;#p;#h;#y;#f;#m;#g;get url(){return this.#l}set url(e){this.#l=String(e)}get body(){return null==this.#u?null:new Uint8Array(this.#u)}set body(e){if(null==e)this.#u=void 0,this.#c=void 0;else if("string"==typeof e)this.#u=q(e),this.#c="text/plain";else if(e instanceof Uint8Array)this.#u=e,this.#c="application/octet-stream";else{if("object"!=typeof e)throw new Error("invalid body");this.#u=q(JSON.stringify(e)),this.#c="application/json"}}hasBody(){return null!=this.#u}get method(){return this.#s?this.#s:this.hasBody()?"POST":"GET"}set method(e){null==e&&(e=""),this.#s=String(e).toUpperCase()}get headers(){const e=Object.assign({},this.#a);return this.#d&&(e.authorization=`Basic ${function(e){const t=m(e);let n="";for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)}(q(this.#d))}`),this.allowGzip&&(e["accept-encoding"]="gzip"),null==e["content-type"]&&this.#c&&(e["content-type"]=this.#c),this.body&&(e["content-length"]=String(this.body.length)),e}getHeader(e){return this.headers[e.toLowerCase()]}setHeader(e,t){this.#a[String(e).toLowerCase()]=String(t)}clearHeaders(){this.#a={}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}get credentials(){return this.#d||null}setCredentials(e,t){c(!e.match(/:/),"invalid basic authentication username","username","[REDACTED]"),this.#d=`${e}:${t}`}get allowGzip(){return this.#i}set allowGzip(e){this.#i=!!e}get allowInsecureAuthentication(){return!!this.#r}set allowInsecureAuthentication(e){this.#r=!!e}get timeout(){return this.#o}set timeout(e){c(e>=0,"timeout must be non-zero","timeout",e),this.#o=e}get preflightFunc(){return this.#p||null}set preflightFunc(e){this.#p=e}get processFunc(){return this.#h||null}set processFunc(e){this.#h=e}get retryFunc(){return this.#y||null}set retryFunc(e){this.#y=e}get getUrlFunc(){return this.#g||X}set getUrlFunc(e){this.#g=e}constructor(e){this.#l=String(e),this.#r=!1,this.#i=!0,this.#a={},this.#s="",this.#o=3e5,this.#m={slotInterval:250,maxAttempts:12},this.#g=null}toString(){return`<FetchRequest method=${JSON.stringify(this.method)} url=${JSON.stringify(this.url)} headers=${JSON.stringify(this.headers)} body=${this.#u?A(this.#u):"null"}>`}setThrottleParams(e){null!=e.slotInterval&&(this.#m.slotInterval=e.slotInterval),null!=e.maxAttempts&&(this.#m.maxAttempts=e.maxAttempts)}async#w(e,t,n,r,i){if(e>=this.#m.maxAttempts)return i.makeServerError("exceeded maximum retry limit");u(de()<=t,"timeout","TIMEOUT",{operation:"request.send",reason:"timeout",request:r}),n>0&&await function(e){return new Promise(t=>setTimeout(t,e))}(n);let a=this.clone();const s=(a.url.split(":")[0]||"").toLowerCase();if(s in ae){const e=await ae[s](a.url,le(r.#f));if(e instanceof ce){let t=e;if(this.processFunc){le(r.#f);try{t=await this.processFunc(a,t)}catch(e){null!=e.throttle&&"number"==typeof e.stall||t.makeServerError("error in post-processing function",e).assertOk()}}return t}a=e}this.preflightFunc&&(a=await this.preflightFunc(a));const o=await this.getUrlFunc(a,le(r.#f));let l=new ce(o.statusCode,o.statusMessage,o.headers,o.body,r);if(301===l.statusCode||302===l.statusCode){try{const n=l.headers.location||"";return a.redirect(n).#w(e+1,t,0,r,l)}catch(e){}return l}if(429===l.statusCode&&(null==this.retryFunc||await this.retryFunc(a,l,e))){const n=l.headers["retry-after"];let i=this.#m.slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return"string"==typeof n&&n.match(/^[1-9][0-9]*$/)&&(i=parseInt(n)),a.clone().#w(e+1,t,i,r,l)}if(this.processFunc){le(r.#f);try{l=await this.processFunc(a,l)}catch(n){null!=n.throttle&&"number"==typeof n.stall||l.makeServerError("error in post-processing function",n).assertOk();let i=this.#m.slotInterval*Math.trunc(Math.random()*Math.pow(2,e));return n.stall>=0&&(i=n.stall),a.clone().#w(e+1,t,i,r,l)}}return l}send(){return u(null==this.#f,"request already sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.send"}),this.#f=new oe(this),this.#w(0,de()+this.timeout,0,this,new ce(0,"",{},null,this))}cancel(){u(null!=this.#f,"request has not been sent","UNSUPPORTED_OPERATION",{operation:"fetchRequest.cancel"});const e=se.get(this);if(!e)throw new Error("missing signal; should not happen");e()}redirect(e){const t=this.url.split(":")[0].toLowerCase(),n=e.split(":")[0].toLowerCase();u("GET"===this.method&&("https"!==t||"http"!==n)&&e.match(/^https?:/),"unsupported redirect","UNSUPPORTED_OPERATION",{operation:`redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(e)})`});const r=new ue(e);return r.method="GET",r.allowGzip=this.allowGzip,r.timeout=this.timeout,r.#a=Object.assign({},this.#a),this.#u&&(r.#u=new Uint8Array(this.#u)),r.#c=this.#c,r}clone(){const e=new ue(this.url);return e.#s=this.#s,this.#u&&(e.#u=this.#u),e.#c=this.#c,e.#a=Object.assign({},this.#a),e.#d=this.#d,this.allowGzip&&(e.allowGzip=!0),e.timeout=this.timeout,this.allowInsecureAuthentication&&(e.allowInsecureAuthentication=!0),e.#p=this.#p,e.#h=this.#h,e.#y=this.#y,e.#m=Object.assign({},this.#m),e.#g=this.#g,e}static lockConfig(){ne=!0}static getGateway(e){return ae[e.toLowerCase()]||null}static registerGateway(e,t){if("http"===(e=e.toLowerCase())||"https"===e)throw new Error(`cannot intercept ${e}; use registerGetUrl`);if(ne)throw new Error("gateways locked");ae[e]=t}static registerGetUrl(e){if(ne)throw new Error("gateways locked");X=e}static createGetUrlFunc(e){return Y(e)}static createDataGateway(){return re}static createIpfsGatewayFunc(e){return ie(e)}}class ce{#v;#b;#a;#u;#A;#T;toString(){return`<FetchResponse status=${this.statusCode} body=${this.#u?A(this.#u):"null"}>`}get statusCode(){return this.#v}get statusMessage(){return this.#b}get headers(){return Object.assign({},this.#a)}get body(){return null==this.#u?null:new Uint8Array(this.#u)}get bodyText(){try{return null==this.#u?"":Z(this.#u)}catch(e){u(!1,"response body is not valid UTF-8 data","UNSUPPORTED_OPERATION",{operation:"bodyText",info:{response:this}})}}get bodyJson(){try{return JSON.parse(this.bodyText)}catch(e){u(!1,"response body is not valid JSON","UNSUPPORTED_OPERATION",{operation:"bodyJson",info:{response:this}})}}[Symbol.iterator](){const e=this.headers,t=Object.keys(e);let n=0;return{next:()=>{if(n<t.length){const r=t[n++];return{value:[r,e[r]],done:!1}}return{value:void 0,done:!0}}}}constructor(e,t,n,r,i){this.#v=e,this.#b=t,this.#a=Object.keys(n).reduce((e,t)=>(e[t.toLowerCase()]=String(n[t]),e),{}),this.#u=null==r?null:new Uint8Array(r),this.#A=i||null,this.#T={message:""}}makeServerError(e,t){let n;n=e?`CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${e})`:`CLIENT ESCALATED SERVER ERROR (${e=`${this.statusCode} ${this.statusMessage}`})`;const r=new ce(599,n,this.headers,this.body,this.#A||void 0);return r.#T={message:e,error:t},r}throwThrottleError(e,t){null==t?t=-1:c(Number.isInteger(t)&&t>=0,"invalid stall timeout","stall",t);const n=new Error(e||"throttling requests");throw i(n,{stall:t,throttle:!0}),n}getHeader(e){return this.headers[e.toLowerCase()]}hasBody(){return null!=this.#u}get request(){return this.#A}ok(){return""===this.#T.message&&this.statusCode>=200&&this.statusCode<300}assertOk(){if(this.ok())return;let{message:e,error:t}=this.#T;""===e&&(e=`server response ${this.statusCode} ${this.statusMessage}`);let n=null;this.request&&(n=this.request.url);let r=null;try{this.#u&&(r=Z(this.#u))}catch(e){}u(!1,e,"SERVER_ERROR",{request:this.request||"unknown request",response:this,error:t,info:{requestUrl:n,responseBody:r,responseStatus:`${this.statusCode} ${this.statusMessage}`}})}}function de(){return(new Date).getTime()}const pe=BigInt(-1),he=BigInt(0),ye=BigInt(1),fe=BigInt(5),me={};let ge="0000";for(;ge.length<80;)ge+=ge;function we(e){let t=ge;for(;t.length<e;)t+=t;return BigInt("1"+t.substring(0,e))}function ve(e,t,n){const r=BigInt(t.width);if(t.signed){const t=ye<<r-ye;u(null==n||e>=-t&&e<t,"overflow","NUMERIC_FAULT",{operation:n,fault:"overflow",value:e}),e=e>he?N(D(e,r),r):-N(D(-e,r),r)}else{const t=ye<<r;u(null==n||e>=0&&e<t,"overflow","NUMERIC_FAULT",{operation:n,fault:"overflow",value:e}),e=(e%t+t)%t&t-ye}return e}function be(e){"number"==typeof e&&(e=`fixed128x${e}`);let t=!0,n=128,r=18;if("string"==typeof e)if("fixed"===e);else if("ufixed"===e)t=!1;else{const i=e.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);c(i,"invalid fixed format","format",e),t="u"!==i[1],n=parseInt(i[2]),r=parseInt(i[3])}else if(e){const i=e,a=(e,t,n)=>null==i[e]?n:(c(typeof i[e]===t,"invalid fixed format ("+e+" not "+t+")","format."+e,i[e]),i[e]);t=a("signed","boolean",t),n=a("width","number",n),r=a("decimals","number",r)}c(n%8==0,"invalid FixedNumber width (not byte aligned)","format.width",n),c(r<=80,"invalid FixedNumber decimals (too large)","format.decimals",r);return{signed:t,width:n,decimals:r,name:(t?"":"u")+"fixed"+String(n)+"x"+String(r)}}class Ae{format;#P;#S;#E;_value;constructor(e,t,n){y(e,me,"FixedNumber"),this.#S=t,this.#P=n;const r=function(e,t){let n="";e<he&&(n="-",e*=pe);let r=e.toString();if(0===t)return n+r;for(;r.length<=t;)r=ge+r;const i=r.length-t;for(r=r.substring(0,i)+"."+r.substring(i);"0"===r[0]&&"."!==r[1];)r=r.substring(1);for(;"0"===r[r.length-1]&&"."!==r[r.length-2];)r=r.substring(0,r.length-1);return n+r}(t,n.decimals);i(this,{format:n.name,_value:r}),this.#E=we(n.decimals)}get signed(){return this.#P.signed}get width(){return this.#P.width}get decimals(){return this.#P.decimals}get value(){return this.#S}#I(e){c(this.format===e.format,"incompatible format; use fixedNumber.toFormat","other",e)}#C(e,t){return e=ve(e,this.#P,t),new Ae(me,e,this.#P)}#x(e,t){return this.#I(e),this.#C(this.#S+e.#S,t)}addUnsafe(e){return this.#x(e)}add(e){return this.#x(e,"add")}#k(e,t){return this.#I(e),this.#C(this.#S-e.#S,t)}subUnsafe(e){return this.#k(e)}sub(e){return this.#k(e,"sub")}#N(e,t){return this.#I(e),this.#C(this.#S*e.#S/this.#E,t)}mulUnsafe(e){return this.#N(e)}mul(e){return this.#N(e,"mul")}mulSignal(e){this.#I(e);const t=this.#S*e.#S;return u(t%this.#E===he,"precision lost during signalling mul","NUMERIC_FAULT",{operation:"mulSignal",fault:"underflow",value:this}),this.#C(t/this.#E,"mulSignal")}#R(e,t){return u(e.#S!==he,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),this.#I(e),this.#C(this.#S*this.#E/e.#S,t)}divUnsafe(e){return this.#R(e)}div(e){return this.#R(e,"div")}divSignal(e){u(e.#S!==he,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),this.#I(e);const t=this.#S*this.#E;return u(t%e.#S===he,"precision lost during signalling div","NUMERIC_FAULT",{operation:"divSignal",fault:"underflow",value:this}),this.#C(t/e.#S,"divSignal")}cmp(e){let t=this.value,n=e.value;const r=this.decimals-e.decimals;return r>0?n*=we(r):r<0&&(t*=we(-r)),t<n?-1:t>n?1:0}eq(e){return 0===this.cmp(e)}lt(e){return this.cmp(e)<0}lte(e){return this.cmp(e)<=0}gt(e){return this.cmp(e)>0}gte(e){return this.cmp(e)>=0}floor(){let e=this.#S;return this.#S<he&&(e-=this.#E-ye),e=this.#S/this.#E*this.#E,this.#C(e,"floor")}ceiling(){let e=this.#S;return this.#S>he&&(e+=this.#E-ye),e=this.#S/this.#E*this.#E,this.#C(e,"ceiling")}round(e){if(null==e&&(e=0),e>=this.decimals)return this;const t=this.decimals-e,n=fe*we(t-1);let r=this.value+n;const i=we(t);return r=r/i*i,ve(r,this.#P,"round"),new Ae(me,r,this.#P)}isZero(){return this.#S===he}isNegative(){return this.#S<he}toString(){return this._value}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(e){return Ae.fromString(this.toString(),e)}static fromValue(e,t,n){const r=null==t?0:F(t),i=be(n);let a=B(e,"value");const s=r-i.decimals;if(s>0){const t=we(s);u(a%t===he,"value loses precision for format","NUMERIC_FAULT",{operation:"fromValue",fault:"underflow",value:e}),a/=t}else s<0&&(a*=we(-s));return ve(a,i,"fromValue"),new Ae(me,a,i)}static fromString(e,t){const n=e.match(/^(-?)([0-9]*)\.?([0-9]*)$/);c(n&&n[2].length+n[3].length>0,"invalid FixedNumber string value","value",e);const r=be(t);let i=n[2]||"0",a=n[3]||"";for(;a.length<r.decimals;)a+=ge;u(a.substring(r.decimals).match(/^0*$/),"too many decimals for format","NUMERIC_FAULT",{operation:"fromString",fault:"underflow",value:e}),a=a.substring(0,r.decimals);const s=BigInt(n[1]+i+a);return ve(s,r,"fromString"),new Ae(me,s,r)}static fromBytes(e,t){let n=M(m(e,"value"));const r=be(t);return r.signed&&(n=N(n,r.width)),ve(n,r,"fromBytes"),new Ae(me,n,r)}}function Te(e){let t=e.toString(16);for(;t.length<2;)t="0"+t;return"0x"+t}function Pe(e,t,n){let r=0;for(let i=0;i<n;i++)r=256*r+e[t+i];return r}function Se(e,t,n,r){const i=[];for(;n<t+1+r;){const a=Ee(e,n);i.push(a.result),u((n+=a.consumed)<=t+1+r,"child data too short","BUFFER_OVERRUN",{buffer:e,length:r,offset:t})}return{consumed:1+r,result:i}}function Ee(e,t){u(0!==e.length,"data too short","BUFFER_OVERRUN",{buffer:e,length:0,offset:1});const n=t=>{u(t<=e.length,"data short segment too short","BUFFER_OVERRUN",{buffer:e,length:e.length,offset:t})};if(e[t]>=248){const r=e[t]-247;n(t+1+r);const i=Pe(e,t+1,r);return n(t+1+r+i),Se(e,t,t+1+r,r+i)}if(e[t]>=192){const r=e[t]-192;return n(t+1+r),Se(e,t,t+1,r)}if(e[t]>=184){const r=e[t]-183;n(t+1+r);const i=Pe(e,t+1,r);n(t+1+r+i);return{consumed:1+r+i,result:A(e.slice(t+1+r,t+1+r+i))}}if(e[t]>=128){const r=e[t]-128;n(t+1+r);return{consumed:1+r,result:A(e.slice(t+1,t+1+r))}}return{consumed:1,result:Te(e[t])}}function Ie(e){const t=m(e,"data"),n=Ee(t,0);return c(n.consumed===t.length,"unexpected junk after rlp payload","data",e),n.result}function Ce(e){const t=[];for(;e;)t.unshift(255&e),e>>=8;return t}function xe(e){if(Array.isArray(e)){let t=[];if(e.forEach(function(e){t=t.concat(xe(e))}),t.length<=55)return t.unshift(192+t.length),t;const n=Ce(t.length);return n.unshift(247+n.length),n.concat(t)}const t=Array.prototype.slice.call(m(e,"object"));if(1===t.length&&t[0]<=127)return t;if(t.length<=55)return t.unshift(128+t.length),t;const n=Ce(t.length);return n.unshift(183+n.length),n.concat(t)}const ke="0123456789abcdef";function Ne(e){let t="0x";for(const n of xe(e))t+=ke[n>>4],t+=ke[15&n];return t}const Re=["wei","kwei","mwei","gwei","szabo","finney","ether"];function De(e,t){let n=18;if("string"==typeof t){const e=Re.indexOf(t);c(e>=0,"invalid unit","unit",t),n=3*e}else null!=t&&(n=F(t,"unit"));return Ae.fromValue(e,n,{decimals:n,width:512}).toString()}function Be(e){const t=m(e,"randomBytes");t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=A(t);return[n.substring(2,10),n.substring(10,14),n.substring(14,18),n.substring(18,22),n.substring(22,34)].join("-")}const Oe=32,Ue=new Uint8Array(Oe),Me=["then"],Fe={},Le=new WeakMap;function _e(e){return Le.get(e)}function Ge(e,t){Le.set(e,t)}function ze(e,t){const n=new Error(`deferred error during ABI decoding triggered accessing ${e}`);throw n.error=t,n}function Ve(e,t,n){return e.indexOf(null)>=0?t.map((e,t)=>e instanceof He?Ve(_e(e),e,n):e):e.reduce((e,r,i)=>{let a=t.getValue(r);return r in e||(n&&a instanceof He&&(a=Ve(_e(a),a,n)),e[r]=a),e},{})}class He extends Array{#D;constructor(...e){const t=e[0];let n=e[1],r=(e[2]||[]).slice(),i=!0;t!==Fe&&(n=e,r=[],i=!1),super(n.length),n.forEach((e,t)=>{this[t]=e});const a=r.reduce((e,t)=>("string"==typeof t&&e.set(t,(e.get(t)||0)+1),e),new Map);if(Ge(this,Object.freeze(n.map((e,t)=>{const n=r[t];return null!=n&&1===a.get(n)?n:null}))),this.#D=[],null==this.#D&&this.#D,!i)return;Object.freeze(this);const s=new Proxy(this,{get:(e,t,n)=>{if("string"==typeof t){if(t.match(/^[0-9]+$/)){const n=F(t,"%index");if(n<0||n>=this.length)throw new RangeError("out of result range");const r=e[n];return r instanceof Error&&ze(`index ${n}`,r),r}if(Me.indexOf(t)>=0)return Reflect.get(e,t,n);const r=e[t];if(r instanceof Function)return function(...t){return r.apply(this===n?e:this,t)};if(!(t in e))return e.getValue.apply(this===n?e:this,[t])}return Reflect.get(e,t,n)}});return Ge(s,_e(this)),s}toArray(e){const t=[];return this.forEach((n,r)=>{n instanceof Error&&ze(`index ${r}`,n),e&&n instanceof He&&(n=n.toArray(e)),t.push(n)}),t}toObject(e){const t=_e(this);return t.reduce((n,r,i)=>(u(null!=r,`value at index ${i} unnamed`,"UNSUPPORTED_OPERATION",{operation:"toObject()"}),Ve(t,this,e)),{})}slice(e,t){null==e&&(e=0),e<0&&(e+=this.length)<0&&(e=0),null==t&&(t=this.length),t<0&&(t+=this.length)<0&&(t=0),t>this.length&&(t=this.length);const n=_e(this),r=[],i=[];for(let a=e;a<t;a++)r.push(this[a]),i.push(n[a]);return new He(Fe,r,i)}filter(e,t){const n=_e(this),r=[],i=[];for(let a=0;a<this.length;a++){const s=this[a];s instanceof Error&&ze(`index ${a}`,s),e.call(t,s,a,this)&&(r.push(s),i.push(n[a]))}return new He(Fe,r,i)}map(e,t){const n=[];for(let r=0;r<this.length;r++){const i=this[r];i instanceof Error&&ze(`index ${r}`,i),n.push(e.call(t,i,r,this))}return n}getValue(e){const t=_e(this).indexOf(e);if(-1===t)return;const n=this[t];return n instanceof Error&&ze(`property ${JSON.stringify(e)}`,n.error),n}static fromItems(e,t){return new He(Fe,e,t)}}function je(e){let t=_(e);return u(t.length<=Oe,"value out-of-bounds","BUFFER_OVERRUN",{buffer:t,length:Oe,offset:t.length}),t.length!==Oe&&(t=g(T([Ue.slice(t.length%Oe),t]))),t}class Qe{name;type;localName;dynamic;constructor(e,t,n,r){i(this,{name:e,type:t,localName:n,dynamic:r},{name:"string",type:"string",localName:"string",dynamic:"boolean"})}_throwError(e,t){c(!1,e,this.localName,t)}}class Ke{#B;#O;constructor(){this.#B=[],this.#O=0}get data(){return T(this.#B)}get length(){return this.#O}#U(e){return this.#B.push(e),this.#O+=e.length,e.length}appendWriter(e){return this.#U(g(e.data))}writeBytes(e){let t=g(e);const n=t.length%Oe;return n&&(t=g(T([t,Ue.slice(n)]))),this.#U(t)}writeValue(e){return this.#U(je(e))}writeUpdatableValue(){const e=this.#B.length;return this.#B.push(Ue),this.#O+=Oe,t=>{this.#B[e]=je(t)}}}class $e{allowLoose;#B;#M;#F;#L;#_;constructor(e,t,n){i(this,{allowLoose:!!t}),this.#B=g(e),this.#F=0,this.#L=null,this.#_=null!=n?n:1024,this.#M=0}get data(){return A(this.#B)}get dataLength(){return this.#B.length}get consumed(){return this.#M}get bytes(){return new Uint8Array(this.#B)}#G(e){if(this.#L)return this.#L.#G(e);this.#F+=e,u(this.#_<1||this.#F<=this.#_*this.dataLength,`compressed ABI data exceeds inflation ratio of ${this.#_} ( see: https://github.com/ethers-io/ethers.js/issues/4537 )`,"BUFFER_OVERRUN",{buffer:g(this.#B),offset:this.#M,length:e,info:{bytesRead:this.#F,dataLength:this.dataLength}})}#z(e,t,n){let r=Math.ceil(t/Oe)*Oe;return this.#M+r>this.#B.length&&(this.allowLoose&&n&&this.#M+t<=this.#B.length?r=t:u(!1,"data out-of-bounds","BUFFER_OVERRUN",{buffer:g(this.#B),length:this.#B.length,offset:this.#M+r})),this.#B.slice(this.#M,this.#M+r)}subReader(e){const t=new $e(this.#B.slice(this.#M+e),this.allowLoose,this.#_);return t.#L=this,t}readBytes(e,t){let n=this.#z(0,e,!!t);return this.#G(e),this.#M+=n.length,n.slice(0,e)}readValue(){return M(this.readBytes(Oe))}readIndex(){return F(M(this.readBytes(Oe)))}}var We="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function Je(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function qe(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ze(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Je(e.outputLen),Je(e.blockLen)}function Ye(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Xe(e,t){qe(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const et="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,tt=e=>e instanceof Uint8Array,nt=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4)),rt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),it=(e,t)=>e<<32-t|e>>>t; /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");const at=async()=>{};async function st(e,t,n){let r=Date.now();for(let i=0;i<e;i++){n(i);const e=Date.now()-r;e>=0&&e<t||(await at(),r+=e)}}function ot(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!tt(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class lt{clone(){return this._cloneInto()}}const ut={}.toString;function ct(e,t){if(void 0!==t&&"[object Object]"!==ut.call(t))throw new Error("Options should be object or undefined");return Object.assign(e,t)}function dt(e){const t=t=>e().update(ot(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function pt(e=32){if(et&&"function"==typeof et.getRandomValues)return et.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class ht extends lt{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ze(e);const n=ot(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),i.fill(0)}update(e){return Ye(this),this.iHash.update(e),this}digestInto(e){Ye(this),qe(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const yt=(e,t,n)=>new ht(e,t).update(n).digest();function ft(e,t,n,r){Ze(e);const i=ct({dkLen:32,asyncTick:10},r),{c:a,dkLen:s,asyncTick:o}=i;if(Je(a),Je(s),Je(o),a<1)throw new Error("PBKDF2: iterations (c) should be >= 1");const l=ot(t),u=ot(n),c=new Uint8Array(s),d=yt.create(e,l),p=d._cloneInto().update(u);return{c:a,dkLen:s,asyncTick:o,DK:c,PRF:d,PRFSalt:p}}function mt(e,t,n,r){const{c:i,dkLen:a,DK:s,PRF:o,PRFSalt:l}=ft(e,t,n,r);let u;const c=new Uint8Array(4),d=rt(c),p=new Uint8Array(o.outputLen);for(let e=1,t=0;t<a;e++,t+=o.outputLen){const n=s.subarray(t,t+o.outputLen);d.setInt32(0,e,!1),(u=l._cloneInto(u)).update(c).digestInto(p),n.set(p.subarray(0,n.length));for(let e=1;e<i;e++){o._cloneInto(u).update(p).digestInto(p);for(let e=0;e<n.length;e++)n[e]^=p[e]}}return function(e,t,n,r,i){return e.destroy(),t.destroy(),r&&r.destroy(),i.fill(0),n}(o,l,s,u,p)}yt.create=(e,t)=>new ht(e,t);class gt extends lt{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=rt(this.buffer)}update(e){Ye(this);const{view:t,buffer:n,blockLen:r}=this,i=(e=ot(e)).length;for(let a=0;a<i;){const s=Math.min(r-this.pos,i-a);if(s===r){const t=rt(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ye(this),Xe(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:a}=this;t[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),a=BigInt(4294967295),s=Number(n>>i&a),o=Number(n&a),l=r?4:0,u=r?0:4;e.setUint32(t+l,s,r),e.setUint32(t+u,o,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=rt(e),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=o/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)s.setUint32(4*e,u[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:s}=this;return e.length=r,e.pos=s,e.finished=i,e.destroyed=a,r%t&&e.buffer.set(n),e}}const wt=(e,t,n)=>e&t^~e&n,vt=(e,t,n)=>e&t^e&n^t&n,bt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),At=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tt=new Uint32Array(64);class Pt extends gt{constructor(){super(64,32,8,!1),this.A=0|At[0],this.B=0|At[1],this.C=0|At[2],this.D=0|At[3],this.E=0|At[4],this.F=0|At[5],this.G=0|At[6],this.H=0|At[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:a,G:s,H:o}=this;return[e,t,n,r,i,a,s,o]}set(e,t,n,r,i,a,s,o){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|a,this.G=0|s,this.H=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)Tt[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Tt[e-15],n=Tt[e-2],r=it(t,7)^it(t,18)^t>>>3,i=it(n,17)^it(n,19)^n>>>10;Tt[e]=i+Tt[e-7]+r+Tt[e-16]|0}let{A:n,B:r,C:i,D:a,E:s,F:o,G:l,H:u}=this;for(let e=0;e<64;e++){const t=u+(it(s,6)^it(s,11)^it(s,25))+wt(s,o,l)+bt[e]+Tt[e]|0,c=(it(n,2)^it(n,13)^it(n,22))+vt(n,r,i)|0;u=l,l=o,o=s,s=a+t|0,a=i,i=r,r=n,n=t+c|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,o=o+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,r,i,a,s,o,l,u)}roundClean(){Tt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const St=dt(()=>new Pt),Et=BigInt(2**32-1),It=BigInt(32);function Ct(e,t=!1){return t?{h:Number(e&Et),l:Number(e>>It&Et)}:{h:0|Number(e>>It&Et),l:0|Number(e&Et)}}function xt(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:a,l:s}=Ct(e[i],t);[n[i],r[i]]=[a,s]}return[n,r]}const kt=(e,t,n)=>e<<n|t>>>32-n,Nt=(e,t,n)=>t<<n|e>>>32-n,Rt=(e,t,n)=>t<<n-32|e>>>64-n,Dt=(e,t,n)=>e<<n-32|t>>>64-n;var Bt={fromBig:Ct,split:xt,toBig:(e,t)=>BigInt(e>>>0)<<It|BigInt(t>>>0),shrSH:(e,t,n)=>e>>>n,shrSL:(e,t,n)=>e<<32-n|t>>>n,rotrSH:(e,t,n)=>e>>>n|t<<32-n,rotrSL:(e,t,n)=>e<<32-n|t>>>n,rotrBH:(e,t,n)=>e<<64-n|t>>>n-32,rotrBL:(e,t,n)=>e>>>n-32|t<<64-n,rotr32H:(e,t)=>t,rotr32L:(e,t)=>e,rotlSH:kt,rotlSL:Nt,rotlBH:Rt,rotlBL:Dt,add:function(e,t,n,r){const i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:0|i}},add3L:(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),add3H:(e,t,n,r)=>t+n+r+(e/2**32|0)|0,add4L:(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),add4H:(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,add5H:(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0,add5L:(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0)};const[Ot,Ut]=(()=>Bt.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))))(),Mt=new Uint32Array(80),Ft=new Uint32Array(80);class Lt extends gt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:a,Dh:s,Dl:o,Eh:l,El:u,Fh:c,Fl:d,Gh:p,Gl:h,Hh:y,Hl:f}=this;return[e,t,n,r,i,a,s,o,l,u,c,d,p,h,y,f]}set(e,t,n,r,i,a,s,o,l,u,c,d,p,h,y,f){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|i,this.Cl=0|a,this.Dh=0|s,this.Dl=0|o,this.Eh=0|l,this.El=0|u,this.Fh=0|c,this.Fl=0|d,this.Gh=0|p,this.Gl=0|h,this.Hh=0|y,this.Hl=0|f}process(e,t){for(let n=0;n<16;n++,t+=4)Mt[n]=e.getUint32(t),Ft[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|Mt[e-15],n=0|Ft[e-15],r=Bt.rotrSH(t,n,1)^Bt.rotrSH(t,n,8)^Bt.shrSH(t,n,7),i=Bt.rotrSL(t,n,1)^Bt.rotrSL(t,n,8)^Bt.shrSL(t,n,7),a=0|Mt[e-2],s=0|Ft[e-2],o=Bt.rotrSH(a,s,19)^Bt.rotrBH(a,s,61)^Bt.shrSH(a,s,6),l=Bt.rotrSL(a,s,19)^Bt.rotrBL(a,s,61)^Bt.shrSL(a,s,6),u=Bt.add4L(i,l,Ft[e-7],Ft[e-16]),c=Bt.add4H(u,r,o,Mt[e-7],Mt[e-16]);Mt[e]=0|c,Ft[e]=0|u}let{Ah:n,Al:r,Bh:i,Bl:a,Ch:s,Cl:o,Dh:l,Dl:u,Eh:c,El:d,Fh:p,Fl:h,Gh:y,Gl:f,Hh:m,Hl:g}=this;for(let e=0;e<80;e++){const t=Bt.rotrSH(c,d,14)^Bt.rotrSH(c,d,18)^Bt.rotrBH(c,d,41),w=Bt.rotrSL(c,d,14)^Bt.rotrSL(c,d,18)^Bt.rotrBL(c,d,41),v=c&p^~c&y,b=d&h^~d&f,A=Bt.add5L(g,w,b,Ut[e],Ft[e]),T=Bt.add5H(A,m,t,v,Ot[e],Mt[e]),P=0|A,S=Bt.rotrSH(n,r,28)^Bt.rotrBH(n,r,34)^Bt.rotrBH(n,r,39),E=Bt.rotrSL(n,r,28)^Bt.rotrBL(n,r,34)^Bt.rotrBL(n,r,39),I=n&i^n&s^i&s,C=r&a^r&o^a&o;m=0|y,g=0|f,y=0|p,f=0|h,p=0|c,h=0|d,({h:c,l:d}=Bt.add(0|l,0|u,0|T,0|P)),l=0|s,u=0|o,s=0|i,o=0|a,i=0|n,a=0|r;const x=Bt.add3L(P,E,C);n=Bt.add3H(x,T,S,I),r=0|x}({h:n,l:r}=Bt.add(0|this.Ah,0|this.Al,0|n,0|r)),({h:i,l:a}=Bt.add(0|this.Bh,0|this.Bl,0|i,0|a)),({h:s,l:o}=Bt.add(0|this.Ch,0|this.Cl,0|s,0|o)),({h:l,l:u}=Bt.add(0|this.Dh,0|this.Dl,0|l,0|u)),({h:c,l:d}=Bt.add(0|this.Eh,0|this.El,0|c,0|d)),({h:p,l:h}=Bt.add(0|this.Fh,0|this.Fl,0|p,0|h)),({h:y,l:f}=Bt.add(0|this.Gh,0|this.Gl,0|y,0|f)),({h:m,l:g}=Bt.add(0|this.Hh,0|this.Hl,0|m,0|g)),this.set(n,r,i,a,s,o,l,u,c,d,p,h,y,f,m,g)}roundClean(){Mt.fill(0),Ft.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const _t=dt(()=>new Lt);const Gt=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==We)return We;throw new Error("unable to locate global object")}(),zt=Gt.crypto||Gt.msCrypto;let Vt=!1;const Ht=function(e,t,n){return function(e,t){const n={sha256:St,sha512:_t}[e];return c(null!=n,"invalid hmac algorithm","algorithm",e),yt.create(n,t)}(e,t).update(n).digest()};let jt=Ht;function Qt(e,t,n){const r=m(t,"key"),i=m(n,"data");return A(jt(e,r,i))}Qt._=Ht,Qt.lock=function(){Vt=!0},Qt.register=function(e){if(Vt)throw new Error("computeHmac is locked");jt=e},Object.freeze(Qt);const[Kt,$t,Wt]=[[],[],[]],Jt=BigInt(0),qt=BigInt(1),Zt=BigInt(2),Yt=BigInt(7),Xt=BigInt(256),en=BigInt(113);for(let e=0,t=qt,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Kt.push(2*(5*r+n)),$t.push((e+1)*(e+2)/2%64);let i=Jt;for(let e=0;e<7;e++)t=(t<<qt^(t>>Yt)*en)%Xt,t&Zt&&(i^=qt<<(qt<<BigInt(e))-qt);Wt.push(i)}const[tn,nn]=xt(Wt,!0),rn=(e,t,n)=>n>32?Rt(e,t,n):kt(e,t,n),an=(e,t,n)=>n>32?Dt(e,t,n):Nt(e,t,n);class sn extends lt{constructor(e,t,n,r=!1,i=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Je(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=nt(this.state)}keccak(){!function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,i=(t+2)%10,a=n[i],s=n[i+1],o=rn(a,s,1)^n[r],l=an(a,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=l}let t=e[2],i=e[3];for(let n=0;n<24;n++){const r=$t[n],a=rn(t,i,r),s=an(t,i,r),o=Kt[n];t=e[o],i=e[o+1],e[o]=a,e[o+1]=s}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=tn[r],e[1]^=nn[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){Ye(this);const{blockLen:t,state:n}=this,r=(e=ot(e)).length;for(let i=0;i<r;){const a=Math.min(t-this.pos,r-i);for(let t=0;t<a;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Ye(this,!1),qe(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();const a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Je(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Xe(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:i,enableXOF:a}=this;return e||(e=new sn(t,n,r,a,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=r,e.enableXOF=a,e.destroyed=this.destroyed,e}}const on=((e,t,n)=>dt(()=>new sn(t,e,n)))(1,136,32);let ln=!1;const un=function(e){return on(e)};let cn=un;function dn(e){const t=m(e,"data");return A(cn(t))}dn._=un,dn.lock=function(){ln=!0},dn.register=function(e){if(ln)throw new TypeError("keccak256 is locked");cn=e},Object.freeze(dn);const pn=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),hn=Uint8Array.from({length:16},(e,t)=>t);let yn=[hn],fn=[hn.map(e=>(9*e+5)%16)];for(let e=0;e<4;e++)for(let t of[yn,fn])t.push(t[e].map(e=>pn[e]));const mn=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),gn=yn.map((e,t)=>e.map(e=>mn[t][e])),wn=fn.map((e,t)=>e.map(e=>mn[t][e])),vn=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),bn=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),An=(e,t)=>e<<t|e>>>32-t;function Tn(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const Pn=new Uint32Array(16);class Sn extends gt{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(e,t){for(let n=0;n<16;n++,t+=4)Pn[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,a=i,s=0|this.h2,o=s,l=0|this.h3,u=l,c=0|this.h4,d=c;for(let e=0;e<5;e++){const t=4-e,p=vn[e],h=bn[e],y=yn[e],f=fn[e],m=gn[e],g=wn[e];for(let t=0;t<16;t++){const r=An(n+Tn(e,i,s,l)+Pn[y[t]]+p,m[t])+c|0;n=c,c=l,l=0|An(s,10),s=i,i=r}for(let e=0;e<16;e++){const n=An(r+Tn(t,a,o,u)+Pn[f[e]]+h,g[e])+d|0;r=d,d=u,u=0|An(o,10),o=a,a=n}}this.set(this.h1+s+u|0,this.h2+l+d|0,this.h3+c+r|0,this.h4+n+a|0,this.h0+i+o|0)}roundClean(){Pn.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}const En=dt(()=>new Sn);let In=!1;const Cn=function(e){return En(e)};let xn=Cn;function kn(e){const t=m(e,"data");return A(xn(t))}kn._=Cn,kn.lock=function(){In=!0},kn.register=function(e){if(In)throw new TypeError("ripemd160 is locked");xn=e},Object.freeze(kn);let Nn=!1;const Rn=function(e,t,n,r,i){return function(e,t,n,r,i){const a={sha256:St,sha512:_t}[i];return c(null!=a,"invalid pbkdf2 algorithm","algorithm",i),mt(a,e,t,{c:n,dkLen:r})}(e,t,n,r,i)};let Dn=Rn;function Bn(e,t,n,r,i){const a=m(e,"password"),s=m(t,"salt");return A(Dn(a,s,n,r,i))}Bn._=Rn,Bn.lock=function(){Nn=!0},Bn.register=function(e){if(Nn)throw new Error("pbkdf2 is locked");Dn=e},Object.freeze(Bn);let On=!1;const Un=function(e){return new Uint8Array(function(e){u(null!=zt,"platform does not support secure random numbers","UNSUPPORTED_OPERATION",{operation:"randomBytes"}),c(Number.isInteger(e)&&e>0&&e<=1024,"invalid length","length",e);const t=new Uint8Array(e);return zt.getRandomValues(t),t}(e))};let Mn=Un;function Fn(e){return Mn(e)}Fn._=Un,Fn.lock=function(){On=!0},Fn.register=function(e){if(On)throw new Error("randomBytes is locked");Mn=e},Object.freeze(Fn);const Ln=(e,t)=>e<<t|e>>>32-t;function _n(e,t,n,r,i,a){let s=e[t++]^n[r++],o=e[t++]^n[r++],l=e[t++]^n[r++],u=e[t++]^n[r++],c=e[t++]^n[r++],d=e[t++]^n[