diff --git a/dist/ckb-js-toolkit.esm.js b/dist/ckb-js-toolkit.esm.js index b3260d1..a4241c8 100644 --- a/dist/ckb-js-toolkit.esm.js +++ b/dist/ckb-js-toolkit.esm.js @@ -1 +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;t255)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;nl.__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=0t||36this.length&&(r=this.length);for(var n=65535&t,i=t>>>16,o=0,a=65535&e,s=e>>>16,_=0;_>>16,c=u(f,n),g=u(f,i),d=u(h,n),p=u(h,i),v=a+(65535&c),b=s+o+(v>>>16)+(c>>>16)+(65535&g)+(65535&d);o=(a=(g>>>16)+(d>>>16)+(65535&p)+(b>>>16))>>>16,a&=65535,s=p>>>16,this.__setDigit(_,65535&v|b<<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>>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>>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>>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),b=(65535&p)-(65535&v)-n;n=1&b>>>16;var y=0;0==(1&r)&&(n=1&(y=(p>>>16)-(v>>>16)-n)>>>16),this.__setDigit(e+f,y<<16|65535&b)}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>>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>>=12;var c=f-12,g=12<=f?0:s<<20+f,d=20+f;0>>32-c,g=s<>>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=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;il.__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.__kMaxLengthBits)return e;var r=t+31>>>5;if(e.lengthl.__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>>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(0e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}var o=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>>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<>>32-h,o=a<=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=11073741824/s)return null;var _=new l(31+(s*a+u>>>l.__kBitsPerCharTableShift)>>>5,!1),f=10>e?e:10,h=10>=l.__kBitsPerCharTableShift;var c=[],g=[],d=!1;do{for(var p,v=0,b=0;;){if(p=void 0,o-48>>>0>>0>>0>>0>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(D,k,P)}while(!y)}if(i!==n){if(!l.__isWhitespace(o))return null;for(i++;i>>u-(o-=32))}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;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>>v,c=32-v;c>=i;)u[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var b=(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 b=l.__absoluteDivLarge(t,c,!0,!0);o=b.quotient;var y=b.remainder.__trim();a=l.__toStringGeneric(y,e,!0)}o.__trim();for(var m=l.__toStringGeneric(o,e,!0);a.lengthn?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(1i?l.__absoluteGreater(r):oe)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(uf)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>>b,h=h<<32-b|c>>>b,c<<=32-b}else if(d===g)v=32,p=h,h=c;else{var y=d-g;v=32-y,p=h<>>32-y,h=c<>>=0)>(p>>>=0))return l.__absoluteGreater(r);if(a>>0,h=c,c=0):p=0;var w=t.__unsignedDigit(m);if(w>p)return l.__absoluteGreater(r);if(we&&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 0e;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?te:3===r?t>=e:void 0}},{key:"__absoluteAdd",value:function(t,e,r){if(t.length>>16)+(s>>>16)+(_>>>16);o=f>>>16,i.__setDigit(a,65535&_|f<<16)}for(;a>>16)+(c>>>16);o=g>>>16,i.__setDigit(a,65535&c|g<<16)}return a>>16)-(s>>>16)-(i=1&u>>>16);i=1&_>>>16,n.__setDigit(o,65535&u|_<<16)}for(;o>>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=2n?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>>16,g=t.__digit(l),d=65535&g,p=g>>>16,v=u(d,i),b=u(d,o),y=u(p,i),m=u(p,o);a=(s=(b>>>16)+(y>>>16)+(65535&m)+(a=(c+=_+a+((h+=s+(65535&v))>>>16)+(v>>>16)+(65535&b)+(65535&y))>>>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>>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>>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>>0;p=0|b/c;for(var y=0|b%c,m=e.__halfDigit(i-2),w=h.__halfDigit(d+i-2);u(p,m)>>>0>(y<<16|w)>>>0&&(p--,!(65535<(y+=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>>32-e;return 0r)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;_>>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,d=r-o-1,p=0;p>>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(1l.__kMaxLengthBits?-1:e}},{key:"__toPrimitive",value:function(e){var r=1>>5,n=new l(r,e.sign),i=r-1,o=0;o>>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>>16)-(u=1&v>>>16)<<16}else{var b=32-p,y=1<<32-b,m=(65535&y)-(65535&(d=d<>>b))-u;g=65535&m|(y>>>16)-(d>>>16)-(u=1&m>>>16)<<16,g&=y-1}return o.__setDigit(s,g),o.__trim()}},{key:"__digitPow",value:function(t,e){for(var r=1;0>>=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<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"}={}){a(r,t,["code_hash","hash_type","args"],[]),u(r+".code_hash",t.code_hash),s(r+".args",t.args);if("type"!==t.hash_type&&!/^data([1-9][0-9]*)?$/.test(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=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-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)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},v.call(y.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 y(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=y,t.Response=w),e.Headers=h,e.Request=y,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}));function x(t,e){e=e||{};const r=Object.assign({},e.headers||{},t.headers||{});return Object.assign({},e,t,{headers:r})}const O={get:(t,e,r)=>"send"===e?async()=>{const e=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)},t.defaultOptions));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}},C={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri,defaultOptions:t.defaultOptions},O):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})},t.defaultOptions)),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 I{constructor(t,e={},r=S){return this.uri=t,this.defaultOptions=e,this.fetch=r,new Proxy(this,C)}static create(t){return new I(t)}}function j(t){return o.BigInt(t)}function R(t){return"0x"+t.toString(16)}function z(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=R(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;t0&&n.byteLength!==t)throw new Error(`${e} has invalid length ${n.byteLength}, required: ${t}`);return n}}function N(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 L(t,{debugPath:e="script"}={}){return N(e,t,{code_hash:M(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:M(-1)})}function U(t,{debugPath:e="out_point"}={}){return N(e,t,{tx_hash:M(32),index:z(4)})}function $(t){return function(e,r){return t(r,{debugPath:e})}}function q(t,{debugPath:e="cell_input"}={}){return N(e,t,{since:z(8),previous_output:$(U)})}function V(t,{debugPath:e="cell_output"}={}){const r=N(e,t,{capacity:z(8),lock:$(L)});return t.type&&(r.type_=L(t.type,{debugPath:e+".type"})),r}function F(t,{debugPath:e="cell_dep"}={}){return N(e,t,{out_point:$(U),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 G(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function H(t,{debugPath:e="raw_transaction"}={}){return N(e,t,{version:z(4),cell_deps:G($(F)),header_deps:G(M(32)),inputs:G($(q)),outputs:G($(V)),outputs_data:G(M(-1))})}function W(t,{debugPath:e="transaction"}={}){const r=H(t,{debugPath:"(raw)"+e}),n=N(e,t,{witnesses:G(M(-1))});return n.raw=r,n}function J(t,{debugPath:e="raw_header"}={}){return N(e,t,{version:z(4),compact_target:z(4),timestamp:z(8),number:z(8),epoch:z(8),parent_hash:M(32),transactions_root:M(32),proposals_hash:M(32),uncles_hash:M(32),dao:M(32)})}function X(t,{debugPath:e="header"}={}){const r=J(t,{debugPath:"(raw)"+e}),n=N(e,t,{nonce:z(16)});return n.raw=r,n}function Q(t,{debugPath:e="uncle_block"}={}){return N(e,t,{header:$(X),proposals:G(M(10))})}var K=Object.freeze({__proto__:null,NormalizeScript:L,NormalizeOutPoint:U,NormalizeCellInput:q,NormalizeCellOutput:V,NormalizeCellDep:F,NormalizeRawTransaction:H,NormalizeTransaction:W,NormalizeRawHeader:J,NormalizeHeader:X,NormalizeUncleBlock:Q,NormalizeBlock:function(t,{debugPath:e="block"}={}){return N(e,t,{header:$(X),uncles:G($(Q)),transactions:G($(W)),proposals:G(M(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return N(e,t,{lock:$(L),message:M(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=M(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=M(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=M(-1)(e+".output_type",t.output_type)),r}});function Y(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Z(t,e,r){if(!((e=Y(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 tt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Z(r,t,{code_hash:Y,hash_type:Y,args:Y}),e&&l(t,{debugPath:"(transformed) "+r}),t}function et(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Z(r,t,{tx_hash:Y,index:Y}),e&&f(t,{debugPath:"(transformed) "+r}),t}function rt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function nt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Z(r,t,{since:Y,previous_output:rt(et)}),e&&h(t,{debugPath:"(transformed) "+r}),t}function it(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Z(r,t,{capacity:Y,lock:rt(tt),type:rt(tt)}),e&&c(t,{debugPath:"(transformed) "+r}),t}function ot(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Z(r,t,{out_point:rt(et),dep_type:Y}),e&&g(t,{debugPath:"(transformed) "+r}),t}function at(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function st(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y),witnesses:at(Y)}),e&&y(t,{debugPath:"(transformed) "+r}),t}function ut(t,{validation:e=!0,debugPath:r="header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y,nonce:Y}),e&&w(t,{debugPath:"(transformed) "+r}),t}function _t(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Z(r,t,{header:rt(ut),proposals:at(Y)}),e&&D(t,{debugPath:"(transformed) "+r}),t}var lt=Object.freeze({__proto__:null,TransformScript:tt,TransformOutPoint:et,TransformCellInput:nt,TransformCellOutput:it,TransformCellDep:ot,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y)}),e&&b(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:st,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y}),e&&m(t,{debugPath:"(transformed) "+r}),t},TransformHeader:ut,TransformUncleBlock:_t,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Z(r,t,{header:rt(ut),uncles:at(rt(_t)),transactions:at(rt(st)),proposals:at(Y)}),e&&B(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Z(r,t,{lock:rt(tt),message:Y}),e&&P(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Z(r,t,{lock:Y,input_type:Y,output_type:Y}),e&&A(t,{debugPath:"(transformed) "+r}),t}});var ft=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=j(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,R(e),R(r));for(const t of n){if(this.skipCellWithContent&&(t.type||o.greaterThan(j(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 ht="0.11.0";export{R as BigIntToHexString,j as HexStringToBigInt,I as RPC,r as Reader,E as TransactionDumper,ht as VERSION,ft as cell_collectors,K as normalizers,lt 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;t255)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;nl.__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=0t||36this.length&&(r=this.length);for(var n=65535&t,i=t>>>16,o=0,a=65535&e,s=e>>>16,_=0;_>>16,c=u(f,n),g=u(f,i),d=u(h,n),p=u(h,i),v=a+(65535&c),b=s+o+(v>>>16)+(c>>>16)+(65535&g)+(65535&d);o=(a=(g>>>16)+(d>>>16)+(65535&p)+(b>>>16))>>>16,a&=65535,s=p>>>16,this.__setDigit(_,65535&v|b<<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>>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>>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>>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),b=(65535&p)-(65535&v)-n;n=1&b>>>16;var y=0;0==(1&r)&&(n=1&(y=(p>>>16)-(v>>>16)-n)>>>16),this.__setDigit(e+f,y<<16|65535&b)}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>>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>>=12;var c=f-12,g=12<=f?0:s<<20+f,d=20+f;0>>32-c,g=s<>>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=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;il.__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.__kMaxLengthBits)return e;var r=t+31>>>5;if(e.lengthl.__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>>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(0e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}var o=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>>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<>>32-h,o=a<=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=11073741824/s)return null;var _=new l(31+(s*a+u>>>l.__kBitsPerCharTableShift)>>>5,!1),f=10>e?e:10,h=10>=l.__kBitsPerCharTableShift;var c=[],g=[],d=!1;do{for(var p,v=0,b=0;;){if(p=void 0,o-48>>>0>>0>>0>>0>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(D,k,P)}while(!y)}if(i!==n){if(!l.__isWhitespace(o))return null;for(i++;i>>u-(o-=32))}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;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>>v,c=32-v;c>=i;)u[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var b=(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 b=l.__absoluteDivLarge(t,c,!0,!0);o=b.quotient;var y=b.remainder.__trim();a=l.__toStringGeneric(y,e,!0)}o.__trim();for(var m=l.__toStringGeneric(o,e,!0);a.lengthn?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(1i?l.__absoluteGreater(r):oe)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(uf)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>>b,h=h<<32-b|c>>>b,c<<=32-b}else if(d===g)v=32,p=h,h=c;else{var y=d-g;v=32-y,p=h<>>32-y,h=c<>>=0)>(p>>>=0))return l.__absoluteGreater(r);if(a>>0,h=c,c=0):p=0;var w=t.__unsignedDigit(m);if(w>p)return l.__absoluteGreater(r);if(we&&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 0e;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?te:3===r?t>=e:void 0}},{key:"__absoluteAdd",value:function(t,e,r){if(t.length>>16)+(s>>>16)+(_>>>16);o=f>>>16,i.__setDigit(a,65535&_|f<<16)}for(;a>>16)+(c>>>16);o=g>>>16,i.__setDigit(a,65535&c|g<<16)}return a>>16)-(s>>>16)-(i=1&u>>>16);i=1&_>>>16,n.__setDigit(o,65535&u|_<<16)}for(;o>>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=2n?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>>16,g=t.__digit(l),d=65535&g,p=g>>>16,v=u(d,i),b=u(d,o),y=u(p,i),m=u(p,o);a=(s=(b>>>16)+(y>>>16)+(65535&m)+(a=(c+=_+a+((h+=s+(65535&v))>>>16)+(v>>>16)+(65535&b)+(65535&y))>>>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>>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>>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>>0;p=0|b/c;for(var y=0|b%c,m=e.__halfDigit(i-2),w=h.__halfDigit(d+i-2);u(p,m)>>>0>(y<<16|w)>>>0&&(p--,!(65535<(y+=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>>32-e;return 0r)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;_>>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,d=r-o-1,p=0;p>>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(1l.__kMaxLengthBits?-1:e}},{key:"__toPrimitive",value:function(e){var r=1>>5,n=new l(r,e.sign),i=r-1,o=0;o>>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>>16)-(u=1&v>>>16)<<16}else{var b=32-p,y=1<<32-b,m=(65535&y)-(65535&(d=d<>>b))-u;g=65535&m|(y>>>16)-(d>>>16)-(u=1&m>>>16)<<16,g&=y-1}return o.__setDigit(s,g),o.__trim()}},{key:"__digitPow",value:function(t,e){for(var r=1;0>>=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<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"}={}){a(r,t,["code_hash","hash_type","args"],[]),u(r+".code_hash",t.code_hash),s(r+".args",t.args);if("type"!==t.hash_type&&!/^data([1-9][0-9]*)?$/.test(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=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-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)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},v.call(y.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 y(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=y,t.Response=w),e.Headers=h,e.Request=y,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}));function x(t,e){e=e||{};const r=Object.assign({},e.headers||{},t.headers||{});return Object.assign({},e,t,{headers:r})}const O={get:(t,e,r)=>"send"===e?async()=>{const e=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)},t.defaultOptions));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}},C={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri,defaultOptions:t.defaultOptions},O):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})},t.defaultOptions)),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 I{constructor(t,e={},r=S){return this.uri=t,this.defaultOptions=e,this.fetch=r,new Proxy(this,C)}static create(t){return new I(t)}}function j(t){return o.BigInt(t)}function R(t){return"0x"+t.toString(16)}function z(t){return function(e,r){if(!(r instanceof ArrayBuffer)){let n=R(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;t0&&n.byteLength!==t)throw new Error(`${e} has invalid length ${n.byteLength}, required: ${t}`);return n}}function N(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 L(t,{debugPath:e="script"}={}){return N(e,t,{code_hash:M(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:M(-1)})}function U(t,{debugPath:e="out_point"}={}){return N(e,t,{tx_hash:M(32),index:z(4)})}function $(t){return function(e,r){return t(r,{debugPath:e})}}function q(t,{debugPath:e="cell_input"}={}){return N(e,t,{since:z(8),previous_output:$(U)})}function V(t,{debugPath:e="cell_output"}={}){const r=N(e,t,{capacity:z(8),lock:$(L)});return t.type&&(r.type_=L(t.type,{debugPath:e+".type"})),r}function F(t,{debugPath:e="cell_dep"}={}){return N(e,t,{out_point:$(U),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 G(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function H(t,{debugPath:e="raw_transaction"}={}){return N(e,t,{version:z(4),cell_deps:G($(F)),header_deps:G(M(32)),inputs:G($(q)),outputs:G($(V)),outputs_data:G(M(-1))})}function W(t,{debugPath:e="transaction"}={}){const r=H(t,{debugPath:"(raw)"+e}),n=N(e,t,{witnesses:G(M(-1))});return n.raw=r,n}function J(t,{debugPath:e="raw_header"}={}){return N(e,t,{version:z(4),compact_target:z(4),timestamp:z(8),number:z(8),epoch:z(8),parent_hash:M(32),transactions_root:M(32),proposals_hash:M(32),uncles_hash:M(32),dao:M(32)})}function X(t,{debugPath:e="header"}={}){const r=J(t,{debugPath:"(raw)"+e}),n=N(e,t,{nonce:z(16)});return n.raw=r,n}function Q(t,{debugPath:e="uncle_block"}={}){return N(e,t,{header:$(X),proposals:G(M(10))})}var K=Object.freeze({__proto__:null,NormalizeScript:L,NormalizeOutPoint:U,NormalizeCellInput:q,NormalizeCellOutput:V,NormalizeCellDep:F,NormalizeRawTransaction:H,NormalizeTransaction:W,NormalizeRawHeader:J,NormalizeHeader:X,NormalizeUncleBlock:Q,NormalizeBlock:function(t,{debugPath:e="block"}={}){return N(e,t,{header:$(X),uncles:G($(Q)),transactions:G($(W)),proposals:G(M(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return N(e,t,{lock:$(L),message:M(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=M(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=M(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=M(-1)(e+".output_type",t.output_type)),r}});function Y(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Z(t,e,r){if(!((e=Y(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 tt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Z(r,t,{code_hash:Y,hash_type:Y,args:Y}),e&&l(t,{debugPath:"(transformed) "+r}),t}function et(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Z(r,t,{tx_hash:Y,index:Y}),e&&f(t,{debugPath:"(transformed) "+r}),t}function rt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function nt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Z(r,t,{since:Y,previous_output:rt(et)}),e&&h(t,{debugPath:"(transformed) "+r}),t}function it(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Z(r,t,{capacity:Y,lock:rt(tt),type:rt(tt)}),e&&c(t,{debugPath:"(transformed) "+r}),t}function ot(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Z(r,t,{out_point:rt(et),dep_type:Y}),e&&g(t,{debugPath:"(transformed) "+r}),t}function at(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function st(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y),witnesses:at(Y)}),e&&y(t,{debugPath:"(transformed) "+r}),t}function ut(t,{validation:e=!0,debugPath:r="header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y,nonce:Y}),e&&w(t,{debugPath:"(transformed) "+r}),t}function _t(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Z(r,t,{header:rt(ut),proposals:at(Y)}),e&&D(t,{debugPath:"(transformed) "+r}),t}var lt=Object.freeze({__proto__:null,TransformScript:tt,TransformOutPoint:et,TransformCellInput:nt,TransformCellOutput:it,TransformCellDep:ot,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y)}),e&&b(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:st,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y}),e&&m(t,{debugPath:"(transformed) "+r}),t},TransformHeader:ut,TransformUncleBlock:_t,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Z(r,t,{header:rt(ut),uncles:at(rt(_t)),transactions:at(rt(st)),proposals:at(Y)}),e&&B(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Z(r,t,{lock:rt(tt),message:Y}),e&&P(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Z(r,t,{lock:Y,input_type:Y,output_type:Y}),e&&A(t,{debugPath:"(transformed) "+r}),t}});var ft=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=j(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,R(e),R(r));for(const t of n){if(this.skipCellWithContent&&(t.type||o.greaterThan(j(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 ht="0.11.1";export{R as BigIntToHexString,j as HexStringToBigInt,I as RPC,r as Reader,E as TransactionDumper,ht as VERSION,ft as cell_collectors,K as normalizers,lt as transformers,T as validators}; diff --git a/dist/ckb-js-toolkit.node.js b/dist/ckb-js-toolkit.node.js index 9c9737c..72ea717 100644 --- a/dist/ckb-js-toolkit.node.js +++ b/dist/ckb-js-toolkit.node.js @@ -1,2 +1,2 @@ -"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;t255)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>>=12;const _=l-12;let f=12<=l?0:a<<20+l,h=20+l;0<_&&0>>32-_,f=a<<_,h=_),0>>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=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;rg.__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.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.lengthg.__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>>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;ee)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}let o=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<>>32-t,i=o<=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>=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>>0<_)a=o-48;else{if(!((32|o)-97>>>0>>g.__kBitsPerCharTableShift+5;c.__inplaceMultiplyAdd(h,l,d)}while(!r)}if(i!==n){if(!g.__isWhitespace(o))return null;for(i++;i>>u-o)}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;n>>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>>i,f=32-i;f>=o;)l[c--]=g.__kConversionChars[_&s],_>>>=o,f-=o}const 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(;_.lengthn?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(1i?g.__absoluteGreater(r):oe)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(lc)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=_<>>32-t,_=f<>>=0,d>>>=0,a>d)return g.__absoluteGreater(n);if(a>>0,_=f,f=0):d=0;const r=t.__unsignedDigit(e);if(r>d)return g.__absoluteGreater(n);if(re&&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 0e;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?te:3===r?t>=e:void 0}__clzmsd(){return Math.clz32(this[this.length-1])}static __absoluteAdd(t,e,r){if(t.length>>16)+(r>>>16)+(a>>>16);o=u>>>16,i.__setDigit(s,65535&a|u<<16)}for(;s>>16)+(r>>>16);o=n>>>16,i.__setDigit(s,65535&r|n<<16)}return s>>16;const u=(r>>>16)-(s>>>16)-i;i=1&u>>>16,n.__setDigit(o,65535&a|u<<16)}for(;o>>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;on?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>>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>>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);nthis.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>>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>>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>>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>>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>>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>>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>>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>>32-e}return 0r)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>>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;const n=r-o-1;for(let r=0;r>>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(1g.__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>>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>>16;const n=0-(t>>>16)-u;u=1&n>>>16,o.__setDigit(s,65535&r|n<<16)}for(;s>>16;_=65535&t|0-(l>>>16)-u<<16}else{const t=32-c;l=l<>>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>>=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.lengths)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"}={}){d(r,t,["code_hash","hash_type","args"],[]),b(r+".code_hash",t.code_hash),p(r+".args",t.args);if("type"!==t.hash_type&&!/^data([1-9][0-9]*)?$/.test(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;n1&&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=/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(;n1&&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);function kt(t,e){e=e||{};const r=Object.assign({},e.headers||{},t.headers||{});return Object.assign({},e,t,{headers:r})}const xt={get:(t,e,r)=>"send"===e?async()=>{const e=await t.fetch(t.uri,kt({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)},t.defaultOptions));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}},Ct={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri,defaultOptions:t.defaultOptions},xt):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await t.fetch(t.uri,kt({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})},t.defaultOptions)),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 Et{constructor(t,e={},r=Tt){return this.uri=t,this.defaultOptions=e,this.fetch=r,new Proxy(this,Ct)}static create(t){return new Et(t)}}function Ot(t){return g.BigInt(t)}function At(t){return"0x"+t.toString(16)}function jt(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;t0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function It(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 Rt(t,{debugPath:e="script"}={}){return It(e,t,{code_hash:zt(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:zt(-1)})}function Lt(t,{debugPath:e="out_point"}={}){return It(e,t,{tx_hash:zt(32),index:jt(4)})}function Mt(t){return function(e,r){return t(r,{debugPath:e})}}function Nt(t,{debugPath:e="cell_input"}={}){return It(e,t,{since:jt(8),previous_output:Mt(Lt)})}function $t(t,{debugPath:e="cell_output"}={}){const r=It(e,t,{capacity:jt(8),lock:Mt(Rt)});return t.type&&(r.type_=Rt(t.type,{debugPath:e+".type"})),r}function qt(t,{debugPath:e="cell_dep"}={}){return It(e,t,{out_point:Mt(Lt),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 Ut(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function Vt(t,{debugPath:e="raw_transaction"}={}){return It(e,t,{version:jt(4),cell_deps:Ut(Mt(qt)),header_deps:Ut(zt(32)),inputs:Ut(Mt(Nt)),outputs:Ut(Mt($t)),outputs_data:Ut(zt(-1))})}function Ht(t,{debugPath:e="transaction"}={}){const r=Vt(t,{debugPath:"(raw)"+e}),n=It(e,t,{witnesses:Ut(zt(-1))});return n.raw=r,n}function Ft(t,{debugPath:e="raw_header"}={}){return It(e,t,{version:jt(4),compact_target:jt(4),timestamp:jt(8),number:jt(8),epoch:jt(8),parent_hash:zt(32),transactions_root:zt(32),proposals_hash:zt(32),uncles_hash:zt(32),dao:zt(32)})}function Gt(t,{debugPath:e="header"}={}){const r=Ft(t,{debugPath:"(raw)"+e}),n=It(e,t,{nonce:jt(16)});return n.raw=r,n}function Wt(t,{debugPath:e="uncle_block"}={}){return It(e,t,{header:Mt(Gt),proposals:Ut(zt(10))})}var Jt=Object.freeze({__proto__:null,NormalizeScript:Rt,NormalizeOutPoint:Lt,NormalizeCellInput:Nt,NormalizeCellOutput:$t,NormalizeCellDep:qt,NormalizeRawTransaction:Vt,NormalizeTransaction:Ht,NormalizeRawHeader:Ft,NormalizeHeader:Gt,NormalizeUncleBlock:Wt,NormalizeBlock:function(t,{debugPath:e="block"}={}){return It(e,t,{header:Mt(Gt),uncles:Ut(Mt(Wt)),transactions:Ut(Mt(Ht)),proposals:Ut(zt(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return It(e,t,{lock:Mt(Rt),message:zt(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=zt(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=zt(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=zt(-1)(e+".output_type",t.output_type)),r}});function Xt(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Qt(t,e,r){if(!((e=Xt(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 Zt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Qt(r,t,{code_hash:Xt,hash_type:Xt,args:Xt}),e&&y(t,{debugPath:"(transformed) "+r}),t}function Kt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Qt(r,t,{tx_hash:Xt,index:Xt}),e&&w(t,{debugPath:"(transformed) "+r}),t}function Yt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function te(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Qt(r,t,{since:Xt,previous_output:Yt(Kt)}),e&&v(t,{debugPath:"(transformed) "+r}),t}function ee(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Qt(r,t,{capacity:Xt,lock:Yt(Zt),type:Yt(Zt)}),e&&B(t,{debugPath:"(transformed) "+r}),t}function re(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Qt(r,t,{out_point:Yt(Kt),dep_type:Xt}),e&&P(t,{debugPath:"(transformed) "+r}),t}function ne(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function ie(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Qt(r,t,{version:Xt,cell_deps:ne(Yt(re)),header_deps:ne(Xt),inputs:ne(Yt(te)),outputs:ne(Yt(ee)),outputs_data:ne(Xt),witnesses:ne(Xt)}),e&&x(t,{debugPath:"(transformed) "+r}),t}function oe(t,{validation:e=!0,debugPath:r="header"}={}){return t=Qt(r,t,{version:Xt,compact_target:Xt,timestamp:Xt,number:Xt,epoch:Xt,parent_hash:Xt,transactions_root:Xt,proposals_hash:Xt,uncles_hash:Xt,dao:Xt,nonce:Xt}),e&&E(t,{debugPath:"(transformed) "+r}),t}function se(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Qt(r,t,{header:Yt(oe),proposals:ne(Xt)}),e&&A(t,{debugPath:"(transformed) "+r}),t}var ae=Object.freeze({__proto__:null,TransformScript:Zt,TransformOutPoint:Kt,TransformCellInput:te,TransformCellOutput:ee,TransformCellDep:re,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Qt(r,t,{version:Xt,cell_deps:ne(Yt(re)),header_deps:ne(Xt),inputs:ne(Yt(te)),outputs:ne(Yt(ee)),outputs_data:ne(Xt)}),e&&k(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:ie,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Qt(r,t,{version:Xt,compact_target:Xt,timestamp:Xt,number:Xt,epoch:Xt,parent_hash:Xt,transactions_root:Xt,proposals_hash:Xt,uncles_hash:Xt,dao:Xt}),e&&C(t,{debugPath:"(transformed) "+r}),t},TransformHeader:oe,TransformUncleBlock:se,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Qt(r,t,{header:Yt(oe),uncles:ne(Yt(se)),transactions:ne(Yt(ie)),proposals:ne(Xt)}),e&&j(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Qt(r,t,{lock:Yt(Zt),message:Xt}),e&&z(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Qt(r,t,{lock:Xt,input_type:Xt,output_type:Xt}),e&&I(t,{debugPath:"(transformed) "+r}),t}});var ue=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=Ot(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(Ot(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=Ot,exports.RPC=Et,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.11.0",exports.cell_collectors=ue,exports.normalizers=Jt,exports.transformers=ae,exports.validators=R; +"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;t255)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>>=12;const _=l-12;let f=12<=l?0:a<<20+l,h=20+l;0<_&&0>>32-_,f=a<<_,h=_),0>>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=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;rg.__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.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.lengthg.__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>>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;ee)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}let o=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<>>32-t,i=o<=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>=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>>0<_)a=o-48;else{if(!((32|o)-97>>>0>>g.__kBitsPerCharTableShift+5;c.__inplaceMultiplyAdd(h,l,d)}while(!r)}if(i!==n){if(!g.__isWhitespace(o))return null;for(i++;i>>u-o)}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;n>>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>>i,f=32-i;f>=o;)l[c--]=g.__kConversionChars[_&s],_>>>=o,f-=o}const 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(;_.lengthn?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(1i?g.__absoluteGreater(r):oe)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(lc)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=_<>>32-t,_=f<>>=0,d>>>=0,a>d)return g.__absoluteGreater(n);if(a>>0,_=f,f=0):d=0;const r=t.__unsignedDigit(e);if(r>d)return g.__absoluteGreater(n);if(re&&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 0e;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?te:3===r?t>=e:void 0}__clzmsd(){return Math.clz32(this[this.length-1])}static __absoluteAdd(t,e,r){if(t.length>>16)+(r>>>16)+(a>>>16);o=u>>>16,i.__setDigit(s,65535&a|u<<16)}for(;s>>16)+(r>>>16);o=n>>>16,i.__setDigit(s,65535&r|n<<16)}return s>>16;const u=(r>>>16)-(s>>>16)-i;i=1&u>>>16,n.__setDigit(o,65535&a|u<<16)}for(;o>>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;on?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>>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>>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);nthis.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>>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>>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>>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>>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>>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>>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>>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>>32-e}return 0r)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>>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;const n=r-o-1;for(let r=0;r>>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(1g.__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>>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>>16;const n=0-(t>>>16)-u;u=1&n>>>16,o.__setDigit(s,65535&r|n<<16)}for(;s>>16;_=65535&t|0-(l>>>16)-u<<16}else{const t=32-c;l=l<>>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>>=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.lengths)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"}={}){d(r,t,["code_hash","hash_type","args"],[]),b(r+".code_hash",t.code_hash),p(r+".args",t.args);if("type"!==t.hash_type&&!/^data([1-9][0-9]*)?$/.test(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;n1&&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=/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(;n1&&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);function kt(t,e){e=e||{};const r=Object.assign({},e.headers||{},t.headers||{});return Object.assign({},e,t,{headers:r})}const xt={get:(t,e,r)=>"send"===e?async()=>{const e=await t.fetch(t.uri,kt({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)},t.defaultOptions));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}},Ct={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri,defaultOptions:t.defaultOptions},xt):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await t.fetch(t.uri,kt({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})},t.defaultOptions)),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 Et{constructor(t,e={},r=Tt){return this.uri=t,this.defaultOptions=e,this.fetch=r,new Proxy(this,Ct)}static create(t){return new Et(t)}}function Ot(t){return g.BigInt(t)}function At(t){return"0x"+t.toString(16)}function jt(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;t0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function It(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 Rt(t,{debugPath:e="script"}={}){return It(e,t,{code_hash:zt(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:zt(-1)})}function Lt(t,{debugPath:e="out_point"}={}){return It(e,t,{tx_hash:zt(32),index:jt(4)})}function Mt(t){return function(e,r){return t(r,{debugPath:e})}}function Nt(t,{debugPath:e="cell_input"}={}){return It(e,t,{since:jt(8),previous_output:Mt(Lt)})}function $t(t,{debugPath:e="cell_output"}={}){const r=It(e,t,{capacity:jt(8),lock:Mt(Rt)});return t.type&&(r.type_=Rt(t.type,{debugPath:e+".type"})),r}function qt(t,{debugPath:e="cell_dep"}={}){return It(e,t,{out_point:Mt(Lt),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 Ut(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function Vt(t,{debugPath:e="raw_transaction"}={}){return It(e,t,{version:jt(4),cell_deps:Ut(Mt(qt)),header_deps:Ut(zt(32)),inputs:Ut(Mt(Nt)),outputs:Ut(Mt($t)),outputs_data:Ut(zt(-1))})}function Ht(t,{debugPath:e="transaction"}={}){const r=Vt(t,{debugPath:"(raw)"+e}),n=It(e,t,{witnesses:Ut(zt(-1))});return n.raw=r,n}function Ft(t,{debugPath:e="raw_header"}={}){return It(e,t,{version:jt(4),compact_target:jt(4),timestamp:jt(8),number:jt(8),epoch:jt(8),parent_hash:zt(32),transactions_root:zt(32),proposals_hash:zt(32),uncles_hash:zt(32),dao:zt(32)})}function Gt(t,{debugPath:e="header"}={}){const r=Ft(t,{debugPath:"(raw)"+e}),n=It(e,t,{nonce:jt(16)});return n.raw=r,n}function Wt(t,{debugPath:e="uncle_block"}={}){return It(e,t,{header:Mt(Gt),proposals:Ut(zt(10))})}var Jt=Object.freeze({__proto__:null,NormalizeScript:Rt,NormalizeOutPoint:Lt,NormalizeCellInput:Nt,NormalizeCellOutput:$t,NormalizeCellDep:qt,NormalizeRawTransaction:Vt,NormalizeTransaction:Ht,NormalizeRawHeader:Ft,NormalizeHeader:Gt,NormalizeUncleBlock:Wt,NormalizeBlock:function(t,{debugPath:e="block"}={}){return It(e,t,{header:Mt(Gt),uncles:Ut(Mt(Wt)),transactions:Ut(Mt(Ht)),proposals:Ut(zt(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return It(e,t,{lock:Mt(Rt),message:zt(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=zt(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=zt(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=zt(-1)(e+".output_type",t.output_type)),r}});function Xt(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Qt(t,e,r){if(!((e=Xt(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 Zt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Qt(r,t,{code_hash:Xt,hash_type:Xt,args:Xt}),e&&y(t,{debugPath:"(transformed) "+r}),t}function Kt(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Qt(r,t,{tx_hash:Xt,index:Xt}),e&&w(t,{debugPath:"(transformed) "+r}),t}function Yt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function te(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Qt(r,t,{since:Xt,previous_output:Yt(Kt)}),e&&v(t,{debugPath:"(transformed) "+r}),t}function ee(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Qt(r,t,{capacity:Xt,lock:Yt(Zt),type:Yt(Zt)}),e&&B(t,{debugPath:"(transformed) "+r}),t}function re(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Qt(r,t,{out_point:Yt(Kt),dep_type:Xt}),e&&P(t,{debugPath:"(transformed) "+r}),t}function ne(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function ie(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Qt(r,t,{version:Xt,cell_deps:ne(Yt(re)),header_deps:ne(Xt),inputs:ne(Yt(te)),outputs:ne(Yt(ee)),outputs_data:ne(Xt),witnesses:ne(Xt)}),e&&x(t,{debugPath:"(transformed) "+r}),t}function oe(t,{validation:e=!0,debugPath:r="header"}={}){return t=Qt(r,t,{version:Xt,compact_target:Xt,timestamp:Xt,number:Xt,epoch:Xt,parent_hash:Xt,transactions_root:Xt,proposals_hash:Xt,uncles_hash:Xt,dao:Xt,nonce:Xt}),e&&E(t,{debugPath:"(transformed) "+r}),t}function se(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Qt(r,t,{header:Yt(oe),proposals:ne(Xt)}),e&&A(t,{debugPath:"(transformed) "+r}),t}var ae=Object.freeze({__proto__:null,TransformScript:Zt,TransformOutPoint:Kt,TransformCellInput:te,TransformCellOutput:ee,TransformCellDep:re,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Qt(r,t,{version:Xt,cell_deps:ne(Yt(re)),header_deps:ne(Xt),inputs:ne(Yt(te)),outputs:ne(Yt(ee)),outputs_data:ne(Xt)}),e&&k(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:ie,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Qt(r,t,{version:Xt,compact_target:Xt,timestamp:Xt,number:Xt,epoch:Xt,parent_hash:Xt,transactions_root:Xt,proposals_hash:Xt,uncles_hash:Xt,dao:Xt}),e&&C(t,{debugPath:"(transformed) "+r}),t},TransformHeader:oe,TransformUncleBlock:se,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Qt(r,t,{header:Yt(oe),uncles:ne(Yt(se)),transactions:ne(Yt(ie)),proposals:ne(Xt)}),e&&j(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Qt(r,t,{lock:Yt(Zt),message:Xt}),e&&z(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Qt(r,t,{lock:Xt,input_type:Xt,output_type:Xt}),e&&I(t,{debugPath:"(transformed) "+r}),t}});var ue=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=Ot(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(Ot(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=Ot,exports.RPC=Et,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.11.1",exports.cell_collectors=ue,exports.normalizers=Jt,exports.transformers=ae,exports.validators=R; //# sourceMappingURL=ckb-js-toolkit.node.js.map diff --git a/dist/ckb-js-toolkit.umd.js b/dist/ckb-js-toolkit.umd.js index e4e7c73..1e7246b 100644 --- a/dist/ckb-js-toolkit.umd.js +++ b/dist/ckb-js-toolkit.umd.js @@ -1 +1 @@ -!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;t255)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;nl.__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=0t||36this.length&&(r=this.length);for(var n=65535&t,i=t>>>16,o=0,a=65535&e,s=e>>>16,_=0;_>>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>>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>>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>>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>>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>>=12;var c=f-12,g=12<=f?0:s<<20+f,d=20+f;0>>32-c,g=s<>>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=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;il.__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.__kMaxLengthBits)return e;var r=t+31>>>5;if(e.lengthl.__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>>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(0e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}var o=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>>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<>>32-h,o=a<=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=11073741824/s)return null;var _=new l(31+(s*a+u>>>l.__kBitsPerCharTableShift)>>>5,!1),f=10>e?e:10,h=10>=l.__kBitsPerCharTableShift;var c=[],g=[],d=!1;do{for(var p,v=0,y=0;;){if(p=void 0,o-48>>>0>>0>>0>>0>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(D,k,P)}while(!b)}if(i!==n){if(!l.__isWhitespace(o))return null;for(i++;i>>u-(o-=32))}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;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>>v,c=32-v;c>=i;)u[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var 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.lengthn?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(1i?l.__absoluteGreater(r):oe)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(uf)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>>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<>>32-b,h=c<>>=0)>(p>>>=0))return l.__absoluteGreater(r);if(a>>0,h=c,c=0):p=0;var w=t.__unsignedDigit(m);if(w>p)return l.__absoluteGreater(r);if(we&&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 0e;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?te:3===r?t>=e:void 0}},{key:"__absoluteAdd",value:function(t,e,r){if(t.length>>16)+(s>>>16)+(_>>>16);o=f>>>16,i.__setDigit(a,65535&_|f<<16)}for(;a>>16)+(c>>>16);o=g>>>16,i.__setDigit(a,65535&c|g<<16)}return a>>16)-(s>>>16)-(i=1&u>>>16);i=1&_>>>16,n.__setDigit(o,65535&u|_<<16)}for(;o>>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=2n?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>>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>>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>>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>>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>>32-e;return 0r)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;_>>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,d=r-o-1,p=0;p>>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(1l.__kMaxLengthBits?-1:e}},{key:"__toPrimitive",value:function(e){var r=1>>5,n=new l(r,e.sign),i=r-1,o=0;o>>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>>16)-(u=1&v>>>16)<<16}else{var y=32-p,b=1<<32-y,m=(65535&b)-(65535&(d=d<>>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>>=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<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"}={}){s(r,t,["code_hash","hash_type","args"],[]),_(r+".code_hash",t.code_hash),u(r+".args",t.args);if("type"!==t.hash_type&&!/^data([1-9][0-9]*)?$/.test(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-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-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}));function x(t,e){e=e||{};const r=Object.assign({},e.headers||{},t.headers||{});return Object.assign({},e,t,{headers:r})}const O={get:(t,e,r)=>"send"===e?async()=>{const e=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)},t.defaultOptions));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}},C={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri,defaultOptions:t.defaultOptions},O):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})},t.defaultOptions)),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 I{constructor(t,e={},r=S){return this.uri=t,this.defaultOptions=e,this.fetch=r,new Proxy(this,C)}static create(t){return new I(t)}}function j(t){return a.BigInt(t)}function R(t){return"0x"+t.toString(16)}function z(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;t0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function N(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 L(t,{debugPath:e="script"}={}){return N(e,t,{code_hash:M(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:M(-1)})}function U(t,{debugPath:e="out_point"}={}){return N(e,t,{tx_hash:M(32),index:z(4)})}function V(t){return function(e,r){return t(r,{debugPath:e})}}function $(t,{debugPath:e="cell_input"}={}){return N(e,t,{since:z(8),previous_output:V(U)})}function q(t,{debugPath:e="cell_output"}={}){const r=N(e,t,{capacity:z(8),lock:V(L)});return t.type&&(r.type_=L(t.type,{debugPath:e+".type"})),r}function F(t,{debugPath:e="cell_dep"}={}){return N(e,t,{out_point:V(U),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 H(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function G(t,{debugPath:e="raw_transaction"}={}){return N(e,t,{version:z(4),cell_deps:H(V(F)),header_deps:H(M(32)),inputs:H(V($)),outputs:H(V(q)),outputs_data:H(M(-1))})}function W(t,{debugPath:e="transaction"}={}){const r=G(t,{debugPath:"(raw)"+e}),n=N(e,t,{witnesses:H(M(-1))});return n.raw=r,n}function J(t,{debugPath:e="raw_header"}={}){return N(e,t,{version:z(4),compact_target:z(4),timestamp:z(8),number:z(8),epoch:z(8),parent_hash:M(32),transactions_root:M(32),proposals_hash:M(32),uncles_hash:M(32),dao:M(32)})}function X(t,{debugPath:e="header"}={}){const r=J(t,{debugPath:"(raw)"+e}),n=N(e,t,{nonce:z(16)});return n.raw=r,n}function Q(t,{debugPath:e="uncle_block"}={}){return N(e,t,{header:V(X),proposals:H(M(10))})}var K=Object.freeze({__proto__:null,NormalizeScript:L,NormalizeOutPoint:U,NormalizeCellInput:$,NormalizeCellOutput:q,NormalizeCellDep:F,NormalizeRawTransaction:G,NormalizeTransaction:W,NormalizeRawHeader:J,NormalizeHeader:X,NormalizeUncleBlock:Q,NormalizeBlock:function(t,{debugPath:e="block"}={}){return N(e,t,{header:V(X),uncles:H(V(Q)),transactions:H(V(W)),proposals:H(M(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return N(e,t,{lock:V(L),message:M(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=M(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=M(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=M(-1)(e+".output_type",t.output_type)),r}});function Y(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Z(t,e,r){if(!((e=Y(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 tt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Z(r,t,{code_hash:Y,hash_type:Y,args:Y}),e&&f(t,{debugPath:"(transformed) "+r}),t}function et(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Z(r,t,{tx_hash:Y,index:Y}),e&&h(t,{debugPath:"(transformed) "+r}),t}function rt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function nt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Z(r,t,{since:Y,previous_output:rt(et)}),e&&c(t,{debugPath:"(transformed) "+r}),t}function it(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Z(r,t,{capacity:Y,lock:rt(tt),type:rt(tt)}),e&&g(t,{debugPath:"(transformed) "+r}),t}function ot(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Z(r,t,{out_point:rt(et),dep_type:Y}),e&&d(t,{debugPath:"(transformed) "+r}),t}function at(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function st(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y),witnesses:at(Y)}),e&&m(t,{debugPath:"(transformed) "+r}),t}function ut(t,{validation:e=!0,debugPath:r="header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y,nonce:Y}),e&&k(t,{debugPath:"(transformed) "+r}),t}function _t(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Z(r,t,{header:rt(ut),proposals:at(Y)}),e&&B(t,{debugPath:"(transformed) "+r}),t}var lt=Object.freeze({__proto__:null,TransformScript:tt,TransformOutPoint:et,TransformCellInput:nt,TransformCellOutput:it,TransformCellDep:ot,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y)}),e&&b(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:st,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y}),e&&w(t,{debugPath:"(transformed) "+r}),t},TransformHeader:ut,TransformUncleBlock:_t,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Z(r,t,{header:rt(ut),uncles:at(rt(_t)),transactions:at(rt(st)),proposals:at(Y)}),e&&P(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Z(r,t,{lock:rt(tt),message:Y}),e&&T(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Z(r,t,{lock:Y,input_type:Y,output_type:Y}),e&&A(t,{debugPath:"(transformed) "+r}),t}});var ft=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=j(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(j(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=j,t.RPC=I,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.11.0",t.cell_collectors=ft,t.normalizers=K,t.transformers=lt,t.validators=E,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;t255)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;nl.__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=0t||36this.length&&(r=this.length);for(var n=65535&t,i=t>>>16,o=0,a=65535&e,s=e>>>16,_=0;_>>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>>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>>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>>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>>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>>=12;var c=f-12,g=12<=f?0:s<<20+f,d=20+f;0>>32-c,g=s<>>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=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;il.__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.__kMaxLengthBits)return e;var r=t+31>>>5;if(e.lengthl.__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>>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(0e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}var o=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>>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<>>32-h,o=a<=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=11073741824/s)return null;var _=new l(31+(s*a+u>>>l.__kBitsPerCharTableShift)>>>5,!1),f=10>e?e:10,h=10>=l.__kBitsPerCharTableShift;var c=[],g=[],d=!1;do{for(var p,v=0,y=0;;){if(p=void 0,o-48>>>0>>0>>0>>0>>l.__kBitsPerCharTableShift+5;_.__inplaceMultiplyAdd(D,k,P)}while(!b)}if(i!==n){if(!l.__isWhitespace(o))return null;for(i++;i>>u-(o-=32))}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;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>>v,c=32-v;c>=i;)u[f--]=l.__kConversionChars[h&o],h>>>=i,c-=i}var 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.lengthn?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(1i?l.__absoluteGreater(r):oe)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(uf)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>>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<>>32-b,h=c<>>=0)>(p>>>=0))return l.__absoluteGreater(r);if(a>>0,h=c,c=0):p=0;var w=t.__unsignedDigit(m);if(w>p)return l.__absoluteGreater(r);if(we&&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 0e;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?te:3===r?t>=e:void 0}},{key:"__absoluteAdd",value:function(t,e,r){if(t.length>>16)+(s>>>16)+(_>>>16);o=f>>>16,i.__setDigit(a,65535&_|f<<16)}for(;a>>16)+(c>>>16);o=g>>>16,i.__setDigit(a,65535&c|g<<16)}return a>>16)-(s>>>16)-(i=1&u>>>16);i=1&_>>>16,n.__setDigit(o,65535&u|_<<16)}for(;o>>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=2n?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>>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>>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>>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>>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>>32-e;return 0r)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;_>>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,d=r-o-1,p=0;p>>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(1l.__kMaxLengthBits?-1:e}},{key:"__toPrimitive",value:function(e){var r=1>>5,n=new l(r,e.sign),i=r-1,o=0;o>>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>>16)-(u=1&v>>>16)<<16}else{var y=32-p,b=1<<32-y,m=(65535&b)-(65535&(d=d<>>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>>=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<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"}={}){s(r,t,["code_hash","hash_type","args"],[]),_(r+".code_hash",t.code_hash),u(r+".args",t.args);if("type"!==t.hash_type&&!/^data([1-9][0-9]*)?$/.test(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-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-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}));function x(t,e){e=e||{};const r=Object.assign({},e.headers||{},t.headers||{});return Object.assign({},e,t,{headers:r})}const O={get:(t,e,r)=>"send"===e?async()=>{const e=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.payload)},t.defaultOptions));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}},C={get:(t,e)=>"batch"===e?()=>new Proxy({id:Math.round(1e7*Math.random()),payload:[],uri:t.uri,defaultOptions:t.defaultOptions},O):async(...r)=>{const n=Math.round(1e7*Math.random()),i=await t.fetch(t.uri,x({method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:n,method:e,params:r})},t.defaultOptions)),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 I{constructor(t,e={},r=S){return this.uri=t,this.defaultOptions=e,this.fetch=r,new Proxy(this,C)}static create(t){return new I(t)}}function j(t){return a.BigInt(t)}function R(t){return"0x"+t.toString(16)}function z(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;t0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function N(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 L(t,{debugPath:e="script"}={}){return N(e,t,{code_hash:M(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:M(-1)})}function U(t,{debugPath:e="out_point"}={}){return N(e,t,{tx_hash:M(32),index:z(4)})}function V(t){return function(e,r){return t(r,{debugPath:e})}}function $(t,{debugPath:e="cell_input"}={}){return N(e,t,{since:z(8),previous_output:V(U)})}function q(t,{debugPath:e="cell_output"}={}){const r=N(e,t,{capacity:z(8),lock:V(L)});return t.type&&(r.type_=L(t.type,{debugPath:e+".type"})),r}function F(t,{debugPath:e="cell_dep"}={}){return N(e,t,{out_point:V(U),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 H(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function G(t,{debugPath:e="raw_transaction"}={}){return N(e,t,{version:z(4),cell_deps:H(V(F)),header_deps:H(M(32)),inputs:H(V($)),outputs:H(V(q)),outputs_data:H(M(-1))})}function W(t,{debugPath:e="transaction"}={}){const r=G(t,{debugPath:"(raw)"+e}),n=N(e,t,{witnesses:H(M(-1))});return n.raw=r,n}function J(t,{debugPath:e="raw_header"}={}){return N(e,t,{version:z(4),compact_target:z(4),timestamp:z(8),number:z(8),epoch:z(8),parent_hash:M(32),transactions_root:M(32),proposals_hash:M(32),uncles_hash:M(32),dao:M(32)})}function X(t,{debugPath:e="header"}={}){const r=J(t,{debugPath:"(raw)"+e}),n=N(e,t,{nonce:z(16)});return n.raw=r,n}function Q(t,{debugPath:e="uncle_block"}={}){return N(e,t,{header:V(X),proposals:H(M(10))})}var K=Object.freeze({__proto__:null,NormalizeScript:L,NormalizeOutPoint:U,NormalizeCellInput:$,NormalizeCellOutput:q,NormalizeCellDep:F,NormalizeRawTransaction:G,NormalizeTransaction:W,NormalizeRawHeader:J,NormalizeHeader:X,NormalizeUncleBlock:Q,NormalizeBlock:function(t,{debugPath:e="block"}={}){return N(e,t,{header:V(X),uncles:H(V(Q)),transactions:H(V(W)),proposals:H(M(10))})},NormalizeCellbaseWitness:function(t,{debugPath:e="cellbase_witness"}={}){return N(e,t,{lock:V(L),message:M(-1)})},NormalizeWitnessArgs:function(t,{debugPath:e="witness_args"}={}){const r={};return t.lock&&(r.lock=M(-1)(e+".lock",t.lock)),t.input_type&&(r.input_type=M(-1)(e+".input_type",t.input_type)),t.output_type&&(r.output_type=M(-1)(e+".output_type",t.output_type)),r}});function Y(t,e){return e instanceof Object&&e.serializeJson instanceof Function?e.serializeJson.call(e):e}function Z(t,e,r){if(!((e=Y(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 tt(t,{validation:e=!0,debugPath:r="script"}={}){return t=Z(r,t,{code_hash:Y,hash_type:Y,args:Y}),e&&f(t,{debugPath:"(transformed) "+r}),t}function et(t,{validation:e=!0,debugPath:r="out_point"}={}){return t=Z(r,t,{tx_hash:Y,index:Y}),e&&h(t,{debugPath:"(transformed) "+r}),t}function rt(t){return function(e,r){return t(r,{validation:!1,debugPath:e})}}function nt(t,{validation:e=!0,debugPath:r="cell_input"}={}){return t=Z(r,t,{since:Y,previous_output:rt(et)}),e&&c(t,{debugPath:"(transformed) "+r}),t}function it(t,{validation:e=!0,debugPath:r="cell_output"}={}){return t=Z(r,t,{capacity:Y,lock:rt(tt),type:rt(tt)}),e&&g(t,{debugPath:"(transformed) "+r}),t}function ot(t,{validation:e=!0,debugPath:r="cell_dep"}={}){return t=Z(r,t,{out_point:rt(et),dep_type:Y}),e&&d(t,{debugPath:"(transformed) "+r}),t}function at(t){return function(e,r){return r.map((r,n)=>t(`${e}[${n}]`,r))}}function st(t,{validation:e=!0,debugPath:r="transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y),witnesses:at(Y)}),e&&m(t,{debugPath:"(transformed) "+r}),t}function ut(t,{validation:e=!0,debugPath:r="header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y,nonce:Y}),e&&k(t,{debugPath:"(transformed) "+r}),t}function _t(t,{validation:e=!0,debugPath:r="uncle_block"}={}){return t=Z(r,t,{header:rt(ut),proposals:at(Y)}),e&&B(t,{debugPath:"(transformed) "+r}),t}var lt=Object.freeze({__proto__:null,TransformScript:tt,TransformOutPoint:et,TransformCellInput:nt,TransformCellOutput:it,TransformCellDep:ot,TransformRawTransaction:function(t,{validation:e=!0,debugPath:r="raw_transaction"}={}){return t=Z(r,t,{version:Y,cell_deps:at(rt(ot)),header_deps:at(Y),inputs:at(rt(nt)),outputs:at(rt(it)),outputs_data:at(Y)}),e&&b(t,{debugPath:"(transformed) "+r}),t},TransformTransaction:st,TransformRawHeader:function(t,{validation:e=!0,debugPath:r="raw_header"}={}){return t=Z(r,t,{version:Y,compact_target:Y,timestamp:Y,number:Y,epoch:Y,parent_hash:Y,transactions_root:Y,proposals_hash:Y,uncles_hash:Y,dao:Y}),e&&w(t,{debugPath:"(transformed) "+r}),t},TransformHeader:ut,TransformUncleBlock:_t,TransformBlock:function(t,{validation:e=!0,debugPath:r="block"}={}){return t=Z(r,t,{header:rt(ut),uncles:at(rt(_t)),transactions:at(rt(st)),proposals:at(Y)}),e&&P(t,{debugPath:"(transformed) "+r}),t},TransformCellbaseWitness:function(t,{validation:e=!0,debugPath:r="cellbase_witness"}={}){return t=Z(r,t,{lock:rt(tt),message:Y}),e&&T(t,{debugPath:"(transformed) "+r}),t},TransformWitnessArgs:function(t,{validation:e=!0,debugPath:r="witness_args"}={}){return t=Z(r,t,{lock:Y,input_type:Y,output_type:Y}),e&&A(t,{debugPath:"(transformed) "+r}),t}});var ft=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=j(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(j(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=j,t.RPC=I,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.11.1",t.cell_collectors=ft,t.normalizers=K,t.transformers=lt,t.validators=E,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/package-lock.json b/package-lock.json index 76c6a65..86c5110 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ckb-js-toolkit", - "version": "0.11.0", + "version": "0.11.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ckb-js-toolkit", - "version": "0.11.0", + "version": "0.11.1", "license": "MIT", "dependencies": { "cross-fetch": "^3.0.6", diff --git a/package.json b/package.json index f98de4d..dd5c4cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ckb-js-toolkit", - "version": "0.11.0", + "version": "0.11.1", "description": "JavaScript toolkits used to build dapps for Nervos CKB", "main": "dist/ckb-js-toolkit.node.js", "browser": "dist/ckb-js-toolkit.esm.js",