text: class t{constructor(t){this.view=new DataView(t)}length(){return this.view.byteLength}indexAt(t){return this.view.getUint8(t)}toArrayBuffer(){return this.view.buffer}serializeJson(){return"0x"+Array.prototype.map.call(new Uint8Array(this.view.buffer),t=>("00"+t.toString(16)).slice(-2)).join("")}}class e{constructor(t){this.string=t}length(){return this.string.length/2-1}indexAt(t){return parseInt(this.string.substr(2+2*t,2),16)}toArrayBuffer(){const t=new ArrayBuffer(this.length()),e=new DataView(t);for(let t=0;t<this.length();t++)e.setUint8(t,this.indexAt(t));return t}serializeJson(){return this.string}}class r{constructor(r){if(r instanceof e||r instanceof t)return r;if("string"==typeof r){if(!r.startsWith("0x")||r.length%2!=0)throw new Error("Hex string must start with 0x, and has even numbered length!");return new e(r)}if(r instanceof ArrayBuffer)return new t(r);throw new Error("Reader can only accept hex string or ArrayBuffer!")}static fromRawString(e){const r=new ArrayBuffer(e.length),n=new DataView(r);for(let t=0;t<e.length;t++){const r=e.charCodeAt(t);if(r>255)throw new Error("fromRawString can only accept UTF-8 raw string!");n.setUint8(t,r)}return new t(r)}}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t,e){return t(e={exports:{}},e.exports),e.exports}var o=i((function(t,e){var r=function(t){function e(){this.fetch=!1,this.DOMException=t.DOMException}return e.prototype=t,new e}("undefined"!=typeof self?self:n);!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,i="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),o="FormData"in t,a="ArrayBuffer"in t;if(a)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&s.indexOf(Object.prototype.toString.call(t))>-1};function _(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function l(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function g(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function d(t){var e=new FileReader,r=g(e);return e.readAsArrayBuffer(t),r}function p(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:o&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=p(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=p(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var t,e,r,n=c(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=g(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},o&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=_(t),e=l(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},h.prototype.delete=function(t){delete this.map[_(t)]},h.prototype.get=function(t){return t=_(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(_(t))},h.prototype.set=function(t,e){this.map[_(t)]=l(e)},h.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),f(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),f(t)},n&&(h.prototype[Symbol.iterator]=h.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(t,e){var r,n,i=(e=e||{}).body;if(t instanceof b){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),y.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function m(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}})),e}function w(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},v.call(b.prototype),v.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var k=[301,302,303,307,308];w.redirect=function(t,e){if(-1===k.indexOf(e))throw new RangeError("Invalid status code");return new w(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function D(t,r){return new Promise((function(n,o){var a=new b(t,r);if(a.signal&&a.signal.aborted)return o(new e.DOMException("Aborted","AbortError"));var s=new XMLHttpRequest;function u(){s.abort()}s.onload=function(){var t,e,r={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}})),e)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var i="response"in s?s.response:s.responseText;n(new w(i,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new e.DOMException("Aborted","AbortError"))},s.open(a.method,a.url,!0),"include"===a.credentials?s.withCredentials=!0:"omit"===a.credentials&&(s.withCredentials=!1),"responseType"in s&&i&&(s.responseType="blob"),a.headers.forEach((function(t,e){s.setRequestHeader(e,t)})),a.signal&&(a.signal.addEventListener("abort",u),s.onreadystatechange=function(){4===s.readyState&&a.signal.removeEventListener("abort",u)}),s.send(void 0===a._bodyInit?null:a._bodyInit)}))}D.polyfill=!0,t.fetch||(t.fetch=D,t.Headers=h,t.Request=b,t.Response=w),e.Headers=h,e.Request=b,e.Response=w,e.fetch=D}({})}(r),delete r.fetch.polyfill,(e=r.fetch).default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,t.exports=e})),a=(o.fetch,o.Headers,o.Request,o.Response,i((function(t,e){t.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e){for(var r,n=0;n<e.length;n++)(r=e[n]).enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}function r(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&o(t,e)}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function s(){return(s=a()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&o(i,r.prototype),i}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){function r(){return s(t,arguments,i(this).constructor)}if(null===t||!function(t){return-1!==Function.toString.call(t).indexOf("[native code]")}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)})(t)}function _(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var l=function(e){var o=Math.abs,a=Math.max,s=Math.imul,u=Math.clz32;function l(t,e){var r;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,l),t>l.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");return(r=_(this,i(l).call(this,t))).sign=e,r}return n(l,e),r(l,[{key:"toDebugString",value:function(){var t=["BigInt["],e=!0,r=!1,n=void 0;try{for(var i,o,a=this[Symbol.iterator]();!(e=(i=a.next()).done);e=!0)o=i.value,t.push((o?(o>>>0).toString(16):o)+", ")}catch(t){r=!0,n=t}finally{try{e||null==a.return||a.return()}finally{if(r)throw n}}return t.push("]"),t.join("")}},{key:"toString",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:10;if(2>t||36<t)throw new RangeError("toString() radix argument must be between 2 and 36");return 0===this.length?"0":0==(t&t-1)?l.__toStringBasePowerOfTwo(this,t):l.__toStringGeneric(this,t,!1)}},{key:"__copy",value:function(){for(var t=new l(this.length,this.sign),e=0;e<this.length;e++)t[e]=this[e];return t}},{key:"__trim",value:function(){for(var t=this.length,e=this[t-1];0===e;)e=this[--t-1],this.pop();return 0===t&&(this.sign=!1),this}},{key:"__initializeDigits",value:function(){for(var t=0;t<this.length;t++)this[t]=0}},{key:"__clzmsd",value:function(){return u(this[this.length-1])}},{key:"__inplaceMultiplyAdd",value:function(t,e,r){r>this.length&&(r=this.length);for(var n=65535&t,i=t>>>16,o=0,a=65535&e,u=e>>>16,_=0;_<r;_++){var l=this.__digit(_),f=65535&l,h=l>>>16,c=s(f,n),g=s(f,i),d=s(h,n),p=s(h,i),v=a+(65535&c),y=u+o+(v>>>16)+(c>>>16)+(65535&g)+(65535&d);o=(a=(g>>>16)+(d>>>16)+(65535&p)+(y>>>16))>>>16,a&=65535,u=p>>>16,this.__setDigit(_,65535&v|y<<16)}if(0!==o||0!==a||0!==u)throw new Error("implementation bug")}},{key:"__inplaceAdd",value:function(t,e,r){for(var n,i=0,o=0;o<r;o++)i=(n=this.__halfDigit(e+o)+t.__halfDigit(o)+i)>>>16,this.__setHalfDigit(e+o,n);return i}},{key:"__inplaceSub",value:function(t,e,r){var n=0;if(1&e){e>>=1;for(var i=this.__digit(e),o=65535&i,a=0;a<r-1>>>1;a++){var s=t.__digit(a),u=(i>>>16)-(65535&s)-n;n=1&u>>>16,this.__setDigit(e+a,u<<16|65535&o),n=1&(o=(65535&(i=this.__digit(e+a+1)))-(s>>>16)-n)>>>16}var _=t.__digit(a),l=(i>>>16)-(65535&_)-n;if(n=1&l>>>16,this.__setDigit(e+a,l<<16|65535&o),e+a+1>=this.length)throw new RangeError("out of bounds");0==(1&r)&&(n=1&(o=(65535&(i=this.__digit(e+a+1)))-(_>>>16)-n)>>>16,this.__setDigit(e+t.length,4294901760&i|65535&o))}else{e>>=1;for(var f=0;f<t.length-1;f++){var h=this.__digit(e+f),c=t.__digit(f),g=(65535&h)-(65535&c)-n,d=(h>>>16)-(c>>>16)-(n=1&g>>>16);n=1&d>>>16,this.__setDigit(e+f,d<<16|65535&g)}var p=this.__digit(e+f),v=t.__digit(f),y=(65535&p)-(65535&v)-n;n=1&y>>>16;var b=0;0==(1&r)&&(n=1&(b=(p>>>16)-(v>>>16)-n)>>>16),this.__setDigit(e+f,b<<16|65535&y)}return n}},{key:"__inplaceRightShift",value:function(t){if(0!==t){for(var e,r=this.__digit(0)>>>t,n=this.length-1,i=0;i<n;i++)e=this.__digit(i+1),this.__setDigit(i,e<<32-t|r),r=e>>>t;this.__setDigit(n,r)}}},{key:"__digit",value:function(t){return this[t]}},{key:"__unsignedDigit",value:function(t){return this[t]>>>0}},{key:"__setDigit",value:function(t,e){this[t]=0|e}},{key:"__setDigitGrow",value:function(t,e){this[t]=0|e}},{key:"__halfDigitLength",value:function(){var t=this.length;return 65535>=this.__unsignedDigit(t-1)?2*t-1:2*t}},{key:"__halfDigit",value:function(t){return 65535&this[t>>>1]>>>((1&t)<<4)}},{key:"__setHalfDigit",value:function(t,e){var r=t>>>1,n=this.__digit(r),i=1&t?65535&n|e<<16:4294901760&n|65535&e;this.__setDigit(r,i)}}],[{key:"BigInt",value:function(e){var r=Math.floor,n=Number.isFinite;if("number"==typeof e){if(0===e)return l.__zero();if((0|e)===e)return 0>e?l.__oneDigit(-e,!0):l.__oneDigit(e,!1);if(!n(e)||r(e)!==e)throw new RangeError("The number "+e+" cannot be converted to BigInt because it is not an integer");return l.__fromDouble(e)}if("string"==typeof e){var i=l.__fromString(e);if(null===i)throw new SyntaxError("Cannot convert "+e+" to a BigInt");return i}if("boolean"==typeof e)return!0===e?l.__oneDigit(1,!1):l.__zero();if("object"===t(e)){if(e.constructor===l)return e;var o=l.__toPrimitive(e);return l.BigInt(o)}throw new TypeError("Cannot convert "+e+" to a BigInt")}},{key:"toNumber",value:function(t){var e=t.length;if(0===e)return 0;if(1===e){var r=t.__unsignedDigit(0);return t.sign?-r:r}var n=t.__digit(e-1),i=u(n),o=32*e-i;if(1024<o)return t.sign?-1/0:1/0;var a=o-1,s=n,_=e-1,f=i+1,h=32===f?0:s<<f;h>>>=12;var c=f-12,g=12<=f?0:s<<20+f,d=20+f;0<c&&0<_&&(_--,h|=(s=t.__digit(_))>>>32-c,g=s<<c,d=c),0<d&&0<_&&(_--,g|=(s=t.__digit(_))>>>32-d,d-=32);var p=l.__decideRounding(t,d,_,s);if((1===p||0===p&&1==(1&g))&&0==(g=g+1>>>0)&&0!=++h>>>20&&(h=0,1023<++a))return t.sign?-1/0:1/0;var v=t.sign?-2147483648:0;return a=a+1023<<20,l.__kBitConversionInts[1]=v|a|h,l.__kBitConversionInts[0]=g,l.__kBitConversionDouble[0]}},{key:"unaryMinus",value:function(t){if(0===t.length)return t;var e=t.__copy();return e.sign=!t.sign,e}},{key:"bitwiseNot",value:function(t){return t.sign?l.__absoluteSubOne(t).__trim():l.__absoluteAddOne(t,!0)}},{key:"exponentiate",value:function(t,e){if(e.sign)throw new RangeError("Exponent must be positive");if(0===e.length)return l.__oneDigit(1,!1);if(0===t.length)return t;if(1===t.length&&1===t.__digit(0))return t.sign&&0==(1&e.__digit(0))?l.unaryMinus(t):t;if(1<e.length)throw new RangeError("BigInt too big");var r=e.__unsignedDigit(0);if(1===r)return t;if(r>=l.__kMaxLengthBits)throw new RangeError("BigInt too big");if(1===t.length&&2===t.__digit(0)){var n=1+(r>>>5),i=new l(n,t.sign&&0!=(1&r));i.__initializeDigits();var o=1<<(31&r);return i.__setDigit(n-1,o),i}var a=null,s=t;for(0!=(1&r)&&(a=t),r>>=1;0!==r;r>>=1)s=l.multiply(s,s),0!=(1&r)&&(a=null===a?s:l.multiply(a,s));return a}},{key:"multiply",value:function(t,e){if(0===t.length)return t;if(0===e.length)return e;var r=t.length+e.length;32<=t.__clzmsd()+e.__clzmsd()&&r--;var n=new l(r,t.sign!==e.sign);n.__initializeDigits();for(var i=0;i<t.length;i++)l.__multiplyAccumulate(e,t.__digit(i),n,i);return n.__trim()}},{key:"divide",value:function(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>l.__absoluteCompare(t,e))return l.__zero();var r,n=t.sign!==e.sign,i=e.__unsignedDigit(0);if(1===e.length&&65535>=i){if(1===i)return n===t.sign?t:l.unaryMinus(t);r=l.__absoluteDivSmall(t,i,null)}else r=l.__absoluteDivLarge(t,e,!0,!1);return r.sign=n,r.__trim()}},{key:"remainder",value:function(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>l.__absoluteCompare(t,e))return t;var r=e.__unsignedDigit(0);if(1===e.length&&65535>=r){if(1===r)return l.__zero();var n=l.__absoluteModSmall(t,r);return 0===n?l.__zero():l.__oneDigit(n,t.sign)}var i=l.__absoluteDivLarge(t,e,!1,!0);return i.sign=t.sign,i.__trim()}},{key:"add",value:function(t,e){var r=t.sign;return r===e.sign?l.__absoluteAdd(t,e,r):0<=l.__absoluteCompare(t,e)?l.__absoluteSub(t,e,r):l.__absoluteSub(e,t,!r)}},{key:"subtract",value:function(t,e){var r=t.sign;return r===e.sign?0<=l.__absoluteCompare(t,e)?l.__absoluteSub(t,e,r):l.__absoluteSub(e,t,!r):l.__absoluteAdd(t,e,r)}},{key:"leftShift",value:function(t,e){return 0===e.length||0===t.length?t:e.sign?l.__rightShiftByAbsolute(t,e):l.__leftShiftByAbsolute(t,e)}},{key:"signedRightShift",value:function(t,e){return 0===e.length||0===t.length?t:e.sign?l.__leftShiftByAbsolute(t,e):l.__rightShiftByAbsolute(t,e)}},{key:"unsignedRightShift",value:function(){throw new TypeError("BigInts have no unsigned right shift; use >> instead")}},{key:"lessThan",value:function(t,e){return 0>l.__compareToBigInt(t,e)}},{key:"lessThanOrEqual",value:function(t,e){return 0>=l.__compareToBigInt(t,e)}},{key:"greaterThan",value:function(t,e){return 0<l.__compareToBigInt(t,e)}},{key:"greaterThanOrEqual",value:function(t,e){return 0<=l.__compareToBigInt(t,e)}},{key:"equal",value:function(t,e){if(t.sign!==e.sign)return!1;if(t.length!==e.length)return!1;for(var r=0;r<t.length;r++)if(t.__digit(r)!==e.__digit(r))return!1;return!0}},{key:"notEqual",value:function(t,e){return!l.equal(t,e)}},{key:"bitwiseAnd",value:function(t,e){if(!t.sign&&!e.sign)return l.__absoluteAnd(t,e).__trim();if(t.sign&&e.sign){var r=a(t.length,e.length)+1,n=l.__absoluteSubOne(t,r),i=l.__absoluteSubOne(e);return n=l.__absoluteOr(n,i,n),l.__absoluteAddOne(n,!0,n).__trim()}if(t.sign){var o=[e,t];t=o[0],e=o[1]}return l.__absoluteAndNot(t,l.__absoluteSubOne(e)).__trim()}},{key:"bitwiseXor",value:function(t,e){if(!t.sign&&!e.sign)return l.__absoluteXor(t,e).__trim();if(t.sign&&e.sign){var r=a(t.length,e.length),n=l.__absoluteSubOne(t,r),i=l.__absoluteSubOne(e);return l.__absoluteXor(n,i,n).__trim()}var o=a(t.length,e.length)+1;if(t.sign){var s=[e,t];t=s[0],e=s[1]}var u=l.__absoluteSubOne(e,o);return u=l.__absoluteXor(u,t,u),l.__absoluteAddOne(u,!0,u).__trim()}},{key:"bitwiseOr",value:function(t,e){var r=a(t.length,e.length);if(!t.sign&&!e.sign)return l.__absoluteOr(t,e).__trim();if(t.sign&&e.sign){var n=l.__absoluteSubOne(t,r),i=l.__absoluteSubOne(e);return n=l.__absoluteAnd(n,i,n),l.__absoluteAddOne(n,!0,n).__trim()}if(t.sign){var o=[e,t];t=o[0],e=o[1]}var s=l.__absoluteSubOne(e,r);return s=l.__absoluteAndNot(s,t,s),l.__absoluteAddOne(s,!0,s).__trim()}},{key:"asIntN",value:function(t,e){if(0===e.length)return e;if(0===t)return l.__zero();if(t>=l.__kMaxLengthBits)return e;var r=t+31>>>5;if(e.length<r)return e;var n=e.__unsignedDigit(r-1),i=1<<(31&t-1);if(e.length===r&&n<i)return e;if((n&i)!==i)return l.__truncateToNBits(t,e);if(!e.sign)return l.__truncateAndSubFromPowerOfTwo(t,e,!0);if(0==(n&i-1)){for(var o=r-2;0<=o;o--)if(0!==e.__digit(o))return l.__truncateAndSubFromPowerOfTwo(t,e,!1);return e.length===r&&n===i?e:l.__truncateToNBits(t,e)}return l.__truncateAndSubFromPowerOfTwo(t,e,!1)}},{key:"asUintN",value:function(t,e){if(0===e.length)return e;if(0===t)return l.__zero();if(e.sign){if(t>l.__kMaxLengthBits)throw new RangeError("BigInt too big");return l.__truncateAndSubFromPowerOfTwo(t,e,!1)}if(t>=l.__kMaxLengthBits)return e;var r=t+31>>>5;if(e.length<r)return e;var n=31&t;if(e.length==r){if(0==n)return e;if(0==e.__digit(r-1)>>>n)return e}return l.__truncateToNBits(t,e)}},{key:"ADD",value:function(t,e){if(t=l.__toPrimitive(t),e=l.__toPrimitive(e),"string"==typeof t)return"string"!=typeof e&&(e=e.toString()),t+e;if("string"==typeof e)return t.toString()+e;if(t=l.__toNumeric(t),e=l.__toNumeric(e),l.__isBigInt(t)&&l.__isBigInt(e))return l.add(t,e);if("number"==typeof t&&"number"==typeof e)return t+e;throw new TypeError("Cannot mix BigInt and other types, use explicit conversions")}},{key:"LT",value:function(t,e){return l.__compare(t,e,0)}},{key:"LE",value:function(t,e){return l.__compare(t,e,1)}},{key:"GT",value:function(t,e){return l.__compare(t,e,2)}},{key:"GE",value:function(t,e){return l.__compare(t,e,3)}},{key:"EQ",value:function(e,r){for(;;){if(l.__isBigInt(e))return l.__isBigInt(r)?l.equal(e,r):l.EQ(r,e);if("number"==typeof e){if(l.__isBigInt(r))return l.__equalToNumber(r,e);if("object"!==t(r))return e==r;r=l.__toPrimitive(r)}else if("string"==typeof e){if(l.__isBigInt(r))return null!==(e=l.__fromString(e))&&l.equal(e,r);if("object"!==t(r))return e==r;r=l.__toPrimitive(r)}else if("boolean"==typeof e){if(l.__isBigInt(r))return l.__equalToNumber(r,+e);if("object"!==t(r))return e==r;r=l.__toPrimitive(r)}else if("symbol"===t(e)){if(l.__isBigInt(r))return!1;if("object"!==t(r))return e==r;r=l.__toPrimitive(r)}else{if("object"!==t(e))return e==r;if("object"===t(r)&&r.constructor!==l)return e==r;e=l.__toPrimitive(e)}}}},{key:"NE",value:function(t,e){return!l.EQ(t,e)}},{key:"__zero",value:function(){return new l(0,!1)}},{key:"__oneDigit",value:function(t,e){var r=new l(1,e);return r.__setDigit(0,t),r}},{key:"__decideRounding",value:function(t,e,r,n){if(0<e)return-1;var i;if(0>e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}var o=1<<i;if(0==(n&o))return-1;if(0!=(n&(o-=1)))return 1;for(;0<r;)if(r--,0!==t.__digit(r))return 1;return 0}},{key:"__fromDouble",value:function(t){l.__kBitConversionDouble[0]=t;var e,r=(2047&l.__kBitConversionInts[1]>>>20)-1023,n=1+(r>>>5),i=new l(n,0>t),o=1048575&l.__kBitConversionInts[1]|1048576,a=l.__kBitConversionInts[0],s=31&r,u=0;if(s<20){var _=20-s;u=_+32,e=o>>>_,o=o<<32-_|a>>>_,a<<=32-_}else if(20===s)u=32,e=o,o=a;else{var f=s-20;u=32-f,e=o<<f|a>>>32-f,o=a<<f}i.__setDigit(n-1,e);for(var h=n-2;0<=h;h--)0<u?(u-=32,e=o,o=a):e=0,i.__setDigit(h,e);return i.__trim()}},{key:"__isWhitespace",value:function(t){return!!(13>=t&&9<=t)||(159>=t?32==t:131071>=t?160==t||5760==t:196607>=t?10>=(t&=131071)||40==t||41==t||47==t||95==t||4096==t:65279==t)}},{key:"__fromString",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,r=0,n=t.length,i=0;if(i===n)return l.__zero();for(var o=t.charCodeAt(i);l.__isWhitespace(o);){if(++i===n)return l.__zero();o=t.charCodeAt(i)}if(43===o){if(++i===n)return null;o=t.charCodeAt(i),r=1}else if(45===o){if(++i===n)return null;o=t.charCodeAt(i),r=-1}if(0===e){if(e=10,48===o){if(++i===n)return l.__zero();if(88===(o=t.charCodeAt(i))||120===o){if(e=16,++i===n)return null;o=t.charCodeAt(i)}else if(79===o||111===o){if(e=8,++i===n)return null;o=t.charCodeAt(i)}else if(66===o||98===o){if(e=2,++i===n)return null;o=t.charCodeAt(i)}}}else if(16===e&&48===o){if(++i===n)return l.__zero();if(88===(o=t.charCodeAt(i))||120===o){if(++i===n)return null;o=t.charCodeAt(i)}}for(;48===o;){if(++i===n)return l.__zero();o=t.charCodeAt(i)}var a=n-i,s=l.__kMaxBitsPerChar[e],u=l.__kBitsPerCharTableMultiplier-1;if(a>1073741824/s)return null;var _=s*a+u>>>l.__kBitsPerCharTableShift,f=new l(_+31>>>5,!1),h=10>e?e:10,c=10<e?e-10:0;if(0==(e&e-1)){s>>=l.__kBitsPerCharTableShift;var g=[],d=[],p=!1;do{for(var v,y=0,b=0;;){if(v=void 0,o-48>>>0<h)v=o-48;else{if(!((32|o)-97>>>0<c)){p=!0;break}v=(32|o)-87}if(b+=s,y=y<<s|v,++i===n){p=!0;break}if(o=t.charCodeAt(i),32<b+s)break}g.push(y),d.push(b)}while(!p);l.__fillFromParts(f,g,d)}else{f.__initializeDigits();var m=!1,w=0;do{for(var k,D=0,B=1;;){if(k=void 0,o-48>>>0<h)k=o-48;else{if(!((32|o)-97>>>0<c)){m=!0;break}k=(32|o)-87}var A=B*e;if(4294967295<A)break;if(B=A,D=D*e+k,w++,++i===n){m=!0;break}o=t.charCodeAt(i)}var P=s*w+(u=32*l.__kBitsPerCharTableMultiplier-1)>>>l.__kBitsPerCharTableShift+5;f.__inplaceMultiplyAdd(B,D,P)}while(!m)}if(i!==n){if(!l.__isWhitespace(o))return null;for(i++;i<n;i++)if(o=t.charCodeAt(i),!l.__isWhitespace(o))return null}return 0!==r&&10!==e?null:(f.sign=-1===r,f.__trim())}},{key:"__fillFromParts",value:function(t,e,r){for(var n=0,i=0,o=0,a=e.length-1;0<=a;a--){var s=e[a],u=r[a];i|=s<<o,32===(o+=u)?(t.__setDigit(n++,i),o=0,i=0):32<o&&(t.__setDigit(n++,i),i=s>>>u-(o-=32))}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;n<t.length;n++)t.__setDigit(n,0)}},{key:"__toStringBasePowerOfTwo",value:function(t,e){var r=t.length,n=e-1,i=n=(15&(n=(51&(n=(85&n>>>1)+(85&n))>>>2)+(51&n))>>>4)+(15&n),o=e-1,a=t.__digit(r-1),s=0|(32*r-u(a)+i-1)/i;if(t.sign&&s++,268435456<s)throw new Error("string too long");for(var _=Array(s),f=s-1,h=0,c=0,g=0;g<r-1;g++){var d=t.__digit(g),p=(h|d<<c)&o;_[f--]=l.__kConversionChars[p];var v=i-c;for(h=d>>>v,c=32-v;c>=i;)_[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var y=(h|a<<c)&o;for(_[f--]=l.__kConversionChars[y],h=a>>>i-c;0!==h;)_[f--]=l.__kConversionChars[h&o],h>>>=i;if(t.sign&&(_[f--]="-"),-1!==f)throw new Error("implementation bug");return _.join("")}},{key:"__toStringGeneric",value:function(t,e,r){var n=t.length;if(0===n)return"";if(1===n){var i=t.__unsignedDigit(0).toString(e);return!1===r&&t.sign&&(i="-"+i),i}var o,a,s=32*n-u(t.__digit(n-1)),_=l.__kMaxBitsPerChar[e]-1,f=s*l.__kBitsPerCharTableMultiplier,h=1+(f=0|(f+=_-1)/_)>>1,c=l.exponentiate(l.__oneDigit(e,!1),l.__oneDigit(h,!1)),g=c.__unsignedDigit(0);if(1===c.length&&65535>=g){(o=new l(t.length,!1)).__initializeDigits();for(var d,p=0,v=2*t.length-1;0<=v;v--)d=p<<16|t.__halfDigit(v),o.__setHalfDigit(v,0|d/g),p=0|d%g;a=p.toString(e)}else{var y=l.__absoluteDivLarge(t,c,!0,!0);o=y.quotient;var b=y.remainder.__trim();a=l.__toStringGeneric(b,e,!0)}o.__trim();for(var m=l.__toStringGeneric(o,e,!0);a.length<h;)a="0"+a;return!1===r&&t.sign&&(m="-"+m),m+a}},{key:"__unequalSign",value:function(t){return t?-1:1}},{key:"__absoluteGreater",value:function(t){return t?-1:1}},{key:"__absoluteLess",value:function(t){return t?1:-1}},{key:"__compareToBigInt",value:function(t,e){var r=t.sign;if(r!==e.sign)return l.__unequalSign(r);var n=l.__absoluteCompare(t,e);return 0<n?l.__absoluteGreater(r):0>n?l.__absoluteLess(r):0}},{key:"__compareToNumber",value:function(t,e){if(!0|e){var r=t.sign,n=0>e;if(r!==n)return l.__unequalSign(r);if(0===t.length){if(n)throw new Error("implementation bug");return 0===e?0:-1}if(1<t.length)return l.__absoluteGreater(r);var i=o(e),a=t.__unsignedDigit(0);return a>i?l.__absoluteGreater(r):a<i?l.__absoluteLess(r):0}return l.__compareToDouble(t,e)}},{key:"__compareToDouble",value:function(t,e){if(e!=e)return e;if(e===1/0)return-1;if(e===-1/0)return 1;var r=t.sign;if(r!==0>e)return l.__unequalSign(r);if(0===e)throw new Error("implementation bug: should be handled elsewhere");if(0===t.length)return-1;l.__kBitConversionDouble[0]=e;var n=2047&l.__kBitConversionInts[1]>>>20;if(2047==n)throw new Error("implementation bug: handled elsewhere");var i=n-1023;if(0>i)return l.__absoluteGreater(r);var o=t.length,a=t.__digit(o-1),s=u(a),_=32*o-s,f=i+1;if(_<f)return l.__absoluteLess(r);if(_>f)return l.__absoluteGreater(r);var h=1048576|1048575&l.__kBitConversionInts[1],c=l.__kBitConversionInts[0],g=31-s;if(g!==(_-1)%31)throw new Error("implementation bug");var d,p=0;if(g<20){var v=20-g;p=v+32,d=h>>>v,h=h<<32-v|c>>>v,c<<=32-v}else if(20===g)p=32,d=h,h=c;else{var y=g-20;p=32-y,d=h<<y|c>>>32-y,h=c<<y}if((a>>>=0)>(d>>>=0))return l.__absoluteGreater(r);if(a<d)return l.__absoluteLess(r);for(var b=o-2;0<=b;b--){0<p?(p-=32,d=h>>>0,h=c,c=0):d=0;var m=t.__unsignedDigit(b);if(m>d)return l.__absoluteGreater(r);if(m<d)return l.__absoluteLess(r)}if(0!==h||0!==c){if(0===p)throw new Error("implementation bug");return l.__absoluteLess(r)}return 0}},{key:"__equalToNumber",value:function(t,e){return e|0===e?0===e?0===t.length:1===t.length&&t.sign===0>e&&t.__unsignedDigit(0)===o(e):0===l.__compareToDouble(t,e)}},{key:"__comparisonResultToBool",value:function(t,e){switch(e){case 0:return 0>t;case 1:return 0>=t;case 2:return 0<t;case 3:return 0<=t}throw new Error("unreachable")}},{key:"__compare",value:function(t,e,r){if(t=l.__toPrimitive(t),e=l.__toPrimitive(e),"string"==typeof t&&"string"==typeof e)switch(r){case 0:return t<e;case 1:return t<=e;case 2:return t>e;case 3:return t>=e}if(l.__isBigInt(t)&&"string"==typeof e)return null!==(e=l.__fromString(e))&&l.__comparisonResultToBool(l.__compareToBigInt(t,e),r);if("string"==typeof t&&l.__isBigInt(e))return null!==(t=l.__fromString(t))&&l.__comparisonResultToBool(l.__compareToBigInt(t,e),r);if(t=l.__toNumeric(t),e=l.__toNumeric(e),l.__isBigInt(t)){if(l.__isBigInt(e))return l.__comparisonResultToBool(l.__compareToBigInt(t,e),r);if("number"!=typeof e)throw new Error("implementation bug");return l.__comparisonResultToBool(l.__compareToNumber(t,e),r)}if("number"!=typeof t)throw new Error("implementation bug");if(l.__isBigInt(e))return l.__comparisonResultToBool(l.__compareToNumber(e,t),2^r);if("number"!=typeof e)throw new Error("implementation bug");return 0===r?t<e:1===r?t<=e:2===r?t>e:3===r?t>=e:void 0}},{key:"__absoluteAdd",value:function(t,e,r){if(t.length<e.length)return l.__absoluteAdd(e,t,r);if(0===t.length)return t;if(0===e.length)return t.sign===r?t:l.unaryMinus(t);var n=t.length;(0===t.__clzmsd()||e.length===t.length&&0===e.__clzmsd())&&n++;for(var i=new l(n,r),o=0,a=0;a<e.length;a++){var s=e.__digit(a),u=t.__digit(a),_=(65535&u)+(65535&s)+o,f=(u>>>16)+(s>>>16)+(_>>>16);o=f>>>16,i.__setDigit(a,65535&_|f<<16)}for(;a<t.length;a++){var h=t.__digit(a),c=(65535&h)+o,g=(h>>>16)+(c>>>16);o=g>>>16,i.__setDigit(a,65535&c|g<<16)}return a<i.length&&i.__setDigit(a,o),i.__trim()}},{key:"__absoluteSub",value:function(t,e,r){if(0===t.length)return t;if(0===e.length)return t.sign===r?t:l.unaryMinus(t);for(var n=new l(t.length,r),i=0,o=0;o<e.length;o++){var a=t.__digit(o),s=e.__digit(o),u=(65535&a)-(65535&s)-i,_=(a>>>16)-(s>>>16)-(i=1&u>>>16);i=1&_>>>16,n.__setDigit(o,65535&u|_<<16)}for(;o<t.length;o++){var f=t.__digit(o),h=(65535&f)-i,c=(f>>>16)-(i=1&h>>>16);i=1&c>>>16,n.__setDigit(o,65535&h|c<<16)}return n.__trim()}},{key:"__absoluteAddOne",value:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,n=t.length;null===r?r=new l(n,e):r.sign=e;for(var i=!0,o=0;o<n;o++){var a=t.__digit(o),s=-1===a;i&&(a=0|a+1),i=s,r.__setDigit(o,a)}return i&&r.__setDigitGrow(n,1),r}},{key:"__absoluteSubOne",value:function(t,e){for(var r=t.length,n=new l(e=e||r,!1),i=!0,o=0;o<r;o++){var a=t.__digit(o),s=0===a;i&&(a=0|a-1),i=s,n.__setDigit(o,a)}for(var u=r;u<e;u++)n.__setDigit(u,0);return n}},{key:"__absoluteAnd",value:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,n=t.length,i=e.length,o=i;if(n<i){o=n;var a=t,s=n;t=e,n=i,e=a,i=s}var u=o;null===r?r=new l(u,!1):u=r.length;for(var _=0;_<o;_++)r.__setDigit(_,t.__digit(_)&e.__digit(_));for(;_<u;_++)r.__setDigit(_,0);return r}},{key:"__absoluteAndNot",value:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,n=t.length,i=e.length,o=i;n<i&&(o=n);var a=n;null===r?r=new l(a,!1):a=r.length;for(var s=0;s<o;s++)r.__setDigit(s,t.__digit(s)&~e.__digit(s));for(;s<n;s++)r.__setDigit(s,t.__digit(s));for(;s<a;s++)r.__setDigit(s,0);return r}},{key:"__absoluteOr",value:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,n=t.length,i=e.length,o=i;if(n<i){o=n;var a=t,s=n;t=e,n=i,e=a,i=s}var u=n;null===r?r=new l(u,!1):u=r.length;for(var _=0;_<o;_++)r.__setDigit(_,t.__digit(_)|e.__digit(_));for(;_<n;_++)r.__setDigit(_,t.__digit(_));for(;_<u;_++)r.__setDigit(_,0);return r}},{key:"__absoluteXor",value:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,n=t.length,i=e.length,o=i;if(n<i){o=n;var a=t,s=n;t=e,n=i,e=a,i=s}var u=n;null===r?r=new l(u,!1):u=r.length;for(var _=0;_<o;_++)r.__setDigit(_,t.__digit(_)^e.__digit(_));for(;_<n;_++)r.__setDigit(_,t.__digit(_));for(;_<u;_++)r.__setDigit(_,0);return r}},{key:"__absoluteCompare",value:function(t,e){var r=t.length-e.length;if(0!=r)return r;for(var n=t.length-1;0<=n&&t.__digit(n)===e.__digit(n);)n--;return 0>n?0:t.__unsignedDigit(n)>e.__unsignedDigit(n)?1:-1}},{key:"__multiplyAccumulate",value:function(t,e,r,n){if(0!==e){for(var i=65535&e,o=e>>>16,a=0,u=0,_=0,l=0;l<t.length;l++,n++){var f=r.__digit(n),h=65535&f,c=f>>>16,g=t.__digit(l),d=65535&g,p=g>>>16,v=s(d,i),y=s(d,o),b=s(p,i),m=s(p,o);a=(u=(y>>>16)+(b>>>16)+(65535&m)+(a=(c+=_+a+((h+=u+(65535&v))>>>16)+(v>>>16)+(65535&y)+(65535&b))>>>16))>>>16,u&=65535,_=m>>>16,f=65535&h|c<<16,r.__setDigit(n,f)}for(;0!==a||0!==u||0!==_;n++){var w=r.__digit(n),k=(65535&w)+u,D=(w>>>16)+(k>>>16)+_+a;u=0,_=0,a=D>>>16,w=65535&k|D<<16,r.__setDigit(n,w)}}}},{key:"__internalMultiplyAdd",value:function(t,e,r,n,i){for(var o=r,a=0,u=0;u<n;u++){var _=t.__digit(u),l=s(65535&_,e),f=(65535&l)+a+o;o=f>>>16;var h=s(_>>>16,e),c=(65535&h)+(l>>>16)+o;o=c>>>16,a=h>>>16,i.__setDigit(u,c<<16|65535&f)}if(i.length>n)for(i.__setDigit(n++,o+a);n<i.length;)i.__setDigit(n++,0);else if(0!==o+a)throw new Error("implementation bug")}},{key:"__absoluteDivSmall",value:function(t,e,r){null===r&&(r=new l(t.length,!1));for(var n=0,i=2*t.length-1;0<=i;i-=2){var o=(n<<16|t.__halfDigit(i))>>>0,a=0|o/e,s=0|(o=((n=0|o%e)<<16|t.__halfDigit(i-1))>>>0)/e;n=0|o%e,r.__setDigit(i>>>1,a<<16|s)}return r}},{key:"__absoluteModSmall",value:function(t,e){for(var r=0,n=2*t.length-1;0<=n;n--)r=0|((r<<16|t.__halfDigit(n))>>>0)%e;return r}},{key:"__absoluteDivLarge",value:function(t,e,r,n){var i=e.__halfDigitLength(),o=e.length,a=t.__halfDigitLength()-i,u=null;r&&(u=new l(a+2>>>1,!1)).__initializeDigits();var _=new l(i+2>>>1,!1);_.__initializeDigits();var f=l.__clz16(e.__halfDigit(i-1));0<f&&(e=l.__specialLeftShift(e,f,0));for(var h=l.__specialLeftShift(t,f,1),c=e.__halfDigit(i-1),g=0,d=a;0<=d;d--){var p=65535,v=h.__halfDigit(d+i);if(v!==c){var y=(v<<16|h.__halfDigit(d+i-1))>>>0;p=0|y/c;for(var b=0|y%c,m=e.__halfDigit(i-2),w=h.__halfDigit(d+i-2);s(p,m)>>>0>(b<<16|w)>>>0&&(p--,!(65535<(b+=c))););}l.__internalMultiplyAdd(e,p,0,o,_);var k=h.__inplaceSub(_,d,i+1);0!==k&&(k=h.__inplaceAdd(e,d,i),h.__setHalfDigit(d+i,h.__halfDigit(d+i)+k),p--),r&&(1&d?g=p<<16:u.__setDigit(d>>>1,g|p))}return n?(h.__inplaceRightShift(f),r?{quotient:u,remainder:h}:h):r?u:void 0}},{key:"__clz16",value:function(t){return u(t)-16}},{key:"__specialLeftShift",value:function(t,e,r){var n=t.length,i=new l(n+r,!1);if(0===e){for(var o=0;o<n;o++)i.__setDigit(o,t.__digit(o));return 0<r&&i.__setDigit(n,0),i}for(var a,s=0,u=0;u<n;u++)a=t.__digit(u),i.__setDigit(u,a<<e|s),s=a>>>32-e;return 0<r&&i.__setDigit(n,s),i}},{key:"__leftShiftByAbsolute",value:function(t,e){var r=l.__toShiftAmount(e);if(0>r)throw new RangeError("BigInt too big");var n=r>>>5,i=31&r,o=t.length,a=0!==i&&0!=t.__digit(o-1)>>>32-i,s=o+n+(a?1:0),u=new l(s,t.sign);if(0===i){for(var _=0;_<n;_++)u.__setDigit(_,0);for(;_<s;_++)u.__setDigit(_,t.__digit(_-n))}else{for(var f=0,h=0;h<n;h++)u.__setDigit(h,0);for(var c,g=0;g<o;g++)c=t.__digit(g),u.__setDigit(g+n,c<<i|f),f=c>>>32-i;if(a)u.__setDigit(o+n,f);else if(0!==f)throw new Error("implementation bug")}return u.__trim()}},{key:"__rightShiftByAbsolute",value:function(t,e){var r=t.length,n=t.sign,i=l.__toShiftAmount(e);if(0>i)return l.__rightShiftByMaximum(n);var o=i>>>5,a=31&i,s=r-o;if(0>=s)return l.__rightShiftByMaximum(n);var u=!1;if(n)if(0!=(t.__digit(o)&(1<<a)-1))u=!0;else for(var _=0;_<o;_++)if(0!==t.__digit(_)){u=!0;break}u&&0===a&&0==~t.__digit(r-1)&&s++;var f=new l(s,n);if(0===a)for(var h=o;h<r;h++)f.__setDigit(h-o,t.__digit(h));else{for(var c,g=t.__digit(o)>>>a,d=r-o-1,p=0;p<d;p++)c=t.__digit(p+o+1),f.__setDigit(p,c<<32-a|g),g=c>>>a;f.__setDigit(d,g)}return u&&(f=l.__absoluteAddOne(f,!0,f)),f.__trim()}},{key:"__rightShiftByMaximum",value:function(t){return t?l.__oneDigit(1,!0):l.__zero()}},{key:"__toShiftAmount",value:function(t){if(1<t.length)return-1;var e=t.__unsignedDigit(0);return e>l.__kMaxLengthBits?-1:e}},{key:"__toPrimitive",value:function(e){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"default";if("object"!==t(e))return e;if(e.constructor===l)return e;var n=e[Symbol.toPrimitive];if(n){var i=n(r);if("object"!==t(i))return i;throw new TypeError("Cannot convert object to primitive value")}var o=e.valueOf;if(o){var a=o.call(e);if("object"!==t(a))return a}var s=e.toString;if(s){var u=s.call(e);if("object"!==t(u))return u}throw new TypeError("Cannot convert object to primitive value")}},{key:"__toNumeric",value:function(t){return l.__isBigInt(t)?t:+t}},{key:"__isBigInt",value:function(e){return"object"===t(e)&&e.constructor===l}},{key:"__truncateToNBits",value:function(t,e){for(var r=t+31>>>5,n=new l(r,e.sign),i=r-1,o=0;o<i;o++)n.__setDigit(o,e.__digit(o));var a=e.__digit(i);if(0!=(31&t)){var s=32-(31&t);a=a<<s>>>s}return n.__setDigit(i,a),n.__trim()}},{key:"__truncateAndSubFromPowerOfTwo",value:function(t,e,r){for(var n=Math.min,i=t+31>>>5,o=new l(i,r),a=0,s=i-1,u=0,_=n(s,e.length);a<_;a++){var f=e.__digit(a),h=0-(65535&f)-u,c=0-(f>>>16)-(u=1&h>>>16);u=1&c>>>16,o.__setDigit(a,65535&h|c<<16)}for(;a<s;a++)o.__setDigit(a,0|-u);var g,d=s<e.length?e.__digit(s):0,p=31&t;if(0===p){var v=0-(65535&d)-u;g=65535&v|0-(d>>>16)-(u=1&v>>>16)<<16}else{var y=32-p,b=1<<32-y,m=(65535&b)-(65535&(d=d<<y>>>y))-u;g=65535&m|(b>>>16)-(d>>>16)-(u=1&m>>>16)<<16,g&=b-1}return o.__setDigit(s,g),o.__trim()}},{key:"__digitPow",value:function(t,e){for(var r=1;0<e;)1&e&&(r*=t),e>>>=1,t*=t;return r}}]),l}(u(Array));return l.__kMaxLength=33554432,l.__kMaxLengthBits=l.__kMaxLength<<5,l.__kMaxBitsPerChar=[0,0,32,51,64,75,83,90,96,102,107,111,115,119,122,126,128,131,134,136,139,141,143,145,147,149,151,153,154,156,158,159,160,162,163,165,166],l.__kBitsPerCharTableShift=5,l.__kBitsPerCharTableMultiplier=1<<l.__kBitsPerCharTableShift,l.__kConversionChars=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],l.__kBitConversionBuffer=new ArrayBuffer(8),l.__kBitConversionDouble=new Float64Array(l.__kBitConversionBuffer),l.__kBitConversionInts=new Int32Array(l.__kBitConversionBuffer),l}()})));const s={get:(t,e)=>async(...r)=>{const n=Math.round(1e7*Math.random()),i=await o(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),a=await i.json();if(a.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(a.error)throw new Error(`JSONRPCError: server error ${JSON.stringify(a.error)}`);return a.result}};class u{constructor(t){return this.uri=t,new Proxy(this,s)}}function _(t){return a.BigInt(t)}function l(t){return"0x"+t.toString(16)}function f(t,e,r,n=[]){!function(t,e){if(!(e instanceof Object))throw new Error(`${t} is not an object!`)}(t,e);const i=Object.keys(e).sort(),o=r.length,a=r.length+n.length,s=`${t} does not have correct keys! Required keys: [${r.sort().join(", ")}], optional keys: [${n.sort().join(", ")}], actual keys: [${i.join(", ")}]`;if(i.length<o||i.length>a)throw new Error(s);let u=i.filter(t=>!r.includes(t));if(i.length-u.length!==o)throw new Error(s);if(u.find(t=>!n.includes(t)))throw new Error(s)}function h(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(`${t} must be a hex string!`)}function c(t,e){if(h(t,e),66!=e.length)throw new Error(`${t} must be a hex string of 66 bytes long!`)}function g(t,e){if("0x0"!==e&&!/^0x[1-9a-fA-F][0-9a-fA-F]*$/.test(e))throw new Error(`${t} must be a hex integer!`)}function d(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(f(r,t,["code_hash","hash_type","args"],[]),c(`${r}.code_hash`,t.code_hash),h(`${r}.args`,t.args),"data"!==t.hash_type&&"type"!==t.hash_type)throw new Error(`${r}.hash_type must be either data or type!`)}function p(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){f(r,t,["tx_hash","index"],[]),c(`${r}.tx_hash`,t.tx_hash),g(`${r}.index`,t.index)}function v(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){f(r,t,["since","previous_output"],[]),g(`${r}.since`,t.since),e&&p(t.previous_output,{debugPath:`${r}.previous_output`})}function y(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){f(r,t,["capacity","lock"],["type"]),g(`${r}.capacity`,t.capacity),e&&(d(t.lock,{debugPath:`${r}.lock`}),t.type&&d(t.type,{debugPath:`${r}.type`}))}function b(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(f(r,t,["out_point","dep_type"],[]),"code"!==t.dep_type&&"dep_group"!==t.dep_type)throw new Error(`${r}.dep_type must be either code or dep_group!`);e&&p(t.out_point,{debugPath:`${r}.out_point`})}function m(t,e,r,n){if(!Array.isArray(e))throw new Error(`${t} is not an array!`);if(n)for(let n=0;n<e.length;n++)r(`${t}[${n}]`,e[n])}function w(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function k(t,e,r){g(`${t}.version`,e.version),m(`${t}.cell_deps`,e.cell_deps,w(b,r),r),m(`${t}.header_deps`,e.header_deps,c,r),m(`${t}.inputs`,e.inputs,w(v,r),r),m(`${t}.outputs`,e.outputs,w(y,r),r),m(`${t}.outputs_data`,e.outputs_data,h,r)}function D(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){f(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),k(r,t,e)}function B(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){f(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),k(r,t,e),m(`${r}.witnesses`,t.witnesses,h,e)}function A(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){f(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){g(`${t}.version`,e.version),g(`${t}.compact_target`,e.compact_target),g(`${t}.timestamp`,e.timestamp),g(`${t}.number`,e.number),g(`${t}.epoch`,e.epoch),c(`${t}.parent_hash`,e.parent_hash),c(`${t}.transactions_root`,e.transactions_root),c(`${t}.proposals_hash`,e.proposals_hash),c(`${t}.uncles_hash`,e.uncles_hash),c(`${t}.dao`,e.dao)}(r,t)}function P(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(f(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),h(`${r}.nonce`,t.nonce),34!=t.nonce.length)throw new Error(`${r}.nonce must be a hex string of 34 bytes long!`)}function T(t,e){if(h(t,e),22!=e.length)throw new Error(`${t} must be a hex string of 22 bytes long!`)}function S(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){f(r,t,["header","proposals"],[]),e&&P(t.header,{debugPath:`${r}.header`}),m(`${r}.proposals`,t.proposals,T,e)}function E(t,{nestedValidation:e=!0,debugPath:r="block"}={}){f(r,t,["header","uncles","transactions","proposals"],[]),e&&P(t.header,{debugPath:`${r}.header`}),m(`${r}.uncles`,t.uncles,w(S,e),e),m(`${r}.transactions`,t.transactions,w(B,e),e),m(`${r}.proposals`,t.proposals,T,e)}function x(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){f(r,t,["lock","message"],[]),h(`${r}.message`,t.message),e&&d(t.lock,{debugPath:`${r}.lock`})}function C(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){f(r,t,[],["lock","input_type","output_type"]),t.lock&&h(`${r}.lock`,t.lock),t.input_type&&h(`${r}.input_type`,t.input_type),t.output_type&&h(`${r}.output_type`,t.output_type)}var O=Object.freeze({__proto__:null,ValidateScript:d,ValidateOutPoint:p,ValidateCellInput:v,ValidateCellOutput:y,ValidateCellDep:b,ValidateRawTransaction:D,ValidateTransaction:B,ValidateRawHeader:A,ValidateHeader:P,ValidateUncleBlock:S,ValidateBlock:E,ValidateCellbaseWitness:x,ValidateWitnessArgs:C});function $(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function I(t,e,r){if(!((e=$(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){const r=e[i];r&&(n[i]=o(`${t}.${i}`,r))}return n}function R(t,{validation:e=!0,debugPath:r="script"}={}){return t=I(r,t,{code_hash:$,hash_type:$,args:$}),e&&d(t,{debugPath:`(transformed) ${r}`}),t}function j(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=I(r,t,{tx_hash:$,index:$}),e&&p(t,{debugPath:`(transformed) ${r}`}),t}function M(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function z(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=I(r,t,{since:$,previous_output:M(j)}),e&&v(t,{debugPath:`(transformed) ${r}`}),t}function L(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=I(r,t,{capacity:$,lock:M(R),type:M(R)}),e&&y(t,{debugPath:`(transformed) ${r}`}),t}function N(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=I(r,t,{out_point:M(j),dep_type:$}),e&&b(t,{debugPath:`(transformed) ${r}`}),t}function F(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function U(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=I(r,t,{version:$,cell_deps:F(M(N)),header_deps:F($),inputs:F(M(z)),outputs:F(M(L)),outputs_data:F($),witnesses:F($)}),e&&B(t,{debugPath:`(transformed) ${r}`}),t}function V(t,{validation:e=!0,debugPath:r="header"}={}){return t=I(r,t,{version:$,compact_target:$,timestamp:$,number:$,epoch:$,parent_hash:$,transactions_root:$,proposals_hash:$,uncles_hash:$,dao:$,nonce:$}),e&&P(t,{debugPath:`(transformed) ${r}`}),t}function q(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=I(r,t,{header:M(V),proposals:F($)}),e&&S(t,{debugPath:`(transformed) ${r}`}),t}var H=Object.freeze({__proto__:null,TransformScript:R,TransformOutPoint:j,TransformCellInput:z,TransformCellOutput:L,TransformCellDep:N,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=I(r,t,{version:$,cell_deps:F(M(N)),header_deps:F($),inputs:F(M(z)),outputs:F(M(L)),outputs_data:F($)}),e&&D(t,{debugPath:`(transformed) ${r}`}),t},TransformTransaction:U,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=I(r,t,{version:$,compact_target:$,timestamp:$,number:$,epoch:$,parent_hash:$,transactions_root:$,proposals_hash:$,uncles_hash:$,dao:$}),e&&A(t,{debugPath:`(transformed) ${r}`}),t},TransformHeader:V,TransformUncleBlock:q,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=I(r,t,{header:M(V),uncles:F(M(q)),transactions:F(M(U)),proposals:F($)}),e&&E(t,{debugPath:`(transformed) ${r}`}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=I(r,t,{lock:M(R),message:$}),e&&x(t,{debugPath:`(transformed) ${r}`}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=I(r,t,{lock:$,input_type:$,output_type:$}),e&&C(t,{debugPath:`(transformed) ${r}`}),t}});var G=Object.freeze({__proto__:null,RPCCollector:class{constructor(t,e,{skipCellWithContent:n=!0,loadData:i=!1}={}){this.rpc=t,this.lockHash=new r(e).serializeJson(),this.skipCellWithContent=n,this.loadData=i}async*collect(){const t=_(await this.rpc.get_tip_block_number());let e=a.BigInt(0);for(;a.lessThanOrEqual(e,t);){let r=a.add(e,a.BigInt(100));a.greaterThan(r,t)&&(r=t);const n=await this.rpc.get_cells_by_lock_hash(this.lockHash,l(e),l(r));for(const t of n)if(this.skipCellWithContent){if(t.type||a.greaterThan(_(t.output_data_len),a.BigInt(100)))continue;let e=null;if(this.loadData){e=(await this.rpc.get_live_cell(t.out_point,!0)).cell.data.content}yield{cell_output:{capacity:t.capacity,lock:t.lock,type:t.type},out_point:t.out_point,block_hash:t.block_hash,data:e}}e=a.add(r,a.BigInt(1))}}}});const W="0.5.0";export{l as BigIntToHexString,_ as HexStringToBigInt,u as RPC,r as Reader,W as VERSION,G as cell_collectors,H as transformers,O as validators};
  