New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ckb-js-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ckb-js-toolkit - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

2

dist/ckb-js-toolkit.esm.js

@@ -1,1 +0,1 @@

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){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 P=B*e;if(4294967295<P)break;if(B=P,D=D*e+k,w++,++i===n){m=!0;break}o=t.charCodeAt(i)}var A=s*w+(u=32*l.__kBitsPerCharTableMultiplier-1)>>>l.__kBitsPerCharTableShift+5;f.__inplaceMultiplyAdd(B,D,A)}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}()}));function a(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 s(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(`${t} must be a hex string!`)}function u(t,e){if(s(t,e),66!=e.length)throw new Error(`${t} must be a hex string of 66 bytes long!`)}function _(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 l(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(a(r,t,["code_hash","hash_type","args"],[]),u(`${r}.code_hash`,t.code_hash),s(`${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 f(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){a(r,t,["tx_hash","index"],[]),u(`${r}.tx_hash`,t.tx_hash),_(`${r}.index`,t.index)}function h(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){a(r,t,["since","previous_output"],[]),_(`${r}.since`,t.since),e&&f(t.previous_output,{debugPath:`${r}.previous_output`})}function c(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){a(r,t,["capacity","lock"],["type"]),_(`${r}.capacity`,t.capacity),e&&(l(t.lock,{debugPath:`${r}.lock`}),t.type&&l(t.type,{debugPath:`${r}.type`}))}function g(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(a(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&&f(t.out_point,{debugPath:`${r}.out_point`})}function d(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 p(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function v(t,e,r){_(`${t}.version`,e.version),d(`${t}.cell_deps`,e.cell_deps,p(g,r),r),d(`${t}.header_deps`,e.header_deps,u,r),d(`${t}.inputs`,e.inputs,p(h,r),r),d(`${t}.outputs`,e.outputs,p(c,r),r),d(`${t}.outputs_data`,e.outputs_data,s,r)}function y(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){a(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),v(r,t,e)}function b(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){a(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),v(r,t,e),d(`${r}.witnesses`,t.witnesses,s,e)}function m(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){a(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){_(`${t}.version`,e.version),_(`${t}.compact_target`,e.compact_target),_(`${t}.timestamp`,e.timestamp),_(`${t}.number`,e.number),_(`${t}.epoch`,e.epoch),u(`${t}.parent_hash`,e.parent_hash),u(`${t}.transactions_root`,e.transactions_root),u(`${t}.proposals_hash`,e.proposals_hash),u(`${t}.uncles_hash`,e.uncles_hash),u(`${t}.dao`,e.dao)}(r,t)}function w(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(a(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),s(`${r}.nonce`,t.nonce),34!=t.nonce.length)throw new Error(`${r}.nonce must be a hex string of 34 bytes long!`)}function k(t,e){if(s(t,e),22!=e.length)throw new Error(`${t} must be a hex string of 22 bytes long!`)}function D(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){a(r,t,["header","proposals"],[]),e&&w(t.header,{debugPath:`${r}.header`}),d(`${r}.proposals`,t.proposals,k,e)}function B(t,{nestedValidation:e=!0,debugPath:r="block"}={}){a(r,t,["header","uncles","transactions","proposals"],[]),e&&w(t.header,{debugPath:`${r}.header`}),d(`${r}.uncles`,t.uncles,p(D,e),e),d(`${r}.transactions`,t.transactions,p(b,e),e),d(`${r}.proposals`,t.proposals,k,e)}function P(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){a(r,t,["lock","message"],[]),s(`${r}.message`,t.message),e&&l(t.lock,{debugPath:`${r}.lock`})}function A(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){a(r,t,[],["lock","input_type","output_type"]),t.lock&&s(`${r}.lock`,t.lock),t.input_type&&s(`${r}.input_type`,t.input_type),t.output_type&&s(`${r}.output_type`,t.output_type)}var T=Object.freeze({__proto__:null,ValidateScript:l,ValidateOutPoint:f,ValidateCellInput:h,ValidateCellOutput:c,ValidateCellDep:g,ValidateRawTransaction:y,ValidateTransaction:b,ValidateRawHeader:m,ValidateHeader:w,ValidateUncleBlock:D,ValidateBlock:B,ValidateCellbaseWitness:P,ValidateWitnessArgs:A});class E{constructor(t,{validateTransaction:e=!0,depGroupUnpacker:r=null}={}){this.rpc=t,this.validateTransaction=e,this.depGroupUnpacker=r}async dumpByHash(t){const e=(await this.rpc.get_transaction(t)).transaction;return delete e.hash,await this.dump(e)}async dump(t){this.validateTransaction&&b(t);const e=[];for(const r of t.inputs){const{output:t,data:n,header:i}=await this._resolveOutPoint(r.previous_output);e.push({input:r,output:t,data:n,header:i})}const n=[];for(const e of t.cell_deps){const{output:t,data:i,header:o}=await this._resolveOutPoint(e.out_point);if(n.push({cell_dep:e,output:t,data:i,header:o}),"dep_group"===e.dep_type){if(!this.depGroupUnpacker)throw new Error("depGroupUnpacker must be provided when the transaction contains dep_group!");const t=this.depGroupUnpacker(new r(i));for(const e of t){f(e);const{output:t,data:r,header:i}=await this._resolveOutPoint(e);n.push({cell_dep:{out_point:e,dep_type:"code"},output:t,data:r,header:i})}}}const i=[];for(const e of t.header_deps)i.push(await this.rpc.get_header(e));return JSON.stringify({mock_info:{inputs:e,cell_deps:n,header_deps:i},tx:t})}async _resolveOutPoint(t){const e=await this.rpc.get_transaction(t.tx_hash);if(!e||!e.transaction)throw new Error(`Transaction ${t.tx_hash} cannot be found!`);const r=e.transaction,n=o.toNumber(o.BigInt(t.index));if(n>=r.outputs.length)throw new Error(`Transaction ${t.tx_hash} does not have output ${n}!`);const i={output:r.outputs[n],data:r.outputs_data[n]};return"committed"===e.tx_status.status&&(i.header=e.tx_status.block_hash),i}}var S=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}));S.fetch,S.Headers,S.Request,S.Response;const x={get:(t,e,r)=>"send"===e?async()=>{const e=await S(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)});return await e.json()}:(...n)=>{const i=t.id;return t.id=t.id+1,t.payload.push({jsonrpc:"2.0",id:i,method:e,params:n}),r}},O={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri},x):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await S(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),o=await i.json();if(o.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(o.error)throw new Error(`JSONRPCError: server error ${JSON.stringify(o.error)}`);return o.result}};class ${constructor(t){return this.uri=t,new Proxy(this,O)}static create(t){return new $(t)}}function C(t){return o.BigInt(t)}function I(t){return"0x"+t.toString(16)}function R(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=I(o.BigInt(r)).substr(2);if(n.length%2!=0&&(n="0"+n),n.length/2>t)throw new Error(`${e} is ${n.length/2} bytes long, expected length is ${t}!`);const i=new DataView(new ArrayBuffer(t));for(let t=0;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function j(t){return function(e,n){if(n=new r(n).toArrayBuffer(),t>0&&n.byteLength!==t)throw new Error(`${e} has invalid length ${n.byteLength}, required: ${t}`);return n}}function z(t,e,r){const n={};for(const[i,o]of Object.entries(r)){const r=e[i];if(!r)throw new Error(`${t} is missing ${i}!`);n[i]=o(`${t}.${i}`,r)}return n}function M(t,{debugPath:e="script"}={}){return z(e,t,{code_hash:j(32),hash_type:function(t,e){switch(e){case"data":return 0;case"type":return 1;case 0:case 1:return e;default:throw new Error(`${t}.hash_type has invalid value: ${e}`)}},args:j(-1)})}function N(t,{debugPath:e="out_point"}={}){return z(e,t,{tx_hash:j(32),index:R(4)})}function L(t){return function(e,r){return t(r,{debugPath:e})}}function U(t,{debugPath:e="cell_input"}={}){return z(e,t,{since:R(8),previous_output:L(N)})}function V(t,{debugPath:e="cell_output"}={}){const r=z(e,t,{capacity:R(8),lock:L(M)});return t.type&&(r.type_=M(t.type,{debugPath:`${e}.type`})),r}function q(t,{debugPath:e="cell_dep"}={}){return z(e,t,{out_point:L(N),dep_type:function(t,e){switch(e){case"code":return 0;case"dep_group":return 1;case 0:case 1:return e;default:throw new Error(`${t}.dep_type has invalid value: ${e}`)}}})}function F(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function G(t,{debugPath:e="raw_transaction"}={}){return z(e,t,{version:R(4),cell_deps:F(L(q)),header_deps:F(j(32)),inputs:F(L(U)),outputs:F(L(V)),outputs_data:F(j(-1))})}function H(t,{debugPath:e="transaction"}={}){const r=G(t,{debugPath:`(raw)${e}`}),n=z(e,t,{witnesses:F(j(-1))});return n.raw=r,n}function W(t,{debugPath:e="raw_header"}={}){return z(e,t,{version:R(4),compact_target:R(4),timestamp:R(8),number:R(8),epoch:R(8),parent_hash:j(32),transactions_root:j(32),proposals_hash:j(32),uncles_hash:j(32),dao:j(32)})}function J(t,{debugPath:e="header"}={}){const r=W(t,{debugPath:`(raw)${e}`}),n=z(e,t,{nonce:R(16)});return n.raw=r,n}function X(t,{debugPath:e="uncle_block"}={}){return z(e,t,{header:L(J),proposals:F(j(10))})}var Q=Object.freeze({__proto__:null,NormalizeScript:M,NormalizeOutPoint:N,NormalizeCellInput:U,NormalizeCellOutput:V,NormalizeCellDep:q,NormalizeRawTransaction:G,NormalizeTransaction:H,NormalizeRawHeader:W,NormalizeHeader:J,NormalizeUncleBlock:X,NormalizeBlock:function(t,{debugPath:e="block"}={}){return z(e,t,{header:L(J),uncles:F(L(X)),transactions:F(L(H)),proposals:F(j(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return z(e,t,{lock:L(M),message:j(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=j(-1)(`${e}.lock`,t.lock)),t.input_type&&(r.input_type=j(-1)(`${e}.input_type`,t.input_type)),t.output_type&&(r.output_type=j(-1)(`${e}.output_type`,t.output_type)),r}});function K(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Y(t,e,r){if(!((e=K(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){let r=e[i];if(!r){r=e[i.replace(/(_[a-z])/g,t=>t.toUpperCase().replace("_",""))]}r&&(n[i]=o(`${t}.${i}`,r))}return n}function Z(t,{validation:e=!0,debugPath:r="script"}={}){return t=Y(r,t,{code_hash:K,hash_type:K,args:K}),e&&l(t,{debugPath:`(transformed) ${r}`}),t}function tt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Y(r,t,{tx_hash:K,index:K}),e&&f(t,{debugPath:`(transformed) ${r}`}),t}function et(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function rt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Y(r,t,{since:K,previous_output:et(tt)}),e&&h(t,{debugPath:`(transformed) ${r}`}),t}function nt(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Y(r,t,{capacity:K,lock:et(Z),type:et(Z)}),e&&c(t,{debugPath:`(transformed) ${r}`}),t}function it(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Y(r,t,{out_point:et(tt),dep_type:K}),e&&g(t,{debugPath:`(transformed) ${r}`}),t}function ot(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function at(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K),witnesses:ot(K)}),e&&b(t,{debugPath:`(transformed) ${r}`}),t}function st(t,{validation:e=!0,debugPath:r="header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K,nonce:K}),e&&w(t,{debugPath:`(transformed) ${r}`}),t}function ut(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Y(r,t,{header:et(st),proposals:ot(K)}),e&&D(t,{debugPath:`(transformed) ${r}`}),t}var _t=Object.freeze({__proto__:null,TransformScript:Z,TransformOutPoint:tt,TransformCellInput:rt,TransformCellOutput:nt,TransformCellDep:it,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K)}),e&&y(t,{debugPath:`(transformed) ${r}`}),t},TransformTransaction:at,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K}),e&&m(t,{debugPath:`(transformed) ${r}`}),t},TransformHeader:st,TransformUncleBlock:ut,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Y(r,t,{header:et(st),uncles:ot(et(ut)),transactions:ot(et(at)),proposals:ot(K)}),e&&B(t,{debugPath:`(transformed) ${r}`}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Y(r,t,{lock:et(Z),message:K}),e&&P(t,{debugPath:`(transformed) ${r}`}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Y(r,t,{lock:K,input_type:K,output_type:K}),e&&A(t,{debugPath:`(transformed) ${r}`}),t}});var lt=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=C(await this.rpc.get_tip_block_number());let e=o.BigInt(0);for(;o.lessThanOrEqual(e,t);){let r=o.add(e,o.BigInt(100));o.greaterThan(r,t)&&(r=t);const n=await this.rpc.get_cells_by_lock_hash(this.lockHash,I(e),I(r));for(const t of n)if(this.skipCellWithContent){if(t.type||o.greaterThan(C(t.output_data_len),o.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=o.add(r,o.BigInt(1))}}}});const ft="0.9.1";export{I as BigIntToHexString,C as HexStringToBigInt,$ as RPC,r as Reader,E as TransactionDumper,ft as VERSION,lt as cell_collectors,Q as normalizers,_t as transformers,T as validators};
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,r){return t(r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}var o=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){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(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 n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(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&&a(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(){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=u()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&a(i,r.prototype),i}).apply(null,arguments)}function _(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function l(t){var e="function"==typeof Map?new Map:void 0;return(l=function(t){function r(){return s(t,arguments,o(this).constructor)}if(null===t||!_(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}}),a(r,t)})(t)}function f(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function h(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?f(t):e}var c=function(r){var a=Math.abs,u=Math.max,s=Math.imul,_=Math.clz32;function l(t,r){var n;if(e(this,l),t>l.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");return(n=h(this,o(l).call(this,t))).sign=r,n}return i(l,r),n(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 _(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 u=t.__digit(a),s=(i>>>16)-(65535&u)-n;n=1&s>>>16,this.__setDigit(e+a,s<<16|65535&o),n=1&(o=(65535&(i=this.__digit(e+a+1)))-(u>>>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=_(n),o=32*e-i;if(1024<o)return t.sign?-1/0:1/0;var a=o-1,u=n,s=e-1,f=i+1,h=32===f?0:u<<f;h>>>=12;var c=f-12,g=12<=f?0:u<<20+f,d=20+f;0<c&&0<s&&(s--,h|=(u=t.__digit(s))>>>32-c,g=u<<c,d=c),0<d&&0<s&&(s--,g|=(u=t.__digit(s))>>>32-d,d-=32);var p=l.__decideRounding(t,d,s,u);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,u=t;for(0!=(1&r)&&(a=t),r>>=1;0!==r;r>>=1)u=l.multiply(u,u),0!=(1&r)&&(a=null===a?u:l.multiply(a,u));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=u(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=u(t.length,e.length),n=l.__absoluteSubOne(t,r),i=l.__absoluteSubOne(e);return l.__absoluteXor(n,i,n).__trim()}var o=u(t.length,e.length)+1;if(t.sign){var a=[e,t];t=a[0],e=a[1]}var s=l.__absoluteSubOne(e,o);return s=l.__absoluteXor(s,t,s),l.__absoluteAddOne(s,!0,s).__trim()}},{key:"bitwiseOr",value:function(t,e){var r=u(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 a=l.__absoluteSubOne(e,r);return a=l.__absoluteAndNot(a,t,a),l.__absoluteAddOne(a,!0,a).__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],u=20,s=31&r,_=0;if(s<u){var f=u-s;_=f+32,e=o>>>f,o=o<<32-f|a>>>f,a<<=32-f}else if(s===u)_=32,e=o,o=a;else{var h=s-u;_=32-h,e=o<<h|a>>>32-h,o=a<<h}i.__setDigit(n-1,e);for(var c=n-2;0<=c;c--)0<_?(_-=32,e=o,o=a):e=0,i.__setDigit(c,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,u=l.__kMaxBitsPerChar[e],s=l.__kBitsPerCharTableMultiplier-1;if(a>1073741824/u)return null;var _=new l(31+(u*a+s>>>l.__kBitsPerCharTableShift)>>>5,!1),f=10>e?e:10,h=10<e?e-10:0;if(0==(e&e-1)){u>>=l.__kBitsPerCharTableShift;var c=[],g=[],d=!1;do{for(var p,v=0,y=0;;){if(p=void 0,o-48>>>0<f)p=o-48;else{if(!((32|o)-97>>>0<h)){d=!0;break}p=(32|o)-87}if(y+=u,v=v<<u|p,++i===n){d=!0;break}if(o=t.charCodeAt(i),32<y+u)break}c.push(v),g.push(y)}while(!d);l.__fillFromParts(_,c,g)}else{_.__initializeDigits();var b=!1,m=0;do{for(var w,k=0,D=1;;){if(w=void 0,o-48>>>0<f)w=o-48;else{if(!((32|o)-97>>>0<h)){b=!0;break}w=(32|o)-87}var B=D*e;if(4294967295<B)break;if(D=B,k=k*e+w,m++,++i===n){b=!0;break}o=t.charCodeAt(i)}var P=u*m+(s=32*l.__kBitsPerCharTableMultiplier-1)>>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(D,k,P)}while(!b)}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:(_.sign=-1===r,_.__trim())}},{key:"__fillFromParts",value:function(t,e,r){for(var n=0,i=0,o=0,a=e.length-1;0<=a;a--){var u=e[a],s=r[a];i|=u<<o,32===(o+=s)?(t.__setDigit(n++,i),o=0,i=0):32<o&&(t.__setDigit(n++,i),i=u>>>s-(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),u=0|(32*r-_(a)+i-1)/i;if(t.sign&&u++,268435456<u)throw new Error("string too long");for(var s=Array(u),f=u-1,h=0,c=0,g=0;g<r-1;g++){var d=t.__digit(g),p=(h|d<<c)&o;s[f--]=l.__kConversionChars[p];var v=i-c;for(h=d>>>v,c=32-v;c>=i;)s[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var y=(h|a<<c)&o;for(s[f--]=l.__kConversionChars[y],h=a>>>i-c;0!==h;)s[f--]=l.__kConversionChars[h&o],h>>>=i;if(t.sign&&(s[f--]="-"),-1!==f)throw new Error("implementation bug");return s.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,u=32*n-_(t.__digit(n-1)),s=l.__kMaxBitsPerChar[e]-1,f=u*l.__kBitsPerCharTableMultiplier,h=1+(f=0|(f+=s-1)/s)>>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=a(e),o=t.__unsignedDigit(0);return o>i?l.__absoluteGreater(r):o<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),u=_(a),s=32*o-u,f=i+1;if(s<f)return l.__absoluteLess(r);if(s>f)return l.__absoluteGreater(r);var h=1048576|1048575&l.__kBitConversionInts[1],c=l.__kBitConversionInts[0],g=20,d=31-u;if(d!==(s-1)%31)throw new Error("implementation bug");var p,v=0;if(d<g){var y=g-d;v=y+32,p=h>>>y,h=h<<32-y|c>>>y,c<<=32-y}else if(d===g)v=32,p=h,h=c;else{var b=d-g;v=32-b,p=h<<b|c>>>32-b,h=c<<b}if((a>>>=0)>(p>>>=0))return l.__absoluteGreater(r);if(a<p)return l.__absoluteLess(r);for(var m=o-2;0<=m;m--){0<v?(v-=32,p=h>>>0,h=c,c=0):p=0;var w=t.__unsignedDigit(m);if(w>p)return l.__absoluteGreater(r);if(w<p)return l.__absoluteLess(r)}if(0!==h||0!==c){if(0===v)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)===a(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 u=e.__digit(a),s=t.__digit(a),_=(65535&s)+(65535&u)+o,f=(s>>>16)+(u>>>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),u=e.__digit(o),s=(65535&a)-(65535&u)-i,_=(a>>>16)-(u>>>16)-(i=1&s>>>16);i=1&_>>>16,n.__setDigit(o,65535&s|_<<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),u=-1===a;i&&(a=0|a+1),i=u,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),u=0===a;i&&(a=0|a-1),i=u,n.__setDigit(o,a)}for(var s=r;s<e;s++)n.__setDigit(s,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,u=n;t=e,n=i,e=a,i=u}var s=o;null===r?r=new l(s,!1):s=r.length;for(var _=0;_<o;_++)r.__setDigit(_,t.__digit(_)&e.__digit(_));for(;_<s;_++)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 u=0;u<o;u++)r.__setDigit(u,t.__digit(u)&~e.__digit(u));for(;u<n;u++)r.__setDigit(u,t.__digit(u));for(;u<a;u++)r.__setDigit(u,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,u=n;t=e,n=i,e=a,i=u}var s=n;null===r?r=new l(s,!1):s=r.length;for(var _=0;_<o;_++)r.__setDigit(_,t.__digit(_)|e.__digit(_));for(;_<n;_++)r.__setDigit(_,t.__digit(_));for(;_<s;_++)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,u=n;t=e,n=i,e=a,i=u}var s=n;null===r?r=new l(s,!1):s=r.length;for(var _=0;_<o;_++)r.__setDigit(_,t.__digit(_)^e.__digit(_));for(;_<n;_++)r.__setDigit(_,t.__digit(_));for(;_<s;_++)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,u=0|(o=((n=0|o%e)<<16|t.__halfDigit(i-1))>>>0)/e;n=0|o%e,r.__setDigit(i>>>1,a<<16|u)}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 _(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,u=0,s=0;s<n;s++)a=t.__digit(s),i.__setDigit(s,a<<e|u),u=a>>>32-e;return 0<r&&i.__setDigit(n,u),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,u=o+n+(a?1:0),s=new l(u,t.sign);if(0===i){for(var _=0;_<n;_++)s.__setDigit(_,0);for(;_<u;_++)s.__setDigit(_,t.__digit(_-n))}else{for(var f=0,h=0;h<n;h++)s.__setDigit(h,0);for(var c,g=0;g<o;g++)c=t.__digit(g),s.__setDigit(g+n,c<<i|f),f=c>>>32-i;if(a)s.__setDigit(o+n,f);else if(0!==f)throw new Error("implementation bug")}return s.__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,u=r-o;if(0>=u)return l.__rightShiftByMaximum(n);var s=!1;if(n)if(0!=(t.__digit(o)&(1<<a)-1))s=!0;else for(var _=0;_<o;_++)if(0!==t.__digit(_)){s=!0;break}s&&0===a&&0==~t.__digit(r-1)&&u++;var f=new l(u,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 s&&(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 u=e.toString;if(u){var s=u.call(e);if("object"!==t(s))return s}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 u=32-(31&t);a=a<<u>>>u}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,u=i-1,s=0,_=n(u,e.length);a<_;a++){var f=e.__digit(a),h=0-(65535&f)-s,c=0-(f>>>16)-(s=1&h>>>16);s=1&c>>>16,o.__setDigit(a,65535&h|c<<16)}for(;a<u;a++)o.__setDigit(a,0|-s);var g,d=u<e.length?e.__digit(u):0,p=31&t;if(0===p){var v=0-(65535&d)-s;g=65535&v|0-(d>>>16)-(s=1&v>>>16)<<16}else{var y=32-p,b=1<<32-y,m=(65535&b)-(65535&(d=d<<y>>>y))-s;g=65535&m|(b>>>16)-(d>>>16)-(s=1&m>>>16)<<16,g&=b-1}return o.__setDigit(u,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}(l(Array));return c.__kMaxLength=33554432,c.__kMaxLengthBits=c.__kMaxLength<<5,c.__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],c.__kBitsPerCharTableShift=5,c.__kBitsPerCharTableMultiplier=1<<c.__kBitsPerCharTableShift,c.__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"],c.__kBitConversionBuffer=new ArrayBuffer(8),c.__kBitConversionDouble=new Float64Array(c.__kBitConversionBuffer),c.__kBitConversionInts=new Int32Array(c.__kBitConversionBuffer),c}()}));function a(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,u=`${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(u);let s=i.filter(t=>!r.includes(t));if(i.length-s.length!==o)throw new Error(u);if(s.find(t=>!n.includes(t)))throw new Error(u)}function u(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(t+" must be a hex string!")}function s(t,e){if(u(t,e),66!=e.length)throw new Error(t+" must be a hex string of 66 bytes long!")}function _(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 l(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(a(r,t,["code_hash","hash_type","args"],[]),s(r+".code_hash",t.code_hash),u(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 f(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){a(r,t,["tx_hash","index"],[]),s(r+".tx_hash",t.tx_hash),_(r+".index",t.index)}function h(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){a(r,t,["since","previous_output"],[]),_(r+".since",t.since),e&&f(t.previous_output,{debugPath:r+".previous_output"})}function c(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){a(r,t,["capacity","lock"],["type"]),_(r+".capacity",t.capacity),e&&(l(t.lock,{debugPath:r+".lock"}),t.type&&l(t.type,{debugPath:r+".type"}))}function g(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(a(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&&f(t.out_point,{debugPath:r+".out_point"})}function d(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 p(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function v(t,e,r){_(t+".version",e.version),d(t+".cell_deps",e.cell_deps,p(g,r),r),d(t+".header_deps",e.header_deps,s,r),d(t+".inputs",e.inputs,p(h,r),r),d(t+".outputs",e.outputs,p(c,r),r),d(t+".outputs_data",e.outputs_data,u,r)}function y(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){a(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),v(r,t,e)}function b(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){a(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),v(r,t,e),d(r+".witnesses",t.witnesses,u,e)}function m(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){a(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){_(t+".version",e.version),_(t+".compact_target",e.compact_target),_(t+".timestamp",e.timestamp),_(t+".number",e.number),_(t+".epoch",e.epoch),s(t+".parent_hash",e.parent_hash),s(t+".transactions_root",e.transactions_root),s(t+".proposals_hash",e.proposals_hash),s(t+".uncles_hash",e.uncles_hash),s(t+".dao",e.dao)}(r,t)}function w(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(a(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),u(r+".nonce",t.nonce),34!=t.nonce.length)throw new Error(r+".nonce must be a hex string of 34 bytes long!")}function k(t,e){if(u(t,e),22!=e.length)throw new Error(t+" must be a hex string of 22 bytes long!")}function D(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){a(r,t,["header","proposals"],[]),e&&w(t.header,{debugPath:r+".header"}),d(r+".proposals",t.proposals,k,e)}function B(t,{nestedValidation:e=!0,debugPath:r="block"}={}){a(r,t,["header","uncles","transactions","proposals"],[]),e&&w(t.header,{debugPath:r+".header"}),d(r+".uncles",t.uncles,p(D,e),e),d(r+".transactions",t.transactions,p(b,e),e),d(r+".proposals",t.proposals,k,e)}function P(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){a(r,t,["lock","message"],[]),u(r+".message",t.message),e&&l(t.lock,{debugPath:r+".lock"})}function A(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){a(r,t,[],["lock","input_type","output_type"]),t.lock&&u(r+".lock",t.lock),t.input_type&&u(r+".input_type",t.input_type),t.output_type&&u(r+".output_type",t.output_type)}var T=Object.freeze({__proto__:null,ValidateScript:l,ValidateOutPoint:f,ValidateCellInput:h,ValidateCellOutput:c,ValidateCellDep:g,ValidateRawTransaction:y,ValidateTransaction:b,ValidateRawHeader:m,ValidateHeader:w,ValidateUncleBlock:D,ValidateBlock:B,ValidateCellbaseWitness:P,ValidateWitnessArgs:A});class E{constructor(t,{validateTransaction:e=!0,depGroupUnpacker:r=null}={}){this.rpc=t,this.validateTransaction=e,this.depGroupUnpacker=r}async dumpByHash(t){const e=(await this.rpc.get_transaction(t)).transaction;return delete e.hash,await this.dump(e)}async dump(t){this.validateTransaction&&b(t);const e=[];for(const r of t.inputs){const{output:t,data:n,header:i}=await this._resolveOutPoint(r.previous_output);e.push({input:r,output:t,data:n,header:i})}const n=[];for(const e of t.cell_deps){const{output:t,data:i,header:o}=await this._resolveOutPoint(e.out_point);if(n.push({cell_dep:e,output:t,data:i,header:o}),"dep_group"===e.dep_type){if(!this.depGroupUnpacker)throw new Error("depGroupUnpacker must be provided when the transaction contains dep_group!");const t=this.depGroupUnpacker(new r(i));for(const e of t){f(e);const{output:t,data:r,header:i}=await this._resolveOutPoint(e);n.push({cell_dep:{out_point:e,dep_type:"code"},output:t,data:r,header:i})}}}const i=[];for(const e of t.header_deps)i.push(await this.rpc.get_header(e));return JSON.stringify({mock_info:{inputs:e,cell_deps:n,header_deps:i},tx:t})}async _resolveOutPoint(t){const e=await this.rpc.get_transaction(t.tx_hash);if(!e||!e.transaction)throw new Error(`Transaction ${t.tx_hash} cannot be found!`);const r=e.transaction,n=o.toNumber(o.BigInt(t.index));if(n>=r.outputs.length)throw new Error(`Transaction ${t.tx_hash} does not have output ${n}!`);const i={output:r.outputs[n],data:r.outputs_data[n]};return"committed"===e.tx_status.status&&(i.header=e.tx_status.block_hash),i}}var S=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 u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],s=ArrayBuffer.isView||function(t){return t&&u.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)||s(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 u=new XMLHttpRequest;function s(){u.abort()}u.onload=function(){var t,e,r={status:u.status,statusText:u.statusText,headers:(t=u.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 u?u.responseURL:r.headers.get("X-Request-URL");var i="response"in u?u.response:u.responseText;n(new w(i,r))},u.onerror=function(){o(new TypeError("Network request failed"))},u.ontimeout=function(){o(new TypeError("Network request failed"))},u.onabort=function(){o(new e.DOMException("Aborted","AbortError"))},u.open(a.method,a.url,!0),"include"===a.credentials?u.withCredentials=!0:"omit"===a.credentials&&(u.withCredentials=!1),"responseType"in u&&i&&(u.responseType="blob"),a.headers.forEach((function(t,e){u.setRequestHeader(e,t)})),a.signal&&(a.signal.addEventListener("abort",s),u.onreadystatechange=function(){4===u.readyState&&a.signal.removeEventListener("abort",s)}),u.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}));const x={get:(t,e,r)=>"send"===e?async()=>{const e=await S(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)});return await e.json()}:(...n)=>{const i=t.id;return t.id=t.id+1,t.payload.push({jsonrpc:"2.0",id:i,method:e,params:n}),r}},O={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri},x):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await S(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),o=await i.json();if(o.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(o.error)throw new Error("JSONRPCError: server error "+JSON.stringify(o.error));return o.result}};class C{constructor(t){return this.uri=t,new Proxy(this,O)}static create(t){return new C(t)}}function I(t){return o.BigInt(t)}function j(t){return"0x"+t.toString(16)}function R(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=j(o.BigInt(r)).substr(2);if(n.length%2!=0&&(n="0"+n),n.length/2>t)throw new Error(`${e} is ${n.length/2} bytes long, expected length is ${t}!`);const i=new DataView(new ArrayBuffer(t));for(let t=0;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function z(t){return function(e,n){if(n=new r(n).toArrayBuffer(),t>0&&n.byteLength!==t)throw new Error(`${e} has invalid length ${n.byteLength}, required: ${t}`);return n}}function M(t,e,r){const n={};for(const[i,o]of Object.entries(r)){const r=e[i];if(!r)throw new Error(`${t} is missing ${i}!`);n[i]=o(`${t}.${i}`,r)}return n}function N(t,{debugPath:e="script"}={}){return M(e,t,{code_hash:z(32),hash_type:function(t,e){switch(e){case"data":return 0;case"type":return 1;case 0:case 1:return e;default:throw new Error(`${t}.hash_type has invalid value: ${e}`)}},args:z(-1)})}function L(t,{debugPath:e="out_point"}={}){return M(e,t,{tx_hash:z(32),index:R(4)})}function U(t){return function(e,r){return t(r,{debugPath:e})}}function q(t,{debugPath:e="cell_input"}={}){return M(e,t,{since:R(8),previous_output:U(L)})}function V(t,{debugPath:e="cell_output"}={}){const r=M(e,t,{capacity:R(8),lock:U(N)});return t.type&&(r.type_=N(t.type,{debugPath:e+".type"})),r}function $(t,{debugPath:e="cell_dep"}={}){return M(e,t,{out_point:U(L),dep_type:function(t,e){switch(e){case"code":return 0;case"dep_group":return 1;case 0:case 1:return e;default:throw new Error(`${t}.dep_type has invalid value: ${e}`)}}})}function F(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function G(t,{debugPath:e="raw_transaction"}={}){return M(e,t,{version:R(4),cell_deps:F(U($)),header_deps:F(z(32)),inputs:F(U(q)),outputs:F(U(V)),outputs_data:F(z(-1))})}function H(t,{debugPath:e="transaction"}={}){const r=G(t,{debugPath:"(raw)"+e}),n=M(e,t,{witnesses:F(z(-1))});return n.raw=r,n}function W(t,{debugPath:e="raw_header"}={}){return M(e,t,{version:R(4),compact_target:R(4),timestamp:R(8),number:R(8),epoch:R(8),parent_hash:z(32),transactions_root:z(32),proposals_hash:z(32),uncles_hash:z(32),dao:z(32)})}function J(t,{debugPath:e="header"}={}){const r=W(t,{debugPath:"(raw)"+e}),n=M(e,t,{nonce:R(16)});return n.raw=r,n}function X(t,{debugPath:e="uncle_block"}={}){return M(e,t,{header:U(J),proposals:F(z(10))})}var Q=Object.freeze({__proto__:null,NormalizeScript:N,NormalizeOutPoint:L,NormalizeCellInput:q,NormalizeCellOutput:V,NormalizeCellDep:$,NormalizeRawTransaction:G,NormalizeTransaction:H,NormalizeRawHeader:W,NormalizeHeader:J,NormalizeUncleBlock:X,NormalizeBlock:function(t,{debugPath:e="block"}={}){return M(e,t,{header:U(J),uncles:F(U(X)),transactions:F(U(H)),proposals:F(z(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return M(e,t,{lock:U(N),message:z(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=z(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=z(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=z(-1)(e+".output_type",t.output_type)),r}});function K(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Y(t,e,r){if(!((e=K(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){let r=e[i];if(!r){r=e[i.replace(/(_[a-z])/g,t=>t.toUpperCase().replace("_",""))]}r&&(n[i]=o(`${t}.${i}`,r))}return n}function Z(t,{validation:e=!0,debugPath:r="script"}={}){return t=Y(r,t,{code_hash:K,hash_type:K,args:K}),e&&l(t,{debugPath:"(transformed) "+r}),t}function tt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Y(r,t,{tx_hash:K,index:K}),e&&f(t,{debugPath:"(transformed) "+r}),t}function et(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function rt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Y(r,t,{since:K,previous_output:et(tt)}),e&&h(t,{debugPath:"(transformed) "+r}),t}function nt(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Y(r,t,{capacity:K,lock:et(Z),type:et(Z)}),e&&c(t,{debugPath:"(transformed) "+r}),t}function it(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Y(r,t,{out_point:et(tt),dep_type:K}),e&&g(t,{debugPath:"(transformed) "+r}),t}function ot(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function at(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K),witnesses:ot(K)}),e&&b(t,{debugPath:"(transformed) "+r}),t}function ut(t,{validation:e=!0,debugPath:r="header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K,nonce:K}),e&&w(t,{debugPath:"(transformed) "+r}),t}function st(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Y(r,t,{header:et(ut),proposals:ot(K)}),e&&D(t,{debugPath:"(transformed) "+r}),t}var _t=Object.freeze({__proto__:null,TransformScript:Z,TransformOutPoint:tt,TransformCellInput:rt,TransformCellOutput:nt,TransformCellDep:it,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K)}),e&&y(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:at,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K}),e&&m(t,{debugPath:"(transformed) "+r}),t},TransformHeader:ut,TransformUncleBlock:st,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Y(r,t,{header:et(ut),uncles:ot(et(st)),transactions:ot(et(at)),proposals:ot(K)}),e&&B(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Y(r,t,{lock:et(Z),message:K}),e&&P(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Y(r,t,{lock:K,input_type:K,output_type:K}),e&&A(t,{debugPath:"(transformed) "+r}),t}});var lt=Object.freeze({__proto__:null,RPCCollector:class{constructor(t,e,{skipCellWithContent:n=!0,loadData:i=!1,loadBlockNumber:o=!0}={}){this.rpc=t,this.lockHash=new r(e).serializeJson(),this.skipCellWithContent=n,this.loadData=i,this.loadBlockNumber=o}async*collect(){const t=I(await this.rpc.get_tip_block_number());let e=o.BigInt(0);for(;o.lessThanOrEqual(e,t);){let r=o.add(e,o.BigInt(100));o.greaterThan(r,t)&&(r=t);const n=await this.rpc.get_cells_by_lock_hash(this.lockHash,j(e),j(r));for(const t of n){if(this.skipCellWithContent&&(t.type||o.greaterThan(I(t.output_data_len),o.BigInt(100))))continue;let e=null;if(this.loadData){e=(await this.rpc.get_live_cell(t.out_point,!0)).cell.data.content}let r=null;if(this.loadBlockNumber){r=(await this.rpc.get_header(t.block_hash)).number}yield{cellbase:t.cellbase,cell_output:{capacity:t.capacity,lock:t.lock,type:t.type},out_point:t.out_point,block_hash:t.block_hash,data:e,output_data_len:t.output_data_len,block_number:r}}e=o.add(r,o.BigInt(1))}}}});const ft="0.9.2";export{j as BigIntToHexString,I as HexStringToBigInt,C as RPC,r as Reader,E as TransactionDumper,ft as VERSION,lt as cell_collectors,Q as normalizers,_t as transformers,T as validators};

@@ -1,2 +0,2 @@

"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("stream")),r=t(require("http")),n=t(require("url")),i=t(require("https")),o=t(require("zlib"));class s{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 a{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 u{constructor(t){if(t instanceof a||t instanceof s)return t;if("string"==typeof t){if(!t.startsWith("0x")||t.length%2!=0)throw new Error("Hex string must start with 0x, and has even numbered length!");return new a(t)}if(t instanceof ArrayBuffer)return new s(t);throw new Error("Reader can only accept hex string or ArrayBuffer!")}static fromRawString(t){const e=new ArrayBuffer(t.length),r=new DataView(e);for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n>255)throw new Error("fromRawString can only accept UTF-8 raw string!");r.setUint8(e,n)}return new s(e)}}class l extends Array{constructor(t,e){if(t>l.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");super(t),this.sign=e}static BigInt(t){var e=Math.floor,r=Number.isFinite;if("number"==typeof t){if(0===t)return l.__zero();if((0|t)===t)return 0>t?l.__oneDigit(-t,!0):l.__oneDigit(t,!1);if(!r(t)||e(t)!==t)throw new RangeError("The number "+t+" cannot be converted to BigInt because it is not an integer");return l.__fromDouble(t)}if("string"==typeof t){const e=l.__fromString(t);if(null===e)throw new SyntaxError("Cannot convert "+t+" to a BigInt");return e}if("boolean"==typeof t)return!0===t?l.__oneDigit(1,!1):l.__zero();if("object"==typeof t){if(t.constructor===l)return t;const e=l.__toPrimitive(t);return l.BigInt(e)}throw new TypeError("Cannot convert "+t+" to a BigInt")}toDebugString(){const t=["BigInt["];for(const e of this)t.push((e?(e>>>0).toString(16):e)+", ");return t.push("]"),t.join("")}toString(t=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)}static toNumber(t){var e=Math.clz32;const r=t.length;if(0===r)return 0;if(1===r){const e=t.__unsignedDigit(0);return t.sign?-e:e}const n=t.__digit(r-1),i=e(n),o=32*r-i;if(1024<o)return t.sign?-1/0:1/0;let s=o-1,a=n,u=r-1;const c=i+1;let _=32===c?0:a<<c;_>>>=12;const h=c-12;let f=12<=c?0:a<<20+c,g=20+c;0<h&&0<u&&(u--,a=t.__digit(u),_|=a>>>32-h,f=a<<h,g=h),0<g&&0<u&&(u--,a=t.__digit(u),f|=a>>>32-g,g-=32);const d=l.__decideRounding(t,g,u,a);if((1===d||0===d&&1==(1&f))&&(f=f+1>>>0,0==f&&(_++,0!=_>>>20&&(_=0,s++,1023<s))))return t.sign?-1/0:1/0;const p=t.sign?-2147483648:0;return s=s+1023<<20,l.__kBitConversionInts[1]=p|s|_,l.__kBitConversionInts[0]=f,l.__kBitConversionDouble[0]}static unaryMinus(t){if(0===t.length)return t;const e=t.__copy();return e.sign=!t.sign,e}static bitwiseNot(t){return t.sign?l.__absoluteSubOne(t).__trim():l.__absoluteAddOne(t,!0)}static exponentiate(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");let 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)){const e=1+(r>>>5),n=t.sign&&0!=(1&r),i=new l(e,n);i.__initializeDigits();const o=1<<(31&r);return i.__setDigit(e-1,o),i}let n=null,i=t;for(0!=(1&r)&&(n=t),r>>=1;0!==r;r>>=1)i=l.multiply(i,i),0!=(1&r)&&(n=null===n?i:l.multiply(n,i));return n}static multiply(t,e){if(0===t.length)return t;if(0===e.length)return e;let r=t.length+e.length;32<=t.__clzmsd()+e.__clzmsd()&&r--;const n=new l(r,t.sign!==e.sign);n.__initializeDigits();for(let r=0;r<t.length;r++)l.__multiplyAccumulate(e,t.__digit(r),n,r);return n.__trim()}static divide(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>l.__absoluteCompare(t,e))return l.__zero();const r=t.sign!==e.sign,n=e.__unsignedDigit(0);let i;if(1===e.length&&65535>=n){if(1===n)return r===t.sign?t:l.unaryMinus(t);i=l.__absoluteDivSmall(t,n,null)}else i=l.__absoluteDivLarge(t,e,!0,!1);return i.sign=r,i.__trim()}static remainder(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>l.__absoluteCompare(t,e))return t;const r=e.__unsignedDigit(0);if(1===e.length&&65535>=r){if(1===r)return l.__zero();const e=l.__absoluteModSmall(t,r);return 0===e?l.__zero():l.__oneDigit(e,t.sign)}const n=l.__absoluteDivLarge(t,e,!1,!0);return n.sign=t.sign,n.__trim()}static add(t,e){const 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)}static subtract(t,e){const 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)}static leftShift(t,e){return 0===e.length||0===t.length?t:e.sign?l.__rightShiftByAbsolute(t,e):l.__leftShiftByAbsolute(t,e)}static signedRightShift(t,e){return 0===e.length||0===t.length?t:e.sign?l.__leftShiftByAbsolute(t,e):l.__rightShiftByAbsolute(t,e)}static unsignedRightShift(){throw new TypeError("BigInts have no unsigned right shift; use >> instead")}static lessThan(t,e){return 0>l.__compareToBigInt(t,e)}static lessThanOrEqual(t,e){return 0>=l.__compareToBigInt(t,e)}static greaterThan(t,e){return 0<l.__compareToBigInt(t,e)}static greaterThanOrEqual(t,e){return 0<=l.__compareToBigInt(t,e)}static equal(t,e){if(t.sign!==e.sign)return!1;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t.__digit(r)!==e.__digit(r))return!1;return!0}static notEqual(t,e){return!l.equal(t,e)}static bitwiseAnd(t,e){var r=Math.max;if(!t.sign&&!e.sign)return l.__absoluteAnd(t,e).__trim();if(t.sign&&e.sign){const n=r(t.length,e.length)+1;let i=l.__absoluteSubOne(t,n);const o=l.__absoluteSubOne(e);return i=l.__absoluteOr(i,o,i),l.__absoluteAddOne(i,!0,i).__trim()}return t.sign&&([t,e]=[e,t]),l.__absoluteAndNot(t,l.__absoluteSubOne(e)).__trim()}static bitwiseXor(t,e){var r=Math.max;if(!t.sign&&!e.sign)return l.__absoluteXor(t,e).__trim();if(t.sign&&e.sign){const n=r(t.length,e.length),i=l.__absoluteSubOne(t,n),o=l.__absoluteSubOne(e);return l.__absoluteXor(i,o,i).__trim()}const n=r(t.length,e.length)+1;t.sign&&([t,e]=[e,t]);let i=l.__absoluteSubOne(e,n);return i=l.__absoluteXor(i,t,i),l.__absoluteAddOne(i,!0,i).__trim()}static bitwiseOr(t,e){const r=(0,Math.max)(t.length,e.length);if(!t.sign&&!e.sign)return l.__absoluteOr(t,e).__trim();if(t.sign&&e.sign){let n=l.__absoluteSubOne(t,r);const i=l.__absoluteSubOne(e);return n=l.__absoluteAnd(n,i,n),l.__absoluteAddOne(n,!0,n).__trim()}t.sign&&([t,e]=[e,t]);let n=l.__absoluteSubOne(e,r);return n=l.__absoluteAndNot(n,t,n),l.__absoluteAddOne(n,!0,n).__trim()}static asIntN(t,e){if(0===e.length)return e;if(0===t)return l.__zero();if(t>=l.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.length<r)return e;const 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(let n=r-2;0<=n;n--)if(0!==e.__digit(n))return l.__truncateAndSubFromPowerOfTwo(t,e,!1);return e.length===r&&n===i?e:l.__truncateToNBits(t,e)}return l.__truncateAndSubFromPowerOfTwo(t,e,!1)}static asUintN(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;const r=t+31>>>5;if(e.length<r)return e;const 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)}static ADD(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")}static LT(t,e){return l.__compare(t,e,0)}static LE(t,e){return l.__compare(t,e,1)}static GT(t,e){return l.__compare(t,e,2)}static GE(t,e){return l.__compare(t,e,3)}static EQ(t,e){for(;;){if(l.__isBigInt(t))return l.__isBigInt(e)?l.equal(t,e):l.EQ(e,t);if("number"==typeof t){if(l.__isBigInt(e))return l.__equalToNumber(e,t);if("object"!=typeof e)return t==e;e=l.__toPrimitive(e)}else if("string"==typeof t){if(l.__isBigInt(e))return null!==(t=l.__fromString(t))&&l.equal(t,e);if("object"!=typeof e)return t==e;e=l.__toPrimitive(e)}else if("boolean"==typeof t){if(l.__isBigInt(e))return l.__equalToNumber(e,+t);if("object"!=typeof e)return t==e;e=l.__toPrimitive(e)}else if("symbol"==typeof t){if(l.__isBigInt(e))return!1;if("object"!=typeof e)return t==e;e=l.__toPrimitive(e)}else{if("object"!=typeof t)return t==e;if("object"==typeof e&&e.constructor!==l)return t==e;t=l.__toPrimitive(t)}}}static NE(t,e){return!l.EQ(t,e)}static __zero(){return new l(0,!1)}static __oneDigit(t,e){const r=new l(1,e);return r.__setDigit(0,t),r}__copy(){const t=new l(this.length,this.sign);for(let e=0;e<this.length;e++)t[e]=this[e];return t}__trim(){let t=this.length,e=this[t-1];for(;0===e;)t--,e=this[t-1],this.pop();return 0===t&&(this.sign=!1),this}__initializeDigits(){for(let t=0;t<this.length;t++)this[t]=0}static __decideRounding(t,e,r,n){if(0<e)return-1;let i;if(0>e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}let o=1<<i;if(0==(n&o))return-1;if(o-=1,0!=(n&o))return 1;for(;0<r;)if(r--,0!==t.__digit(r))return 1;return 0}static __fromDouble(t){l.__kBitConversionDouble[0]=t;const e=(2047&l.__kBitConversionInts[1]>>>20)-1023,r=1+(e>>>5),n=new l(r,0>t);let i=1048575&l.__kBitConversionInts[1]|1048576,o=l.__kBitConversionInts[0];const s=31&e;let a,u=0;if(s<20){const t=20-s;u=t+32,a=i>>>t,i=i<<32-t|o>>>t,o<<=32-t}else if(20===s)u=32,a=i,i=o;else{const t=s-20;u=32-t,a=i<<t|o>>>32-t,i=o<<t}n.__setDigit(r-1,a);for(let t=r-2;0<=t;t--)0<u?(u-=32,a=i,i=o):a=0,n.__setDigit(t,a);return n.__trim()}static __isWhitespace(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)}static __fromString(t,e=0){let r=0;const n=t.length;let i=0;if(i===n)return l.__zero();let o=t.charCodeAt(i);for(;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(o=t.charCodeAt(i),88===o||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(o=t.charCodeAt(i),88===o||120===o){if(++i===n)return null;o=t.charCodeAt(i)}}for(;48===o;){if(++i===n)return l.__zero();o=t.charCodeAt(i)}const s=n-i;let a=l.__kMaxBitsPerChar[e],u=l.__kBitsPerCharTableMultiplier-1;if(s>1073741824/a)return null;const c=a*s+u>>>l.__kBitsPerCharTableShift,_=new l(c+31>>>5,!1),h=10>e?e:10,f=10<e?e-10:0;if(0==(e&e-1)){a>>=l.__kBitsPerCharTableShift;const e=[],r=[];let s=!1;do{let u=0,l=0;for(;;){let e;if(o-48>>>0<h)e=o-48;else{if(!((32|o)-97>>>0<f)){s=!0;break}e=(32|o)-87}if(l+=a,u=u<<a|e,++i===n){s=!0;break}if(o=t.charCodeAt(i),32<l+a)break}e.push(u),r.push(l)}while(!s);l.__fillFromParts(_,e,r)}else{_.__initializeDigits();let r=!1,s=0;do{let c=0,g=1;for(;;){let a;if(o-48>>>0<h)a=o-48;else{if(!((32|o)-97>>>0<f)){r=!0;break}a=(32|o)-87}const u=g*e;if(4294967295<u)break;if(g=u,c=c*e+a,s++,++i===n){r=!0;break}o=t.charCodeAt(i)}u=32*l.__kBitsPerCharTableMultiplier-1;const d=a*s+u>>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(g,c,d)}while(!r)}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:(_.sign=-1==r,_.__trim())}static __fillFromParts(t,e,r){let n=0,i=0,o=0;for(let s=e.length-1;0<=s;s--){const a=e[s],u=r[s];i|=a<<o,o+=u,32===o?(t.__setDigit(n++,i),o=0,i=0):32<o&&(t.__setDigit(n++,i),o-=32,i=a>>>u-o)}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)}static __toStringBasePowerOfTwo(t,e){var r=Math.clz32;const n=t.length;let i=e-1;i=(85&i>>>1)+(85&i),i=(51&i>>>2)+(51&i),i=(15&i>>>4)+(15&i);const o=i,s=e-1,a=t.__digit(n-1);let u=0|(32*n-r(a)+o-1)/o;if(t.sign&&u++,268435456<u)throw new Error("string too long");const c=Array(u);let _=u-1,h=0,f=0;for(let e=0;e<n-1;e++){const r=t.__digit(e),n=(h|r<<f)&s;c[_--]=l.__kConversionChars[n];const i=o-f;for(h=r>>>i,f=32-i;f>=o;)c[_--]=l.__kConversionChars[h&s],h>>>=o,f-=o}const g=(h|a<<f)&s;for(c[_--]=l.__kConversionChars[g],h=a>>>o-f;0!==h;)c[_--]=l.__kConversionChars[h&s],h>>>=o;if(t.sign&&(c[_--]="-"),-1!=_)throw new Error("implementation bug");return c.join("")}static __toStringGeneric(t,e,r){var n=Math.clz32;const i=t.length;if(0===i)return"";if(1===i){let n=t.__unsignedDigit(0).toString(e);return!1===r&&t.sign&&(n="-"+n),n}const o=32*i-n(t.__digit(i-1)),s=l.__kMaxBitsPerChar[e]-1;let a=o*l.__kBitsPerCharTableMultiplier;a+=s-1,a=0|a/s;const u=a+1>>1,c=l.exponentiate(l.__oneDigit(e,!1),l.__oneDigit(u,!1));let _,h;const f=c.__unsignedDigit(0);if(1===c.length&&65535>=f){_=new l(t.length,!1),_.__initializeDigits();let r=0;for(let e=2*t.length-1;0<=e;e--){const n=r<<16|t.__halfDigit(e);_.__setHalfDigit(e,0|n/f),r=0|n%f}h=r.toString(e)}else{const r=l.__absoluteDivLarge(t,c,!0,!0);_=r.quotient;const n=r.remainder.__trim();h=l.__toStringGeneric(n,e,!0)}_.__trim();let g=l.__toStringGeneric(_,e,!0);for(;h.length<u;)h="0"+h;return!1===r&&t.sign&&(g="-"+g),g+h}static __unequalSign(t){return t?-1:1}static __absoluteGreater(t){return t?-1:1}static __absoluteLess(t){return t?1:-1}static __compareToBigInt(t,e){const r=t.sign;if(r!==e.sign)return l.__unequalSign(r);const n=l.__absoluteCompare(t,e);return 0<n?l.__absoluteGreater(r):0>n?l.__absoluteLess(r):0}static __compareToNumber(t,e){if(!0|e){const 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);const i=Math.abs(e),o=t.__unsignedDigit(0);return o>i?l.__absoluteGreater(r):o<i?l.__absoluteLess(r):0}return l.__compareToDouble(t,e)}static __compareToDouble(t,e){var r=Math.clz32;if(e!=e)return e;if(e===1/0)return-1;if(e===-1/0)return 1;const n=t.sign;if(n!==0>e)return l.__unequalSign(n);if(0===e)throw new Error("implementation bug: should be handled elsewhere");if(0===t.length)return-1;l.__kBitConversionDouble[0]=e;const i=2047&l.__kBitConversionInts[1]>>>20;if(2047==i)throw new Error("implementation bug: handled elsewhere");const o=i-1023;if(0>o)return l.__absoluteGreater(n);const s=t.length;let a=t.__digit(s-1);const u=r(a),c=32*s-u,_=o+1;if(c<_)return l.__absoluteLess(n);if(c>_)return l.__absoluteGreater(n);let h=1048576|1048575&l.__kBitConversionInts[1],f=l.__kBitConversionInts[0];const g=31-u;if(g!==(c-1)%31)throw new Error("implementation bug");let d,p=0;if(20>g){const t=20-g;p=t+32,d=h>>>t,h=h<<32-t|f>>>t,f<<=32-t}else if(20===g)p=32,d=h,h=f;else{const t=g-20;p=32-t,d=h<<t|f>>>32-t,h=f<<t}if(a>>>=0,d>>>=0,a>d)return l.__absoluteGreater(n);if(a<d)return l.__absoluteLess(n);for(let e=s-2;0<=e;e--){0<p?(p-=32,d=h>>>0,h=f,f=0):d=0;const r=t.__unsignedDigit(e);if(r>d)return l.__absoluteGreater(n);if(r<d)return l.__absoluteLess(n)}if(0!==h||0!==f){if(0===p)throw new Error("implementation bug");return l.__absoluteLess(n)}return 0}static __equalToNumber(t,e){var r=Math.abs;return e|0===e?0===e?0===t.length:1===t.length&&t.sign===0>e&&t.__unsignedDigit(0)===r(e):0===l.__compareToDouble(t,e)}static __comparisonResultToBool(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")}static __compare(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}__clzmsd(){return Math.clz32(this[this.length-1])}static __absoluteAdd(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);let n=t.length;(0===t.__clzmsd()||e.length===t.length&&0===e.__clzmsd())&&n++;const i=new l(n,r);let o=0,s=0;for(;s<e.length;s++){const r=e.__digit(s),n=t.__digit(s),a=(65535&n)+(65535&r)+o,u=(n>>>16)+(r>>>16)+(a>>>16);o=u>>>16,i.__setDigit(s,65535&a|u<<16)}for(;s<t.length;s++){const e=t.__digit(s),r=(65535&e)+o,n=(e>>>16)+(r>>>16);o=n>>>16,i.__setDigit(s,65535&r|n<<16)}return s<i.length&&i.__setDigit(s,o),i.__trim()}static __absoluteSub(t,e,r){if(0===t.length)return t;if(0===e.length)return t.sign===r?t:l.unaryMinus(t);const n=new l(t.length,r);let i=0,o=0;for(;o<e.length;o++){const r=t.__digit(o),s=e.__digit(o),a=(65535&r)-(65535&s)-i;i=1&a>>>16;const u=(r>>>16)-(s>>>16)-i;i=1&u>>>16,n.__setDigit(o,65535&a|u<<16)}for(;o<t.length;o++){const e=t.__digit(o),r=(65535&e)-i;i=1&r>>>16;const s=(e>>>16)-i;i=1&s>>>16,n.__setDigit(o,65535&r|s<<16)}return n.__trim()}static __absoluteAddOne(t,e,r=null){const n=t.length;null===r?r=new l(n,e):r.sign=e;let i=!0;for(let e,o=0;o<n;o++){e=t.__digit(o);const n=-1===e;i&&(e=0|e+1),i=n,r.__setDigit(o,e)}return i&&r.__setDigitGrow(n,1),r}static __absoluteSubOne(t,e){const r=t.length,n=new l(e=e||r,!1);let i=!0;for(let e,o=0;o<r;o++){e=t.__digit(o);const r=0===e;i&&(e=0|e-1),i=r,n.__setDigit(o,e)}for(let t=r;t<e;t++)n.__setDigit(t,0);return n}static __absoluteAnd(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=o;null===r?r=new l(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)&e.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteAndNot(t,e,r=null){const n=t.length,i=e.length;let o=i;n<i&&(o=n);let s=n;null===r?r=new l(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)&~e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteOr(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=n;null===r?r=new l(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)|e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteXor(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=n;null===r?r=new l(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)^e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteCompare(t,e){const r=t.length-e.length;if(0!=r)return r;let n=t.length-1;for(;0<=n&&t.__digit(n)===e.__digit(n);)n--;return 0>n?0:t.__unsignedDigit(n)>e.__unsignedDigit(n)?1:-1}static __multiplyAccumulate(t,e,r,n){var i=Math.imul;if(0===e)return;const o=65535&e,s=e>>>16;let a=0,u=0,l=0;for(let e=0;e<t.length;e++,n++){let c=r.__digit(n),_=65535&c,h=c>>>16;const f=t.__digit(e),g=65535&f,d=f>>>16,p=i(g,o),b=i(g,s),m=i(d,o),y=i(d,s);_+=u+(65535&p),h+=l+a+(_>>>16)+(p>>>16)+(65535&b)+(65535&m),a=h>>>16,u=(b>>>16)+(m>>>16)+(65535&y)+a,a=u>>>16,u&=65535,l=y>>>16,c=65535&_|h<<16,r.__setDigit(n,c)}for(;0!=a||0!==u||0!==l;n++){let t=r.__digit(n);const e=(65535&t)+u,i=(t>>>16)+(e>>>16)+l+a;u=0,l=0,a=i>>>16,t=65535&e|i<<16,r.__setDigit(n,t)}}static __internalMultiplyAdd(t,e,r,n,i){var o=Math.imul;let s=r,a=0;for(let r=0;r<n;r++){const n=t.__digit(r),u=o(65535&n,e),l=(65535&u)+a+s;s=l>>>16;const c=o(n>>>16,e),_=(65535&c)+(u>>>16)+s;s=_>>>16,a=c>>>16,i.__setDigit(r,_<<16|65535&l)}if(i.length>n)for(i.__setDigit(n++,s+a);n<i.length;)i.__setDigit(n++,0);else if(0!==s+a)throw new Error("implementation bug")}__inplaceMultiplyAdd(t,e,r){var n=Math.imul;r>this.length&&(r=this.length);const i=65535&t,o=t>>>16;let s=0,a=65535&e,u=e>>>16;for(let t=0;t<r;t++){const e=this.__digit(t),r=65535&e,l=e>>>16,c=n(r,i),_=n(r,o),h=n(l,i),f=n(l,o),g=a+(65535&c),d=u+s+(g>>>16)+(c>>>16)+(65535&_)+(65535&h);a=(_>>>16)+(h>>>16)+(65535&f)+(d>>>16),s=a>>>16,a&=65535,u=f>>>16,this.__setDigit(t,65535&g|d<<16)}if(0!=s||0!==a||0!==u)throw new Error("implementation bug")}static __absoluteDivSmall(t,e,r){null===r&&(r=new l(t.length,!1));let n=0;for(let i,o=2*t.length-1;0<=o;o-=2){i=(n<<16|t.__halfDigit(o))>>>0;const s=0|i/e;n=0|i%e,i=(n<<16|t.__halfDigit(o-1))>>>0;const a=0|i/e;n=0|i%e,r.__setDigit(o>>>1,s<<16|a)}return r}static __absoluteModSmall(t,e){let r=0;for(let n=2*t.length-1;0<=n;n--){r=0|((r<<16|t.__halfDigit(n))>>>0)%e}return r}static __absoluteDivLarge(t,e,r,n){var i=Math.imul;const o=e.__halfDigitLength(),s=e.length,a=t.__halfDigitLength()-o;let u=null;r&&(u=new l(a+2>>>1,!1),u.__initializeDigits());const c=new l(o+2>>>1,!1);c.__initializeDigits();const _=l.__clz16(e.__halfDigit(o-1));0<_&&(e=l.__specialLeftShift(e,_,0));const h=l.__specialLeftShift(t,_,1),f=e.__halfDigit(o-1);let g=0;for(let t,n=a;0<=n;n--){t=65535;const a=h.__halfDigit(n+o);if(a!==f){const r=(a<<16|h.__halfDigit(n+o-1))>>>0;t=0|r/f;let s=0|r%f;const u=e.__halfDigit(o-2),l=h.__halfDigit(n+o-2);for(;i(t,u)>>>0>(s<<16|l)>>>0&&(t--,s+=f,!(65535<s)););}l.__internalMultiplyAdd(e,t,0,s,c);let _=h.__inplaceSub(c,n,o+1);0!==_&&(_=h.__inplaceAdd(e,n,o),h.__setHalfDigit(n+o,h.__halfDigit(n+o)+_),t--),r&&(1&n?g=t<<16:u.__setDigit(n>>>1,g|t))}return n?(h.__inplaceRightShift(_),r?{quotient:u,remainder:h}:h):r?u:void 0}static __clz16(t){return Math.clz32(t)-16}__inplaceAdd(t,e,r){let n=0;for(let i=0;i<r;i++){const r=this.__halfDigit(e+i)+t.__halfDigit(i)+n;n=r>>>16,this.__setHalfDigit(e+i,r)}return n}__inplaceSub(t,e,r){let n=0;if(1&e){e>>=1;let i=this.__digit(e),o=65535&i,s=0;for(;s<r-1>>>1;s++){const r=t.__digit(s),a=(i>>>16)-(65535&r)-n;n=1&a>>>16,this.__setDigit(e+s,a<<16|65535&o),i=this.__digit(e+s+1),o=(65535&i)-(r>>>16)-n,n=1&o>>>16}const a=t.__digit(s),u=(i>>>16)-(65535&a)-n;if(n=1&u>>>16,this.__setDigit(e+s,u<<16|65535&o),e+s+1>=this.length)throw new RangeError("out of bounds");0==(1&r)&&(i=this.__digit(e+s+1),o=(65535&i)-(a>>>16)-n,n=1&o>>>16,this.__setDigit(e+t.length,4294901760&i|65535&o))}else{e>>=1;let i=0;for(;i<t.length-1;i++){const r=this.__digit(e+i),o=t.__digit(i),s=(65535&r)-(65535&o)-n;n=1&s>>>16;const a=(r>>>16)-(o>>>16)-n;n=1&a>>>16,this.__setDigit(e+i,a<<16|65535&s)}const o=this.__digit(e+i),s=t.__digit(i),a=(65535&o)-(65535&s)-n;n=1&a>>>16;let u=0;0==(1&r)&&(u=(o>>>16)-(s>>>16)-n,n=1&u>>>16),this.__setDigit(e+i,u<<16|65535&a)}return n}__inplaceRightShift(t){if(0===t)return;let e=this.__digit(0)>>>t;const r=this.length-1;for(let n=0;n<r;n++){const r=this.__digit(n+1);this.__setDigit(n,r<<32-t|e),e=r>>>t}this.__setDigit(r,e)}static __specialLeftShift(t,e,r){const n=t.length,i=new l(n+r,!1);if(0===e){for(let e=0;e<n;e++)i.__setDigit(e,t.__digit(e));return 0<r&&i.__setDigit(n,0),i}let o=0;for(let r=0;r<n;r++){const n=t.__digit(r);i.__setDigit(r,n<<e|o),o=n>>>32-e}return 0<r&&i.__setDigit(n,o),i}static __leftShiftByAbsolute(t,e){const r=l.__toShiftAmount(e);if(0>r)throw new RangeError("BigInt too big");const n=r>>>5,i=31&r,o=t.length,s=0!==i&&0!=t.__digit(o-1)>>>32-i,a=o+n+(s?1:0),u=new l(a,t.sign);if(0===i){let e=0;for(;e<n;e++)u.__setDigit(e,0);for(;e<a;e++)u.__setDigit(e,t.__digit(e-n))}else{let e=0;for(let t=0;t<n;t++)u.__setDigit(t,0);for(let r=0;r<o;r++){const o=t.__digit(r);u.__setDigit(r+n,o<<i|e),e=o>>>32-i}if(s)u.__setDigit(o+n,e);else if(0!=e)throw new Error("implementation bug")}return u.__trim()}static __rightShiftByAbsolute(t,e){const r=t.length,n=t.sign,i=l.__toShiftAmount(e);if(0>i)return l.__rightShiftByMaximum(n);const o=i>>>5,s=31&i;let a=r-o;if(0>=a)return l.__rightShiftByMaximum(n);let u=!1;if(n)if(0!=(t.__digit(o)&(1<<s)-1))u=!0;else for(let e=0;e<o;e++)if(0!==t.__digit(e)){u=!0;break}if(u&&0===s){0==~t.__digit(r-1)&&a++}let c=new l(a,n);if(0===s)for(let e=o;e<r;e++)c.__setDigit(e-o,t.__digit(e));else{let e=t.__digit(o)>>>s;const n=r-o-1;for(let r=0;r<n;r++){const n=t.__digit(r+o+1);c.__setDigit(r,n<<32-s|e),e=n>>>s}c.__setDigit(n,e)}return u&&(c=l.__absoluteAddOne(c,!0,c)),c.__trim()}static __rightShiftByMaximum(t){return t?l.__oneDigit(1,!0):l.__zero()}static __toShiftAmount(t){if(1<t.length)return-1;const e=t.__unsignedDigit(0);return e>l.__kMaxLengthBits?-1:e}static __toPrimitive(t,e="default"){if("object"!=typeof t)return t;if(t.constructor===l)return t;const r=t[Symbol.toPrimitive];if(r){const t=r(e);if("object"!=typeof t)return t;throw new TypeError("Cannot convert object to primitive value")}const n=t.valueOf;if(n){const e=n.call(t);if("object"!=typeof e)return e}const i=t.toString;if(i){const e=i.call(t);if("object"!=typeof e)return e}throw new TypeError("Cannot convert object to primitive value")}static __toNumeric(t){return l.__isBigInt(t)?t:+t}static __isBigInt(t){return"object"==typeof t&&t.constructor===l}static __truncateToNBits(t,e){const r=t+31>>>5,n=new l(r,e.sign),i=r-1;for(let t=0;t<i;t++)n.__setDigit(t,e.__digit(t));let o=e.__digit(i);if(0!=(31&t)){const e=32-(31&t);o=o<<e>>>e}return n.__setDigit(i,o),n.__trim()}static __truncateAndSubFromPowerOfTwo(t,e,r){var n=Math.min;const i=t+31>>>5,o=new l(i,r);let s=0;const a=i-1;let u=0;for(const t=n(a,e.length);s<t;s++){const t=e.__digit(s),r=0-(65535&t)-u;u=1&r>>>16;const n=0-(t>>>16)-u;u=1&n>>>16,o.__setDigit(s,65535&r|n<<16)}for(;s<a;s++)o.__setDigit(s,0|-u);let c=a<e.length?e.__digit(a):0;const _=31&t;let h;if(0==_){const t=0-(65535&c)-u;u=1&t>>>16,h=65535&t|0-(c>>>16)-u<<16}else{const t=32-_;c=c<<t>>>t;const e=1<<32-t,r=(65535&e)-(65535&c)-u;u=1&r>>>16,h=65535&r|(e>>>16)-(c>>>16)-u<<16,h&=e-1}return o.__setDigit(a,h),o.__trim()}__digit(t){return this[t]}__unsignedDigit(t){return this[t]>>>0}__setDigit(t,e){this[t]=0|e}__setDigitGrow(t,e){this[t]=0|e}__halfDigitLength(){const t=this.length;return 65535>=this.__unsignedDigit(t-1)?2*t-1:2*t}__halfDigit(t){return 65535&this[t>>>1]>>>((1&t)<<4)}__setHalfDigit(t,e){const r=t>>>1,n=this.__digit(r),i=1&t?65535&n|e<<16:4294901760&n|65535&e;this.__setDigit(r,i)}static __digitPow(t,e){let r=1;for(;0<e;)1&e&&(r*=t),e>>>=1,t*=t;return r}}function c(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,s=r.length+n.length,a=`${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>s)throw new Error(a);let u=i.filter(t=>!r.includes(t));if(i.length-u.length!==o)throw new Error(a);if(u.find(t=>!n.includes(t)))throw new Error(a)}function _(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(`${t} must be a hex string!`)}function h(t,e){if(_(t,e),66!=e.length)throw new Error(`${t} must be a hex string of 66 bytes long!`)}function f(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 g(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(c(r,t,["code_hash","hash_type","args"],[]),h(`${r}.code_hash`,t.code_hash),_(`${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 d(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){c(r,t,["tx_hash","index"],[]),h(`${r}.tx_hash`,t.tx_hash),f(`${r}.index`,t.index)}function p(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){c(r,t,["since","previous_output"],[]),f(`${r}.since`,t.since),e&&d(t.previous_output,{debugPath:`${r}.previous_output`})}function b(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){c(r,t,["capacity","lock"],["type"]),f(`${r}.capacity`,t.capacity),e&&(g(t.lock,{debugPath:`${r}.lock`}),t.type&&g(t.type,{debugPath:`${r}.type`}))}function m(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(c(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&&d(t.out_point,{debugPath:`${r}.out_point`})}function y(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 v(t,e,r){f(`${t}.version`,e.version),y(`${t}.cell_deps`,e.cell_deps,w(m,r),r),y(`${t}.header_deps`,e.header_deps,h,r),y(`${t}.inputs`,e.inputs,w(p,r),r),y(`${t}.outputs`,e.outputs,w(b,r),r),y(`${t}.outputs_data`,e.outputs_data,_,r)}function B(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){c(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),v(r,t,e)}function P(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){c(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),v(r,t,e),y(`${r}.witnesses`,t.witnesses,_,e)}function D(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){c(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){f(`${t}.version`,e.version),f(`${t}.compact_target`,e.compact_target),f(`${t}.timestamp`,e.timestamp),f(`${t}.number`,e.number),f(`${t}.epoch`,e.epoch),h(`${t}.parent_hash`,e.parent_hash),h(`${t}.transactions_root`,e.transactions_root),h(`${t}.proposals_hash`,e.proposals_hash),h(`${t}.uncles_hash`,e.uncles_hash),h(`${t}.dao`,e.dao)}(r,t)}function S(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(c(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),_(`${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(_(t,e),22!=e.length)throw new Error(`${t} must be a hex string of 22 bytes long!`)}function $(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){c(r,t,["header","proposals"],[]),e&&S(t.header,{debugPath:`${r}.header`}),y(`${r}.proposals`,t.proposals,T,e)}function k(t,{nestedValidation:e=!0,debugPath:r="block"}={}){c(r,t,["header","uncles","transactions","proposals"],[]),e&&S(t.header,{debugPath:`${r}.header`}),y(`${r}.uncles`,t.uncles,w($,e),e),y(`${r}.transactions`,t.transactions,w(P,e),e),y(`${r}.proposals`,t.proposals,T,e)}function x(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){c(r,t,["lock","message"],[]),_(`${r}.message`,t.message),e&&g(t.lock,{debugPath:`${r}.lock`})}function C(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){c(r,t,[],["lock","input_type","output_type"]),t.lock&&_(`${r}.lock`,t.lock),t.input_type&&_(`${r}.input_type`,t.input_type),t.output_type&&_(`${r}.output_type`,t.output_type)}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);var E=Object.freeze({__proto__:null,ValidateScript:g,ValidateOutPoint:d,ValidateCellInput:p,ValidateCellOutput:b,ValidateCellDep:m,ValidateRawTransaction:B,ValidateTransaction:P,ValidateRawHeader:D,ValidateHeader:S,ValidateUncleBlock:$,ValidateBlock:k,ValidateCellbaseWitness:x,ValidateWitnessArgs:C});const A=e.Readable,O=Symbol("buffer"),j=Symbol("type");class z{constructor(){this[j]="";const t=arguments[0],e=arguments[1],r=[];let n=0;if(t){const e=t,i=Number(e.length);for(let t=0;t<i;t++){const i=e[t];let o;o=i instanceof Buffer?i:ArrayBuffer.isView(i)?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i instanceof ArrayBuffer?Buffer.from(i):i instanceof z?i[O]:Buffer.from("string"==typeof i?i:String(i)),n+=o.length,r.push(o)}}this[O]=Buffer.concat(r);let i=e&&void 0!==e.type&&String(e.type).toLowerCase();i&&!/[^\u0020-\u007E]/.test(i)&&(this[j]=i)}get size(){return this[O].length}get type(){return this[j]}text(){return Promise.resolve(this[O].toString())}arrayBuffer(){const t=this[O],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new A;return t._read=function(){},t.push(this[O]),t.push(null),t}toString(){return"[object Blob]"}slice(){const t=this.size,e=arguments[0],r=arguments[1];let n,i;n=void 0===e?0:e<0?Math.max(t+e,0):Math.min(e,t),i=void 0===r?t:r<0?Math.max(t+r,0):Math.min(r,t);const o=Math.max(i-n,0),s=this[O].slice(n,n+o),a=new z([],{type:arguments[2]});return a[O]=s,a}}function I(t,e,r){Error.call(this,t),this.message=t,this.type=e,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let R;Object.defineProperties(z.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(z.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),I.prototype=Object.create(Error.prototype),I.prototype.constructor=I,I.prototype.name="FetchError";try{R=require("encoding").convert}catch(t){}const L=Symbol("Body internals"),M=e.PassThrough;function N(t){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=n.size;let o=void 0===i?0:i;var s=n.timeout;let a=void 0===s?0:s;null==t?t=null:U(t)?t=Buffer.from(t.toString()):V(t)||Buffer.isBuffer(t)||("[object ArrayBuffer]"===Object.prototype.toString.call(t)?t=Buffer.from(t):ArrayBuffer.isView(t)?t=Buffer.from(t.buffer,t.byteOffset,t.byteLength):t instanceof e||(t=Buffer.from(String(t)))),this[L]={body:t,disturbed:!1,error:null},this.size=o,this.timeout=a,t instanceof e&&t.on("error",(function(t){const e="AbortError"===t.name?t:new I(`Invalid response body while trying to fetch ${r.url}: ${t.message}`,"system",t);r[L].error=e}))}function q(){var t=this;if(this[L].disturbed)return N.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[L].disturbed=!0,this[L].error)return N.Promise.reject(this[L].error);let r=this.body;if(null===r)return N.Promise.resolve(Buffer.alloc(0));if(V(r)&&(r=r.stream()),Buffer.isBuffer(r))return N.Promise.resolve(r);if(!(r instanceof e))return N.Promise.resolve(Buffer.alloc(0));let n=[],i=0,o=!1;return new N.Promise((function(e,s){let a;t.timeout&&(a=setTimeout((function(){o=!0,s(new I(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),r.on("error",(function(e){"AbortError"===e.name?(o=!0,s(e)):s(new I(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),r.on("data",(function(e){if(!o&&null!==e){if(t.size&&i+e.length>t.size)return o=!0,void s(new I(`content size at ${t.url} over limit: ${t.size}`,"max-size"));i+=e.length,n.push(e)}})),r.on("end",(function(){if(!o){clearTimeout(a);try{e(Buffer.concat(n,i))}catch(e){s(new I(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function U(t){return"object"==typeof t&&"function"==typeof t.append&&"function"==typeof t.delete&&"function"==typeof t.get&&"function"==typeof t.getAll&&"function"==typeof t.has&&"function"==typeof t.set&&("URLSearchParams"===t.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(t)||"function"==typeof t.sort)}function V(t){return"object"==typeof t&&"function"==typeof t.arrayBuffer&&"string"==typeof t.type&&"function"==typeof t.stream&&"function"==typeof t.constructor&&"string"==typeof t.constructor.name&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag])}function H(t){let r,n,i=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return i instanceof e&&"function"!=typeof i.getBoundary&&(r=new M,n=new M,i.pipe(r),i.pipe(n),t[L].body=r,i=n),i}function F(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":U(t)?"application/x-www-form-urlencoded;charset=UTF-8":V(t)?t.type||null:Buffer.isBuffer(t)||"[object ArrayBuffer]"===Object.prototype.toString.call(t)||ArrayBuffer.isView(t)?null:"function"==typeof t.getBoundary?`multipart/form-data;boundary=${t.getBoundary()}`:t instanceof e?null:"text/plain;charset=UTF-8"}function G(t){const e=t.body;return null===e?0:V(e)?e.size:Buffer.isBuffer(e)?e.length:e&&"function"==typeof e.getLengthSync&&(e._lengthRetrievers&&0==e._lengthRetrievers.length||e.hasKnownLength&&e.hasKnownLength())?e.getLengthSync():null}N.prototype={get body(){return this[L].body},get bodyUsed(){return this[L].disturbed},arrayBuffer(){return q.call(this).then((function(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}))},blob(){let t=this.headers&&this.headers.get("content-type")||"";return q.call(this).then((function(e){return Object.assign(new z([],{type:t.toLowerCase()}),{[O]:e})}))},json(){var t=this;return q.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return N.Promise.reject(new I(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return q.call(this).then((function(t){return t.toString()}))},buffer(){return q.call(this)},textConverted(){var t=this;return q.call(this).then((function(e){return function(t,e){if("function"!=typeof R)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=e.get("content-type");let n,i,o="utf-8";r&&(n=/charset=([^;]*)/i.exec(r));i=t.slice(0,1024).toString(),!n&&i&&(n=/<meta.+?charset=(['"])(.+?)\1/i.exec(i));!n&&i&&(n=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(i),n&&(n=/charset=(.*)/i.exec(n.pop())));!n&&i&&(n=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(i));n&&(o=n.pop(),"gb2312"!==o&&"gbk"!==o||(o="gb18030"));return R(t,"UTF-8",o).toString()}(e,t.headers)}))}},Object.defineProperties(N.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),N.mixIn=function(t){for(const e of Object.getOwnPropertyNames(N.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(N.prototype,e);Object.defineProperty(t,e,r)}},N.Promise=global.Promise;const W=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,J=/[^\t\x20-\x7e\x80-\xff]/;function X(t){if(t=`${t}`,W.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function Q(t){if(t=`${t}`,J.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function Z(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const K=Symbol("map");class Y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[K]=Object.create(null),t instanceof Y){const e=t.raw(),r=Object.keys(e);for(const t of r)for(const r of e[t])this.append(t,r)}else if(null==t);else{if("object"!=typeof t)throw new TypeError("Provided initializer must be an object");{const e=t[Symbol.iterator];if(null!=e){if("function"!=typeof e)throw new TypeError("Header pairs must be iterable");const r=[];for(const e of t){if("object"!=typeof e||"function"!=typeof e[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(e))}for(const t of r){if(2!==t.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(t[0],t[1])}}else for(const e of Object.keys(t)){const r=t[e];this.append(e,r)}}}}get(t){X(t=`${t}`);const e=Z(this[K],t);return void 0===e?null:this[K][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=tt(this),n=0;for(;n<r.length;){var i=r[n];const o=i[0],s=i[1];t.call(e,s,o,this),r=tt(this),n++}}set(t,e){e=`${e}`,X(t=`${t}`),Q(e);const r=Z(this[K],t);this[K][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,X(t=`${t}`),Q(e);const r=Z(this[K],t);void 0!==r?this[K][r].push(e):this[K][t]=[e]}has(t){return X(t=`${t}`),void 0!==Z(this[K],t)}delete(t){X(t=`${t}`);const e=Z(this[K],t);void 0!==e&&delete this[K][e]}raw(){return this[K]}keys(){return rt(this,"key")}values(){return rt(this,"value")}[Symbol.iterator](){return rt(this,"key+value")}}function tt(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[K]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[K][e].join(", ")}:function(e){return[e.toLowerCase(),t[K][e].join(", ")]})}Y.prototype.entries=Y.prototype[Symbol.iterator],Object.defineProperty(Y.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(Y.prototype,{get:{enumerable:!0},forEach:{enumerable:!0},set:{enumerable:!0},append:{enumerable:!0},has:{enumerable:!0},delete:{enumerable:!0},keys:{enumerable:!0},values:{enumerable:!0},entries:{enumerable:!0}});const et=Symbol("internal");function rt(t,e){const r=Object.create(nt);return r[et]={target:t,kind:e,index:0},r}const nt=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==nt)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[et];const e=t.target,r=t.kind,n=t.index,i=tt(e,r);return n>=i.length?{value:void 0,done:!0}:(this[et].index=n+1,{value:i[n],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function it(t){const e=Object.assign({__proto__:null},t[K]),r=Z(t[K],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(nt,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const ot=Symbol("Response internals"),st=r.STATUS_CODES;class at{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};N.call(this,t,e);const r=e.status||200,n=new Y(e.headers);if(null!=t&&!n.has("Content-Type")){const e=F(t);e&&n.append("Content-Type",e)}this[ot]={url:e.url,status:r,statusText:e.statusText||st[r],headers:n,counter:e.counter}}get url(){return this[ot].url||""}get status(){return this[ot].status}get ok(){return this[ot].status>=200&&this[ot].status<300}get redirected(){return this[ot].counter>0}get statusText(){return this[ot].statusText}get headers(){return this[ot].headers}clone(){return new at(H(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}N.mixIn(at.prototype),Object.defineProperties(at.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(at.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ut=Symbol("Request internals"),lt=n.parse,ct=n.format,_t="destroy"in e.Readable.prototype;function ht(t){return"object"==typeof t&&"object"==typeof t[ut]}class ft{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ht(t)?e=lt(t.url):(e=t&&t.href?lt(t.href):lt(`${t}`),t={});let n=r.method||t.method||"GET";if(n=n.toUpperCase(),(null!=r.body||ht(t)&&null!==t.body)&&("GET"===n||"HEAD"===n))throw new TypeError("Request with GET/HEAD method cannot have body");let i=null!=r.body?r.body:ht(t)&&null!==t.body?H(t):null;N.call(this,i,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const o=new Y(r.headers||t.headers||{});if(null!=i&&!o.has("Content-Type")){const t=F(i);t&&o.append("Content-Type",t)}let s=ht(t)?t.signal:null;if("signal"in r&&(s=r.signal),null!=s&&!function(t){const e=t&&"object"==typeof t&&Object.getPrototypeOf(t);return!(!e||"AbortSignal"!==e.constructor.name)}(s))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[ut]={method:n,redirect:r.redirect||t.redirect||"follow",headers:o,parsedURL:e,signal:s},this.follow=void 0!==r.follow?r.follow:void 0!==t.follow?t.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===t.compress||t.compress,this.counter=r.counter||t.counter||0,this.agent=r.agent||t.agent}get method(){return this[ut].method}get url(){return ct(this[ut].parsedURL)}get headers(){return this[ut].headers}get redirect(){return this[ut].redirect}get signal(){return this[ut].signal}clone(){return new ft(this)}}function gt(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}N.mixIn(ft.prototype),Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(ft.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),gt.prototype=Object.create(Error.prototype),gt.prototype.constructor=gt,gt.prototype.name="AbortError";const dt=e.PassThrough,pt=n.resolve;function bt(t,n){if(!bt.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return N.Promise=bt.Promise,new bt.Promise((function(s,a){const u=new ft(t,n),l=function(t){const r=t[ut].parsedURL,n=new Y(t[ut].headers);if(n.has("Accept")||n.set("Accept","*/*"),!r.protocol||!r.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(r.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(t.signal&&t.body instanceof e.Readable&&!_t)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let i=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(i="0"),null!=t.body){const e=G(t);"number"==typeof e&&(i=String(e))}i&&n.set("Content-Length",i),n.has("User-Agent")||n.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!n.has("Accept-Encoding")&&n.set("Accept-Encoding","gzip,deflate");let o=t.agent;return"function"==typeof o&&(o=o(r)),n.has("Connection")||o||n.set("Connection","close"),Object.assign({},r,{method:t.method,headers:it(n),agent:o})}(u),c=("https:"===l.protocol?i:r).request,_=u.signal;let h=null;const f=function(){let t=new gt("The user aborted a request.");a(t),u.body&&u.body instanceof e.Readable&&u.body.destroy(t),h&&h.body&&h.body.emit("error",t)};if(_&&_.aborted)return void f();const g=function(){f(),b()},d=c(l);let p;function b(){d.abort(),_&&_.removeEventListener("abort",g),clearTimeout(p)}_&&_.addEventListener("abort",g),u.timeout&&d.once("socket",(function(t){p=setTimeout((function(){a(new I(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),d.on("error",(function(t){a(new I(`request to ${u.url} failed, reason: ${t.message}`,"system",t)),b()})),d.on("response",(function(t){clearTimeout(p);const e=function(t){const e=new Y;for(const r of Object.keys(t))if(!W.test(r))if(Array.isArray(t[r]))for(const n of t[r])J.test(n)||(void 0===e[K][r]?e[K][r]=[n]:e[K][r].push(n));else J.test(t[r])||(e[K][r]=[t[r]]);return e}(t.headers);if(bt.isRedirect(t.statusCode)){const r=e.get("Location"),n=null===r?null:pt(u.url,r);switch(u.redirect){case"error":return a(new I(`redirect mode is set to error: ${u.url}`,"no-redirect")),void b();case"manual":if(null!==n)try{e.set("Location",n)}catch(t){a(t)}break;case"follow":if(null===n)break;if(u.counter>=u.follow)return a(new I(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new Y(u.headers),follow:u.follow,counter:u.counter+1,agent:u.agent,compress:u.compress,method:u.method,body:u.body,signal:u.signal,timeout:u.timeout};return 303!==t.statusCode&&u.body&&null===G(u)?(a(new I("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==u.method)||(r.method="GET",r.body=void 0,r.headers.delete("content-length")),s(bt(new ft(n,r))),void b())}}t.once("end",(function(){_&&_.removeEventListener("abort",g)}));let r=t.pipe(new dt);const n={url:u.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:u.size,timeout:u.timeout,counter:u.counter},i=e.get("Content-Encoding");if(!u.compress||"HEAD"===u.method||null===i||204===t.statusCode||304===t.statusCode)return h=new at(r,n),void s(h);const l={flush:o.Z_SYNC_FLUSH,finishFlush:o.Z_SYNC_FLUSH};if("gzip"==i||"x-gzip"==i)return r=r.pipe(o.createGunzip(l)),h=new at(r,n),void s(h);if("deflate"!=i&&"x-deflate"!=i){if("br"==i&&"function"==typeof o.createBrotliDecompress)return r=r.pipe(o.createBrotliDecompress()),h=new at(r,n),void s(h);h=new at(r,n),s(h)}else{t.pipe(new dt).once("data",(function(t){r=8==(15&t[0])?r.pipe(o.createInflate()):r.pipe(o.createInflateRaw()),h=new at(r,n),s(h)}))}})),function(t,e){const r=e.body;null===r?t.end():V(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(d,u)}))}bt.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},bt.Promise=global.Promise;var mt,yt=(mt=Object.freeze({__proto__:null,default:bt,Headers:Y,Request:ft,Response:at,FetchError:I}))&&mt.default||mt,wt=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){var r=yt.default||yt,n=function(t,e){return/^\/\//.test(t)&&(t="https:"+t),r.call(this,t,e)};t.exports=e=n,e.fetch=n,e.Headers=yt.Headers,e.Request=yt.Request,e.Response=yt.Response,e.default=n}));wt.fetch,wt.Headers,wt.Request,wt.Response;const vt={get:(t,e,r)=>"send"===e?async()=>{const e=await wt(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)});return await e.json()}:(...n)=>{const i=t.id;return t.id=t.id+1,t.payload.push({jsonrpc:"2.0",id:i,method:e,params:n}),r}},Bt={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri},vt):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await wt(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),o=await i.json();if(o.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(o.error)throw new Error(`JSONRPCError: server error ${JSON.stringify(o.error)}`);return o.result}};class Pt{constructor(t){return this.uri=t,new Proxy(this,Bt)}static create(t){return new Pt(t)}}function Dt(t){return l.BigInt(t)}function St(t){return"0x"+t.toString(16)}function Tt(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=St(l.BigInt(r)).substr(2);if(n.length%2!=0&&(n="0"+n),n.length/2>t)throw new Error(`${e} is ${n.length/2} bytes long, expected length is ${t}!`);const i=new DataView(new ArrayBuffer(t));for(let t=0;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function $t(t){return function(e,r){if(r=new u(r).toArrayBuffer(),t>0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function kt(t,e,r){const n={};for(const[i,o]of Object.entries(r)){const r=e[i];if(!r)throw new Error(`${t} is missing ${i}!`);n[i]=o(`${t}.${i}`,r)}return n}function xt(t,{debugPath:e="script"}={}){return kt(e,t,{code_hash:$t(32),hash_type:function(t,e){switch(e){case"data":return 0;case"type":return 1;case 0:case 1:return e;default:throw new Error(`${t}.hash_type has invalid value: ${e}`)}},args:$t(-1)})}function Ct(t,{debugPath:e="out_point"}={}){return kt(e,t,{tx_hash:$t(32),index:Tt(4)})}function Et(t){return function(e,r){return t(r,{debugPath:e})}}function At(t,{debugPath:e="cell_input"}={}){return kt(e,t,{since:Tt(8),previous_output:Et(Ct)})}function Ot(t,{debugPath:e="cell_output"}={}){const r=kt(e,t,{capacity:Tt(8),lock:Et(xt)});return t.type&&(r.type_=xt(t.type,{debugPath:`${e}.type`})),r}function jt(t,{debugPath:e="cell_dep"}={}){return kt(e,t,{out_point:Et(Ct),dep_type:function(t,e){switch(e){case"code":return 0;case"dep_group":return 1;case 0:case 1:return e;default:throw new Error(`${t}.dep_type has invalid value: ${e}`)}}})}function zt(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function It(t,{debugPath:e="raw_transaction"}={}){return kt(e,t,{version:Tt(4),cell_deps:zt(Et(jt)),header_deps:zt($t(32)),inputs:zt(Et(At)),outputs:zt(Et(Ot)),outputs_data:zt($t(-1))})}function Rt(t,{debugPath:e="transaction"}={}){const r=It(t,{debugPath:`(raw)${e}`}),n=kt(e,t,{witnesses:zt($t(-1))});return n.raw=r,n}function Lt(t,{debugPath:e="raw_header"}={}){return kt(e,t,{version:Tt(4),compact_target:Tt(4),timestamp:Tt(8),number:Tt(8),epoch:Tt(8),parent_hash:$t(32),transactions_root:$t(32),proposals_hash:$t(32),uncles_hash:$t(32),dao:$t(32)})}function Mt(t,{debugPath:e="header"}={}){const r=Lt(t,{debugPath:`(raw)${e}`}),n=kt(e,t,{nonce:Tt(16)});return n.raw=r,n}function Nt(t,{debugPath:e="uncle_block"}={}){return kt(e,t,{header:Et(Mt),proposals:zt($t(10))})}var qt=Object.freeze({__proto__:null,NormalizeScript:xt,NormalizeOutPoint:Ct,NormalizeCellInput:At,NormalizeCellOutput:Ot,NormalizeCellDep:jt,NormalizeRawTransaction:It,NormalizeTransaction:Rt,NormalizeRawHeader:Lt,NormalizeHeader:Mt,NormalizeUncleBlock:Nt,NormalizeBlock:function(t,{debugPath:e="block"}={}){return kt(e,t,{header:Et(Mt),uncles:zt(Et(Nt)),transactions:zt(Et(Rt)),proposals:zt($t(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return kt(e,t,{lock:Et(xt),message:$t(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=$t(-1)(`${e}.lock`,t.lock)),t.input_type&&(r.input_type=$t(-1)(`${e}.input_type`,t.input_type)),t.output_type&&(r.output_type=$t(-1)(`${e}.output_type`,t.output_type)),r}});function Ut(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Vt(t,e,r){if(!((e=Ut(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){let r=e[i];if(!r){r=e[i.replace(/(_[a-z])/g,t=>t.toUpperCase().replace("_",""))]}r&&(n[i]=o(`${t}.${i}`,r))}return n}function Ht(t,{validation:e=!0,debugPath:r="script"}={}){return t=Vt(r,t,{code_hash:Ut,hash_type:Ut,args:Ut}),e&&g(t,{debugPath:`(transformed) ${r}`}),t}function Ft(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Vt(r,t,{tx_hash:Ut,index:Ut}),e&&d(t,{debugPath:`(transformed) ${r}`}),t}function Gt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function Wt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Vt(r,t,{since:Ut,previous_output:Gt(Ft)}),e&&p(t,{debugPath:`(transformed) ${r}`}),t}function Jt(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Vt(r,t,{capacity:Ut,lock:Gt(Ht),type:Gt(Ht)}),e&&b(t,{debugPath:`(transformed) ${r}`}),t}function Xt(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Vt(r,t,{out_point:Gt(Ft),dep_type:Ut}),e&&m(t,{debugPath:`(transformed) ${r}`}),t}function Qt(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function Zt(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Vt(r,t,{version:Ut,cell_deps:Qt(Gt(Xt)),header_deps:Qt(Ut),inputs:Qt(Gt(Wt)),outputs:Qt(Gt(Jt)),outputs_data:Qt(Ut),witnesses:Qt(Ut)}),e&&P(t,{debugPath:`(transformed) ${r}`}),t}function Kt(t,{validation:e=!0,debugPath:r="header"}={}){return t=Vt(r,t,{version:Ut,compact_target:Ut,timestamp:Ut,number:Ut,epoch:Ut,parent_hash:Ut,transactions_root:Ut,proposals_hash:Ut,uncles_hash:Ut,dao:Ut,nonce:Ut}),e&&S(t,{debugPath:`(transformed) ${r}`}),t}function Yt(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Vt(r,t,{header:Gt(Kt),proposals:Qt(Ut)}),e&&$(t,{debugPath:`(transformed) ${r}`}),t}var te=Object.freeze({__proto__:null,TransformScript:Ht,TransformOutPoint:Ft,TransformCellInput:Wt,TransformCellOutput:Jt,TransformCellDep:Xt,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Vt(r,t,{version:Ut,cell_deps:Qt(Gt(Xt)),header_deps:Qt(Ut),inputs:Qt(Gt(Wt)),outputs:Qt(Gt(Jt)),outputs_data:Qt(Ut)}),e&&B(t,{debugPath:`(transformed) ${r}`}),t},TransformTransaction:Zt,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Vt(r,t,{version:Ut,compact_target:Ut,timestamp:Ut,number:Ut,epoch:Ut,parent_hash:Ut,transactions_root:Ut,proposals_hash:Ut,uncles_hash:Ut,dao:Ut}),e&&D(t,{debugPath:`(transformed) ${r}`}),t},TransformHeader:Kt,TransformUncleBlock:Yt,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Vt(r,t,{header:Gt(Kt),uncles:Qt(Gt(Yt)),transactions:Qt(Gt(Zt)),proposals:Qt(Ut)}),e&&k(t,{debugPath:`(transformed) ${r}`}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Vt(r,t,{lock:Gt(Ht),message:Ut}),e&&x(t,{debugPath:`(transformed) ${r}`}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Vt(r,t,{lock:Ut,input_type:Ut,output_type:Ut}),e&&C(t,{debugPath:`(transformed) ${r}`}),t}});var ee=Object.freeze({__proto__:null,RPCCollector:class{constructor(t,e,{skipCellWithContent:r=!0,loadData:n=!1}={}){this.rpc=t,this.lockHash=new u(e).serializeJson(),this.skipCellWithContent=r,this.loadData=n}async*collect(){const t=Dt(await this.rpc.get_tip_block_number());let e=l.BigInt(0);for(;l.lessThanOrEqual(e,t);){let r=l.add(e,l.BigInt(100));l.greaterThan(r,t)&&(r=t);const n=await this.rpc.get_cells_by_lock_hash(this.lockHash,St(e),St(r));for(const t of n)if(this.skipCellWithContent){if(t.type||l.greaterThan(Dt(t.output_data_len),l.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=l.add(r,l.BigInt(1))}}}});exports.BigIntToHexString=St,exports.HexStringToBigInt=Dt,exports.RPC=Pt,exports.Reader=u,exports.TransactionDumper=class{constructor(t,{validateTransaction:e=!0,depGroupUnpacker:r=null}={}){this.rpc=t,this.validateTransaction=e,this.depGroupUnpacker=r}async dumpByHash(t){const e=(await this.rpc.get_transaction(t)).transaction;return delete e.hash,await this.dump(e)}async dump(t){this.validateTransaction&&P(t);const e=[];for(const r of t.inputs){const{output:t,data:n,header:i}=await this._resolveOutPoint(r.previous_output);e.push({input:r,output:t,data:n,header:i})}const r=[];for(const e of t.cell_deps){const{output:t,data:n,header:i}=await this._resolveOutPoint(e.out_point);if(r.push({cell_dep:e,output:t,data:n,header:i}),"dep_group"===e.dep_type){if(!this.depGroupUnpacker)throw new Error("depGroupUnpacker must be provided when the transaction contains dep_group!");const t=this.depGroupUnpacker(new u(n));for(const e of t){d(e);const{output:t,data:n,header:i}=await this._resolveOutPoint(e);r.push({cell_dep:{out_point:e,dep_type:"code"},output:t,data:n,header:i})}}}const n=[];for(const e of t.header_deps)n.push(await this.rpc.get_header(e));return JSON.stringify({mock_info:{inputs:e,cell_deps:r,header_deps:n},tx:t})}async _resolveOutPoint(t){const e=await this.rpc.get_transaction(t.tx_hash);if(!e||!e.transaction)throw new Error(`Transaction ${t.tx_hash} cannot be found!`);const r=e.transaction,n=l.toNumber(l.BigInt(t.index));if(n>=r.outputs.length)throw new Error(`Transaction ${t.tx_hash} does not have output ${n}!`);const i={output:r.outputs[n],data:r.outputs_data[n]};return"committed"===e.tx_status.status&&(i.header=e.tx_status.block_hash),i}},exports.VERSION="0.9.1",exports.cell_collectors=ee,exports.normalizers=qt,exports.transformers=te,exports.validators=E;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("stream"),e=require("http"),r=require("url"),n=require("https"),i=require("zlib");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=o(t),a=o(e),u=o(r),l=o(n),c=o(i);class _{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 f{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 h{constructor(t){if(t instanceof f||t instanceof _)return t;if("string"==typeof t){if(!t.startsWith("0x")||t.length%2!=0)throw new Error("Hex string must start with 0x, and has even numbered length!");return new f(t)}if(t instanceof ArrayBuffer)return new _(t);throw new Error("Reader can only accept hex string or ArrayBuffer!")}static fromRawString(t){const e=new ArrayBuffer(t.length),r=new DataView(e);for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n>255)throw new Error("fromRawString can only accept UTF-8 raw string!");r.setUint8(e,n)}return new _(e)}}class g extends Array{constructor(t,e){if(t>g.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");super(t),this.sign=e}static BigInt(t){var e=Math.floor,r=Number.isFinite;if("number"==typeof t){if(0===t)return g.__zero();if((0|t)===t)return 0>t?g.__oneDigit(-t,!0):g.__oneDigit(t,!1);if(!r(t)||e(t)!==t)throw new RangeError("The number "+t+" cannot be converted to BigInt because it is not an integer");return g.__fromDouble(t)}if("string"==typeof t){const e=g.__fromString(t);if(null===e)throw new SyntaxError("Cannot convert "+t+" to a BigInt");return e}if("boolean"==typeof t)return!0===t?g.__oneDigit(1,!1):g.__zero();if("object"==typeof t){if(t.constructor===g)return t;const e=g.__toPrimitive(t);return g.BigInt(e)}throw new TypeError("Cannot convert "+t+" to a BigInt")}toDebugString(){const t=["BigInt["];for(const e of this)t.push((e?(e>>>0).toString(16):e)+", ");return t.push("]"),t.join("")}toString(t=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)?g.__toStringBasePowerOfTwo(this,t):g.__toStringGeneric(this,t,!1)}static toNumber(t){var e=Math.clz32;const r=t.length;if(0===r)return 0;if(1===r){const e=t.__unsignedDigit(0);return t.sign?-e:e}const n=t.__digit(r-1),i=e(n),o=32*r-i;if(1024<o)return t.sign?-1/0:1/0;let s=o-1,a=n,u=r-1;const l=i+1;let c=32===l?0:a<<l;c>>>=12;const _=l-12;let f=12<=l?0:a<<20+l,h=20+l;0<_&&0<u&&(u--,a=t.__digit(u),c|=a>>>32-_,f=a<<_,h=_),0<h&&0<u&&(u--,a=t.__digit(u),f|=a>>>32-h,h-=32);const d=g.__decideRounding(t,h,u,a);if((1===d||0===d&&1==(1&f))&&(f=f+1>>>0,0==f&&(c++,0!=c>>>20&&(c=0,s++,1023<s))))return t.sign?-1/0:1/0;const p=t.sign?-2147483648:0;return s=s+1023<<20,g.__kBitConversionInts[1]=p|s|c,g.__kBitConversionInts[0]=f,g.__kBitConversionDouble[0]}static unaryMinus(t){if(0===t.length)return t;const e=t.__copy();return e.sign=!t.sign,e}static bitwiseNot(t){return t.sign?g.__absoluteSubOne(t).__trim():g.__absoluteAddOne(t,!0)}static exponentiate(t,e){if(e.sign)throw new RangeError("Exponent must be positive");if(0===e.length)return g.__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))?g.unaryMinus(t):t;if(1<e.length)throw new RangeError("BigInt too big");let r=e.__unsignedDigit(0);if(1===r)return t;if(r>=g.__kMaxLengthBits)throw new RangeError("BigInt too big");if(1===t.length&&2===t.__digit(0)){const e=1+(r>>>5),n=t.sign&&0!=(1&r),i=new g(e,n);i.__initializeDigits();const o=1<<(31&r);return i.__setDigit(e-1,o),i}let n=null,i=t;for(0!=(1&r)&&(n=t),r>>=1;0!==r;r>>=1)i=g.multiply(i,i),0!=(1&r)&&(n=null===n?i:g.multiply(n,i));return n}static multiply(t,e){if(0===t.length)return t;if(0===e.length)return e;let r=t.length+e.length;32<=t.__clzmsd()+e.__clzmsd()&&r--;const n=new g(r,t.sign!==e.sign);n.__initializeDigits();for(let r=0;r<t.length;r++)g.__multiplyAccumulate(e,t.__digit(r),n,r);return n.__trim()}static divide(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>g.__absoluteCompare(t,e))return g.__zero();const r=t.sign!==e.sign,n=e.__unsignedDigit(0);let i;if(1===e.length&&65535>=n){if(1===n)return r===t.sign?t:g.unaryMinus(t);i=g.__absoluteDivSmall(t,n,null)}else i=g.__absoluteDivLarge(t,e,!0,!1);return i.sign=r,i.__trim()}static remainder(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>g.__absoluteCompare(t,e))return t;const r=e.__unsignedDigit(0);if(1===e.length&&65535>=r){if(1===r)return g.__zero();const e=g.__absoluteModSmall(t,r);return 0===e?g.__zero():g.__oneDigit(e,t.sign)}const n=g.__absoluteDivLarge(t,e,!1,!0);return n.sign=t.sign,n.__trim()}static add(t,e){const r=t.sign;return r===e.sign?g.__absoluteAdd(t,e,r):0<=g.__absoluteCompare(t,e)?g.__absoluteSub(t,e,r):g.__absoluteSub(e,t,!r)}static subtract(t,e){const r=t.sign;return r===e.sign?0<=g.__absoluteCompare(t,e)?g.__absoluteSub(t,e,r):g.__absoluteSub(e,t,!r):g.__absoluteAdd(t,e,r)}static leftShift(t,e){return 0===e.length||0===t.length?t:e.sign?g.__rightShiftByAbsolute(t,e):g.__leftShiftByAbsolute(t,e)}static signedRightShift(t,e){return 0===e.length||0===t.length?t:e.sign?g.__leftShiftByAbsolute(t,e):g.__rightShiftByAbsolute(t,e)}static unsignedRightShift(){throw new TypeError("BigInts have no unsigned right shift; use >> instead")}static lessThan(t,e){return 0>g.__compareToBigInt(t,e)}static lessThanOrEqual(t,e){return 0>=g.__compareToBigInt(t,e)}static greaterThan(t,e){return 0<g.__compareToBigInt(t,e)}static greaterThanOrEqual(t,e){return 0<=g.__compareToBigInt(t,e)}static equal(t,e){if(t.sign!==e.sign)return!1;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t.__digit(r)!==e.__digit(r))return!1;return!0}static notEqual(t,e){return!g.equal(t,e)}static bitwiseAnd(t,e){var r=Math.max;if(!t.sign&&!e.sign)return g.__absoluteAnd(t,e).__trim();if(t.sign&&e.sign){const n=r(t.length,e.length)+1;let i=g.__absoluteSubOne(t,n);const o=g.__absoluteSubOne(e);return i=g.__absoluteOr(i,o,i),g.__absoluteAddOne(i,!0,i).__trim()}return t.sign&&([t,e]=[e,t]),g.__absoluteAndNot(t,g.__absoluteSubOne(e)).__trim()}static bitwiseXor(t,e){var r=Math.max;if(!t.sign&&!e.sign)return g.__absoluteXor(t,e).__trim();if(t.sign&&e.sign){const n=r(t.length,e.length),i=g.__absoluteSubOne(t,n),o=g.__absoluteSubOne(e);return g.__absoluteXor(i,o,i).__trim()}const n=r(t.length,e.length)+1;t.sign&&([t,e]=[e,t]);let i=g.__absoluteSubOne(e,n);return i=g.__absoluteXor(i,t,i),g.__absoluteAddOne(i,!0,i).__trim()}static bitwiseOr(t,e){const r=(0,Math.max)(t.length,e.length);if(!t.sign&&!e.sign)return g.__absoluteOr(t,e).__trim();if(t.sign&&e.sign){let n=g.__absoluteSubOne(t,r);const i=g.__absoluteSubOne(e);return n=g.__absoluteAnd(n,i,n),g.__absoluteAddOne(n,!0,n).__trim()}t.sign&&([t,e]=[e,t]);let n=g.__absoluteSubOne(e,r);return n=g.__absoluteAndNot(n,t,n),g.__absoluteAddOne(n,!0,n).__trim()}static asIntN(t,e){if(0===e.length)return e;if(0===t)return g.__zero();if(t>=g.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.length<r)return e;const n=e.__unsignedDigit(r-1),i=1<<(31&t-1);if(e.length===r&&n<i)return e;if((n&i)!==i)return g.__truncateToNBits(t,e);if(!e.sign)return g.__truncateAndSubFromPowerOfTwo(t,e,!0);if(0==(n&i-1)){for(let n=r-2;0<=n;n--)if(0!==e.__digit(n))return g.__truncateAndSubFromPowerOfTwo(t,e,!1);return e.length===r&&n===i?e:g.__truncateToNBits(t,e)}return g.__truncateAndSubFromPowerOfTwo(t,e,!1)}static asUintN(t,e){if(0===e.length)return e;if(0===t)return g.__zero();if(e.sign){if(t>g.__kMaxLengthBits)throw new RangeError("BigInt too big");return g.__truncateAndSubFromPowerOfTwo(t,e,!1)}if(t>=g.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.length<r)return e;const n=31&t;if(e.length==r){if(0==n)return e;if(0==e.__digit(r-1)>>>n)return e}return g.__truncateToNBits(t,e)}static ADD(t,e){if(t=g.__toPrimitive(t),e=g.__toPrimitive(e),"string"==typeof t)return"string"!=typeof e&&(e=e.toString()),t+e;if("string"==typeof e)return t.toString()+e;if(t=g.__toNumeric(t),e=g.__toNumeric(e),g.__isBigInt(t)&&g.__isBigInt(e))return g.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")}static LT(t,e){return g.__compare(t,e,0)}static LE(t,e){return g.__compare(t,e,1)}static GT(t,e){return g.__compare(t,e,2)}static GE(t,e){return g.__compare(t,e,3)}static EQ(t,e){for(;;){if(g.__isBigInt(t))return g.__isBigInt(e)?g.equal(t,e):g.EQ(e,t);if("number"==typeof t){if(g.__isBigInt(e))return g.__equalToNumber(e,t);if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else if("string"==typeof t){if(g.__isBigInt(e))return null!==(t=g.__fromString(t))&&g.equal(t,e);if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else if("boolean"==typeof t){if(g.__isBigInt(e))return g.__equalToNumber(e,+t);if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else if("symbol"==typeof t){if(g.__isBigInt(e))return!1;if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else{if("object"!=typeof t)return t==e;if("object"==typeof e&&e.constructor!==g)return t==e;t=g.__toPrimitive(t)}}}static NE(t,e){return!g.EQ(t,e)}static __zero(){return new g(0,!1)}static __oneDigit(t,e){const r=new g(1,e);return r.__setDigit(0,t),r}__copy(){const t=new g(this.length,this.sign);for(let e=0;e<this.length;e++)t[e]=this[e];return t}__trim(){let t=this.length,e=this[t-1];for(;0===e;)t--,e=this[t-1],this.pop();return 0===t&&(this.sign=!1),this}__initializeDigits(){for(let t=0;t<this.length;t++)this[t]=0}static __decideRounding(t,e,r,n){if(0<e)return-1;let i;if(0>e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}let o=1<<i;if(0==(n&o))return-1;if(o-=1,0!=(n&o))return 1;for(;0<r;)if(r--,0!==t.__digit(r))return 1;return 0}static __fromDouble(t){g.__kBitConversionDouble[0]=t;const e=(2047&g.__kBitConversionInts[1]>>>20)-1023,r=1+(e>>>5),n=new g(r,0>t);let i=1048575&g.__kBitConversionInts[1]|1048576,o=g.__kBitConversionInts[0];const s=31&e;let a,u=0;if(s<20){const t=20-s;u=t+32,a=i>>>t,i=i<<32-t|o>>>t,o<<=32-t}else if(20===s)u=32,a=i,i=o;else{const t=s-20;u=32-t,a=i<<t|o>>>32-t,i=o<<t}n.__setDigit(r-1,a);for(let t=r-2;0<=t;t--)0<u?(u-=32,a=i,i=o):a=0,n.__setDigit(t,a);return n.__trim()}static __isWhitespace(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)}static __fromString(t,e=0){let r=0;const n=t.length;let i=0;if(i===n)return g.__zero();let o=t.charCodeAt(i);for(;g.__isWhitespace(o);){if(++i===n)return g.__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 g.__zero();if(o=t.charCodeAt(i),88===o||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 g.__zero();if(o=t.charCodeAt(i),88===o||120===o){if(++i===n)return null;o=t.charCodeAt(i)}}for(;48===o;){if(++i===n)return g.__zero();o=t.charCodeAt(i)}const s=n-i;let a=g.__kMaxBitsPerChar[e],u=g.__kBitsPerCharTableMultiplier-1;if(s>1073741824/a)return null;const l=a*s+u>>>g.__kBitsPerCharTableShift,c=new g(l+31>>>5,!1),_=10>e?e:10,f=10<e?e-10:0;if(0==(e&e-1)){a>>=g.__kBitsPerCharTableShift;const e=[],r=[];let s=!1;do{let u=0,l=0;for(;;){let e;if(o-48>>>0<_)e=o-48;else{if(!((32|o)-97>>>0<f)){s=!0;break}e=(32|o)-87}if(l+=a,u=u<<a|e,++i===n){s=!0;break}if(o=t.charCodeAt(i),32<l+a)break}e.push(u),r.push(l)}while(!s);g.__fillFromParts(c,e,r)}else{c.__initializeDigits();let r=!1,s=0;do{let l=0,h=1;for(;;){let a;if(o-48>>>0<_)a=o-48;else{if(!((32|o)-97>>>0<f)){r=!0;break}a=(32|o)-87}const u=h*e;if(4294967295<u)break;if(h=u,l=l*e+a,s++,++i===n){r=!0;break}o=t.charCodeAt(i)}u=32*g.__kBitsPerCharTableMultiplier-1;const d=a*s+u>>>g.__kBitsPerCharTableShift+5;c.__inplaceMultiplyAdd(h,l,d)}while(!r)}if(i!==n){if(!g.__isWhitespace(o))return null;for(i++;i<n;i++)if(o=t.charCodeAt(i),!g.__isWhitespace(o))return null}return 0!=r&&10!==e?null:(c.sign=-1==r,c.__trim())}static __fillFromParts(t,e,r){let n=0,i=0,o=0;for(let s=e.length-1;0<=s;s--){const a=e[s],u=r[s];i|=a<<o,o+=u,32===o?(t.__setDigit(n++,i),o=0,i=0):32<o&&(t.__setDigit(n++,i),o-=32,i=a>>>u-o)}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)}static __toStringBasePowerOfTwo(t,e){var r=Math.clz32;const n=t.length;let i=e-1;i=(85&i>>>1)+(85&i),i=(51&i>>>2)+(51&i),i=(15&i>>>4)+(15&i);const o=i,s=e-1,a=t.__digit(n-1);let u=0|(32*n-r(a)+o-1)/o;if(t.sign&&u++,268435456<u)throw new Error("string too long");const l=Array(u);let c=u-1,_=0,f=0;for(let e=0;e<n-1;e++){const r=t.__digit(e),n=(_|r<<f)&s;l[c--]=g.__kConversionChars[n];const i=o-f;for(_=r>>>i,f=32-i;f>=o;)l[c--]=g.__kConversionChars[_&s],_>>>=o,f-=o}const h=(_|a<<f)&s;for(l[c--]=g.__kConversionChars[h],_=a>>>o-f;0!==_;)l[c--]=g.__kConversionChars[_&s],_>>>=o;if(t.sign&&(l[c--]="-"),-1!=c)throw new Error("implementation bug");return l.join("")}static __toStringGeneric(t,e,r){var n=Math.clz32;const i=t.length;if(0===i)return"";if(1===i){let n=t.__unsignedDigit(0).toString(e);return!1===r&&t.sign&&(n="-"+n),n}const o=32*i-n(t.__digit(i-1)),s=g.__kMaxBitsPerChar[e]-1;let a=o*g.__kBitsPerCharTableMultiplier;a+=s-1,a=0|a/s;const u=a+1>>1,l=g.exponentiate(g.__oneDigit(e,!1),g.__oneDigit(u,!1));let c,_;const f=l.__unsignedDigit(0);if(1===l.length&&65535>=f){c=new g(t.length,!1),c.__initializeDigits();let r=0;for(let e=2*t.length-1;0<=e;e--){const n=r<<16|t.__halfDigit(e);c.__setHalfDigit(e,0|n/f),r=0|n%f}_=r.toString(e)}else{const r=g.__absoluteDivLarge(t,l,!0,!0);c=r.quotient;const n=r.remainder.__trim();_=g.__toStringGeneric(n,e,!0)}c.__trim();let h=g.__toStringGeneric(c,e,!0);for(;_.length<u;)_="0"+_;return!1===r&&t.sign&&(h="-"+h),h+_}static __unequalSign(t){return t?-1:1}static __absoluteGreater(t){return t?-1:1}static __absoluteLess(t){return t?1:-1}static __compareToBigInt(t,e){const r=t.sign;if(r!==e.sign)return g.__unequalSign(r);const n=g.__absoluteCompare(t,e);return 0<n?g.__absoluteGreater(r):0>n?g.__absoluteLess(r):0}static __compareToNumber(t,e){if(!0|e){const r=t.sign,n=0>e;if(r!==n)return g.__unequalSign(r);if(0===t.length){if(n)throw new Error("implementation bug");return 0===e?0:-1}if(1<t.length)return g.__absoluteGreater(r);const i=Math.abs(e),o=t.__unsignedDigit(0);return o>i?g.__absoluteGreater(r):o<i?g.__absoluteLess(r):0}return g.__compareToDouble(t,e)}static __compareToDouble(t,e){var r=Math.clz32;if(e!=e)return e;if(e===1/0)return-1;if(e===-1/0)return 1;const n=t.sign;if(n!==0>e)return g.__unequalSign(n);if(0===e)throw new Error("implementation bug: should be handled elsewhere");if(0===t.length)return-1;g.__kBitConversionDouble[0]=e;const i=2047&g.__kBitConversionInts[1]>>>20;if(2047==i)throw new Error("implementation bug: handled elsewhere");const o=i-1023;if(0>o)return g.__absoluteGreater(n);const s=t.length;let a=t.__digit(s-1);const u=r(a),l=32*s-u,c=o+1;if(l<c)return g.__absoluteLess(n);if(l>c)return g.__absoluteGreater(n);let _=1048576|1048575&g.__kBitConversionInts[1],f=g.__kBitConversionInts[0];const h=31-u;if(h!==(l-1)%31)throw new Error("implementation bug");let d,p=0;if(20>h){const t=20-h;p=t+32,d=_>>>t,_=_<<32-t|f>>>t,f<<=32-t}else if(20===h)p=32,d=_,_=f;else{const t=h-20;p=32-t,d=_<<t|f>>>32-t,_=f<<t}if(a>>>=0,d>>>=0,a>d)return g.__absoluteGreater(n);if(a<d)return g.__absoluteLess(n);for(let e=s-2;0<=e;e--){0<p?(p-=32,d=_>>>0,_=f,f=0):d=0;const r=t.__unsignedDigit(e);if(r>d)return g.__absoluteGreater(n);if(r<d)return g.__absoluteLess(n)}if(0!==_||0!==f){if(0===p)throw new Error("implementation bug");return g.__absoluteLess(n)}return 0}static __equalToNumber(t,e){var r=Math.abs;return e|0===e?0===e?0===t.length:1===t.length&&t.sign===0>e&&t.__unsignedDigit(0)===r(e):0===g.__compareToDouble(t,e)}static __comparisonResultToBool(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")}static __compare(t,e,r){if(t=g.__toPrimitive(t),e=g.__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(g.__isBigInt(t)&&"string"==typeof e)return null!==(e=g.__fromString(e))&&g.__comparisonResultToBool(g.__compareToBigInt(t,e),r);if("string"==typeof t&&g.__isBigInt(e))return null!==(t=g.__fromString(t))&&g.__comparisonResultToBool(g.__compareToBigInt(t,e),r);if(t=g.__toNumeric(t),e=g.__toNumeric(e),g.__isBigInt(t)){if(g.__isBigInt(e))return g.__comparisonResultToBool(g.__compareToBigInt(t,e),r);if("number"!=typeof e)throw new Error("implementation bug");return g.__comparisonResultToBool(g.__compareToNumber(t,e),r)}if("number"!=typeof t)throw new Error("implementation bug");if(g.__isBigInt(e))return g.__comparisonResultToBool(g.__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}__clzmsd(){return Math.clz32(this[this.length-1])}static __absoluteAdd(t,e,r){if(t.length<e.length)return g.__absoluteAdd(e,t,r);if(0===t.length)return t;if(0===e.length)return t.sign===r?t:g.unaryMinus(t);let n=t.length;(0===t.__clzmsd()||e.length===t.length&&0===e.__clzmsd())&&n++;const i=new g(n,r);let o=0,s=0;for(;s<e.length;s++){const r=e.__digit(s),n=t.__digit(s),a=(65535&n)+(65535&r)+o,u=(n>>>16)+(r>>>16)+(a>>>16);o=u>>>16,i.__setDigit(s,65535&a|u<<16)}for(;s<t.length;s++){const e=t.__digit(s),r=(65535&e)+o,n=(e>>>16)+(r>>>16);o=n>>>16,i.__setDigit(s,65535&r|n<<16)}return s<i.length&&i.__setDigit(s,o),i.__trim()}static __absoluteSub(t,e,r){if(0===t.length)return t;if(0===e.length)return t.sign===r?t:g.unaryMinus(t);const n=new g(t.length,r);let i=0,o=0;for(;o<e.length;o++){const r=t.__digit(o),s=e.__digit(o),a=(65535&r)-(65535&s)-i;i=1&a>>>16;const u=(r>>>16)-(s>>>16)-i;i=1&u>>>16,n.__setDigit(o,65535&a|u<<16)}for(;o<t.length;o++){const e=t.__digit(o),r=(65535&e)-i;i=1&r>>>16;const s=(e>>>16)-i;i=1&s>>>16,n.__setDigit(o,65535&r|s<<16)}return n.__trim()}static __absoluteAddOne(t,e,r=null){const n=t.length;null===r?r=new g(n,e):r.sign=e;let i=!0;for(let e,o=0;o<n;o++){e=t.__digit(o);const n=-1===e;i&&(e=0|e+1),i=n,r.__setDigit(o,e)}return i&&r.__setDigitGrow(n,1),r}static __absoluteSubOne(t,e){const r=t.length,n=new g(e=e||r,!1);let i=!0;for(let e,o=0;o<r;o++){e=t.__digit(o);const r=0===e;i&&(e=0|e-1),i=r,n.__setDigit(o,e)}for(let t=r;t<e;t++)n.__setDigit(t,0);return n}static __absoluteAnd(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=o;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)&e.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteAndNot(t,e,r=null){const n=t.length,i=e.length;let o=i;n<i&&(o=n);let s=n;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)&~e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteOr(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=n;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)|e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteXor(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=n;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)^e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteCompare(t,e){const r=t.length-e.length;if(0!=r)return r;let n=t.length-1;for(;0<=n&&t.__digit(n)===e.__digit(n);)n--;return 0>n?0:t.__unsignedDigit(n)>e.__unsignedDigit(n)?1:-1}static __multiplyAccumulate(t,e,r,n){var i=Math.imul;if(0===e)return;const o=65535&e,s=e>>>16;let a=0,u=0,l=0;for(let e=0;e<t.length;e++,n++){let c=r.__digit(n),_=65535&c,f=c>>>16;const h=t.__digit(e),g=65535&h,d=h>>>16,p=i(g,o),b=i(g,s),m=i(d,o),y=i(d,s);_+=u+(65535&p),f+=l+a+(_>>>16)+(p>>>16)+(65535&b)+(65535&m),a=f>>>16,u=(b>>>16)+(m>>>16)+(65535&y)+a,a=u>>>16,u&=65535,l=y>>>16,c=65535&_|f<<16,r.__setDigit(n,c)}for(;0!=a||0!==u||0!==l;n++){let t=r.__digit(n);const e=(65535&t)+u,i=(t>>>16)+(e>>>16)+l+a;u=0,l=0,a=i>>>16,t=65535&e|i<<16,r.__setDigit(n,t)}}static __internalMultiplyAdd(t,e,r,n,i){var o=Math.imul;let s=r,a=0;for(let r=0;r<n;r++){const n=t.__digit(r),u=o(65535&n,e),l=(65535&u)+a+s;s=l>>>16;const c=o(n>>>16,e),_=(65535&c)+(u>>>16)+s;s=_>>>16,a=c>>>16,i.__setDigit(r,_<<16|65535&l)}if(i.length>n)for(i.__setDigit(n++,s+a);n<i.length;)i.__setDigit(n++,0);else if(0!==s+a)throw new Error("implementation bug")}__inplaceMultiplyAdd(t,e,r){var n=Math.imul;r>this.length&&(r=this.length);const i=65535&t,o=t>>>16;let s=0,a=65535&e,u=e>>>16;for(let t=0;t<r;t++){const e=this.__digit(t),r=65535&e,l=e>>>16,c=n(r,i),_=n(r,o),f=n(l,i),h=n(l,o),g=a+(65535&c),d=u+s+(g>>>16)+(c>>>16)+(65535&_)+(65535&f);a=(_>>>16)+(f>>>16)+(65535&h)+(d>>>16),s=a>>>16,a&=65535,u=h>>>16,this.__setDigit(t,65535&g|d<<16)}if(0!=s||0!==a||0!==u)throw new Error("implementation bug")}static __absoluteDivSmall(t,e,r){null===r&&(r=new g(t.length,!1));let n=0;for(let i,o=2*t.length-1;0<=o;o-=2){i=(n<<16|t.__halfDigit(o))>>>0;const s=0|i/e;n=0|i%e,i=(n<<16|t.__halfDigit(o-1))>>>0;const a=0|i/e;n=0|i%e,r.__setDigit(o>>>1,s<<16|a)}return r}static __absoluteModSmall(t,e){let r=0;for(let n=2*t.length-1;0<=n;n--){r=0|((r<<16|t.__halfDigit(n))>>>0)%e}return r}static __absoluteDivLarge(t,e,r,n){var i=Math.imul;const o=e.__halfDigitLength(),s=e.length,a=t.__halfDigitLength()-o;let u=null;r&&(u=new g(a+2>>>1,!1),u.__initializeDigits());const l=new g(o+2>>>1,!1);l.__initializeDigits();const c=g.__clz16(e.__halfDigit(o-1));0<c&&(e=g.__specialLeftShift(e,c,0));const _=g.__specialLeftShift(t,c,1),f=e.__halfDigit(o-1);let h=0;for(let t,n=a;0<=n;n--){t=65535;const a=_.__halfDigit(n+o);if(a!==f){const r=(a<<16|_.__halfDigit(n+o-1))>>>0;t=0|r/f;let s=0|r%f;const u=e.__halfDigit(o-2),l=_.__halfDigit(n+o-2);for(;i(t,u)>>>0>(s<<16|l)>>>0&&(t--,s+=f,!(65535<s)););}g.__internalMultiplyAdd(e,t,0,s,l);let c=_.__inplaceSub(l,n,o+1);0!==c&&(c=_.__inplaceAdd(e,n,o),_.__setHalfDigit(n+o,_.__halfDigit(n+o)+c),t--),r&&(1&n?h=t<<16:u.__setDigit(n>>>1,h|t))}return n?(_.__inplaceRightShift(c),r?{quotient:u,remainder:_}:_):r?u:void 0}static __clz16(t){return Math.clz32(t)-16}__inplaceAdd(t,e,r){let n=0;for(let i=0;i<r;i++){const r=this.__halfDigit(e+i)+t.__halfDigit(i)+n;n=r>>>16,this.__setHalfDigit(e+i,r)}return n}__inplaceSub(t,e,r){let n=0;if(1&e){e>>=1;let i=this.__digit(e),o=65535&i,s=0;for(;s<r-1>>>1;s++){const r=t.__digit(s),a=(i>>>16)-(65535&r)-n;n=1&a>>>16,this.__setDigit(e+s,a<<16|65535&o),i=this.__digit(e+s+1),o=(65535&i)-(r>>>16)-n,n=1&o>>>16}const a=t.__digit(s),u=(i>>>16)-(65535&a)-n;if(n=1&u>>>16,this.__setDigit(e+s,u<<16|65535&o),e+s+1>=this.length)throw new RangeError("out of bounds");0==(1&r)&&(i=this.__digit(e+s+1),o=(65535&i)-(a>>>16)-n,n=1&o>>>16,this.__setDigit(e+t.length,4294901760&i|65535&o))}else{e>>=1;let i=0;for(;i<t.length-1;i++){const r=this.__digit(e+i),o=t.__digit(i),s=(65535&r)-(65535&o)-n;n=1&s>>>16;const a=(r>>>16)-(o>>>16)-n;n=1&a>>>16,this.__setDigit(e+i,a<<16|65535&s)}const o=this.__digit(e+i),s=t.__digit(i),a=(65535&o)-(65535&s)-n;n=1&a>>>16;let u=0;0==(1&r)&&(u=(o>>>16)-(s>>>16)-n,n=1&u>>>16),this.__setDigit(e+i,u<<16|65535&a)}return n}__inplaceRightShift(t){if(0===t)return;let e=this.__digit(0)>>>t;const r=this.length-1;for(let n=0;n<r;n++){const r=this.__digit(n+1);this.__setDigit(n,r<<32-t|e),e=r>>>t}this.__setDigit(r,e)}static __specialLeftShift(t,e,r){const n=t.length,i=new g(n+r,!1);if(0===e){for(let e=0;e<n;e++)i.__setDigit(e,t.__digit(e));return 0<r&&i.__setDigit(n,0),i}let o=0;for(let r=0;r<n;r++){const n=t.__digit(r);i.__setDigit(r,n<<e|o),o=n>>>32-e}return 0<r&&i.__setDigit(n,o),i}static __leftShiftByAbsolute(t,e){const r=g.__toShiftAmount(e);if(0>r)throw new RangeError("BigInt too big");const n=r>>>5,i=31&r,o=t.length,s=0!==i&&0!=t.__digit(o-1)>>>32-i,a=o+n+(s?1:0),u=new g(a,t.sign);if(0===i){let e=0;for(;e<n;e++)u.__setDigit(e,0);for(;e<a;e++)u.__setDigit(e,t.__digit(e-n))}else{let e=0;for(let t=0;t<n;t++)u.__setDigit(t,0);for(let r=0;r<o;r++){const o=t.__digit(r);u.__setDigit(r+n,o<<i|e),e=o>>>32-i}if(s)u.__setDigit(o+n,e);else if(0!=e)throw new Error("implementation bug")}return u.__trim()}static __rightShiftByAbsolute(t,e){const r=t.length,n=t.sign,i=g.__toShiftAmount(e);if(0>i)return g.__rightShiftByMaximum(n);const o=i>>>5,s=31&i;let a=r-o;if(0>=a)return g.__rightShiftByMaximum(n);let u=!1;if(n)if(0!=(t.__digit(o)&(1<<s)-1))u=!0;else for(let e=0;e<o;e++)if(0!==t.__digit(e)){u=!0;break}if(u&&0===s){0==~t.__digit(r-1)&&a++}let l=new g(a,n);if(0===s)for(let e=o;e<r;e++)l.__setDigit(e-o,t.__digit(e));else{let e=t.__digit(o)>>>s;const n=r-o-1;for(let r=0;r<n;r++){const n=t.__digit(r+o+1);l.__setDigit(r,n<<32-s|e),e=n>>>s}l.__setDigit(n,e)}return u&&(l=g.__absoluteAddOne(l,!0,l)),l.__trim()}static __rightShiftByMaximum(t){return t?g.__oneDigit(1,!0):g.__zero()}static __toShiftAmount(t){if(1<t.length)return-1;const e=t.__unsignedDigit(0);return e>g.__kMaxLengthBits?-1:e}static __toPrimitive(t,e="default"){if("object"!=typeof t)return t;if(t.constructor===g)return t;const r=t[Symbol.toPrimitive];if(r){const t=r(e);if("object"!=typeof t)return t;throw new TypeError("Cannot convert object to primitive value")}const n=t.valueOf;if(n){const e=n.call(t);if("object"!=typeof e)return e}const i=t.toString;if(i){const e=i.call(t);if("object"!=typeof e)return e}throw new TypeError("Cannot convert object to primitive value")}static __toNumeric(t){return g.__isBigInt(t)?t:+t}static __isBigInt(t){return"object"==typeof t&&t.constructor===g}static __truncateToNBits(t,e){const r=t+31>>>5,n=new g(r,e.sign),i=r-1;for(let t=0;t<i;t++)n.__setDigit(t,e.__digit(t));let o=e.__digit(i);if(0!=(31&t)){const e=32-(31&t);o=o<<e>>>e}return n.__setDigit(i,o),n.__trim()}static __truncateAndSubFromPowerOfTwo(t,e,r){var n=Math.min;const i=t+31>>>5,o=new g(i,r);let s=0;const a=i-1;let u=0;for(const t=n(a,e.length);s<t;s++){const t=e.__digit(s),r=0-(65535&t)-u;u=1&r>>>16;const n=0-(t>>>16)-u;u=1&n>>>16,o.__setDigit(s,65535&r|n<<16)}for(;s<a;s++)o.__setDigit(s,0|-u);let l=a<e.length?e.__digit(a):0;const c=31&t;let _;if(0==c){const t=0-(65535&l)-u;u=1&t>>>16;_=65535&t|0-(l>>>16)-u<<16}else{const t=32-c;l=l<<t>>>t;const e=1<<32-t,r=(65535&e)-(65535&l)-u;u=1&r>>>16;_=65535&r|(e>>>16)-(l>>>16)-u<<16,_&=e-1}return o.__setDigit(a,_),o.__trim()}__digit(t){return this[t]}__unsignedDigit(t){return this[t]>>>0}__setDigit(t,e){this[t]=0|e}__setDigitGrow(t,e){this[t]=0|e}__halfDigitLength(){const t=this.length;return 65535>=this.__unsignedDigit(t-1)?2*t-1:2*t}__halfDigit(t){return 65535&this[t>>>1]>>>((1&t)<<4)}__setHalfDigit(t,e){const r=t>>>1,n=this.__digit(r),i=1&t?65535&n|e<<16:4294901760&n|65535&e;this.__setDigit(r,i)}static __digitPow(t,e){let r=1;for(;0<e;)1&e&&(r*=t),e>>>=1,t*=t;return r}}function d(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,s=r.length+n.length,a=`${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>s)throw new Error(a);let u=i.filter(t=>!r.includes(t));if(i.length-u.length!==o)throw new Error(a);if(u.find(t=>!n.includes(t)))throw new Error(a)}function p(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(t+" must be a hex string!")}function b(t,e){if(p(t,e),66!=e.length)throw new Error(t+" must be a hex string of 66 bytes long!")}function m(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 y(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(d(r,t,["code_hash","hash_type","args"],[]),b(r+".code_hash",t.code_hash),p(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 w(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){d(r,t,["tx_hash","index"],[]),b(r+".tx_hash",t.tx_hash),m(r+".index",t.index)}function v(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){d(r,t,["since","previous_output"],[]),m(r+".since",t.since),e&&w(t.previous_output,{debugPath:r+".previous_output"})}function B(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){d(r,t,["capacity","lock"],["type"]),m(r+".capacity",t.capacity),e&&(y(t.lock,{debugPath:r+".lock"}),t.type&&y(t.type,{debugPath:r+".type"}))}function P(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(d(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&&w(t.out_point,{debugPath:r+".out_point"})}function D(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 S(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function T(t,e,r){m(t+".version",e.version),D(t+".cell_deps",e.cell_deps,S(P,r),r),D(t+".header_deps",e.header_deps,b,r),D(t+".inputs",e.inputs,S(v,r),r),D(t+".outputs",e.outputs,S(B,r),r),D(t+".outputs_data",e.outputs_data,p,r)}function k(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){d(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),T(r,t,e)}function x(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){d(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),T(r,t,e),D(r+".witnesses",t.witnesses,p,e)}function C(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){d(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){m(t+".version",e.version),m(t+".compact_target",e.compact_target),m(t+".timestamp",e.timestamp),m(t+".number",e.number),m(t+".epoch",e.epoch),b(t+".parent_hash",e.parent_hash),b(t+".transactions_root",e.transactions_root),b(t+".proposals_hash",e.proposals_hash),b(t+".uncles_hash",e.uncles_hash),b(t+".dao",e.dao)}(r,t)}function E(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(d(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),p(r+".nonce",t.nonce),34!=t.nonce.length)throw new Error(r+".nonce must be a hex string of 34 bytes long!")}function A(t,e){if(p(t,e),22!=e.length)throw new Error(t+" must be a hex string of 22 bytes long!")}function O(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){d(r,t,["header","proposals"],[]),e&&E(t.header,{debugPath:r+".header"}),D(r+".proposals",t.proposals,A,e)}function j(t,{nestedValidation:e=!0,debugPath:r="block"}={}){d(r,t,["header","uncles","transactions","proposals"],[]),e&&E(t.header,{debugPath:r+".header"}),D(r+".uncles",t.uncles,S(O,e),e),D(r+".transactions",t.transactions,S(x,e),e),D(r+".proposals",t.proposals,A,e)}function z(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){d(r,t,["lock","message"],[]),p(r+".message",t.message),e&&y(t.lock,{debugPath:r+".lock"})}function I(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){d(r,t,[],["lock","input_type","output_type"]),t.lock&&p(r+".lock",t.lock),t.input_type&&p(r+".input_type",t.input_type),t.output_type&&p(r+".output_type",t.output_type)}g.__kMaxLength=33554432,g.__kMaxLengthBits=g.__kMaxLength<<5,g.__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],g.__kBitsPerCharTableShift=5,g.__kBitsPerCharTableMultiplier=1<<g.__kBitsPerCharTableShift,g.__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"],g.__kBitConversionBuffer=new ArrayBuffer(8),g.__kBitConversionDouble=new Float64Array(g.__kBitConversionBuffer),g.__kBitConversionInts=new Int32Array(g.__kBitConversionBuffer);var R=Object.freeze({__proto__:null,ValidateScript:y,ValidateOutPoint:w,ValidateCellInput:v,ValidateCellOutput:B,ValidateCellDep:P,ValidateRawTransaction:k,ValidateTransaction:x,ValidateRawHeader:C,ValidateHeader:E,ValidateUncleBlock:O,ValidateBlock:j,ValidateCellbaseWitness:z,ValidateWitnessArgs:I});const L=s.default.Readable,M=Symbol("buffer"),N=Symbol("type");class ${constructor(){this[N]="";const t=arguments[0],e=arguments[1],r=[];let n=0;if(t){const e=t,i=Number(e.length);for(let t=0;t<i;t++){const i=e[t];let o;o=i instanceof Buffer?i:ArrayBuffer.isView(i)?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i instanceof ArrayBuffer?Buffer.from(i):i instanceof $?i[M]:Buffer.from("string"==typeof i?i:String(i)),n+=o.length,r.push(o)}}this[M]=Buffer.concat(r);let i=e&&void 0!==e.type&&String(e.type).toLowerCase();i&&!/[^\u0020-\u007E]/.test(i)&&(this[N]=i)}get size(){return this[M].length}get type(){return this[N]}text(){return Promise.resolve(this[M].toString())}arrayBuffer(){const t=this[M],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new L;return t._read=function(){},t.push(this[M]),t.push(null),t}toString(){return"[object Blob]"}slice(){const t=this.size,e=arguments[0],r=arguments[1];let n,i;n=void 0===e?0:e<0?Math.max(t+e,0):Math.min(e,t),i=void 0===r?t:r<0?Math.max(t+r,0):Math.min(r,t);const o=Math.max(i-n,0),s=this[M].slice(n,n+o),a=new $([],{type:arguments[2]});return a[M]=s,a}}function q(t,e,r){Error.call(this,t),this.message=t,this.type=e,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let U;Object.defineProperties($.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty($.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),q.prototype=Object.create(Error.prototype),q.prototype.constructor=q,q.prototype.name="FetchError";try{U=require("encoding").convert}catch(t){}const V=Symbol("Body internals"),H=s.default.PassThrough;function F(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.size;let i=void 0===n?0:n;var o=r.timeout;let a=void 0===o?0:o;null==t?t=null:W(t)?t=Buffer.from(t.toString()):J(t)||Buffer.isBuffer(t)||("[object ArrayBuffer]"===Object.prototype.toString.call(t)?t=Buffer.from(t):ArrayBuffer.isView(t)?t=Buffer.from(t.buffer,t.byteOffset,t.byteLength):t instanceof s.default||(t=Buffer.from(String(t)))),this[V]={body:t,disturbed:!1,error:null},this.size=i,this.timeout=a,t instanceof s.default&&t.on("error",(function(t){const r="AbortError"===t.name?t:new q(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t);e[V].error=r}))}function G(){var t=this;if(this[V].disturbed)return F.Promise.reject(new TypeError("body used already for: "+this.url));if(this[V].disturbed=!0,this[V].error)return F.Promise.reject(this[V].error);let e=this.body;if(null===e)return F.Promise.resolve(Buffer.alloc(0));if(J(e)&&(e=e.stream()),Buffer.isBuffer(e))return F.Promise.resolve(e);if(!(e instanceof s.default))return F.Promise.resolve(Buffer.alloc(0));let r=[],n=0,i=!1;return new F.Promise((function(o,s){let a;t.timeout&&(a=setTimeout((function(){i=!0,s(new q(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),e.on("error",(function(e){"AbortError"===e.name?(i=!0,s(e)):s(new q(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),e.on("data",(function(e){if(!i&&null!==e){if(t.size&&n+e.length>t.size)return i=!0,void s(new q(`content size at ${t.url} over limit: ${t.size}`,"max-size"));n+=e.length,r.push(e)}})),e.on("end",(function(){if(!i){clearTimeout(a);try{o(Buffer.concat(r,n))}catch(e){s(new q(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function W(t){return"object"==typeof t&&"function"==typeof t.append&&"function"==typeof t.delete&&"function"==typeof t.get&&"function"==typeof t.getAll&&"function"==typeof t.has&&"function"==typeof t.set&&("URLSearchParams"===t.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(t)||"function"==typeof t.sort)}function J(t){return"object"==typeof t&&"function"==typeof t.arrayBuffer&&"string"==typeof t.type&&"function"==typeof t.stream&&"function"==typeof t.constructor&&"string"==typeof t.constructor.name&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag])}function X(t){let e,r,n=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof s.default&&"function"!=typeof n.getBoundary&&(e=new H,r=new H,n.pipe(e),n.pipe(r),t[V].body=e,n=r),n}function Q(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":W(t)?"application/x-www-form-urlencoded;charset=UTF-8":J(t)?t.type||null:Buffer.isBuffer(t)||"[object ArrayBuffer]"===Object.prototype.toString.call(t)||ArrayBuffer.isView(t)?null:"function"==typeof t.getBoundary?"multipart/form-data;boundary="+t.getBoundary():t instanceof s.default?null:"text/plain;charset=UTF-8"}function Z(t){const e=t.body;return null===e?0:J(e)?e.size:Buffer.isBuffer(e)?e.length:e&&"function"==typeof e.getLengthSync&&(e._lengthRetrievers&&0==e._lengthRetrievers.length||e.hasKnownLength&&e.hasKnownLength())?e.getLengthSync():null}F.prototype={get body(){return this[V].body},get bodyUsed(){return this[V].disturbed},arrayBuffer(){return G.call(this).then((function(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}))},blob(){let t=this.headers&&this.headers.get("content-type")||"";return G.call(this).then((function(e){return Object.assign(new $([],{type:t.toLowerCase()}),{[M]:e})}))},json(){var t=this;return G.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return F.Promise.reject(new q(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return G.call(this).then((function(t){return t.toString()}))},buffer(){return G.call(this)},textConverted(){var t=this;return G.call(this).then((function(e){return function(t,e){if("function"!=typeof U)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=e.get("content-type");let n,i,o="utf-8";r&&(n=/charset=([^;]*)/i.exec(r));i=t.slice(0,1024).toString(),!n&&i&&(n=/<meta.+?charset=(['"])(.+?)\1/i.exec(i));!n&&i&&(n=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(i),n||(n=/<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(i),n&&n.pop()),n&&(n=/charset=(.*)/i.exec(n.pop())));!n&&i&&(n=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(i));n&&(o=n.pop(),"gb2312"!==o&&"gbk"!==o||(o="gb18030"));return U(t,"UTF-8",o).toString()}(e,t.headers)}))}},Object.defineProperties(F.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),F.mixIn=function(t){for(const e of Object.getOwnPropertyNames(F.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(F.prototype,e);Object.defineProperty(t,e,r)}},F.Promise=global.Promise;const K=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,Y=/[^\t\x20-\x7e\x80-\xff]/;function tt(t){if(t=""+t,K.test(t)||""===t)throw new TypeError(t+" is not a legal HTTP header name")}function et(t){if(t=""+t,Y.test(t))throw new TypeError(t+" is not a legal HTTP header value")}function rt(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const nt=Symbol("map");class it{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[nt]=Object.create(null),t instanceof it){const e=t.raw(),r=Object.keys(e);for(const t of r)for(const r of e[t])this.append(t,r)}else if(null==t);else{if("object"!=typeof t)throw new TypeError("Provided initializer must be an object");{const e=t[Symbol.iterator];if(null!=e){if("function"!=typeof e)throw new TypeError("Header pairs must be iterable");const r=[];for(const e of t){if("object"!=typeof e||"function"!=typeof e[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(e))}for(const t of r){if(2!==t.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(t[0],t[1])}}else for(const e of Object.keys(t)){const r=t[e];this.append(e,r)}}}}get(t){tt(t=""+t);const e=rt(this[nt],t);return void 0===e?null:this[nt][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=ot(this),n=0;for(;n<r.length;){var i=r[n];const o=i[0],s=i[1];t.call(e,s,o,this),r=ot(this),n++}}set(t,e){e=""+e,tt(t=""+t),et(e);const r=rt(this[nt],t);this[nt][void 0!==r?r:t]=[e]}append(t,e){e=""+e,tt(t=""+t),et(e);const r=rt(this[nt],t);void 0!==r?this[nt][r].push(e):this[nt][t]=[e]}has(t){return tt(t=""+t),void 0!==rt(this[nt],t)}delete(t){tt(t=""+t);const e=rt(this[nt],t);void 0!==e&&delete this[nt][e]}raw(){return this[nt]}keys(){return at(this,"key")}values(){return at(this,"value")}[Symbol.iterator](){return at(this,"key+value")}}function ot(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[nt]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[nt][e].join(", ")}:function(e){return[e.toLowerCase(),t[nt][e].join(", ")]})}it.prototype.entries=it.prototype[Symbol.iterator],Object.defineProperty(it.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(it.prototype,{get:{enumerable:!0},forEach:{enumerable:!0},set:{enumerable:!0},append:{enumerable:!0},has:{enumerable:!0},delete:{enumerable:!0},keys:{enumerable:!0},values:{enumerable:!0},entries:{enumerable:!0}});const st=Symbol("internal");function at(t,e){const r=Object.create(ut);return r[st]={target:t,kind:e,index:0},r}const ut=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==ut)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[st];const e=t.target,r=t.kind,n=t.index,i=ot(e,r);return n>=i.length?{value:void 0,done:!0}:(this[st].index=n+1,{value:i[n],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function lt(t){const e=Object.assign({__proto__:null},t[nt]),r=rt(t[nt],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(ut,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const ct=Symbol("Response internals"),_t=a.default.STATUS_CODES;class ft{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};F.call(this,t,e);const r=e.status||200,n=new it(e.headers);if(null!=t&&!n.has("Content-Type")){const e=Q(t);e&&n.append("Content-Type",e)}this[ct]={url:e.url,status:r,statusText:e.statusText||_t[r],headers:n,counter:e.counter}}get url(){return this[ct].url||""}get status(){return this[ct].status}get ok(){return this[ct].status>=200&&this[ct].status<300}get redirected(){return this[ct].counter>0}get statusText(){return this[ct].statusText}get headers(){return this[ct].headers}clone(){return new ft(X(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}F.mixIn(ft.prototype),Object.defineProperties(ft.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ht=Symbol("Request internals"),gt=u.default.parse,dt=u.default.format,pt="destroy"in s.default.Readable.prototype;function bt(t){return"object"==typeof t&&"object"==typeof t[ht]}class mt{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};bt(t)?e=gt(t.url):(e=t&&t.href?gt(t.href):gt(""+t),t={});let n=r.method||t.method||"GET";if(n=n.toUpperCase(),(null!=r.body||bt(t)&&null!==t.body)&&("GET"===n||"HEAD"===n))throw new TypeError("Request with GET/HEAD method cannot have body");let i=null!=r.body?r.body:bt(t)&&null!==t.body?X(t):null;F.call(this,i,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const o=new it(r.headers||t.headers||{});if(null!=i&&!o.has("Content-Type")){const t=Q(i);t&&o.append("Content-Type",t)}let s=bt(t)?t.signal:null;if("signal"in r&&(s=r.signal),null!=s&&!function(t){const e=t&&"object"==typeof t&&Object.getPrototypeOf(t);return!(!e||"AbortSignal"!==e.constructor.name)}(s))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[ht]={method:n,redirect:r.redirect||t.redirect||"follow",headers:o,parsedURL:e,signal:s},this.follow=void 0!==r.follow?r.follow:void 0!==t.follow?t.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===t.compress||t.compress,this.counter=r.counter||t.counter||0,this.agent=r.agent||t.agent}get method(){return this[ht].method}get url(){return dt(this[ht].parsedURL)}get headers(){return this[ht].headers}get redirect(){return this[ht].redirect}get signal(){return this[ht].signal}clone(){return new mt(this)}}function yt(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}F.mixIn(mt.prototype),Object.defineProperty(mt.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(mt.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),yt.prototype=Object.create(Error.prototype),yt.prototype.constructor=yt,yt.prototype.name="AbortError";const wt=s.default.PassThrough,vt=u.default.resolve;function Bt(t,e){if(!Bt.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return F.Promise=Bt.Promise,new Bt.Promise((function(r,n){const i=new mt(t,e),o=function(t){const e=t[ht].parsedURL,r=new it(t[ht].headers);if(r.has("Accept")||r.set("Accept","*/*"),!e.protocol||!e.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(e.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(t.signal&&t.body instanceof s.default.Readable&&!pt)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let n=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(n="0"),null!=t.body){const e=Z(t);"number"==typeof e&&(n=String(e))}n&&r.set("Content-Length",n),r.has("User-Agent")||r.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!r.has("Accept-Encoding")&&r.set("Accept-Encoding","gzip,deflate");let i=t.agent;return"function"==typeof i&&(i=i(e)),r.has("Connection")||i||r.set("Connection","close"),Object.assign({},e,{method:t.method,headers:lt(r),agent:i})}(i),u=("https:"===o.protocol?l.default:a.default).request,_=i.signal;let f=null;const h=function(){let t=new yt("The user aborted a request.");n(t),i.body&&i.body instanceof s.default.Readable&&i.body.destroy(t),f&&f.body&&f.body.emit("error",t)};if(_&&_.aborted)return void h();const g=function(){h(),b()},d=u(o);let p;function b(){d.abort(),_&&_.removeEventListener("abort",g),clearTimeout(p)}_&&_.addEventListener("abort",g),i.timeout&&d.once("socket",(function(t){p=setTimeout((function(){n(new q("network timeout at: "+i.url,"request-timeout")),b()}),i.timeout)})),d.on("error",(function(t){n(new q(`request to ${i.url} failed, reason: ${t.message}`,"system",t)),b()})),d.on("response",(function(t){clearTimeout(p);const e=function(t){const e=new it;for(const r of Object.keys(t))if(!K.test(r))if(Array.isArray(t[r]))for(const n of t[r])Y.test(n)||(void 0===e[nt][r]?e[nt][r]=[n]:e[nt][r].push(n));else Y.test(t[r])||(e[nt][r]=[t[r]]);return e}(t.headers);if(Bt.isRedirect(t.statusCode)){const o=e.get("Location"),s=null===o?null:vt(i.url,o);switch(i.redirect){case"error":return n(new q("uri requested responds with a redirect, redirect mode is set to error: "+i.url,"no-redirect")),void b();case"manual":if(null!==s)try{e.set("Location",s)}catch(t){n(t)}break;case"follow":if(null===s)break;if(i.counter>=i.follow)return n(new q("maximum redirect reached at: "+i.url,"max-redirect")),void b();const o={headers:new it(i.headers),follow:i.follow,counter:i.counter+1,agent:i.agent,compress:i.compress,method:i.method,body:i.body,signal:i.signal,timeout:i.timeout,size:i.size};return 303!==t.statusCode&&i.body&&null===Z(i)?(n(new q("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==i.method)||(o.method="GET",o.body=void 0,o.headers.delete("content-length")),r(Bt(new mt(s,o))),void b())}}t.once("end",(function(){_&&_.removeEventListener("abort",g)}));let o=t.pipe(new wt);const s={url:i.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:i.size,timeout:i.timeout,counter:i.counter},a=e.get("Content-Encoding");if(!i.compress||"HEAD"===i.method||null===a||204===t.statusCode||304===t.statusCode)return f=new ft(o,s),void r(f);const u={flush:c.default.Z_SYNC_FLUSH,finishFlush:c.default.Z_SYNC_FLUSH};if("gzip"==a||"x-gzip"==a)return o=o.pipe(c.default.createGunzip(u)),f=new ft(o,s),void r(f);if("deflate"!=a&&"x-deflate"!=a){if("br"==a&&"function"==typeof c.default.createBrotliDecompress)return o=o.pipe(c.default.createBrotliDecompress()),f=new ft(o,s),void r(f);f=new ft(o,s),r(f)}else{t.pipe(new wt).once("data",(function(t){o=8==(15&t[0])?o.pipe(c.default.createInflate()):o.pipe(c.default.createInflateRaw()),f=new ft(o,s),r(f)}))}})),function(t,e){const r=e.body;null===r?t.end():J(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(d,i)}))}Bt.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},Bt.Promise=global.Promise;var Pt,Dt,St=Object.freeze({__proto__:null,default:Bt,Headers:it,Request:mt,Response:ft,FetchError:q}),Tt=(function(t,e){var r=St.default||St,n=function(t,e){return/^\/\//.test(t)&&(t="https:"+t),r.call(this,t,e)};t.exports=e=n,e.fetch=n,e.Headers=St.Headers,e.Request=St.Request,e.Response=St.Response,e.default=n}(Dt={path:Pt,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&Dt.path)}},Dt.exports),Dt.exports);const kt={get:(t,e,r)=>"send"===e?async()=>{const e=await Tt(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)});return await e.json()}:(...n)=>{const i=t.id;return t.id=t.id+1,t.payload.push({jsonrpc:"2.0",id:i,method:e,params:n}),r}},xt={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri},kt):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await Tt(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),o=await i.json();if(o.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(o.error)throw new Error("JSONRPCError: server error "+JSON.stringify(o.error));return o.result}};class Ct{constructor(t){return this.uri=t,new Proxy(this,xt)}static create(t){return new Ct(t)}}function Et(t){return g.BigInt(t)}function At(t){return"0x"+t.toString(16)}function Ot(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=At(g.BigInt(r)).substr(2);if(n.length%2!=0&&(n="0"+n),n.length/2>t)throw new Error(`${e} is ${n.length/2} bytes long, expected length is ${t}!`);const i=new DataView(new ArrayBuffer(t));for(let t=0;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function jt(t){return function(e,r){if(r=new h(r).toArrayBuffer(),t>0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function zt(t,e,r){const n={};for(const[i,o]of Object.entries(r)){const r=e[i];if(!r)throw new Error(`${t} is missing ${i}!`);n[i]=o(`${t}.${i}`,r)}return n}function It(t,{debugPath:e="script"}={}){return zt(e,t,{code_hash:jt(32),hash_type:function(t,e){switch(e){case"data":return 0;case"type":return 1;case 0:case 1:return e;default:throw new Error(`${t}.hash_type has invalid value: ${e}`)}},args:jt(-1)})}function Rt(t,{debugPath:e="out_point"}={}){return zt(e,t,{tx_hash:jt(32),index:Ot(4)})}function Lt(t){return function(e,r){return t(r,{debugPath:e})}}function Mt(t,{debugPath:e="cell_input"}={}){return zt(e,t,{since:Ot(8),previous_output:Lt(Rt)})}function Nt(t,{debugPath:e="cell_output"}={}){const r=zt(e,t,{capacity:Ot(8),lock:Lt(It)});return t.type&&(r.type_=It(t.type,{debugPath:e+".type"})),r}function $t(t,{debugPath:e="cell_dep"}={}){return zt(e,t,{out_point:Lt(Rt),dep_type:function(t,e){switch(e){case"code":return 0;case"dep_group":return 1;case 0:case 1:return e;default:throw new Error(`${t}.dep_type has invalid value: ${e}`)}}})}function qt(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function Ut(t,{debugPath:e="raw_transaction"}={}){return zt(e,t,{version:Ot(4),cell_deps:qt(Lt($t)),header_deps:qt(jt(32)),inputs:qt(Lt(Mt)),outputs:qt(Lt(Nt)),outputs_data:qt(jt(-1))})}function Vt(t,{debugPath:e="transaction"}={}){const r=Ut(t,{debugPath:"(raw)"+e}),n=zt(e,t,{witnesses:qt(jt(-1))});return n.raw=r,n}function Ht(t,{debugPath:e="raw_header"}={}){return zt(e,t,{version:Ot(4),compact_target:Ot(4),timestamp:Ot(8),number:Ot(8),epoch:Ot(8),parent_hash:jt(32),transactions_root:jt(32),proposals_hash:jt(32),uncles_hash:jt(32),dao:jt(32)})}function Ft(t,{debugPath:e="header"}={}){const r=Ht(t,{debugPath:"(raw)"+e}),n=zt(e,t,{nonce:Ot(16)});return n.raw=r,n}function Gt(t,{debugPath:e="uncle_block"}={}){return zt(e,t,{header:Lt(Ft),proposals:qt(jt(10))})}var Wt=Object.freeze({__proto__:null,NormalizeScript:It,NormalizeOutPoint:Rt,NormalizeCellInput:Mt,NormalizeCellOutput:Nt,NormalizeCellDep:$t,NormalizeRawTransaction:Ut,NormalizeTransaction:Vt,NormalizeRawHeader:Ht,NormalizeHeader:Ft,NormalizeUncleBlock:Gt,NormalizeBlock:function(t,{debugPath:e="block"}={}){return zt(e,t,{header:Lt(Ft),uncles:qt(Lt(Gt)),transactions:qt(Lt(Vt)),proposals:qt(jt(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return zt(e,t,{lock:Lt(It),message:jt(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=jt(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=jt(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=jt(-1)(e+".output_type",t.output_type)),r}});function Jt(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Xt(t,e,r){if(!((e=Jt(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){let r=e[i];if(!r){r=e[i.replace(/(_[a-z])/g,t=>t.toUpperCase().replace("_",""))]}r&&(n[i]=o(`${t}.${i}`,r))}return n}function Qt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Xt(r,t,{code_hash:Jt,hash_type:Jt,args:Jt}),e&&y(t,{debugPath:"(transformed) "+r}),t}function Zt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Xt(r,t,{tx_hash:Jt,index:Jt}),e&&w(t,{debugPath:"(transformed) "+r}),t}function Kt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function Yt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Xt(r,t,{since:Jt,previous_output:Kt(Zt)}),e&&v(t,{debugPath:"(transformed) "+r}),t}function te(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Xt(r,t,{capacity:Jt,lock:Kt(Qt),type:Kt(Qt)}),e&&B(t,{debugPath:"(transformed) "+r}),t}function ee(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Xt(r,t,{out_point:Kt(Zt),dep_type:Jt}),e&&P(t,{debugPath:"(transformed) "+r}),t}function re(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function ne(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Xt(r,t,{version:Jt,cell_deps:re(Kt(ee)),header_deps:re(Jt),inputs:re(Kt(Yt)),outputs:re(Kt(te)),outputs_data:re(Jt),witnesses:re(Jt)}),e&&x(t,{debugPath:"(transformed) "+r}),t}function ie(t,{validation:e=!0,debugPath:r="header"}={}){return t=Xt(r,t,{version:Jt,compact_target:Jt,timestamp:Jt,number:Jt,epoch:Jt,parent_hash:Jt,transactions_root:Jt,proposals_hash:Jt,uncles_hash:Jt,dao:Jt,nonce:Jt}),e&&E(t,{debugPath:"(transformed) "+r}),t}function oe(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Xt(r,t,{header:Kt(ie),proposals:re(Jt)}),e&&O(t,{debugPath:"(transformed) "+r}),t}var se=Object.freeze({__proto__:null,TransformScript:Qt,TransformOutPoint:Zt,TransformCellInput:Yt,TransformCellOutput:te,TransformCellDep:ee,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Xt(r,t,{version:Jt,cell_deps:re(Kt(ee)),header_deps:re(Jt),inputs:re(Kt(Yt)),outputs:re(Kt(te)),outputs_data:re(Jt)}),e&&k(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:ne,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Xt(r,t,{version:Jt,compact_target:Jt,timestamp:Jt,number:Jt,epoch:Jt,parent_hash:Jt,transactions_root:Jt,proposals_hash:Jt,uncles_hash:Jt,dao:Jt}),e&&C(t,{debugPath:"(transformed) "+r}),t},TransformHeader:ie,TransformUncleBlock:oe,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Xt(r,t,{header:Kt(ie),uncles:re(Kt(oe)),transactions:re(Kt(ne)),proposals:re(Jt)}),e&&j(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Xt(r,t,{lock:Kt(Qt),message:Jt}),e&&z(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Xt(r,t,{lock:Jt,input_type:Jt,output_type:Jt}),e&&I(t,{debugPath:"(transformed) "+r}),t}});var ae=Object.freeze({__proto__:null,RPCCollector:class{constructor(t,e,{skipCellWithContent:r=!0,loadData:n=!1,loadBlockNumber:i=!0}={}){this.rpc=t,this.lockHash=new h(e).serializeJson(),this.skipCellWithContent=r,this.loadData=n,this.loadBlockNumber=i}async*collect(){const t=Et(await this.rpc.get_tip_block_number());let e=g.BigInt(0);for(;g.lessThanOrEqual(e,t);){let r=g.add(e,g.BigInt(100));g.greaterThan(r,t)&&(r=t);const n=await this.rpc.get_cells_by_lock_hash(this.lockHash,At(e),At(r));for(const t of n){if(this.skipCellWithContent&&(t.type||g.greaterThan(Et(t.output_data_len),g.BigInt(100))))continue;let e=null;if(this.loadData){e=(await this.rpc.get_live_cell(t.out_point,!0)).cell.data.content}let r=null;if(this.loadBlockNumber){r=(await this.rpc.get_header(t.block_hash)).number}yield{cellbase:t.cellbase,cell_output:{capacity:t.capacity,lock:t.lock,type:t.type},out_point:t.out_point,block_hash:t.block_hash,data:e,output_data_len:t.output_data_len,block_number:r}}e=g.add(r,g.BigInt(1))}}}});exports.BigIntToHexString=At,exports.HexStringToBigInt=Et,exports.RPC=Ct,exports.Reader=h,exports.TransactionDumper=class{constructor(t,{validateTransaction:e=!0,depGroupUnpacker:r=null}={}){this.rpc=t,this.validateTransaction=e,this.depGroupUnpacker=r}async dumpByHash(t){const e=(await this.rpc.get_transaction(t)).transaction;return delete e.hash,await this.dump(e)}async dump(t){this.validateTransaction&&x(t);const e=[];for(const r of t.inputs){const{output:t,data:n,header:i}=await this._resolveOutPoint(r.previous_output);e.push({input:r,output:t,data:n,header:i})}const r=[];for(const e of t.cell_deps){const{output:t,data:n,header:i}=await this._resolveOutPoint(e.out_point);if(r.push({cell_dep:e,output:t,data:n,header:i}),"dep_group"===e.dep_type){if(!this.depGroupUnpacker)throw new Error("depGroupUnpacker must be provided when the transaction contains dep_group!");const t=this.depGroupUnpacker(new h(n));for(const e of t){w(e);const{output:t,data:n,header:i}=await this._resolveOutPoint(e);r.push({cell_dep:{out_point:e,dep_type:"code"},output:t,data:n,header:i})}}}const n=[];for(const e of t.header_deps)n.push(await this.rpc.get_header(e));return JSON.stringify({mock_info:{inputs:e,cell_deps:r,header_deps:n},tx:t})}async _resolveOutPoint(t){const e=await this.rpc.get_transaction(t.tx_hash);if(!e||!e.transaction)throw new Error(`Transaction ${t.tx_hash} cannot be found!`);const r=e.transaction,n=g.toNumber(g.BigInt(t.index));if(n>=r.outputs.length)throw new Error(`Transaction ${t.tx_hash} does not have output ${n}!`);const i={output:r.outputs[n],data:r.outputs_data[n]};return"committed"===e.tx_status.status&&(i.header=e.tx_status.block_hash),i}},exports.VERSION="0.9.2",exports.cell_collectors=ae,exports.normalizers=Wt,exports.transformers=se,exports.validators=R;
//# sourceMappingURL=ckb-js-toolkit.node.js.map

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).CKBJSToolkit={})}(this,(function(t){"use strict";class e{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 r{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 n{constructor(t){if(t instanceof r||t instanceof e)return t;if("string"==typeof t){if(!t.startsWith("0x")||t.length%2!=0)throw new Error("Hex string must start with 0x, and has even numbered length!");return new r(t)}if(t instanceof ArrayBuffer)return new e(t);throw new Error("Reader can only accept hex string or ArrayBuffer!")}static fromRawString(t){const r=new ArrayBuffer(t.length),n=new DataView(r);for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r>255)throw new Error("fromRawString can only accept UTF-8 raw string!");n.setUint8(e,r)}return new e(r)}}var i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t,e){return t(e={exports:{}},e.exports),e.exports}var a=o((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 P=B*e;if(4294967295<P)break;if(B=P,D=D*e+k,w++,++i===n){m=!0;break}o=t.charCodeAt(i)}var T=s*w+(u=32*l.__kBitsPerCharTableMultiplier-1)>>>l.__kBitsPerCharTableShift+5;f.__inplaceMultiplyAdd(B,D,T)}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}()}));function s(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 u(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(`${t} must be a hex string!`)}function _(t,e){if(u(t,e),66!=e.length)throw new Error(`${t} must be a hex string of 66 bytes long!`)}function l(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 f(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(s(r,t,["code_hash","hash_type","args"],[]),_(`${r}.code_hash`,t.code_hash),u(`${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 h(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){s(r,t,["tx_hash","index"],[]),_(`${r}.tx_hash`,t.tx_hash),l(`${r}.index`,t.index)}function c(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){s(r,t,["since","previous_output"],[]),l(`${r}.since`,t.since),e&&h(t.previous_output,{debugPath:`${r}.previous_output`})}function g(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){s(r,t,["capacity","lock"],["type"]),l(`${r}.capacity`,t.capacity),e&&(f(t.lock,{debugPath:`${r}.lock`}),t.type&&f(t.type,{debugPath:`${r}.type`}))}function d(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(s(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&&h(t.out_point,{debugPath:`${r}.out_point`})}function p(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 v(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function y(t,e,r){l(`${t}.version`,e.version),p(`${t}.cell_deps`,e.cell_deps,v(d,r),r),p(`${t}.header_deps`,e.header_deps,_,r),p(`${t}.inputs`,e.inputs,v(c,r),r),p(`${t}.outputs`,e.outputs,v(g,r),r),p(`${t}.outputs_data`,e.outputs_data,u,r)}function b(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){s(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),y(r,t,e)}function m(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){s(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),y(r,t,e),p(`${r}.witnesses`,t.witnesses,u,e)}function w(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){s(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){l(`${t}.version`,e.version),l(`${t}.compact_target`,e.compact_target),l(`${t}.timestamp`,e.timestamp),l(`${t}.number`,e.number),l(`${t}.epoch`,e.epoch),_(`${t}.parent_hash`,e.parent_hash),_(`${t}.transactions_root`,e.transactions_root),_(`${t}.proposals_hash`,e.proposals_hash),_(`${t}.uncles_hash`,e.uncles_hash),_(`${t}.dao`,e.dao)}(r,t)}function k(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(s(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),u(`${r}.nonce`,t.nonce),34!=t.nonce.length)throw new Error(`${r}.nonce must be a hex string of 34 bytes long!`)}function D(t,e){if(u(t,e),22!=e.length)throw new Error(`${t} must be a hex string of 22 bytes long!`)}function B(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){s(r,t,["header","proposals"],[]),e&&k(t.header,{debugPath:`${r}.header`}),p(`${r}.proposals`,t.proposals,D,e)}function P(t,{nestedValidation:e=!0,debugPath:r="block"}={}){s(r,t,["header","uncles","transactions","proposals"],[]),e&&k(t.header,{debugPath:`${r}.header`}),p(`${r}.uncles`,t.uncles,v(B,e),e),p(`${r}.transactions`,t.transactions,v(m,e),e),p(`${r}.proposals`,t.proposals,D,e)}function T(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){s(r,t,["lock","message"],[]),u(`${r}.message`,t.message),e&&f(t.lock,{debugPath:`${r}.lock`})}function A(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){s(r,t,[],["lock","input_type","output_type"]),t.lock&&u(`${r}.lock`,t.lock),t.input_type&&u(`${r}.input_type`,t.input_type),t.output_type&&u(`${r}.output_type`,t.output_type)}var S=Object.freeze({__proto__:null,ValidateScript:f,ValidateOutPoint:h,ValidateCellInput:c,ValidateCellOutput:g,ValidateCellDep:d,ValidateRawTransaction:b,ValidateTransaction:m,ValidateRawHeader:w,ValidateHeader:k,ValidateUncleBlock:B,ValidateBlock:P,ValidateCellbaseWitness:T,ValidateWitnessArgs:A});var E=o((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:i);!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}));E.fetch,E.Headers,E.Request,E.Response;const x={get:(t,e,r)=>"send"===e?async()=>{const e=await E(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)});return await e.json()}:(...n)=>{const i=t.id;return t.id=t.id+1,t.payload.push({jsonrpc:"2.0",id:i,method:e,params:n}),r}},O={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri},x):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await E(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),o=await i.json();if(o.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(o.error)throw new Error(`JSONRPCError: server error ${JSON.stringify(o.error)}`);return o.result}};class C{constructor(t){return this.uri=t,new Proxy(this,O)}static create(t){return new C(t)}}function $(t){return a.BigInt(t)}function I(t){return"0x"+t.toString(16)}function R(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=I(a.BigInt(r)).substr(2);if(n.length%2!=0&&(n="0"+n),n.length/2>t)throw new Error(`${e} is ${n.length/2} bytes long, expected length is ${t}!`);const i=new DataView(new ArrayBuffer(t));for(let t=0;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function j(t){return function(e,r){if(r=new n(r).toArrayBuffer(),t>0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function z(t,e,r){const n={};for(const[i,o]of Object.entries(r)){const r=e[i];if(!r)throw new Error(`${t} is missing ${i}!`);n[i]=o(`${t}.${i}`,r)}return n}function M(t,{debugPath:e="script"}={}){return z(e,t,{code_hash:j(32),hash_type:function(t,e){switch(e){case"data":return 0;case"type":return 1;case 0:case 1:return e;default:throw new Error(`${t}.hash_type has invalid value: ${e}`)}},args:j(-1)})}function N(t,{debugPath:e="out_point"}={}){return z(e,t,{tx_hash:j(32),index:R(4)})}function L(t){return function(e,r){return t(r,{debugPath:e})}}function U(t,{debugPath:e="cell_input"}={}){return z(e,t,{since:R(8),previous_output:L(N)})}function V(t,{debugPath:e="cell_output"}={}){const r=z(e,t,{capacity:R(8),lock:L(M)});return t.type&&(r.type_=M(t.type,{debugPath:`${e}.type`})),r}function q(t,{debugPath:e="cell_dep"}={}){return z(e,t,{out_point:L(N),dep_type:function(t,e){switch(e){case"code":return 0;case"dep_group":return 1;case 0:case 1:return e;default:throw new Error(`${t}.dep_type has invalid value: ${e}`)}}})}function F(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function H(t,{debugPath:e="raw_transaction"}={}){return z(e,t,{version:R(4),cell_deps:F(L(q)),header_deps:F(j(32)),inputs:F(L(U)),outputs:F(L(V)),outputs_data:F(j(-1))})}function G(t,{debugPath:e="transaction"}={}){const r=H(t,{debugPath:`(raw)${e}`}),n=z(e,t,{witnesses:F(j(-1))});return n.raw=r,n}function W(t,{debugPath:e="raw_header"}={}){return z(e,t,{version:R(4),compact_target:R(4),timestamp:R(8),number:R(8),epoch:R(8),parent_hash:j(32),transactions_root:j(32),proposals_hash:j(32),uncles_hash:j(32),dao:j(32)})}function J(t,{debugPath:e="header"}={}){const r=W(t,{debugPath:`(raw)${e}`}),n=z(e,t,{nonce:R(16)});return n.raw=r,n}function X(t,{debugPath:e="uncle_block"}={}){return z(e,t,{header:L(J),proposals:F(j(10))})}var Q=Object.freeze({__proto__:null,NormalizeScript:M,NormalizeOutPoint:N,NormalizeCellInput:U,NormalizeCellOutput:V,NormalizeCellDep:q,NormalizeRawTransaction:H,NormalizeTransaction:G,NormalizeRawHeader:W,NormalizeHeader:J,NormalizeUncleBlock:X,NormalizeBlock:function(t,{debugPath:e="block"}={}){return z(e,t,{header:L(J),uncles:F(L(X)),transactions:F(L(G)),proposals:F(j(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return z(e,t,{lock:L(M),message:j(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=j(-1)(`${e}.lock`,t.lock)),t.input_type&&(r.input_type=j(-1)(`${e}.input_type`,t.input_type)),t.output_type&&(r.output_type=j(-1)(`${e}.output_type`,t.output_type)),r}});function K(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Y(t,e,r){if(!((e=K(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){let r=e[i];if(!r){r=e[i.replace(/(_[a-z])/g,t=>t.toUpperCase().replace("_",""))]}r&&(n[i]=o(`${t}.${i}`,r))}return n}function Z(t,{validation:e=!0,debugPath:r="script"}={}){return t=Y(r,t,{code_hash:K,hash_type:K,args:K}),e&&f(t,{debugPath:`(transformed) ${r}`}),t}function tt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Y(r,t,{tx_hash:K,index:K}),e&&h(t,{debugPath:`(transformed) ${r}`}),t}function et(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function rt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Y(r,t,{since:K,previous_output:et(tt)}),e&&c(t,{debugPath:`(transformed) ${r}`}),t}function nt(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Y(r,t,{capacity:K,lock:et(Z),type:et(Z)}),e&&g(t,{debugPath:`(transformed) ${r}`}),t}function it(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Y(r,t,{out_point:et(tt),dep_type:K}),e&&d(t,{debugPath:`(transformed) ${r}`}),t}function ot(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function at(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K),witnesses:ot(K)}),e&&m(t,{debugPath:`(transformed) ${r}`}),t}function st(t,{validation:e=!0,debugPath:r="header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K,nonce:K}),e&&k(t,{debugPath:`(transformed) ${r}`}),t}function ut(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Y(r,t,{header:et(st),proposals:ot(K)}),e&&B(t,{debugPath:`(transformed) ${r}`}),t}var _t=Object.freeze({__proto__:null,TransformScript:Z,TransformOutPoint:tt,TransformCellInput:rt,TransformCellOutput:nt,TransformCellDep:it,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K)}),e&&b(t,{debugPath:`(transformed) ${r}`}),t},TransformTransaction:at,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K}),e&&w(t,{debugPath:`(transformed) ${r}`}),t},TransformHeader:st,TransformUncleBlock:ut,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Y(r,t,{header:et(st),uncles:ot(et(ut)),transactions:ot(et(at)),proposals:ot(K)}),e&&P(t,{debugPath:`(transformed) ${r}`}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Y(r,t,{lock:et(Z),message:K}),e&&T(t,{debugPath:`(transformed) ${r}`}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Y(r,t,{lock:K,input_type:K,output_type:K}),e&&A(t,{debugPath:`(transformed) ${r}`}),t}});var lt=Object.freeze({__proto__:null,RPCCollector:class{constructor(t,e,{skipCellWithContent:r=!0,loadData:i=!1}={}){this.rpc=t,this.lockHash=new n(e).serializeJson(),this.skipCellWithContent=r,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,I(e),I(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))}}}});t.BigIntToHexString=I,t.HexStringToBigInt=$,t.RPC=C,t.Reader=n,t.TransactionDumper=class{constructor(t,{validateTransaction:e=!0,depGroupUnpacker:r=null}={}){this.rpc=t,this.validateTransaction=e,this.depGroupUnpacker=r}async dumpByHash(t){const e=(await this.rpc.get_transaction(t)).transaction;return delete e.hash,await this.dump(e)}async dump(t){this.validateTransaction&&m(t);const e=[];for(const r of t.inputs){const{output:t,data:n,header:i}=await this._resolveOutPoint(r.previous_output);e.push({input:r,output:t,data:n,header:i})}const r=[];for(const e of t.cell_deps){const{output:t,data:i,header:o}=await this._resolveOutPoint(e.out_point);if(r.push({cell_dep:e,output:t,data:i,header:o}),"dep_group"===e.dep_type){if(!this.depGroupUnpacker)throw new Error("depGroupUnpacker must be provided when the transaction contains dep_group!");const t=this.depGroupUnpacker(new n(i));for(const e of t){h(e);const{output:t,data:n,header:i}=await this._resolveOutPoint(e);r.push({cell_dep:{out_point:e,dep_type:"code"},output:t,data:n,header:i})}}}const i=[];for(const e of t.header_deps)i.push(await this.rpc.get_header(e));return JSON.stringify({mock_info:{inputs:e,cell_deps:r,header_deps:i},tx:t})}async _resolveOutPoint(t){const e=await this.rpc.get_transaction(t.tx_hash);if(!e||!e.transaction)throw new Error(`Transaction ${t.tx_hash} cannot be found!`);const r=e.transaction,n=a.toNumber(a.BigInt(t.index));if(n>=r.outputs.length)throw new Error(`Transaction ${t.tx_hash} does not have output ${n}!`);const i={output:r.outputs[n],data:r.outputs_data[n]};return"committed"===e.tx_status.status&&(i.header=e.tx_status.block_hash),i}},t.VERSION="0.9.1",t.cell_collectors=lt,t.normalizers=Q,t.transformers=_t,t.validators=S,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CKBJSToolkit={})}(this,(function(t){"use strict";class e{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 r{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 n{constructor(t){if(t instanceof r||t instanceof e)return t;if("string"==typeof t){if(!t.startsWith("0x")||t.length%2!=0)throw new Error("Hex string must start with 0x, and has even numbered length!");return new r(t)}if(t instanceof ArrayBuffer)return new e(t);throw new Error("Reader can only accept hex string or ArrayBuffer!")}static fromRawString(t){const r=new ArrayBuffer(t.length),n=new DataView(r);for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r>255)throw new Error("fromRawString can only accept UTF-8 raw string!");n.setUint8(e,r)}return new e(r)}}var i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}var a=o((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){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(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 n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(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&&a(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(){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 u(){return(u=s()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&a(i,r.prototype),i}).apply(null,arguments)}function _(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function l(t){var e="function"==typeof Map?new Map:void 0;return(l=function(t){function r(){return u(t,arguments,o(this).constructor)}if(null===t||!_(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}}),a(r,t)})(t)}function f(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function h(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?f(t):e}var c=function(r){var a=Math.abs,s=Math.max,u=Math.imul,_=Math.clz32;function l(t,r){var n;if(e(this,l),t>l.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");return(n=h(this,o(l).call(this,t))).sign=r,n}return i(l,r),n(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 _(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,s=e>>>16,_=0;_<r;_++){var l=this.__digit(_),f=65535&l,h=l>>>16,c=u(f,n),g=u(f,i),d=u(h,n),p=u(h,i),v=a+(65535&c),y=s+o+(v>>>16)+(c>>>16)+(65535&g)+(65535&d);o=(a=(g>>>16)+(d>>>16)+(65535&p)+(y>>>16))>>>16,a&=65535,s=p>>>16,this.__setDigit(_,65535&v|y<<16)}if(0!==o||0!==a||0!==s)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=_(n),o=32*e-i;if(1024<o)return t.sign?-1/0:1/0;var a=o-1,s=n,u=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<u&&(u--,h|=(s=t.__digit(u))>>>32-c,g=s<<c,d=c),0<d&&0<u&&(u--,g|=(s=t.__digit(u))>>>32-d,d-=32);var p=l.__decideRounding(t,d,u,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=s(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=s(t.length,e.length),n=l.__absoluteSubOne(t,r),i=l.__absoluteSubOne(e);return l.__absoluteXor(n,i,n).__trim()}var o=s(t.length,e.length)+1;if(t.sign){var a=[e,t];t=a[0],e=a[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=s(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 a=l.__absoluteSubOne(e,r);return a=l.__absoluteAndNot(a,t,a),l.__absoluteAddOne(a,!0,a).__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=20,u=31&r,_=0;if(u<s){var f=s-u;_=f+32,e=o>>>f,o=o<<32-f|a>>>f,a<<=32-f}else if(u===s)_=32,e=o,o=a;else{var h=u-s;_=32-h,e=o<<h|a>>>32-h,o=a<<h}i.__setDigit(n-1,e);for(var c=n-2;0<=c;c--)0<_?(_-=32,e=o,o=a):e=0,i.__setDigit(c,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 _=new l(31+(s*a+u>>>l.__kBitsPerCharTableShift)>>>5,!1),f=10>e?e:10,h=10<e?e-10:0;if(0==(e&e-1)){s>>=l.__kBitsPerCharTableShift;var c=[],g=[],d=!1;do{for(var p,v=0,y=0;;){if(p=void 0,o-48>>>0<f)p=o-48;else{if(!((32|o)-97>>>0<h)){d=!0;break}p=(32|o)-87}if(y+=s,v=v<<s|p,++i===n){d=!0;break}if(o=t.charCodeAt(i),32<y+s)break}c.push(v),g.push(y)}while(!d);l.__fillFromParts(_,c,g)}else{_.__initializeDigits();var b=!1,m=0;do{for(var w,k=0,D=1;;){if(w=void 0,o-48>>>0<f)w=o-48;else{if(!((32|o)-97>>>0<h)){b=!0;break}w=(32|o)-87}var B=D*e;if(4294967295<B)break;if(D=B,k=k*e+w,m++,++i===n){b=!0;break}o=t.charCodeAt(i)}var P=s*m+(u=32*l.__kBitsPerCharTableMultiplier-1)>>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(D,k,P)}while(!b)}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:(_.sign=-1===r,_.__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-_(a)+i-1)/i;if(t.sign&&s++,268435456<s)throw new Error("string too long");for(var u=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;u[f--]=l.__kConversionChars[p];var v=i-c;for(h=d>>>v,c=32-v;c>=i;)u[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var y=(h|a<<c)&o;for(u[f--]=l.__kConversionChars[y],h=a>>>i-c;0!==h;)u[f--]=l.__kConversionChars[h&o],h>>>=i;if(t.sign&&(u[f--]="-"),-1!==f)throw new Error("implementation bug");return u.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-_(t.__digit(n-1)),u=l.__kMaxBitsPerChar[e]-1,f=s*l.__kBitsPerCharTableMultiplier,h=1+(f=0|(f+=u-1)/u)>>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=a(e),o=t.__unsignedDigit(0);return o>i?l.__absoluteGreater(r):o<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=_(a),u=32*o-s,f=i+1;if(u<f)return l.__absoluteLess(r);if(u>f)return l.__absoluteGreater(r);var h=1048576|1048575&l.__kBitConversionInts[1],c=l.__kBitConversionInts[0],g=20,d=31-s;if(d!==(u-1)%31)throw new Error("implementation bug");var p,v=0;if(d<g){var y=g-d;v=y+32,p=h>>>y,h=h<<32-y|c>>>y,c<<=32-y}else if(d===g)v=32,p=h,h=c;else{var b=d-g;v=32-b,p=h<<b|c>>>32-b,h=c<<b}if((a>>>=0)>(p>>>=0))return l.__absoluteGreater(r);if(a<p)return l.__absoluteLess(r);for(var m=o-2;0<=m;m--){0<v?(v-=32,p=h>>>0,h=c,c=0):p=0;var w=t.__unsignedDigit(m);if(w>p)return l.__absoluteGreater(r);if(w<p)return l.__absoluteLess(r)}if(0!==h||0!==c){if(0===v)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)===a(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,s=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=u(d,i),y=u(d,o),b=u(p,i),m=u(p,o);a=(s=(y>>>16)+(b>>>16)+(65535&m)+(a=(c+=_+a+((h+=s+(65535&v))>>>16)+(v>>>16)+(65535&y)+(65535&b))>>>16))>>>16,s&=65535,_=m>>>16,f=65535&h|c<<16,r.__setDigit(n,f)}for(;0!==a||0!==s||0!==_;n++){var w=r.__digit(n),k=(65535&w)+s,D=(w>>>16)+(k>>>16)+_+a;s=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,s=0;s<n;s++){var _=t.__digit(s),l=u(65535&_,e),f=(65535&l)+a+o;o=f>>>16;var h=u(_>>>16,e),c=(65535&h)+(l>>>16)+o;o=c>>>16,a=h>>>16,i.__setDigit(s,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,s=null;r&&(s=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);u(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:s.__setDigit(d>>>1,g|p))}return n?(h.__inplaceRightShift(f),r?{quotient:s,remainder:h}:h):r?s:void 0}},{key:"__clz16",value:function(t){return _(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}(l(Array));return c.__kMaxLength=33554432,c.__kMaxLengthBits=c.__kMaxLength<<5,c.__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],c.__kBitsPerCharTableShift=5,c.__kBitsPerCharTableMultiplier=1<<c.__kBitsPerCharTableShift,c.__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"],c.__kBitConversionBuffer=new ArrayBuffer(8),c.__kBitConversionDouble=new Float64Array(c.__kBitConversionBuffer),c.__kBitConversionInts=new Int32Array(c.__kBitConversionBuffer),c}()}));function s(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 u(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(t+" must be a hex string!")}function _(t,e){if(u(t,e),66!=e.length)throw new Error(t+" must be a hex string of 66 bytes long!")}function l(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 f(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(s(r,t,["code_hash","hash_type","args"],[]),_(r+".code_hash",t.code_hash),u(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 h(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){s(r,t,["tx_hash","index"],[]),_(r+".tx_hash",t.tx_hash),l(r+".index",t.index)}function c(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){s(r,t,["since","previous_output"],[]),l(r+".since",t.since),e&&h(t.previous_output,{debugPath:r+".previous_output"})}function g(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){s(r,t,["capacity","lock"],["type"]),l(r+".capacity",t.capacity),e&&(f(t.lock,{debugPath:r+".lock"}),t.type&&f(t.type,{debugPath:r+".type"}))}function d(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(s(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&&h(t.out_point,{debugPath:r+".out_point"})}function p(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 v(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function y(t,e,r){l(t+".version",e.version),p(t+".cell_deps",e.cell_deps,v(d,r),r),p(t+".header_deps",e.header_deps,_,r),p(t+".inputs",e.inputs,v(c,r),r),p(t+".outputs",e.outputs,v(g,r),r),p(t+".outputs_data",e.outputs_data,u,r)}function b(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){s(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),y(r,t,e)}function m(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){s(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),y(r,t,e),p(r+".witnesses",t.witnesses,u,e)}function w(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){s(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){l(t+".version",e.version),l(t+".compact_target",e.compact_target),l(t+".timestamp",e.timestamp),l(t+".number",e.number),l(t+".epoch",e.epoch),_(t+".parent_hash",e.parent_hash),_(t+".transactions_root",e.transactions_root),_(t+".proposals_hash",e.proposals_hash),_(t+".uncles_hash",e.uncles_hash),_(t+".dao",e.dao)}(r,t)}function k(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(s(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),u(r+".nonce",t.nonce),34!=t.nonce.length)throw new Error(r+".nonce must be a hex string of 34 bytes long!")}function D(t,e){if(u(t,e),22!=e.length)throw new Error(t+" must be a hex string of 22 bytes long!")}function B(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){s(r,t,["header","proposals"],[]),e&&k(t.header,{debugPath:r+".header"}),p(r+".proposals",t.proposals,D,e)}function P(t,{nestedValidation:e=!0,debugPath:r="block"}={}){s(r,t,["header","uncles","transactions","proposals"],[]),e&&k(t.header,{debugPath:r+".header"}),p(r+".uncles",t.uncles,v(B,e),e),p(r+".transactions",t.transactions,v(m,e),e),p(r+".proposals",t.proposals,D,e)}function T(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){s(r,t,["lock","message"],[]),u(r+".message",t.message),e&&f(t.lock,{debugPath:r+".lock"})}function A(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){s(r,t,[],["lock","input_type","output_type"]),t.lock&&u(r+".lock",t.lock),t.input_type&&u(r+".input_type",t.input_type),t.output_type&&u(r+".output_type",t.output_type)}var E=Object.freeze({__proto__:null,ValidateScript:f,ValidateOutPoint:h,ValidateCellInput:c,ValidateCellOutput:g,ValidateCellDep:d,ValidateRawTransaction:b,ValidateTransaction:m,ValidateRawHeader:w,ValidateHeader:k,ValidateUncleBlock:B,ValidateBlock:P,ValidateCellbaseWitness:T,ValidateWitnessArgs:A});var S=o((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:i);!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}));const x={get:(t,e,r)=>"send"===e?async()=>{const e=await S(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)});return await e.json()}:(...n)=>{const i=t.id;return t.id=t.id+1,t.payload.push({jsonrpc:"2.0",id:i,method:e,params:n}),r}},O={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri},x):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await S(t.uri,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})}),o=await i.json();if(o.id!==n)throw new Error("JSONRPCError: response ID does not match request ID!");if(o.error)throw new Error("JSONRPCError: server error "+JSON.stringify(o.error));return o.result}};class C{constructor(t){return this.uri=t,new Proxy(this,O)}static create(t){return new C(t)}}function I(t){return a.BigInt(t)}function R(t){return"0x"+t.toString(16)}function j(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=R(a.BigInt(r)).substr(2);if(n.length%2!=0&&(n="0"+n),n.length/2>t)throw new Error(`${e} is ${n.length/2} bytes long, expected length is ${t}!`);const i=new DataView(new ArrayBuffer(t));for(let t=0;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function z(t){return function(e,r){if(r=new n(r).toArrayBuffer(),t>0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function M(t,e,r){const n={};for(const[i,o]of Object.entries(r)){const r=e[i];if(!r)throw new Error(`${t} is missing ${i}!`);n[i]=o(`${t}.${i}`,r)}return n}function N(t,{debugPath:e="script"}={}){return M(e,t,{code_hash:z(32),hash_type:function(t,e){switch(e){case"data":return 0;case"type":return 1;case 0:case 1:return e;default:throw new Error(`${t}.hash_type has invalid value: ${e}`)}},args:z(-1)})}function L(t,{debugPath:e="out_point"}={}){return M(e,t,{tx_hash:z(32),index:j(4)})}function U(t){return function(e,r){return t(r,{debugPath:e})}}function V(t,{debugPath:e="cell_input"}={}){return M(e,t,{since:j(8),previous_output:U(L)})}function q(t,{debugPath:e="cell_output"}={}){const r=M(e,t,{capacity:j(8),lock:U(N)});return t.type&&(r.type_=N(t.type,{debugPath:e+".type"})),r}function $(t,{debugPath:e="cell_dep"}={}){return M(e,t,{out_point:U(L),dep_type:function(t,e){switch(e){case"code":return 0;case"dep_group":return 1;case 0:case 1:return e;default:throw new Error(`${t}.dep_type has invalid value: ${e}`)}}})}function F(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function H(t,{debugPath:e="raw_transaction"}={}){return M(e,t,{version:j(4),cell_deps:F(U($)),header_deps:F(z(32)),inputs:F(U(V)),outputs:F(U(q)),outputs_data:F(z(-1))})}function G(t,{debugPath:e="transaction"}={}){const r=H(t,{debugPath:"(raw)"+e}),n=M(e,t,{witnesses:F(z(-1))});return n.raw=r,n}function W(t,{debugPath:e="raw_header"}={}){return M(e,t,{version:j(4),compact_target:j(4),timestamp:j(8),number:j(8),epoch:j(8),parent_hash:z(32),transactions_root:z(32),proposals_hash:z(32),uncles_hash:z(32),dao:z(32)})}function J(t,{debugPath:e="header"}={}){const r=W(t,{debugPath:"(raw)"+e}),n=M(e,t,{nonce:j(16)});return n.raw=r,n}function X(t,{debugPath:e="uncle_block"}={}){return M(e,t,{header:U(J),proposals:F(z(10))})}var Q=Object.freeze({__proto__:null,NormalizeScript:N,NormalizeOutPoint:L,NormalizeCellInput:V,NormalizeCellOutput:q,NormalizeCellDep:$,NormalizeRawTransaction:H,NormalizeTransaction:G,NormalizeRawHeader:W,NormalizeHeader:J,NormalizeUncleBlock:X,NormalizeBlock:function(t,{debugPath:e="block"}={}){return M(e,t,{header:U(J),uncles:F(U(X)),transactions:F(U(G)),proposals:F(z(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return M(e,t,{lock:U(N),message:z(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=z(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=z(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=z(-1)(e+".output_type",t.output_type)),r}});function K(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Y(t,e,r){if(!((e=K(0,e))instanceof Object))throw new Error(`Transformed ${t} is not an object!`);const n={};for(const[i,o]of Object.entries(r)){let r=e[i];if(!r){r=e[i.replace(/(_[a-z])/g,t=>t.toUpperCase().replace("_",""))]}r&&(n[i]=o(`${t}.${i}`,r))}return n}function Z(t,{validation:e=!0,debugPath:r="script"}={}){return t=Y(r,t,{code_hash:K,hash_type:K,args:K}),e&&f(t,{debugPath:"(transformed) "+r}),t}function tt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Y(r,t,{tx_hash:K,index:K}),e&&h(t,{debugPath:"(transformed) "+r}),t}function et(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function rt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Y(r,t,{since:K,previous_output:et(tt)}),e&&c(t,{debugPath:"(transformed) "+r}),t}function nt(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Y(r,t,{capacity:K,lock:et(Z),type:et(Z)}),e&&g(t,{debugPath:"(transformed) "+r}),t}function it(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Y(r,t,{out_point:et(tt),dep_type:K}),e&&d(t,{debugPath:"(transformed) "+r}),t}function ot(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function at(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K),witnesses:ot(K)}),e&&m(t,{debugPath:"(transformed) "+r}),t}function st(t,{validation:e=!0,debugPath:r="header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K,nonce:K}),e&&k(t,{debugPath:"(transformed) "+r}),t}function ut(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Y(r,t,{header:et(st),proposals:ot(K)}),e&&B(t,{debugPath:"(transformed) "+r}),t}var _t=Object.freeze({__proto__:null,TransformScript:Z,TransformOutPoint:tt,TransformCellInput:rt,TransformCellOutput:nt,TransformCellDep:it,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Y(r,t,{version:K,cell_deps:ot(et(it)),header_deps:ot(K),inputs:ot(et(rt)),outputs:ot(et(nt)),outputs_data:ot(K)}),e&&b(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:at,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Y(r,t,{version:K,compact_target:K,timestamp:K,number:K,epoch:K,parent_hash:K,transactions_root:K,proposals_hash:K,uncles_hash:K,dao:K}),e&&w(t,{debugPath:"(transformed) "+r}),t},TransformHeader:st,TransformUncleBlock:ut,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Y(r,t,{header:et(st),uncles:ot(et(ut)),transactions:ot(et(at)),proposals:ot(K)}),e&&P(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Y(r,t,{lock:et(Z),message:K}),e&&T(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Y(r,t,{lock:K,input_type:K,output_type:K}),e&&A(t,{debugPath:"(transformed) "+r}),t}});var lt=Object.freeze({__proto__:null,RPCCollector:class{constructor(t,e,{skipCellWithContent:r=!0,loadData:i=!1,loadBlockNumber:o=!0}={}){this.rpc=t,this.lockHash=new n(e).serializeJson(),this.skipCellWithContent=r,this.loadData=i,this.loadBlockNumber=o}async*collect(){const t=I(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,R(e),R(r));for(const t of n){if(this.skipCellWithContent&&(t.type||a.greaterThan(I(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}let r=null;if(this.loadBlockNumber){r=(await this.rpc.get_header(t.block_hash)).number}yield{cellbase:t.cellbase,cell_output:{capacity:t.capacity,lock:t.lock,type:t.type},out_point:t.out_point,block_hash:t.block_hash,data:e,output_data_len:t.output_data_len,block_number:r}}e=a.add(r,a.BigInt(1))}}}});t.BigIntToHexString=R,t.HexStringToBigInt=I,t.RPC=C,t.Reader=n,t.TransactionDumper=class{constructor(t,{validateTransaction:e=!0,depGroupUnpacker:r=null}={}){this.rpc=t,this.validateTransaction=e,this.depGroupUnpacker=r}async dumpByHash(t){const e=(await this.rpc.get_transaction(t)).transaction;return delete e.hash,await this.dump(e)}async dump(t){this.validateTransaction&&m(t);const e=[];for(const r of t.inputs){const{output:t,data:n,header:i}=await this._resolveOutPoint(r.previous_output);e.push({input:r,output:t,data:n,header:i})}const r=[];for(const e of t.cell_deps){const{output:t,data:i,header:o}=await this._resolveOutPoint(e.out_point);if(r.push({cell_dep:e,output:t,data:i,header:o}),"dep_group"===e.dep_type){if(!this.depGroupUnpacker)throw new Error("depGroupUnpacker must be provided when the transaction contains dep_group!");const t=this.depGroupUnpacker(new n(i));for(const e of t){h(e);const{output:t,data:n,header:i}=await this._resolveOutPoint(e);r.push({cell_dep:{out_point:e,dep_type:"code"},output:t,data:n,header:i})}}}const i=[];for(const e of t.header_deps)i.push(await this.rpc.get_header(e));return JSON.stringify({mock_info:{inputs:e,cell_deps:r,header_deps:i},tx:t})}async _resolveOutPoint(t){const e=await this.rpc.get_transaction(t.tx_hash);if(!e||!e.transaction)throw new Error(`Transaction ${t.tx_hash} cannot be found!`);const r=e.transaction,n=a.toNumber(a.BigInt(t.index));if(n>=r.outputs.length)throw new Error(`Transaction ${t.tx_hash} does not have output ${n}!`);const i={output:r.outputs[n],data:r.outputs_data[n]};return"committed"===e.tx_status.status&&(i.header=e.tx_status.block_hash),i}},t.VERSION="0.9.2",t.cell_collectors=lt,t.normalizers=Q,t.transformers=_t,t.validators=E,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -126,2 +126,3 @@ import JSBI from "jsbi";

data?: string;
block_number?: string;
}

@@ -128,0 +129,0 @@

{
"name": "ckb-js-toolkit",
"version": "0.9.1",
"version": "0.9.2",
"description": "JavaScript toolkits used to build dapps for Nervos CKB",

@@ -25,14 +25,14 @@ "main": "dist/ckb-js-toolkit.node.js",

"dependencies": {
"cross-fetch": "^3.0.4",
"cross-fetch": "^3.0.6",
"jsbi": "^3.1.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"ava": "^3.5.0",
"prettier": "1.19.1",
"rollup": "^1.32.0",
"rollup-plugin-terser": "^5.2.0"
"rollup": "^2.22.0",
"rollup-plugin-terser": "^7.0.2"
}
}

@@ -167,3 +167,3 @@ ckb-js-toolkit

> const transaction = (await rpc.get_transaction("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c")).transaction
> toolkit.validators.ValidateTransaction(tx.transaction)
> toolkit.validators.ValidateTransaction(transaction)
Uncaught:

@@ -415,3 +415,4 @@ Error: transaction does not have correct keys! Required keys: [cell_deps, header_deps, inputs, outputs, outputs_data, version, witnesses], optional keys: [], actual keys: [cell_deps, hash, header_deps, inputs, outputs, outputs_data, version, witnesses]

block_hash: '0x92b197aa1fba0f63633922c61c92375c9c074a93e85963554f5499fe1450d0e5',
data: null
data: null,
block_number: '0x0'
}

@@ -418,0 +419,0 @@ ```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc