/
ckb-js-toolkit.node.js
2 lines (2 loc) · 60.3 KB
/
ckb-js-toolkit.node.js
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;t<this.length();t++)e.setUint8(t,this.indexAt(t));return t}serializeJson(){return this.string}}class h{constructor(t){if(t instanceof f||t instanceof _)return t;if("string"==typeof t){if(!t.startsWith("0x")||t.length%2!=0)throw new Error("Hex string must start with 0x, and has even numbered length!");return new f(t)}if(t instanceof ArrayBuffer)return new _(t);throw new Error("Reader can only accept hex string or ArrayBuffer!")}static fromRawString(t){const e=new ArrayBuffer(t.length),r=new DataView(e);for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n>255)throw new Error("fromRawString can only accept UTF-8 raw string!");r.setUint8(e,n)}return new _(e)}}class g extends Array{constructor(t,e){if(t>g.__kMaxLength)throw new RangeError("Maximum BigInt size exceeded");super(t),this.sign=e}static BigInt(t){var e=Math.floor,r=Number.isFinite;if("number"==typeof t){if(0===t)return g.__zero();if((0|t)===t)return 0>t?g.__oneDigit(-t,!0):g.__oneDigit(t,!1);if(!r(t)||e(t)!==t)throw new RangeError("The number "+t+" cannot be converted to BigInt because it is not an integer");return g.__fromDouble(t)}if("string"==typeof t){const e=g.__fromString(t);if(null===e)throw new SyntaxError("Cannot convert "+t+" to a BigInt");return e}if("boolean"==typeof t)return!0===t?g.__oneDigit(1,!1):g.__zero();if("object"==typeof t){if(t.constructor===g)return t;const e=g.__toPrimitive(t);return g.BigInt(e)}throw new TypeError("Cannot convert "+t+" to a BigInt")}toDebugString(){const t=["BigInt["];for(const e of this)t.push((e?(e>>>0).toString(16):e)+", ");return t.push("]"),t.join("")}toString(t=10){if(2>t||36<t)throw new RangeError("toString() radix argument must be between 2 and 36");return 0===this.length?"0":0==(t&t-1)?g.__toStringBasePowerOfTwo(this,t):g.__toStringGeneric(this,t,!1)}static toNumber(t){var e=Math.clz32;const r=t.length;if(0===r)return 0;if(1===r){const e=t.__unsignedDigit(0);return t.sign?-e:e}const n=t.__digit(r-1),i=e(n),o=32*r-i;if(1024<o)return t.sign?-1/0:1/0;let s=o-1,a=n,u=r-1;const l=i+1;let c=32===l?0:a<<l;c>>>=12;const _=l-12;let f=12<=l?0:a<<20+l,h=20+l;0<_&&0<u&&(u--,a=t.__digit(u),c|=a>>>32-_,f=a<<_,h=_),0<h&&0<u&&(u--,a=t.__digit(u),f|=a>>>32-h,h-=32);const d=g.__decideRounding(t,h,u,a);if((1===d||0===d&&1==(1&f))&&(f=f+1>>>0,0==f&&(c++,0!=c>>>20&&(c=0,s++,1023<s))))return t.sign?-1/0:1/0;const p=t.sign?-2147483648:0;return s=s+1023<<20,g.__kBitConversionInts[1]=p|s|c,g.__kBitConversionInts[0]=f,g.__kBitConversionDouble[0]}static unaryMinus(t){if(0===t.length)return t;const e=t.__copy();return e.sign=!t.sign,e}static bitwiseNot(t){return t.sign?g.__absoluteSubOne(t).__trim():g.__absoluteAddOne(t,!0)}static exponentiate(t,e){if(e.sign)throw new RangeError("Exponent must be positive");if(0===e.length)return g.__oneDigit(1,!1);if(0===t.length)return t;if(1===t.length&&1===t.__digit(0))return t.sign&&0==(1&e.__digit(0))?g.unaryMinus(t):t;if(1<e.length)throw new RangeError("BigInt too big");let r=e.__unsignedDigit(0);if(1===r)return t;if(r>=g.__kMaxLengthBits)throw new RangeError("BigInt too big");if(1===t.length&&2===t.__digit(0)){const e=1+(r>>>5),n=t.sign&&0!=(1&r),i=new g(e,n);i.__initializeDigits();const o=1<<(31&r);return i.__setDigit(e-1,o),i}let n=null,i=t;for(0!=(1&r)&&(n=t),r>>=1;0!==r;r>>=1)i=g.multiply(i,i),0!=(1&r)&&(n=null===n?i:g.multiply(n,i));return n}static multiply(t,e){if(0===t.length)return t;if(0===e.length)return e;let r=t.length+e.length;32<=t.__clzmsd()+e.__clzmsd()&&r--;const n=new g(r,t.sign!==e.sign);n.__initializeDigits();for(let r=0;r<t.length;r++)g.__multiplyAccumulate(e,t.__digit(r),n,r);return n.__trim()}static divide(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>g.__absoluteCompare(t,e))return g.__zero();const r=t.sign!==e.sign,n=e.__unsignedDigit(0);let i;if(1===e.length&&65535>=n){if(1===n)return r===t.sign?t:g.unaryMinus(t);i=g.__absoluteDivSmall(t,n,null)}else i=g.__absoluteDivLarge(t,e,!0,!1);return i.sign=r,i.__trim()}static remainder(t,e){if(0===e.length)throw new RangeError("Division by zero");if(0>g.__absoluteCompare(t,e))return t;const r=e.__unsignedDigit(0);if(1===e.length&&65535>=r){if(1===r)return g.__zero();const e=g.__absoluteModSmall(t,r);return 0===e?g.__zero():g.__oneDigit(e,t.sign)}const n=g.__absoluteDivLarge(t,e,!1,!0);return n.sign=t.sign,n.__trim()}static add(t,e){const r=t.sign;return r===e.sign?g.__absoluteAdd(t,e,r):0<=g.__absoluteCompare(t,e)?g.__absoluteSub(t,e,r):g.__absoluteSub(e,t,!r)}static subtract(t,e){const r=t.sign;return r===e.sign?0<=g.__absoluteCompare(t,e)?g.__absoluteSub(t,e,r):g.__absoluteSub(e,t,!r):g.__absoluteAdd(t,e,r)}static leftShift(t,e){return 0===e.length||0===t.length?t:e.sign?g.__rightShiftByAbsolute(t,e):g.__leftShiftByAbsolute(t,e)}static signedRightShift(t,e){return 0===e.length||0===t.length?t:e.sign?g.__leftShiftByAbsolute(t,e):g.__rightShiftByAbsolute(t,e)}static unsignedRightShift(){throw new TypeError("BigInts have no unsigned right shift; use >> instead")}static lessThan(t,e){return 0>g.__compareToBigInt(t,e)}static lessThanOrEqual(t,e){return 0>=g.__compareToBigInt(t,e)}static greaterThan(t,e){return 0<g.__compareToBigInt(t,e)}static greaterThanOrEqual(t,e){return 0<=g.__compareToBigInt(t,e)}static equal(t,e){if(t.sign!==e.sign)return!1;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t.__digit(r)!==e.__digit(r))return!1;return!0}static notEqual(t,e){return!g.equal(t,e)}static bitwiseAnd(t,e){var r=Math.max;if(!t.sign&&!e.sign)return g.__absoluteAnd(t,e).__trim();if(t.sign&&e.sign){const n=r(t.length,e.length)+1;let i=g.__absoluteSubOne(t,n);const o=g.__absoluteSubOne(e);return i=g.__absoluteOr(i,o,i),g.__absoluteAddOne(i,!0,i).__trim()}return t.sign&&([t,e]=[e,t]),g.__absoluteAndNot(t,g.__absoluteSubOne(e)).__trim()}static bitwiseXor(t,e){var r=Math.max;if(!t.sign&&!e.sign)return g.__absoluteXor(t,e).__trim();if(t.sign&&e.sign){const n=r(t.length,e.length),i=g.__absoluteSubOne(t,n),o=g.__absoluteSubOne(e);return g.__absoluteXor(i,o,i).__trim()}const n=r(t.length,e.length)+1;t.sign&&([t,e]=[e,t]);let i=g.__absoluteSubOne(e,n);return i=g.__absoluteXor(i,t,i),g.__absoluteAddOne(i,!0,i).__trim()}static bitwiseOr(t,e){const r=(0,Math.max)(t.length,e.length);if(!t.sign&&!e.sign)return g.__absoluteOr(t,e).__trim();if(t.sign&&e.sign){let n=g.__absoluteSubOne(t,r);const i=g.__absoluteSubOne(e);return n=g.__absoluteAnd(n,i,n),g.__absoluteAddOne(n,!0,n).__trim()}t.sign&&([t,e]=[e,t]);let n=g.__absoluteSubOne(e,r);return n=g.__absoluteAndNot(n,t,n),g.__absoluteAddOne(n,!0,n).__trim()}static asIntN(t,e){if(0===e.length)return e;if(0===t)return g.__zero();if(t>=g.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.length<r)return e;const n=e.__unsignedDigit(r-1),i=1<<(31&t-1);if(e.length===r&&n<i)return e;if((n&i)!==i)return g.__truncateToNBits(t,e);if(!e.sign)return g.__truncateAndSubFromPowerOfTwo(t,e,!0);if(0==(n&i-1)){for(let n=r-2;0<=n;n--)if(0!==e.__digit(n))return g.__truncateAndSubFromPowerOfTwo(t,e,!1);return e.length===r&&n===i?e:g.__truncateToNBits(t,e)}return g.__truncateAndSubFromPowerOfTwo(t,e,!1)}static asUintN(t,e){if(0===e.length)return e;if(0===t)return g.__zero();if(e.sign){if(t>g.__kMaxLengthBits)throw new RangeError("BigInt too big");return g.__truncateAndSubFromPowerOfTwo(t,e,!1)}if(t>=g.__kMaxLengthBits)return e;const r=t+31>>>5;if(e.length<r)return e;const n=31&t;if(e.length==r){if(0==n)return e;if(0==e.__digit(r-1)>>>n)return e}return g.__truncateToNBits(t,e)}static ADD(t,e){if(t=g.__toPrimitive(t),e=g.__toPrimitive(e),"string"==typeof t)return"string"!=typeof e&&(e=e.toString()),t+e;if("string"==typeof e)return t.toString()+e;if(t=g.__toNumeric(t),e=g.__toNumeric(e),g.__isBigInt(t)&&g.__isBigInt(e))return g.add(t,e);if("number"==typeof t&&"number"==typeof e)return t+e;throw new TypeError("Cannot mix BigInt and other types, use explicit conversions")}static LT(t,e){return g.__compare(t,e,0)}static LE(t,e){return g.__compare(t,e,1)}static GT(t,e){return g.__compare(t,e,2)}static GE(t,e){return g.__compare(t,e,3)}static EQ(t,e){for(;;){if(g.__isBigInt(t))return g.__isBigInt(e)?g.equal(t,e):g.EQ(e,t);if("number"==typeof t){if(g.__isBigInt(e))return g.__equalToNumber(e,t);if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else if("string"==typeof t){if(g.__isBigInt(e))return null!==(t=g.__fromString(t))&&g.equal(t,e);if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else if("boolean"==typeof t){if(g.__isBigInt(e))return g.__equalToNumber(e,+t);if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else if("symbol"==typeof t){if(g.__isBigInt(e))return!1;if("object"!=typeof e)return t==e;e=g.__toPrimitive(e)}else{if("object"!=typeof t)return t==e;if("object"==typeof e&&e.constructor!==g)return t==e;t=g.__toPrimitive(t)}}}static NE(t,e){return!g.EQ(t,e)}static __zero(){return new g(0,!1)}static __oneDigit(t,e){const r=new g(1,e);return r.__setDigit(0,t),r}__copy(){const t=new g(this.length,this.sign);for(let e=0;e<this.length;e++)t[e]=this[e];return t}__trim(){let t=this.length,e=this[t-1];for(;0===e;)t--,e=this[t-1],this.pop();return 0===t&&(this.sign=!1),this}__initializeDigits(){for(let t=0;t<this.length;t++)this[t]=0}static __decideRounding(t,e,r,n){if(0<e)return-1;let i;if(0>e)i=-e-1;else{if(0===r)return-1;r--,n=t.__digit(r),i=31}let o=1<<i;if(0==(n&o))return-1;if(o-=1,0!=(n&o))return 1;for(;0<r;)if(r--,0!==t.__digit(r))return 1;return 0}static __fromDouble(t){g.__kBitConversionDouble[0]=t;const e=(2047&g.__kBitConversionInts[1]>>>20)-1023,r=1+(e>>>5),n=new g(r,0>t);let i=1048575&g.__kBitConversionInts[1]|1048576,o=g.__kBitConversionInts[0];const s=31&e;let a,u=0;if(s<20){const t=20-s;u=t+32,a=i>>>t,i=i<<32-t|o>>>t,o<<=32-t}else if(20===s)u=32,a=i,i=o;else{const t=s-20;u=32-t,a=i<<t|o>>>32-t,i=o<<t}n.__setDigit(r-1,a);for(let t=r-2;0<=t;t--)0<u?(u-=32,a=i,i=o):a=0,n.__setDigit(t,a);return n.__trim()}static __isWhitespace(t){return!!(13>=t&&9<=t)||(159>=t?32==t:131071>=t?160==t||5760==t:196607>=t?10>=(t&=131071)||40==t||41==t||47==t||95==t||4096==t:65279==t)}static __fromString(t,e=0){let r=0;const n=t.length;let i=0;if(i===n)return g.__zero();let o=t.charCodeAt(i);for(;g.__isWhitespace(o);){if(++i===n)return g.__zero();o=t.charCodeAt(i)}if(43===o){if(++i===n)return null;o=t.charCodeAt(i),r=1}else if(45===o){if(++i===n)return null;o=t.charCodeAt(i),r=-1}if(0===e){if(e=10,48===o){if(++i===n)return g.__zero();if(o=t.charCodeAt(i),88===o||120===o){if(e=16,++i===n)return null;o=t.charCodeAt(i)}else if(79===o||111===o){if(e=8,++i===n)return null;o=t.charCodeAt(i)}else if(66===o||98===o){if(e=2,++i===n)return null;o=t.charCodeAt(i)}}}else if(16===e&&48===o){if(++i===n)return g.__zero();if(o=t.charCodeAt(i),88===o||120===o){if(++i===n)return null;o=t.charCodeAt(i)}}for(;48===o;){if(++i===n)return g.__zero();o=t.charCodeAt(i)}const s=n-i;let a=g.__kMaxBitsPerChar[e],u=g.__kBitsPerCharTableMultiplier-1;if(s>1073741824/a)return null;const l=a*s+u>>>g.__kBitsPerCharTableShift,c=new g(l+31>>>5,!1),_=10>e?e:10,f=10<e?e-10:0;if(0==(e&e-1)){a>>=g.__kBitsPerCharTableShift;const e=[],r=[];let s=!1;do{let u=0,l=0;for(;;){let e;if(o-48>>>0<_)e=o-48;else{if(!((32|o)-97>>>0<f)){s=!0;break}e=(32|o)-87}if(l+=a,u=u<<a|e,++i===n){s=!0;break}if(o=t.charCodeAt(i),32<l+a)break}e.push(u),r.push(l)}while(!s);g.__fillFromParts(c,e,r)}else{c.__initializeDigits();let r=!1,s=0;do{let l=0,h=1;for(;;){let a;if(o-48>>>0<_)a=o-48;else{if(!((32|o)-97>>>0<f)){r=!0;break}a=(32|o)-87}const u=h*e;if(4294967295<u)break;if(h=u,l=l*e+a,s++,++i===n){r=!0;break}o=t.charCodeAt(i)}u=32*g.__kBitsPerCharTableMultiplier-1;const d=a*s+u>>>g.__kBitsPerCharTableShift+5;c.__inplaceMultiplyAdd(h,l,d)}while(!r)}if(i!==n){if(!g.__isWhitespace(o))return null;for(i++;i<n;i++)if(o=t.charCodeAt(i),!g.__isWhitespace(o))return null}return 0!=r&&10!==e?null:(c.sign=-1==r,c.__trim())}static __fillFromParts(t,e,r){let n=0,i=0,o=0;for(let s=e.length-1;0<=s;s--){const a=e[s],u=r[s];i|=a<<o,o+=u,32===o?(t.__setDigit(n++,i),o=0,i=0):32<o&&(t.__setDigit(n++,i),o-=32,i=a>>>u-o)}if(0!==i){if(n>=t.length)throw new Error("implementation bug");t.__setDigit(n++,i)}for(;n<t.length;n++)t.__setDigit(n,0)}static __toStringBasePowerOfTwo(t,e){var r=Math.clz32;const n=t.length;let i=e-1;i=(85&i>>>1)+(85&i),i=(51&i>>>2)+(51&i),i=(15&i>>>4)+(15&i);const o=i,s=e-1,a=t.__digit(n-1);let u=0|(32*n-r(a)+o-1)/o;if(t.sign&&u++,268435456<u)throw new Error("string too long");const l=Array(u);let c=u-1,_=0,f=0;for(let e=0;e<n-1;e++){const r=t.__digit(e),n=(_|r<<f)&s;l[c--]=g.__kConversionChars[n];const i=o-f;for(_=r>>>i,f=32-i;f>=o;)l[c--]=g.__kConversionChars[_&s],_>>>=o,f-=o}const h=(_|a<<f)&s;for(l[c--]=g.__kConversionChars[h],_=a>>>o-f;0!==_;)l[c--]=g.__kConversionChars[_&s],_>>>=o;if(t.sign&&(l[c--]="-"),-1!=c)throw new Error("implementation bug");return l.join("")}static __toStringGeneric(t,e,r){var n=Math.clz32;const i=t.length;if(0===i)return"";if(1===i){let n=t.__unsignedDigit(0).toString(e);return!1===r&&t.sign&&(n="-"+n),n}const o=32*i-n(t.__digit(i-1)),s=g.__kMaxBitsPerChar[e]-1;let a=o*g.__kBitsPerCharTableMultiplier;a+=s-1,a=0|a/s;const u=a+1>>1,l=g.exponentiate(g.__oneDigit(e,!1),g.__oneDigit(u,!1));let c,_;const f=l.__unsignedDigit(0);if(1===l.length&&65535>=f){c=new g(t.length,!1),c.__initializeDigits();let r=0;for(let e=2*t.length-1;0<=e;e--){const n=r<<16|t.__halfDigit(e);c.__setHalfDigit(e,0|n/f),r=0|n%f}_=r.toString(e)}else{const r=g.__absoluteDivLarge(t,l,!0,!0);c=r.quotient;const n=r.remainder.__trim();_=g.__toStringGeneric(n,e,!0)}c.__trim();let h=g.__toStringGeneric(c,e,!0);for(;_.length<u;)_="0"+_;return!1===r&&t.sign&&(h="-"+h),h+_}static __unequalSign(t){return t?-1:1}static __absoluteGreater(t){return t?-1:1}static __absoluteLess(t){return t?1:-1}static __compareToBigInt(t,e){const r=t.sign;if(r!==e.sign)return g.__unequalSign(r);const n=g.__absoluteCompare(t,e);return 0<n?g.__absoluteGreater(r):0>n?g.__absoluteLess(r):0}static __compareToNumber(t,e){if(!0|e){const r=t.sign,n=0>e;if(r!==n)return g.__unequalSign(r);if(0===t.length){if(n)throw new Error("implementation bug");return 0===e?0:-1}if(1<t.length)return g.__absoluteGreater(r);const i=Math.abs(e),o=t.__unsignedDigit(0);return o>i?g.__absoluteGreater(r):o<i?g.__absoluteLess(r):0}return g.__compareToDouble(t,e)}static __compareToDouble(t,e){var r=Math.clz32;if(e!=e)return e;if(e===1/0)return-1;if(e===-1/0)return 1;const n=t.sign;if(n!==0>e)return g.__unequalSign(n);if(0===e)throw new Error("implementation bug: should be handled elsewhere");if(0===t.length)return-1;g.__kBitConversionDouble[0]=e;const i=2047&g.__kBitConversionInts[1]>>>20;if(2047==i)throw new Error("implementation bug: handled elsewhere");const o=i-1023;if(0>o)return g.__absoluteGreater(n);const s=t.length;let a=t.__digit(s-1);const u=r(a),l=32*s-u,c=o+1;if(l<c)return g.__absoluteLess(n);if(l>c)return g.__absoluteGreater(n);let _=1048576|1048575&g.__kBitConversionInts[1],f=g.__kBitConversionInts[0];const h=31-u;if(h!==(l-1)%31)throw new Error("implementation bug");let d,p=0;if(20>h){const t=20-h;p=t+32,d=_>>>t,_=_<<32-t|f>>>t,f<<=32-t}else if(20===h)p=32,d=_,_=f;else{const t=h-20;p=32-t,d=_<<t|f>>>32-t,_=f<<t}if(a>>>=0,d>>>=0,a>d)return g.__absoluteGreater(n);if(a<d)return g.__absoluteLess(n);for(let e=s-2;0<=e;e--){0<p?(p-=32,d=_>>>0,_=f,f=0):d=0;const r=t.__unsignedDigit(e);if(r>d)return g.__absoluteGreater(n);if(r<d)return g.__absoluteLess(n)}if(0!==_||0!==f){if(0===p)throw new Error("implementation bug");return g.__absoluteLess(n)}return 0}static __equalToNumber(t,e){var r=Math.abs;return e|0===e?0===e?0===t.length:1===t.length&&t.sign===0>e&&t.__unsignedDigit(0)===r(e):0===g.__compareToDouble(t,e)}static __comparisonResultToBool(t,e){switch(e){case 0:return 0>t;case 1:return 0>=t;case 2:return 0<t;case 3:return 0<=t}throw new Error("unreachable")}static __compare(t,e,r){if(t=g.__toPrimitive(t),e=g.__toPrimitive(e),"string"==typeof t&&"string"==typeof e)switch(r){case 0:return t<e;case 1:return t<=e;case 2:return t>e;case 3:return t>=e}if(g.__isBigInt(t)&&"string"==typeof e)return null!==(e=g.__fromString(e))&&g.__comparisonResultToBool(g.__compareToBigInt(t,e),r);if("string"==typeof t&&g.__isBigInt(e))return null!==(t=g.__fromString(t))&&g.__comparisonResultToBool(g.__compareToBigInt(t,e),r);if(t=g.__toNumeric(t),e=g.__toNumeric(e),g.__isBigInt(t)){if(g.__isBigInt(e))return g.__comparisonResultToBool(g.__compareToBigInt(t,e),r);if("number"!=typeof e)throw new Error("implementation bug");return g.__comparisonResultToBool(g.__compareToNumber(t,e),r)}if("number"!=typeof t)throw new Error("implementation bug");if(g.__isBigInt(e))return g.__comparisonResultToBool(g.__compareToNumber(e,t),2^r);if("number"!=typeof e)throw new Error("implementation bug");return 0===r?t<e:1===r?t<=e:2===r?t>e:3===r?t>=e:void 0}__clzmsd(){return Math.clz32(this[this.length-1])}static __absoluteAdd(t,e,r){if(t.length<e.length)return g.__absoluteAdd(e,t,r);if(0===t.length)return t;if(0===e.length)return t.sign===r?t:g.unaryMinus(t);let n=t.length;(0===t.__clzmsd()||e.length===t.length&&0===e.__clzmsd())&&n++;const i=new g(n,r);let o=0,s=0;for(;s<e.length;s++){const r=e.__digit(s),n=t.__digit(s),a=(65535&n)+(65535&r)+o,u=(n>>>16)+(r>>>16)+(a>>>16);o=u>>>16,i.__setDigit(s,65535&a|u<<16)}for(;s<t.length;s++){const e=t.__digit(s),r=(65535&e)+o,n=(e>>>16)+(r>>>16);o=n>>>16,i.__setDigit(s,65535&r|n<<16)}return s<i.length&&i.__setDigit(s,o),i.__trim()}static __absoluteSub(t,e,r){if(0===t.length)return t;if(0===e.length)return t.sign===r?t:g.unaryMinus(t);const n=new g(t.length,r);let i=0,o=0;for(;o<e.length;o++){const r=t.__digit(o),s=e.__digit(o),a=(65535&r)-(65535&s)-i;i=1&a>>>16;const u=(r>>>16)-(s>>>16)-i;i=1&u>>>16,n.__setDigit(o,65535&a|u<<16)}for(;o<t.length;o++){const e=t.__digit(o),r=(65535&e)-i;i=1&r>>>16;const s=(e>>>16)-i;i=1&s>>>16,n.__setDigit(o,65535&r|s<<16)}return n.__trim()}static __absoluteAddOne(t,e,r=null){const n=t.length;null===r?r=new g(n,e):r.sign=e;let i=!0;for(let e,o=0;o<n;o++){e=t.__digit(o);const n=-1===e;i&&(e=0|e+1),i=n,r.__setDigit(o,e)}return i&&r.__setDigitGrow(n,1),r}static __absoluteSubOne(t,e){const r=t.length,n=new g(e=e||r,!1);let i=!0;for(let e,o=0;o<r;o++){e=t.__digit(o);const r=0===e;i&&(e=0|e-1),i=r,n.__setDigit(o,e)}for(let t=r;t<e;t++)n.__setDigit(t,0);return n}static __absoluteAnd(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=o;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)&e.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteAndNot(t,e,r=null){const n=t.length,i=e.length;let o=i;n<i&&(o=n);let s=n;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)&~e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteOr(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=n;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)|e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteXor(t,e,r=null){let n=t.length,i=e.length,o=i;if(n<i){o=n;const r=t,s=n;t=e,n=i,e=r,i=s}let s=n;null===r?r=new g(s,!1):s=r.length;let a=0;for(;a<o;a++)r.__setDigit(a,t.__digit(a)^e.__digit(a));for(;a<n;a++)r.__setDigit(a,t.__digit(a));for(;a<s;a++)r.__setDigit(a,0);return r}static __absoluteCompare(t,e){const r=t.length-e.length;if(0!=r)return r;let n=t.length-1;for(;0<=n&&t.__digit(n)===e.__digit(n);)n--;return 0>n?0:t.__unsignedDigit(n)>e.__unsignedDigit(n)?1:-1}static __multiplyAccumulate(t,e,r,n){var i=Math.imul;if(0===e)return;const o=65535&e,s=e>>>16;let a=0,u=0,l=0;for(let e=0;e<t.length;e++,n++){let c=r.__digit(n),_=65535&c,f=c>>>16;const h=t.__digit(e),g=65535&h,d=h>>>16,p=i(g,o),b=i(g,s),m=i(d,o),y=i(d,s);_+=u+(65535&p),f+=l+a+(_>>>16)+(p>>>16)+(65535&b)+(65535&m),a=f>>>16,u=(b>>>16)+(m>>>16)+(65535&y)+a,a=u>>>16,u&=65535,l=y>>>16,c=65535&_|f<<16,r.__setDigit(n,c)}for(;0!=a||0!==u||0!==l;n++){let t=r.__digit(n);const e=(65535&t)+u,i=(t>>>16)+(e>>>16)+l+a;u=0,l=0,a=i>>>16,t=65535&e|i<<16,r.__setDigit(n,t)}}static __internalMultiplyAdd(t,e,r,n,i){var o=Math.imul;let s=r,a=0;for(let r=0;r<n;r++){const n=t.__digit(r),u=o(65535&n,e),l=(65535&u)+a+s;s=l>>>16;const c=o(n>>>16,e),_=(65535&c)+(u>>>16)+s;s=_>>>16,a=c>>>16,i.__setDigit(r,_<<16|65535&l)}if(i.length>n)for(i.__setDigit(n++,s+a);n<i.length;)i.__setDigit(n++,0);else if(0!==s+a)throw new Error("implementation bug")}__inplaceMultiplyAdd(t,e,r){var n=Math.imul;r>this.length&&(r=this.length);const i=65535&t,o=t>>>16;let s=0,a=65535&e,u=e>>>16;for(let t=0;t<r;t++){const e=this.__digit(t),r=65535&e,l=e>>>16,c=n(r,i),_=n(r,o),f=n(l,i),h=n(l,o),g=a+(65535&c),d=u+s+(g>>>16)+(c>>>16)+(65535&_)+(65535&f);a=(_>>>16)+(f>>>16)+(65535&h)+(d>>>16),s=a>>>16,a&=65535,u=h>>>16,this.__setDigit(t,65535&g|d<<16)}if(0!=s||0!==a||0!==u)throw new Error("implementation bug")}static __absoluteDivSmall(t,e,r){null===r&&(r=new g(t.length,!1));let n=0;for(let i,o=2*t.length-1;0<=o;o-=2){i=(n<<16|t.__halfDigit(o))>>>0;const s=0|i/e;n=0|i%e,i=(n<<16|t.__halfDigit(o-1))>>>0;const a=0|i/e;n=0|i%e,r.__setDigit(o>>>1,s<<16|a)}return r}static __absoluteModSmall(t,e){let r=0;for(let n=2*t.length-1;0<=n;n--){r=0|((r<<16|t.__halfDigit(n))>>>0)%e}return r}static __absoluteDivLarge(t,e,r,n){var i=Math.imul;const o=e.__halfDigitLength(),s=e.length,a=t.__halfDigitLength()-o;let u=null;r&&(u=new g(a+2>>>1,!1),u.__initializeDigits());const l=new g(o+2>>>1,!1);l.__initializeDigits();const c=g.__clz16(e.__halfDigit(o-1));0<c&&(e=g.__specialLeftShift(e,c,0));const _=g.__specialLeftShift(t,c,1),f=e.__halfDigit(o-1);let h=0;for(let t,n=a;0<=n;n--){t=65535;const a=_.__halfDigit(n+o);if(a!==f){const r=(a<<16|_.__halfDigit(n+o-1))>>>0;t=0|r/f;let s=0|r%f;const u=e.__halfDigit(o-2),l=_.__halfDigit(n+o-2);for(;i(t,u)>>>0>(s<<16|l)>>>0&&(t--,s+=f,!(65535<s)););}g.__internalMultiplyAdd(e,t,0,s,l);let c=_.__inplaceSub(l,n,o+1);0!==c&&(c=_.__inplaceAdd(e,n,o),_.__setHalfDigit(n+o,_.__halfDigit(n+o)+c),t--),r&&(1&n?h=t<<16:u.__setDigit(n>>>1,h|t))}return n?(_.__inplaceRightShift(c),r?{quotient:u,remainder:_}:_):r?u:void 0}static __clz16(t){return Math.clz32(t)-16}__inplaceAdd(t,e,r){let n=0;for(let i=0;i<r;i++){const r=this.__halfDigit(e+i)+t.__halfDigit(i)+n;n=r>>>16,this.__setHalfDigit(e+i,r)}return n}__inplaceSub(t,e,r){let n=0;if(1&e){e>>=1;let i=this.__digit(e),o=65535&i,s=0;for(;s<r-1>>>1;s++){const r=t.__digit(s),a=(i>>>16)-(65535&r)-n;n=1&a>>>16,this.__setDigit(e+s,a<<16|65535&o),i=this.__digit(e+s+1),o=(65535&i)-(r>>>16)-n,n=1&o>>>16}const a=t.__digit(s),u=(i>>>16)-(65535&a)-n;if(n=1&u>>>16,this.__setDigit(e+s,u<<16|65535&o),e+s+1>=this.length)throw new RangeError("out of bounds");0==(1&r)&&(i=this.__digit(e+s+1),o=(65535&i)-(a>>>16)-n,n=1&o>>>16,this.__setDigit(e+t.length,4294901760&i|65535&o))}else{e>>=1;let i=0;for(;i<t.length-1;i++){const r=this.__digit(e+i),o=t.__digit(i),s=(65535&r)-(65535&o)-n;n=1&s>>>16;const a=(r>>>16)-(o>>>16)-n;n=1&a>>>16,this.__setDigit(e+i,a<<16|65535&s)}const o=this.__digit(e+i),s=t.__digit(i),a=(65535&o)-(65535&s)-n;n=1&a>>>16;let u=0;0==(1&r)&&(u=(o>>>16)-(s>>>16)-n,n=1&u>>>16),this.__setDigit(e+i,u<<16|65535&a)}return n}__inplaceRightShift(t){if(0===t)return;let e=this.__digit(0)>>>t;const r=this.length-1;for(let n=0;n<r;n++){const r=this.__digit(n+1);this.__setDigit(n,r<<32-t|e),e=r>>>t}this.__setDigit(r,e)}static __specialLeftShift(t,e,r){const n=t.length,i=new g(n+r,!1);if(0===e){for(let e=0;e<n;e++)i.__setDigit(e,t.__digit(e));return 0<r&&i.__setDigit(n,0),i}let o=0;for(let r=0;r<n;r++){const n=t.__digit(r);i.__setDigit(r,n<<e|o),o=n>>>32-e}return 0<r&&i.__setDigit(n,o),i}static __leftShiftByAbsolute(t,e){const r=g.__toShiftAmount(e);if(0>r)throw new RangeError("BigInt too big");const n=r>>>5,i=31&r,o=t.length,s=0!==i&&0!=t.__digit(o-1)>>>32-i,a=o+n+(s?1:0),u=new g(a,t.sign);if(0===i){let e=0;for(;e<n;e++)u.__setDigit(e,0);for(;e<a;e++)u.__setDigit(e,t.__digit(e-n))}else{let e=0;for(let t=0;t<n;t++)u.__setDigit(t,0);for(let r=0;r<o;r++){const o=t.__digit(r);u.__setDigit(r+n,o<<i|e),e=o>>>32-i}if(s)u.__setDigit(o+n,e);else if(0!=e)throw new Error("implementation bug")}return u.__trim()}static __rightShiftByAbsolute(t,e){const r=t.length,n=t.sign,i=g.__toShiftAmount(e);if(0>i)return g.__rightShiftByMaximum(n);const o=i>>>5,s=31&i;let a=r-o;if(0>=a)return g.__rightShiftByMaximum(n);let u=!1;if(n)if(0!=(t.__digit(o)&(1<<s)-1))u=!0;else for(let e=0;e<o;e++)if(0!==t.__digit(e)){u=!0;break}if(u&&0===s){0==~t.__digit(r-1)&&a++}let l=new g(a,n);if(0===s)for(let e=o;e<r;e++)l.__setDigit(e-o,t.__digit(e));else{let e=t.__digit(o)>>>s;const n=r-o-1;for(let r=0;r<n;r++){const n=t.__digit(r+o+1);l.__setDigit(r,n<<32-s|e),e=n>>>s}l.__setDigit(n,e)}return u&&(l=g.__absoluteAddOne(l,!0,l)),l.__trim()}static __rightShiftByMaximum(t){return t?g.__oneDigit(1,!0):g.__zero()}static __toShiftAmount(t){if(1<t.length)return-1;const e=t.__unsignedDigit(0);return e>g.__kMaxLengthBits?-1:e}static __toPrimitive(t,e="default"){if("object"!=typeof t)return t;if(t.constructor===g)return t;const r=t[Symbol.toPrimitive];if(r){const t=r(e);if("object"!=typeof t)return t;throw new TypeError("Cannot convert object to primitive value")}const n=t.valueOf;if(n){const e=n.call(t);if("object"!=typeof e)return e}const i=t.toString;if(i){const e=i.call(t);if("object"!=typeof e)return e}throw new TypeError("Cannot convert object to primitive value")}static __toNumeric(t){return g.__isBigInt(t)?t:+t}static __isBigInt(t){return"object"==typeof t&&t.constructor===g}static __truncateToNBits(t,e){const r=t+31>>>5,n=new g(r,e.sign),i=r-1;for(let t=0;t<i;t++)n.__setDigit(t,e.__digit(t));let o=e.__digit(i);if(0!=(31&t)){const e=32-(31&t);o=o<<e>>>e}return n.__setDigit(i,o),n.__trim()}static __truncateAndSubFromPowerOfTwo(t,e,r){var n=Math.min;const i=t+31>>>5,o=new g(i,r);let s=0;const a=i-1;let u=0;for(const t=n(a,e.length);s<t;s++){const t=e.__digit(s),r=0-(65535&t)-u;u=1&r>>>16;const n=0-(t>>>16)-u;u=1&n>>>16,o.__setDigit(s,65535&r|n<<16)}for(;s<a;s++)o.__setDigit(s,0|-u);let l=a<e.length?e.__digit(a):0;const c=31&t;let _;if(0==c){const t=0-(65535&l)-u;u=1&t>>>16;_=65535&t|0-(l>>>16)-u<<16}else{const t=32-c;l=l<<t>>>t;const e=1<<32-t,r=(65535&e)-(65535&l)-u;u=1&r>>>16;_=65535&r|(e>>>16)-(l>>>16)-u<<16,_&=e-1}return o.__setDigit(a,_),o.__trim()}__digit(t){return this[t]}__unsignedDigit(t){return this[t]>>>0}__setDigit(t,e){this[t]=0|e}__setDigitGrow(t,e){this[t]=0|e}__halfDigitLength(){const t=this.length;return 65535>=this.__unsignedDigit(t-1)?2*t-1:2*t}__halfDigit(t){return 65535&this[t>>>1]>>>((1&t)<<4)}__setHalfDigit(t,e){const r=t>>>1,n=this.__digit(r),i=1&t?65535&n|e<<16:4294901760&n|65535&e;this.__setDigit(r,i)}static __digitPow(t,e){let r=1;for(;0<e;)1&e&&(r*=t),e>>>=1,t*=t;return r}}function d(t,e,r,n=[]){!function(t,e){if(!(e instanceof Object))throw new Error(t+" is not an object!")}(t,e);const i=Object.keys(e).sort(),o=r.length,s=r.length+n.length,a=`${t} does not have correct keys! Required keys: [${r.sort().join(", ")}], optional keys: [${n.sort().join(", ")}], actual keys: [${i.join(", ")}]`;if(i.length<o||i.length>s)throw new Error(a);let u=i.filter(t=>!r.includes(t));if(i.length-u.length!==o)throw new Error(a);if(u.find(t=>!n.includes(t)))throw new Error(a)}function p(t,e){if(!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(e))throw new Error(t+" must be a hex string!")}function b(t,e){if(p(t,e),66!=e.length)throw new Error(t+" must be a hex string of 66 bytes long!")}function m(t,e){if("0x0"!==e&&!/^0x[1-9a-fA-F][0-9a-fA-F]*$/.test(e))throw new Error(t+" must be a hex integer!")}function y(t,{nestedValidation:e=!0,debugPath:r="script"}={}){if(d(r,t,["code_hash","hash_type","args"],[]),b(r+".code_hash",t.code_hash),p(r+".args",t.args),"data"!==t.hash_type&&"type"!==t.hash_type)throw new Error(r+".hash_type must be either data or type!")}function w(t,{nestedValidation:e=!0,debugPath:r="out_point"}={}){d(r,t,["tx_hash","index"],[]),b(r+".tx_hash",t.tx_hash),m(r+".index",t.index)}function v(t,{nestedValidation:e=!0,debugPath:r="cell_input"}={}){d(r,t,["since","previous_output"],[]),m(r+".since",t.since),e&&w(t.previous_output,{debugPath:r+".previous_output"})}function B(t,{nestedValidation:e=!0,debugPath:r="cell_output"}={}){d(r,t,["capacity","lock"],["type"]),m(r+".capacity",t.capacity),e&&(y(t.lock,{debugPath:r+".lock"}),t.type&&y(t.type,{debugPath:r+".type"}))}function P(t,{nestedValidation:e=!0,debugPath:r="cell_dep"}={}){if(d(r,t,["out_point","dep_type"],[]),"code"!==t.dep_type&&"dep_group"!==t.dep_type)throw new Error(r+".dep_type must be either code or dep_group!");e&&w(t.out_point,{debugPath:r+".out_point"})}function D(t,e,r,n){if(!Array.isArray(e))throw new Error(t+" is not an array!");if(n)for(let n=0;n<e.length;n++)r(`${t}[${n}]`,e[n])}function S(t,e){return function(r,n){t(n,{nestedValidation:e,debugPath:r})}}function T(t,e,r){m(t+".version",e.version),D(t+".cell_deps",e.cell_deps,S(P,r),r),D(t+".header_deps",e.header_deps,b,r),D(t+".inputs",e.inputs,S(v,r),r),D(t+".outputs",e.outputs,S(B,r),r),D(t+".outputs_data",e.outputs_data,p,r)}function k(t,{nestedValidation:e=!0,debugPath:r="raw_transaction"}={}){d(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data"],[]),T(r,t,e)}function x(t,{nestedValidation:e=!0,debugPath:r="transaction"}={}){d(r,t,["version","cell_deps","header_deps","inputs","outputs","outputs_data","witnesses"],[]),T(r,t,e),D(r+".witnesses",t.witnesses,p,e)}function C(t,{nestedValidation:e=!0,debugPath:r="raw_header"}={}){d(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao"],[]),function(t,e){m(t+".version",e.version),m(t+".compact_target",e.compact_target),m(t+".timestamp",e.timestamp),m(t+".number",e.number),m(t+".epoch",e.epoch),b(t+".parent_hash",e.parent_hash),b(t+".transactions_root",e.transactions_root),b(t+".proposals_hash",e.proposals_hash),b(t+".uncles_hash",e.uncles_hash),b(t+".dao",e.dao)}(r,t)}function E(t,{nestedValidation:e=!0,debugPath:r="header"}={}){if(d(r,t,["version","compact_target","timestamp","number","epoch","parent_hash","transactions_root","proposals_hash","uncles_hash","dao","nonce"],[]),p(r+".nonce",t.nonce),34!=t.nonce.length)throw new Error(r+".nonce must be a hex string of 34 bytes long!")}function O(t,e){if(p(t,e),22!=e.length)throw new Error(t+" must be a hex string of 22 bytes long!")}function A(t,{nestedValidation:e=!0,debugPath:r="uncle_block"}={}){d(r,t,["header","proposals"],[]),e&&E(t.header,{debugPath:r+".header"}),D(r+".proposals",t.proposals,O,e)}function j(t,{nestedValidation:e=!0,debugPath:r="block"}={}){d(r,t,["header","uncles","transactions","proposals"],[]),e&&E(t.header,{debugPath:r+".header"}),D(r+".uncles",t.uncles,S(A,e),e),D(r+".transactions",t.transactions,S(x,e),e),D(r+".proposals",t.proposals,O,e)}function z(t,{nestedValidation:e=!0,debugPath:r="cellbase_witness"}={}){d(r,t,["lock","message"],[]),p(r+".message",t.message),e&&y(t.lock,{debugPath:r+".lock"})}function I(t,{nestedValidation:e=!0,debugPath:r="witness_args"}={}){d(r,t,[],["lock","input_type","output_type"]),t.lock&&p(r+".lock",t.lock),t.input_type&&p(r+".input_type",t.input_type),t.output_type&&p(r+".output_type",t.output_type)}g.__kMaxLength=33554432,g.__kMaxLengthBits=g.__kMaxLength<<5,g.__kMaxBitsPerChar=[0,0,32,51,64,75,83,90,96,102,107,111,115,119,122,126,128,131,134,136,139,141,143,145,147,149,151,153,154,156,158,159,160,162,163,165,166],g.__kBitsPerCharTableShift=5,g.__kBitsPerCharTableMultiplier=1<<g.__kBitsPerCharTableShift,g.__kConversionChars=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],g.__kBitConversionBuffer=new ArrayBuffer(8),g.__kBitConversionDouble=new Float64Array(g.__kBitConversionBuffer),g.__kBitConversionInts=new Int32Array(g.__kBitConversionBuffer);var R=Object.freeze({__proto__:null,ValidateScript:y,ValidateOutPoint:w,ValidateCellInput:v,ValidateCellOutput:B,ValidateCellDep:P,ValidateRawTransaction:k,ValidateTransaction:x,ValidateRawHeader:C,ValidateHeader:E,ValidateUncleBlock:A,ValidateBlock:j,ValidateCellbaseWitness:z,ValidateWitnessArgs:I});const L=s.default.Readable,M=Symbol("buffer"),N=Symbol("type");class ${constructor(){this[N]="";const t=arguments[0],e=arguments[1],r=[];let n=0;if(t){const e=t,i=Number(e.length);for(let t=0;t<i;t++){const i=e[t];let o;o=i instanceof Buffer?i:ArrayBuffer.isView(i)?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i instanceof ArrayBuffer?Buffer.from(i):i instanceof $?i[M]:Buffer.from("string"==typeof i?i:String(i)),n+=o.length,r.push(o)}}this[M]=Buffer.concat(r);let i=e&&void 0!==e.type&&String(e.type).toLowerCase();i&&!/[^\u0020-\u007E]/.test(i)&&(this[N]=i)}get size(){return this[M].length}get type(){return this[N]}text(){return Promise.resolve(this[M].toString())}arrayBuffer(){const t=this[M],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new L;return t._read=function(){},t.push(this[M]),t.push(null),t}toString(){return"[object Blob]"}slice(){const t=this.size,e=arguments[0],r=arguments[1];let n,i;n=void 0===e?0:e<0?Math.max(t+e,0):Math.min(e,t),i=void 0===r?t:r<0?Math.max(t+r,0):Math.min(r,t);const o=Math.max(i-n,0),s=this[M].slice(n,n+o),a=new $([],{type:arguments[2]});return a[M]=s,a}}function q(t,e,r){Error.call(this,t),this.message=t,this.type=e,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let U;Object.defineProperties($.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty($.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),q.prototype=Object.create(Error.prototype),q.prototype.constructor=q,q.prototype.name="FetchError";try{U=require("encoding").convert}catch(t){}const V=Symbol("Body internals"),H=s.default.PassThrough;function F(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.size;let i=void 0===n?0:n;var o=r.timeout;let a=void 0===o?0:o;null==t?t=null:W(t)?t=Buffer.from(t.toString()):J(t)||Buffer.isBuffer(t)||("[object ArrayBuffer]"===Object.prototype.toString.call(t)?t=Buffer.from(t):ArrayBuffer.isView(t)?t=Buffer.from(t.buffer,t.byteOffset,t.byteLength):t instanceof s.default||(t=Buffer.from(String(t)))),this[V]={body:t,disturbed:!1,error:null},this.size=i,this.timeout=a,t instanceof s.default&&t.on("error",(function(t){const r="AbortError"===t.name?t:new q(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t);e[V].error=r}))}function G(){var t=this;if(this[V].disturbed)return F.Promise.reject(new TypeError("body used already for: "+this.url));if(this[V].disturbed=!0,this[V].error)return F.Promise.reject(this[V].error);let e=this.body;if(null===e)return F.Promise.resolve(Buffer.alloc(0));if(J(e)&&(e=e.stream()),Buffer.isBuffer(e))return F.Promise.resolve(e);if(!(e instanceof s.default))return F.Promise.resolve(Buffer.alloc(0));let r=[],n=0,i=!1;return new F.Promise((function(o,s){let a;t.timeout&&(a=setTimeout((function(){i=!0,s(new q(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),e.on("error",(function(e){"AbortError"===e.name?(i=!0,s(e)):s(new q(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),e.on("data",(function(e){if(!i&&null!==e){if(t.size&&n+e.length>t.size)return i=!0,void s(new q(`content size at ${t.url} over limit: ${t.size}`,"max-size"));n+=e.length,r.push(e)}})),e.on("end",(function(){if(!i){clearTimeout(a);try{o(Buffer.concat(r,n))}catch(e){s(new q(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function W(t){return"object"==typeof t&&"function"==typeof t.append&&"function"==typeof t.delete&&"function"==typeof t.get&&"function"==typeof t.getAll&&"function"==typeof t.has&&"function"==typeof t.set&&("URLSearchParams"===t.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(t)||"function"==typeof t.sort)}function J(t){return"object"==typeof t&&"function"==typeof t.arrayBuffer&&"string"==typeof t.type&&"function"==typeof t.stream&&"function"==typeof t.constructor&&"string"==typeof t.constructor.name&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag])}function X(t){let e,r,n=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof s.default&&"function"!=typeof n.getBoundary&&(e=new H,r=new H,n.pipe(e),n.pipe(r),t[V].body=e,n=r),n}function Q(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":W(t)?"application/x-www-form-urlencoded;charset=UTF-8":J(t)?t.type||null:Buffer.isBuffer(t)||"[object ArrayBuffer]"===Object.prototype.toString.call(t)||ArrayBuffer.isView(t)?null:"function"==typeof t.getBoundary?"multipart/form-data;boundary="+t.getBoundary():t instanceof s.default?null:"text/plain;charset=UTF-8"}function Z(t){const e=t.body;return null===e?0:J(e)?e.size:Buffer.isBuffer(e)?e.length:e&&"function"==typeof e.getLengthSync&&(e._lengthRetrievers&&0==e._lengthRetrievers.length||e.hasKnownLength&&e.hasKnownLength())?e.getLengthSync():null}F.prototype={get body(){return this[V].body},get bodyUsed(){return this[V].disturbed},arrayBuffer(){return G.call(this).then((function(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}))},blob(){let t=this.headers&&this.headers.get("content-type")||"";return G.call(this).then((function(e){return Object.assign(new $([],{type:t.toLowerCase()}),{[M]:e})}))},json(){var t=this;return G.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return F.Promise.reject(new q(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return G.call(this).then((function(t){return t.toString()}))},buffer(){return G.call(this)},textConverted(){var t=this;return G.call(this).then((function(e){return function(t,e){if("function"!=typeof U)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=e.get("content-type");let n,i,o="utf-8";r&&(n=/charset=([^;]*)/i.exec(r));i=t.slice(0,1024).toString(),!n&&i&&(n=/<meta.+?charset=(['"])(.+?)\1/i.exec(i));!n&&i&&(n=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(i),n||(n=/<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(i),n&&n.pop()),n&&(n=/charset=(.*)/i.exec(n.pop())));!n&&i&&(n=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(i));n&&(o=n.pop(),"gb2312"!==o&&"gbk"!==o||(o="gb18030"));return U(t,"UTF-8",o).toString()}(e,t.headers)}))}},Object.defineProperties(F.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),F.mixIn=function(t){for(const e of Object.getOwnPropertyNames(F.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(F.prototype,e);Object.defineProperty(t,e,r)}},F.Promise=global.Promise;const K=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,Y=/[^\t\x20-\x7e\x80-\xff]/;function tt(t){if(t=""+t,K.test(t)||""===t)throw new TypeError(t+" is not a legal HTTP header name")}function et(t){if(t=""+t,Y.test(t))throw new TypeError(t+" is not a legal HTTP header value")}function rt(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const nt=Symbol("map");class it{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[nt]=Object.create(null),t instanceof it){const e=t.raw(),r=Object.keys(e);for(const t of r)for(const r of e[t])this.append(t,r)}else if(null==t);else{if("object"!=typeof t)throw new TypeError("Provided initializer must be an object");{const e=t[Symbol.iterator];if(null!=e){if("function"!=typeof e)throw new TypeError("Header pairs must be iterable");const r=[];for(const e of t){if("object"!=typeof e||"function"!=typeof e[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(e))}for(const t of r){if(2!==t.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(t[0],t[1])}}else for(const e of Object.keys(t)){const r=t[e];this.append(e,r)}}}}get(t){tt(t=""+t);const e=rt(this[nt],t);return void 0===e?null:this[nt][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=ot(this),n=0;for(;n<r.length;){var i=r[n];const o=i[0],s=i[1];t.call(e,s,o,this),r=ot(this),n++}}set(t,e){e=""+e,tt(t=""+t),et(e);const r=rt(this[nt],t);this[nt][void 0!==r?r:t]=[e]}append(t,e){e=""+e,tt(t=""+t),et(e);const r=rt(this[nt],t);void 0!==r?this[nt][r].push(e):this[nt][t]=[e]}has(t){return tt(t=""+t),void 0!==rt(this[nt],t)}delete(t){tt(t=""+t);const e=rt(this[nt],t);void 0!==e&&delete this[nt][e]}raw(){return this[nt]}keys(){return at(this,"key")}values(){return at(this,"value")}[Symbol.iterator](){return at(this,"key+value")}}function ot(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[nt]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[nt][e].join(", ")}:function(e){return[e.toLowerCase(),t[nt][e].join(", ")]})}it.prototype.entries=it.prototype[Symbol.iterator],Object.defineProperty(it.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(it.prototype,{get:{enumerable:!0},forEach:{enumerable:!0},set:{enumerable:!0},append:{enumerable:!0},has:{enumerable:!0},delete:{enumerable:!0},keys:{enumerable:!0},values:{enumerable:!0},entries:{enumerable:!0}});const st=Symbol("internal");function at(t,e){const r=Object.create(ut);return r[st]={target:t,kind:e,index:0},r}const ut=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==ut)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[st];const e=t.target,r=t.kind,n=t.index,i=ot(e,r);return n>=i.length?{value:void 0,done:!0}:(this[st].index=n+1,{value:i[n],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function lt(t){const e=Object.assign({__proto__:null},t[nt]),r=rt(t[nt],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(ut,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const ct=Symbol("Response internals"),_t=a.default.STATUS_CODES;class ft{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};F.call(this,t,e);const r=e.status||200,n=new it(e.headers);if(null!=t&&!n.has("Content-Type")){const e=Q(t);e&&n.append("Content-Type",e)}this[ct]={url:e.url,status:r,statusText:e.statusText||_t[r],headers:n,counter:e.counter}}get url(){return this[ct].url||""}get status(){return this[ct].status}get ok(){return this[ct].status>=200&&this[ct].status<300}get redirected(){return this[ct].counter>0}get statusText(){return this[ct].statusText}get headers(){return this[ct].headers}clone(){return new ft(X(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}F.mixIn(ft.prototype),Object.defineProperties(ft.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ht=Symbol("Request internals"),gt=u.default.parse,dt=u.default.format,pt="destroy"in s.default.Readable.prototype;function bt(t){return"object"==typeof t&&"object"==typeof t[ht]}class mt{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};bt(t)?e=gt(t.url):(e=t&&t.href?gt(t.href):gt(""+t),t={});let n=r.method||t.method||"GET";if(n=n.toUpperCase(),(null!=r.body||bt(t)&&null!==t.body)&&("GET"===n||"HEAD"===n))throw new TypeError("Request with GET/HEAD method cannot have body");let i=null!=r.body?r.body:bt(t)&&null!==t.body?X(t):null;F.call(this,i,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const o=new it(r.headers||t.headers||{});if(null!=i&&!o.has("Content-Type")){const t=Q(i);t&&o.append("Content-Type",t)}let s=bt(t)?t.signal:null;if("signal"in r&&(s=r.signal),null!=s&&!function(t){const e=t&&"object"==typeof t&&Object.getPrototypeOf(t);return!(!e||"AbortSignal"!==e.constructor.name)}(s))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[ht]={method:n,redirect:r.redirect||t.redirect||"follow",headers:o,parsedURL:e,signal:s},this.follow=void 0!==r.follow?r.follow:void 0!==t.follow?t.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===t.compress||t.compress,this.counter=r.counter||t.counter||0,this.agent=r.agent||t.agent}get method(){return this[ht].method}get url(){return dt(this[ht].parsedURL)}get headers(){return this[ht].headers}get redirect(){return this[ht].redirect}get signal(){return this[ht].signal}clone(){return new mt(this)}}function yt(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}F.mixIn(mt.prototype),Object.defineProperty(mt.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(mt.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),yt.prototype=Object.create(Error.prototype),yt.prototype.constructor=yt,yt.prototype.name="AbortError";const wt=s.default.PassThrough,vt=u.default.resolve;function Bt(t,e){if(!Bt.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return F.Promise=Bt.Promise,new Bt.Promise((function(r,n){const i=new mt(t,e),o=function(t){const e=t[ht].parsedURL,r=new it(t[ht].headers);if(r.has("Accept")||r.set("Accept","*/*"),!e.protocol||!e.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(e.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(t.signal&&t.body instanceof s.default.Readable&&!pt)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let n=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(n="0"),null!=t.body){const e=Z(t);"number"==typeof e&&(n=String(e))}n&&r.set("Content-Length",n),r.has("User-Agent")||r.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!r.has("Accept-Encoding")&&r.set("Accept-Encoding","gzip,deflate");let i=t.agent;return"function"==typeof i&&(i=i(e)),r.has("Connection")||i||r.set("Connection","close"),Object.assign({},e,{method:t.method,headers:lt(r),agent:i})}(i),u=("https:"===o.protocol?l.default:a.default).request,_=i.signal;let f=null;const h=function(){let t=new yt("The user aborted a request.");n(t),i.body&&i.body instanceof s.default.Readable&&i.body.destroy(t),f&&f.body&&f.body.emit("error",t)};if(_&&_.aborted)return void h();const g=function(){h(),b()},d=u(o);let p;function b(){d.abort(),_&&_.removeEventListener("abort",g),clearTimeout(p)}_&&_.addEventListener("abort",g),i.timeout&&d.once("socket",(function(t){p=setTimeout((function(){n(new q("network timeout at: "+i.url,"request-timeout")),b()}),i.timeout)})),d.on("error",(function(t){n(new q(`request to ${i.url} failed, reason: ${t.message}`,"system",t)),b()})),d.on("response",(function(t){clearTimeout(p);const e=function(t){const e=new it;for(const r of Object.keys(t))if(!K.test(r))if(Array.isArray(t[r]))for(const n of t[r])Y.test(n)||(void 0===e[nt][r]?e[nt][r]=[n]:e[nt][r].push(n));else Y.test(t[r])||(e[nt][r]=[t[r]]);return e}(t.headers);if(Bt.isRedirect(t.statusCode)){const o=e.get("Location"),s=null===o?null:vt(i.url,o);switch(i.redirect){case"error":return n(new q("uri requested responds with a redirect, redirect mode is set to error: "+i.url,"no-redirect")),void b();case"manual":if(null!==s)try{e.set("Location",s)}catch(t){n(t)}break;case"follow":if(null===s)break;if(i.counter>=i.follow)return n(new q("maximum redirect reached at: "+i.url,"max-redirect")),void b();const o={headers:new it(i.headers),follow:i.follow,counter:i.counter+1,agent:i.agent,compress:i.compress,method:i.method,body:i.body,signal:i.signal,timeout:i.timeout,size:i.size};return 303!==t.statusCode&&i.body&&null===Z(i)?(n(new q("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==i.method)||(o.method="GET",o.body=void 0,o.headers.delete("content-length")),r(Bt(new mt(s,o))),void b())}}t.once("end",(function(){_&&_.removeEventListener("abort",g)}));let o=t.pipe(new wt);const s={url:i.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:i.size,timeout:i.timeout,counter:i.counter},a=e.get("Content-Encoding");if(!i.compress||"HEAD"===i.method||null===a||204===t.statusCode||304===t.statusCode)return f=new ft(o,s),void r(f);const u={flush:c.default.Z_SYNC_FLUSH,finishFlush:c.default.Z_SYNC_FLUSH};if("gzip"==a||"x-gzip"==a)return o=o.pipe(c.default.createGunzip(u)),f=new ft(o,s),void r(f);if("deflate"!=a&&"x-deflate"!=a){if("br"==a&&"function"==typeof c.default.createBrotliDecompress)return o=o.pipe(c.default.createBrotliDecompress()),f=new ft(o,s),void r(f);f=new ft(o,s),r(f)}else{t.pipe(new wt).once("data",(function(t){o=8==(15&t[0])?o.pipe(c.default.createInflate()):o.pipe(c.default.createInflateRaw()),f=new ft(o,s),r(f)}))}})),function(t,e){const r=e.body;null===r?t.end():J(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(d,i)}))}Bt.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},Bt.Promise=global.Promise;var Pt,Dt,St=Object.freeze({__proto__:null,default:Bt,Headers:it,Request:mt,Response:ft,FetchError:q}),Tt=(function(t,e){var r=St.default||St,n=function(t,e){return/^\/\//.test(t)&&(t="https:"+t),r.call(this,t,e)};t.exports=e=n,e.fetch=n,e.Headers=St.Headers,e.Request=St.Request,e.Response=St.Response,e.default=n}(Dt={path:Pt,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&Dt.path)}},Dt.exports),Dt.exports);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;t<n.length/2;t++){const e=n.length-2*(t+1);i.setUint8(t,parseInt(n.substr(e,2),16))}r=i.buffer}if(r.byteLength<t){const e=new Uint8Array(t);e.set(new Uint8Array(r),0),r=e.buffer}return r}}function zt(t){return function(e,r){if(r=new h(r).toArrayBuffer(),t>0&&r.byteLength!==t)throw new Error(`${e} has invalid length ${r.byteLength}, required: ${t}`);return r}}function 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.10.2",exports.cell_collectors=ue,exports.normalizers=Jt,exports.transformers=ae,exports.validators=R;
//# sourceMappingURL=ckb-js-toolkit.node.js.map