UNPKG

@naftalimurgor/jsbgl-react-native

Version:

JavaScript Bitgesell library For React Native

1 lines 417 kB
!function(A){var i={};function e(t){if(i[t])return i[t].exports;var I=i[t]={i:t,l:!1,exports:{}};return A[t].call(I.exports,I,I.exports,e),I.l=!0,I.exports}e.m=A,e.c=i,e.d=function(A,i,t){e.o(A,i)||Object.defineProperty(A,i,{configurable:!1,enumerable:!0,get:t})},e.r=function(A){Object.defineProperty(A,"__esModule",{value:!0})},e.n=function(A){var i=A&&A.__esModule?function(){return A.default}:function(){return A};return e.d(i,"a",i),i},e.o=function(A,i){return Object.prototype.hasOwnProperty.call(A,i)},e.p="",e(e.s=25)}([function(A,i,e){"use strict";(function(A){var t=e(21),I=e(20),g=e(19);function r(){return B.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(A,i){if(r()<i)throw new RangeError("Invalid typed array length");return B.TYPED_ARRAY_SUPPORT?(A=new Uint8Array(i)).__proto__=B.prototype:(null===A&&(A=new B(i)),A.length=i),A}function B(A,i,e){if(!(B.TYPED_ARRAY_SUPPORT||this instanceof B))return new B(A,i,e);if("number"==typeof A){if("string"==typeof i)throw new Error("If encoding is specified then the first argument must be a string");return s(this,A)}return n(this,A,i,e)}function n(A,i,e,t){if("number"==typeof i)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&i instanceof ArrayBuffer?function(A,i,e,t){if(i.byteLength,e<0||i.byteLength<e)throw new RangeError("'offset' is out of bounds");if(i.byteLength<e+(t||0))throw new RangeError("'length' is out of bounds");i=void 0===e&&void 0===t?new Uint8Array(i):void 0===t?new Uint8Array(i,e):new Uint8Array(i,e,t);B.TYPED_ARRAY_SUPPORT?(A=i).__proto__=B.prototype:A=E(A,i);return A}(A,i,e,t):"string"==typeof i?function(A,i,e){"string"==typeof e&&""!==e||(e="utf8");if(!B.isEncoding(e))throw new TypeError('"encoding" must be a valid string encoding');var t=0|Q(i,e),I=(A=o(A,t)).write(i,e);I!==t&&(A=A.slice(0,I));return A}(A,i,e):function(A,i){if(B.isBuffer(i)){var e=0|C(i.length);return 0===(A=o(A,e)).length||i.copy(A,0,0,e),A}if(i){if("undefined"!=typeof ArrayBuffer&&i.buffer instanceof ArrayBuffer||"length"in i)return"number"!=typeof i.length||(t=i.length)!=t?o(A,0):E(A,i);if("Buffer"===i.type&&g(i.data))return E(A,i.data)}var t;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(A,i)}function a(A){if("number"!=typeof A)throw new TypeError('"size" argument must be a number');if(A<0)throw new RangeError('"size" argument must not be negative')}function s(A,i){if(a(i),A=o(A,i<0?0:0|C(i)),!B.TYPED_ARRAY_SUPPORT)for(var e=0;e<i;++e)A[e]=0;return A}function E(A,i){var e=i.length<0?0:0|C(i.length);A=o(A,e);for(var t=0;t<e;t+=1)A[t]=255&i[t];return A}function C(A){if(A>=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|A}function Q(A,i){if(B.isBuffer(A))return A.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(A)||A instanceof ArrayBuffer))return A.byteLength;"string"!=typeof A&&(A=""+A);var e=A.length;if(0===e)return 0;for(var t=!1;;)switch(i){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return b(A).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return U(A).length;default:if(t)return b(A).length;i=(""+i).toLowerCase(),t=!0}}function h(A,i,e){var t=!1;if((void 0===i||i<0)&&(i=0),i>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(i>>>=0))return"";for(A||(A="utf8");;)switch(A){case"hex":return k(this,i,e);case"utf8":case"utf-8":return F(this,i,e);case"ascii":return M(this,i,e);case"latin1":case"binary":return S(this,i,e);case"base64":return m(this,i,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return G(this,i,e);default:if(t)throw new TypeError("Unknown encoding: "+A);A=(A+"").toLowerCase(),t=!0}}function c(A,i,e){var t=A[i];A[i]=A[e],A[e]=t}function l(A,i,e,t,I){if(0===A.length)return-1;if("string"==typeof e?(t=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=I?0:A.length-1),e<0&&(e=A.length+e),e>=A.length){if(I)return-1;e=A.length-1}else if(e<0){if(!I)return-1;e=0}if("string"==typeof i&&(i=B.from(i,t)),B.isBuffer(i))return 0===i.length?-1:u(A,i,e,t,I);if("number"==typeof i)return i&=255,B.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?I?Uint8Array.prototype.indexOf.call(A,i,e):Uint8Array.prototype.lastIndexOf.call(A,i,e):u(A,[i],e,t,I);throw new TypeError("val must be string, number or Buffer")}function u(A,i,e,t,I){var g,r=1,o=A.length,B=i.length;if(void 0!==t&&("ucs2"===(t=String(t).toLowerCase())||"ucs-2"===t||"utf16le"===t||"utf-16le"===t)){if(A.length<2||i.length<2)return-1;r=2,o/=2,B/=2,e/=2}function n(A,i){return 1===r?A[i]:A.readUInt16BE(i*r)}if(I){var a=-1;for(g=e;g<o;g++)if(n(A,g)===n(i,-1===a?0:g-a)){if(-1===a&&(a=g),g-a+1===B)return a*r}else-1!==a&&(g-=g-a),a=-1}else for(e+B>o&&(e=o-B),g=e;g>=0;g--){for(var s=!0,E=0;E<B;E++)if(n(A,g+E)!==n(i,E)){s=!1;break}if(s)return g}return-1}function d(A,i,e,t){e=Number(e)||0;var I=A.length-e;t?(t=Number(t))>I&&(t=I):t=I;var g=i.length;if(g%2!=0)throw new TypeError("Invalid hex string");t>g/2&&(t=g/2);for(var r=0;r<t;++r){var o=parseInt(i.substr(2*r,2),16);if(isNaN(o))return r;A[e+r]=o}return r}function f(A,i,e,t){return Y(b(i,A.length-e),A,e,t)}function p(A,i,e,t){return Y(function(A){for(var i=[],e=0;e<A.length;++e)i.push(255&A.charCodeAt(e));return i}(i),A,e,t)}function y(A,i,e,t){return p(A,i,e,t)}function D(A,i,e,t){return Y(U(i),A,e,t)}function w(A,i,e,t){return Y(function(A,i){for(var e,t,I,g=[],r=0;r<A.length&&!((i-=2)<0);++r)e=A.charCodeAt(r),t=e>>8,I=e%256,g.push(I),g.push(t);return g}(i,A.length-e),A,e,t)}function m(A,i,e){return 0===i&&e===A.length?t.fromByteArray(A):t.fromByteArray(A.slice(i,e))}function F(A,i,e){e=Math.min(A.length,e);for(var t=[],I=i;I<e;){var g,r,o,B,n=A[I],a=null,s=n>239?4:n>223?3:n>191?2:1;if(I+s<=e)switch(s){case 1:n<128&&(a=n);break;case 2:128==(192&(g=A[I+1]))&&(B=(31&n)<<6|63&g)>127&&(a=B);break;case 3:g=A[I+1],r=A[I+2],128==(192&g)&&128==(192&r)&&(B=(15&n)<<12|(63&g)<<6|63&r)>2047&&(B<55296||B>57343)&&(a=B);break;case 4:g=A[I+1],r=A[I+2],o=A[I+3],128==(192&g)&&128==(192&r)&&128==(192&o)&&(B=(15&n)<<18|(63&g)<<12|(63&r)<<6|63&o)>65535&&B<1114112&&(a=B)}null===a?(a=65533,s=1):a>65535&&(a-=65536,t.push(a>>>10&1023|55296),a=56320|1023&a),t.push(a),I+=s}return function(A){var i=A.length;if(i<=4096)return String.fromCharCode.apply(String,A);var e="",t=0;for(;t<i;)e+=String.fromCharCode.apply(String,A.slice(t,t+=4096));return e}(t)}i.Buffer=B,i.SlowBuffer=function(A){+A!=A&&(A=0);return B.alloc(+A)},i.INSPECT_MAX_BYTES=50,B.TYPED_ARRAY_SUPPORT=void 0!==A.TYPED_ARRAY_SUPPORT?A.TYPED_ARRAY_SUPPORT:function(){try{var A=new Uint8Array(1);return A.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===A.foo()&&"function"==typeof A.subarray&&0===A.subarray(1,1).byteLength}catch(A){return!1}}(),i.kMaxLength=r(),B.poolSize=8192,B._augment=function(A){return A.__proto__=B.prototype,A},B.from=function(A,i,e){return n(null,A,i,e)},B.TYPED_ARRAY_SUPPORT&&(B.prototype.__proto__=Uint8Array.prototype,B.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&B[Symbol.species]===B&&Object.defineProperty(B,Symbol.species,{value:null,configurable:!0})),B.alloc=function(A,i,e){return function(A,i,e,t){return a(i),i<=0?o(A,i):void 0!==e?"string"==typeof t?o(A,i).fill(e,t):o(A,i).fill(e):o(A,i)}(null,A,i,e)},B.allocUnsafe=function(A){return s(null,A)},B.allocUnsafeSlow=function(A){return s(null,A)},B.isBuffer=function(A){return!(null==A||!A._isBuffer)},B.compare=function(A,i){if(!B.isBuffer(A)||!B.isBuffer(i))throw new TypeError("Arguments must be Buffers");if(A===i)return 0;for(var e=A.length,t=i.length,I=0,g=Math.min(e,t);I<g;++I)if(A[I]!==i[I]){e=A[I],t=i[I];break}return e<t?-1:t<e?1:0},B.isEncoding=function(A){switch(String(A).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},B.concat=function(A,i){if(!g(A))throw new TypeError('"list" argument must be an Array of Buffers');if(0===A.length)return B.alloc(0);var e;if(void 0===i)for(i=0,e=0;e<A.length;++e)i+=A[e].length;var t=B.allocUnsafe(i),I=0;for(e=0;e<A.length;++e){var r=A[e];if(!B.isBuffer(r))throw new TypeError('"list" argument must be an Array of Buffers');r.copy(t,I),I+=r.length}return t},B.byteLength=Q,B.prototype._isBuffer=!0,B.prototype.swap16=function(){var A=this.length;if(A%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var i=0;i<A;i+=2)c(this,i,i+1);return this},B.prototype.swap32=function(){var A=this.length;if(A%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var i=0;i<A;i+=4)c(this,i,i+3),c(this,i+1,i+2);return this},B.prototype.swap64=function(){var A=this.length;if(A%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var i=0;i<A;i+=8)c(this,i,i+7),c(this,i+1,i+6),c(this,i+2,i+5),c(this,i+3,i+4);return this},B.prototype.toString=function(){var A=0|this.length;return 0===A?"":0===arguments.length?F(this,0,A):h.apply(this,arguments)},B.prototype.equals=function(A){if(!B.isBuffer(A))throw new TypeError("Argument must be a Buffer");return this===A||0===B.compare(this,A)},B.prototype.inspect=function(){var A="",e=i.INSPECT_MAX_BYTES;return this.length>0&&(A=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(A+=" ... ")),"<Buffer "+A+">"},B.prototype.compare=function(A,i,e,t,I){if(!B.isBuffer(A))throw new TypeError("Argument must be a Buffer");if(void 0===i&&(i=0),void 0===e&&(e=A?A.length:0),void 0===t&&(t=0),void 0===I&&(I=this.length),i<0||e>A.length||t<0||I>this.length)throw new RangeError("out of range index");if(t>=I&&i>=e)return 0;if(t>=I)return-1;if(i>=e)return 1;if(this===A)return 0;for(var g=(I>>>=0)-(t>>>=0),r=(e>>>=0)-(i>>>=0),o=Math.min(g,r),n=this.slice(t,I),a=A.slice(i,e),s=0;s<o;++s)if(n[s]!==a[s]){g=n[s],r=a[s];break}return g<r?-1:r<g?1:0},B.prototype.includes=function(A,i,e){return-1!==this.indexOf(A,i,e)},B.prototype.indexOf=function(A,i,e){return l(this,A,i,e,!0)},B.prototype.lastIndexOf=function(A,i,e){return l(this,A,i,e,!1)},B.prototype.write=function(A,i,e,t){if(void 0===i)t="utf8",e=this.length,i=0;else if(void 0===e&&"string"==typeof i)t=i,e=this.length,i=0;else{if(!isFinite(i))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");i|=0,isFinite(e)?(e|=0,void 0===t&&(t="utf8")):(t=e,e=void 0)}var I=this.length-i;if((void 0===e||e>I)&&(e=I),A.length>0&&(e<0||i<0)||i>this.length)throw new RangeError("Attempt to write outside buffer bounds");t||(t="utf8");for(var g=!1;;)switch(t){case"hex":return d(this,A,i,e);case"utf8":case"utf-8":return f(this,A,i,e);case"ascii":return p(this,A,i,e);case"latin1":case"binary":return y(this,A,i,e);case"base64":return D(this,A,i,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,A,i,e);default:if(g)throw new TypeError("Unknown encoding: "+t);t=(""+t).toLowerCase(),g=!0}},B.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function M(A,i,e){var t="";e=Math.min(A.length,e);for(var I=i;I<e;++I)t+=String.fromCharCode(127&A[I]);return t}function S(A,i,e){var t="";e=Math.min(A.length,e);for(var I=i;I<e;++I)t+=String.fromCharCode(A[I]);return t}function k(A,i,e){var t=A.length;(!i||i<0)&&(i=0),(!e||e<0||e>t)&&(e=t);for(var I="",g=i;g<e;++g)I+=J(A[g]);return I}function G(A,i,e){for(var t=A.slice(i,e),I="",g=0;g<t.length;g+=2)I+=String.fromCharCode(t[g]+256*t[g+1]);return I}function N(A,i,e){if(A%1!=0||A<0)throw new RangeError("offset is not uint");if(A+i>e)throw new RangeError("Trying to access beyond buffer length")}function K(A,i,e,t,I,g){if(!B.isBuffer(A))throw new TypeError('"buffer" argument must be a Buffer instance');if(i>I||i<g)throw new RangeError('"value" argument is out of bounds');if(e+t>A.length)throw new RangeError("Index out of range")}function R(A,i,e,t){i<0&&(i=65535+i+1);for(var I=0,g=Math.min(A.length-e,2);I<g;++I)A[e+I]=(i&255<<8*(t?I:1-I))>>>8*(t?I:1-I)}function v(A,i,e,t){i<0&&(i=4294967295+i+1);for(var I=0,g=Math.min(A.length-e,4);I<g;++I)A[e+I]=i>>>8*(t?I:3-I)&255}function H(A,i,e,t,I,g){if(e+t>A.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function q(A,i,e,t,g){return g||H(A,0,e,4),I.write(A,i,e,t,23,4),e+4}function P(A,i,e,t,g){return g||H(A,0,e,8),I.write(A,i,e,t,52,8),e+8}B.prototype.slice=function(A,i){var e,t=this.length;if((A=~~A)<0?(A+=t)<0&&(A=0):A>t&&(A=t),(i=void 0===i?t:~~i)<0?(i+=t)<0&&(i=0):i>t&&(i=t),i<A&&(i=A),B.TYPED_ARRAY_SUPPORT)(e=this.subarray(A,i)).__proto__=B.prototype;else{var I=i-A;e=new B(I,void 0);for(var g=0;g<I;++g)e[g]=this[g+A]}return e},B.prototype.readUIntLE=function(A,i,e){A|=0,i|=0,e||N(A,i,this.length);for(var t=this[A],I=1,g=0;++g<i&&(I*=256);)t+=this[A+g]*I;return t},B.prototype.readUIntBE=function(A,i,e){A|=0,i|=0,e||N(A,i,this.length);for(var t=this[A+--i],I=1;i>0&&(I*=256);)t+=this[A+--i]*I;return t},B.prototype.readUInt8=function(A,i){return i||N(A,1,this.length),this[A]},B.prototype.readUInt16LE=function(A,i){return i||N(A,2,this.length),this[A]|this[A+1]<<8},B.prototype.readUInt16BE=function(A,i){return i||N(A,2,this.length),this[A]<<8|this[A+1]},B.prototype.readUInt32LE=function(A,i){return i||N(A,4,this.length),(this[A]|this[A+1]<<8|this[A+2]<<16)+16777216*this[A+3]},B.prototype.readUInt32BE=function(A,i){return i||N(A,4,this.length),16777216*this[A]+(this[A+1]<<16|this[A+2]<<8|this[A+3])},B.prototype.readIntLE=function(A,i,e){A|=0,i|=0,e||N(A,i,this.length);for(var t=this[A],I=1,g=0;++g<i&&(I*=256);)t+=this[A+g]*I;return t>=(I*=128)&&(t-=Math.pow(2,8*i)),t},B.prototype.readIntBE=function(A,i,e){A|=0,i|=0,e||N(A,i,this.length);for(var t=i,I=1,g=this[A+--t];t>0&&(I*=256);)g+=this[A+--t]*I;return g>=(I*=128)&&(g-=Math.pow(2,8*i)),g},B.prototype.readInt8=function(A,i){return i||N(A,1,this.length),128&this[A]?-1*(255-this[A]+1):this[A]},B.prototype.readInt16LE=function(A,i){i||N(A,2,this.length);var e=this[A]|this[A+1]<<8;return 32768&e?4294901760|e:e},B.prototype.readInt16BE=function(A,i){i||N(A,2,this.length);var e=this[A+1]|this[A]<<8;return 32768&e?4294901760|e:e},B.prototype.readInt32LE=function(A,i){return i||N(A,4,this.length),this[A]|this[A+1]<<8|this[A+2]<<16|this[A+3]<<24},B.prototype.readInt32BE=function(A,i){return i||N(A,4,this.length),this[A]<<24|this[A+1]<<16|this[A+2]<<8|this[A+3]},B.prototype.readFloatLE=function(A,i){return i||N(A,4,this.length),I.read(this,A,!0,23,4)},B.prototype.readFloatBE=function(A,i){return i||N(A,4,this.length),I.read(this,A,!1,23,4)},B.prototype.readDoubleLE=function(A,i){return i||N(A,8,this.length),I.read(this,A,!0,52,8)},B.prototype.readDoubleBE=function(A,i){return i||N(A,8,this.length),I.read(this,A,!1,52,8)},B.prototype.writeUIntLE=function(A,i,e,t){(A=+A,i|=0,e|=0,t)||K(this,A,i,e,Math.pow(2,8*e)-1,0);var I=1,g=0;for(this[i]=255&A;++g<e&&(I*=256);)this[i+g]=A/I&255;return i+e},B.prototype.writeUIntBE=function(A,i,e,t){(A=+A,i|=0,e|=0,t)||K(this,A,i,e,Math.pow(2,8*e)-1,0);var I=e-1,g=1;for(this[i+I]=255&A;--I>=0&&(g*=256);)this[i+I]=A/g&255;return i+e},B.prototype.writeUInt8=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,1,255,0),B.TYPED_ARRAY_SUPPORT||(A=Math.floor(A)),this[i]=255&A,i+1},B.prototype.writeUInt16LE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,2,65535,0),B.TYPED_ARRAY_SUPPORT?(this[i]=255&A,this[i+1]=A>>>8):R(this,A,i,!0),i+2},B.prototype.writeUInt16BE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,2,65535,0),B.TYPED_ARRAY_SUPPORT?(this[i]=A>>>8,this[i+1]=255&A):R(this,A,i,!1),i+2},B.prototype.writeUInt32LE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,4,4294967295,0),B.TYPED_ARRAY_SUPPORT?(this[i+3]=A>>>24,this[i+2]=A>>>16,this[i+1]=A>>>8,this[i]=255&A):v(this,A,i,!0),i+4},B.prototype.writeUInt32BE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,4,4294967295,0),B.TYPED_ARRAY_SUPPORT?(this[i]=A>>>24,this[i+1]=A>>>16,this[i+2]=A>>>8,this[i+3]=255&A):v(this,A,i,!1),i+4},B.prototype.writeIntLE=function(A,i,e,t){if(A=+A,i|=0,!t){var I=Math.pow(2,8*e-1);K(this,A,i,e,I-1,-I)}var g=0,r=1,o=0;for(this[i]=255&A;++g<e&&(r*=256);)A<0&&0===o&&0!==this[i+g-1]&&(o=1),this[i+g]=(A/r>>0)-o&255;return i+e},B.prototype.writeIntBE=function(A,i,e,t){if(A=+A,i|=0,!t){var I=Math.pow(2,8*e-1);K(this,A,i,e,I-1,-I)}var g=e-1,r=1,o=0;for(this[i+g]=255&A;--g>=0&&(r*=256);)A<0&&0===o&&0!==this[i+g+1]&&(o=1),this[i+g]=(A/r>>0)-o&255;return i+e},B.prototype.writeInt8=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,1,127,-128),B.TYPED_ARRAY_SUPPORT||(A=Math.floor(A)),A<0&&(A=255+A+1),this[i]=255&A,i+1},B.prototype.writeInt16LE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,2,32767,-32768),B.TYPED_ARRAY_SUPPORT?(this[i]=255&A,this[i+1]=A>>>8):R(this,A,i,!0),i+2},B.prototype.writeInt16BE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,2,32767,-32768),B.TYPED_ARRAY_SUPPORT?(this[i]=A>>>8,this[i+1]=255&A):R(this,A,i,!1),i+2},B.prototype.writeInt32LE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,4,2147483647,-2147483648),B.TYPED_ARRAY_SUPPORT?(this[i]=255&A,this[i+1]=A>>>8,this[i+2]=A>>>16,this[i+3]=A>>>24):v(this,A,i,!0),i+4},B.prototype.writeInt32BE=function(A,i,e){return A=+A,i|=0,e||K(this,A,i,4,2147483647,-2147483648),A<0&&(A=4294967295+A+1),B.TYPED_ARRAY_SUPPORT?(this[i]=A>>>24,this[i+1]=A>>>16,this[i+2]=A>>>8,this[i+3]=255&A):v(this,A,i,!1),i+4},B.prototype.writeFloatLE=function(A,i,e){return q(this,A,i,!0,e)},B.prototype.writeFloatBE=function(A,i,e){return q(this,A,i,!1,e)},B.prototype.writeDoubleLE=function(A,i,e){return P(this,A,i,!0,e)},B.prototype.writeDoubleBE=function(A,i,e){return P(this,A,i,!1,e)},B.prototype.copy=function(A,i,e,t){if(e||(e=0),t||0===t||(t=this.length),i>=A.length&&(i=A.length),i||(i=0),t>0&&t<e&&(t=e),t===e)return 0;if(0===A.length||0===this.length)return 0;if(i<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("sourceStart out of bounds");if(t<0)throw new RangeError("sourceEnd out of bounds");t>this.length&&(t=this.length),A.length-i<t-e&&(t=A.length-i+e);var I,g=t-e;if(this===A&&e<i&&i<t)for(I=g-1;I>=0;--I)A[I+i]=this[I+e];else if(g<1e3||!B.TYPED_ARRAY_SUPPORT)for(I=0;I<g;++I)A[I+i]=this[I+e];else Uint8Array.prototype.set.call(A,this.subarray(e,e+g),i);return g},B.prototype.fill=function(A,i,e,t){if("string"==typeof A){if("string"==typeof i?(t=i,i=0,e=this.length):"string"==typeof e&&(t=e,e=this.length),1===A.length){var I=A.charCodeAt(0);I<256&&(A=I)}if(void 0!==t&&"string"!=typeof t)throw new TypeError("encoding must be a string");if("string"==typeof t&&!B.isEncoding(t))throw new TypeError("Unknown encoding: "+t)}else"number"==typeof A&&(A&=255);if(i<0||this.length<i||this.length<e)throw new RangeError("Out of range index");if(e<=i)return this;var g;if(i>>>=0,e=void 0===e?this.length:e>>>0,A||(A=0),"number"==typeof A)for(g=i;g<e;++g)this[g]=A;else{var r=B.isBuffer(A)?A:b(new B(A,t).toString()),o=r.length;for(g=0;g<e-i;++g)this[g+i]=r[g%o]}return this};var T=/[^+\/0-9A-Za-z-_]/g;function J(A){return A<16?"0"+A.toString(16):A.toString(16)}function b(A,i){var e;i=i||1/0;for(var t=A.length,I=null,g=[],r=0;r<t;++r){if((e=A.charCodeAt(r))>55295&&e<57344){if(!I){if(e>56319){(i-=3)>-1&&g.push(239,191,189);continue}if(r+1===t){(i-=3)>-1&&g.push(239,191,189);continue}I=e;continue}if(e<56320){(i-=3)>-1&&g.push(239,191,189),I=e;continue}e=65536+(I-55296<<10|e-56320)}else I&&(i-=3)>-1&&g.push(239,191,189);if(I=null,e<128){if((i-=1)<0)break;g.push(e)}else if(e<2048){if((i-=2)<0)break;g.push(e>>6|192,63&e|128)}else if(e<65536){if((i-=3)<0)break;g.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((i-=4)<0)break;g.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return g}function U(A){return t.toByteArray(function(A){if((A=function(A){return A.trim?A.trim():A.replace(/^\s+|\s+$/g,"")}(A).replace(T,"")).length<2)return"";for(;A.length%4!=0;)A+="=";return A}(A))}function Y(A,i,e,t){for(var I=0;I<t&&!(I+e>=i.length||I>=A.length);++I)i[I+e]=A[I];return I}}).call(this,e(1))},function(A,i){var e;e=function(){return this}();try{e=e||Function("return this")()||(0,eval)("this")}catch(A){"object"==typeof window&&(e=window)}A.exports=e},function(A,i){A.exports=function(A){let i=A.Buffer,e=(A.defArgs,A.getBuffer,i.from,i.concat,A.OPCODE,A.defArgs);class t{constructor(i={}){e(i,{from:null,passphrase:"",path:null,testnet:!1,strength:256,threshold:1,shares:1,wordList:A.BIP39_WORDLIST,addressType:null,hardenedAddresses:!1,account:0,chain:0}),this.account=i.account,this.chain=i.chain,this.hardenedAddresses=i.hardenedAddresses,"BIP84"===i.path?(this.pathType="BIP84",this.path=`m/84'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/84'/0'/${this.account}'`):"BIP49"===i.path?(this.pathType="BIP49",this.path=`m/49'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/49'/0'/${this.account}'`):"BIP44"===i.path?(this.pathType="BIP44",this.path=`m/44'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/44'/0'/${this.account}'`):null!==i.path?(this.pathType="custom",this.path=i.path):(this.pathType=null,this.path=null);let t=i.from;this.from=t;let I=null;if(null===t){let e=A.generateEntropy({strength:i.strength});this.mnemonic=A.entropyToMnemonic(e,{wordList:i.wordList}),this.seed=A.mnemonicToSeed(this.mnemonic,{hex:!0,wordList:i.wordList,passphrase:i.passphrase}),this.passphrase=i.passphrase,t=A.createMasterXPrivateKey(this.seed,{testnet:i.testnet}),null===this.pathType&&(this.pathType="BIP84",this.path=`m/84'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/84'/0'/${this.account}'`),null!==this.pathType&&"custom"!==this.pathType&&(t=A.BIP32_XKeyToPathXKey(t,this.pathType)),I="xPriv"}else{if(!A.isString(t))throw new Error("invalid initial data");if(A.isXPrivateKeyValid(t))null===this.pathType&&(this.pathType=A.xKeyDerivationType(t),"BIP84"===this.pathType?(this.path=`m/84'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/84'/0'/${this.account}'`):"BIP49"===this.pathType?(this.path=`m/49'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/49'/0'/${this.account}'`):"BIP44"===this.pathType?(this.path=`m/44'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/44'/0'/${this.account}'`):this.path="m"),null!==this.pathType&&"custom"!==this.pathType&&(t=A.BIP32_XKeyToPathXKey(A.pathXKeyTo_BIP32_XKey(t),this.pathType)),I="xPriv";else if(A.isXPublicKeyValid(t))null===this.pathType&&(this.pathType=A.xKeyDerivationType(t),"BIP84"===this.pathType?(this.path=`m/84'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/84'/0'/${this.account}'`):"BIP49"===this.pathType?(this.path=`m/49'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/49'/0'/${this.account}'`):"BIP44"===this.pathType?(this.path=`m/44'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/44'/0'/${this.account}'`):this.path="m"),"custom"!==this.pathType&&(t=A.BIP32_XKeyToPathXKey(A.pathXKeyTo_BIP32_XKey(t),this.pathType),I="xPub",3===this.depth&&(this.__path=""));else{if(!A.isMnemonicValid(t,{wordList:i.BIP39_WORDLIST}))throw new Error("invalid mnemonic");this.mnemonic=t,this.seed=A.mnemonicToSeed(this.mnemonic,{hex:!0,wordList:i.wordList,passphrase:i.passphrase}),this.passphrase=i.passphrase,t=A.createMasterXPrivateKey(this.seed,{testnet:i.testnet}),null===this.pathType&&(this.pathType="BIP84",this.path=`m/84'/0'/${this.account}'/${this.chain}`,this.__account_path=`m/84'/0'/${this.account}'`),null!==this.pathType&&"custom"!==this.pathType&&(t=A.BIP32_XKeyToPathXKey(t,this.pathType)),I="xPriv"}}let g=A.decodeBase58(t,{checkSum:!0,hex:!1});if(this.testnet="testnet"===A.xKeyNetworkType(g),this.version=g.slice(0,4).hex(),this.depth=g[4],"custom"!==this.pathType)if(0===this.depth||3===this.depth){let A=this.path.split("/");this.__path=A.slice(this.depth,4).join("/")}else this.pathType="custom",this.path="m";if(this.fingerprint=g.slice(5,9).hex(),this.child=g.readUIntBE(9,4),this.chainCode=g.slice(9,4).hex(),"xPriv"===I?(0===this.depth&&(this.masterXPrivateKey=t),"custom"!==this.pathType?(this.accountXPrivateKey=A.deriveXKey(t,this.__path,{subPath:!0}),this.accountXPublicKey=A.xPrivateToXPublicKey(this.accountXPrivateKey),this.accountXPrivateKey=A.deriveXKey(t,this.__path,{subPath:!0}),this.accountXPublicKey=A.xPrivateToXPublicKey(this.accountXPrivateKey),this.externalChainXPrivateKey=A.deriveXKey(t,this.__path+"/"+this.chain,{subPath:!0}),this.externalChainXPublicKey=A.xPrivateToXPublicKey(this.externalChainXPrivateKey),this.internalChainXPrivateKey=A.deriveXKey(t,this.__path+"/"+(this.chain+1),{subPath:!0}),this.internalChainXPublicKey=A.xPrivateToXPublicKey(this.internalChainXPrivateKey)):(this.chainXPrivateKey=A.deriveXKey(t,this.path),this.chainXPublicKey=A.xPrivateToXPublicKey(this.chainXPrivateKey))):"custom"!==this.pathType?(this.accountXPublicKey=t,this.externalChainXPublicKey=A.deriveXKey(t,this.__path+"/"+this.chain,{subPath:!0}),this.internalChainXPrivateKey=A.deriveXKey(t,this.__path+"/"+(this.chain+1),{subPath:!0})):this.chainXPublicKey=A.deriveXKey(t,this.path),null!==this.mnemonic){if(this.sharesThreshold=i.threshold,this.sharesTotal=i.shares,this.sharesThreshold>this.sharesTotal)throw new Error("Threshold invalid");if(this.sharesTotal>1){let e=this.mnemonic.trim().split(/\s+/),t=11*e.length%32;if(this.sharesTotal>2**t-1)throw new Error(`Maximum ${2**t-1} shares allowed for ${e.length} mnemonic words`);this.mnemonicShares=A.splitMnemonic(i.threshold,i.shares,this.mnemonic,{wordList:i.BIP39_WORDLIST,embeddedIndex:!0})}}null!==i.addressType?this.addressType=i.addressType:"BIP84"===this.pathType?this.addressType="P2WPKH":"BIP49"===this.pathType?this.addressType="P2SH_P2WPKH":this.addressType="P2PKH"}}t.prototype.setChain=function(A){this.chain=A},t.prototype.getAddress=function(i,e=!0){let t={},I=this.hardenedAddresses?"'":"";if("custom"!==this.pathType){let g="m/"+i+I;if(t.path=`${this.__account_path}/${this.chain+!e}/${i}${I}`,e)if(void 0!==this.externalChainXPrivateKey){let i=A.deriveXKey(this.externalChainXPrivateKey,g);t.privateKey=A.privateFromXPrivateKey(i),t.publicKey=A.privateToPublicKey(t.privateKey)}else{let i=A.deriveXKey(this.externalChainXPublicKey,g);t.publicKey=A.publicFromXPublicKey(i)}else if(void 0!==this.internalChainXPrivateKey){let i=A.deriveXKey(this.internalChainXPrivateKey,g);t.privateKey=A.privateFromXPrivateKey(i),t.publicKey=A.privateToPublicKey(t.privateKey)}else{let i=A.deriveXKey(this.internalChainXPublicKey,g);t.publicKey=A.publicFromXPublicKey(i)}}else{let e="m/"+i+I;if(t.path=this.path+"/"+i+I,void 0!==this.chainXPrivateKey){let i=A.deriveXKey(this.chainXPrivateKey,e);t.privateKey=A.privateFromXPrivateKey(i),t.publicKey=A.privateToPublicKey(t.privateKey)}else{let i=A.deriveXKey(this.chainXPublicKey,e);t.publicKey=A.publicFromXPublicKey(i)}}return"P2WPKH"===this.addressType?t.address=A.publicKeyToAddress(t.publicKey,{testnet:this.testnet}):"P2SH_P2WPKH"===this.addressType?t.address=A.publicKeyToAddress(t.publicKey,{p2sh_p2wpkh:!0,testnet:this.testnet}):"P2PKH"===this.addressType&&(t.address=A.publicKeyToAddress(t.publicKey,{witnessVersion:null,testnet:this.testnet})),t},A.Wallet=t}},function(A,i){A.exports=function(A){let i=A.s2rh,e=A.rh2s,t=A.Buffer,I=(A.BN,A.Buffer.isBuffer),g=A.defArgs,r=A.getBuffer,o=t.from,B=t.alloc,n=t.concat,a=A.OPCODE,s=A.isString;class E{constructor(i={}){if(g(i,{rawTx:null,format:"decoded",version:2,lockTime:0,testnet:!1,autoCommit:!0,keepRawTx:!1}),!["decoded","raw"].includes(i.format))throw new Error("format error, raw or decoded allowed");if(this.autoCommit=i.autoCommit,this.format=i.format,this.testnet=i.testnet,this.segwit=!1,this.txId=null,this.hash=null,this.version=i.version,this.size=0,this.vSize=0,this.bSize=0,this.vIn={},this.vOut={},this.rawTx=null,this.blockHash=null,this.confirmations=null,this.time=null,this.blockTime=null,this.lockTime=i.lockTime,this.blockIndex=null,this.coinbase=!1,this.fee=null,this.data=null,this.amount=null,null===i.rawTx)return;let e=r(i.rawTx);this.amount=0;let I=0,o=0,B=void 0===e.__offset?0:e.__offset;this.version=e.readInt(4);let a=e.readVarInt();0===a[0]&&(I=1,this.flag=e.read(1),a=e.readVarInt());let s=A.varIntToInt(a);for(let i=0;i<s;i++)this.vIn[i]={txId:e.read(32),vOut:e.readInt(4),scriptSig:e.read(A.varIntToInt(e.readVarInt())),sequence:e.readInt(4)};let E=A.varIntToInt(e.readVarInt());for(let i=0;i<E;i++){this.vOut[i]={},this.vOut[i].value=e.readInt(8),this.amount+=this.vOut[i].value,this.vOut[i].scriptPubKey=e.read(A.varIntToInt(e.readVarInt()));let t=A.parseScript(this.vOut[i].scriptPubKey);this.vOut[i].nType=t.nType,this.vOut[i].type=t.type,null===this.data&&3===t.type&&(this.data=t.data),void 0!==t.addressHash&&(this.vOut[i].addressHash=t.addressHash,this.vOut[i].reqSigs=t.reqSigs)}if(I){I=e.__offset-B;for(let i=0;i<s;i++){this.vIn[i].txInWitness=[];let t=A.varIntToInt(e.readVarInt());for(let I=0;I<t;I++)this.vIn[i].txInWitness.push(e.read(A.varIntToInt(e.readVarInt())))}o=e.__offset-B-I+2}this.lockTime=e.readInt(4);let C=e.__offset;this.rawTx=e.slice(B,C),this.size=C-B,this.bSize=C-B-o,this.weight=3*this.bSize+this.size,this.vSize=Math.ceil(this.weight/4),this.coinbase=!(1!==s||!this.vIn[0].txId.equals(t(32))||4294967295!==this.vIn[0].vOut),I>0?(this.segwit=!0,this.hash=A.sha256(this.rawTx),this.txId=A.sha256(n([this.rawTx.slice(0,4),this.rawTx.slice(6,I),this.rawTx.slice(this.rawTx.length-4,this.rawTx.length)]))):(this.txId=A.sha256(this.rawTx),this.hash=this.txId,this.segwit=!1),i.keepRawTx||(this.rawTx=null),"decoded"===i.format&&this.decode()}}E.prototype.decode=function(i){this.format="decoded",void 0!==i&&(this.testnet=i),I(this.txId)&&(this.txId=e(this.txId)),I(this.hash)&&(this.hash=e(this.hash)),I(this.flag)&&(this.flag=e(this.flag)),I(this.rawTx)&&(this.rawTx=this.rawTx.hex());for(let i in this.vIn){if(I(this.vIn[i].txId)&&(this.vIn[i].txId=e(this.vIn[i].txId)),I(this.vIn[i].scriptSig)&&(this.vIn[i].scriptSig=this.vIn[i].scriptSig.hex()),this.vIn[i].amount instanceof A.BN&&(this.vIn[i].amount=this.vIn[i].amount.toString(16)),void 0!==this.vIn[i].txInWitness){let A=[];for(let e of this.vIn[i].txInWitness)A.push(I(e)?e.hex():e);this.vIn[i].txInWitness=A}if(I(this.vIn[i].addressHash)){let e=this.vIn[i].nType<5?null:this.vIn[i].addressHash[0];this.vIn[i].addressHash=this.vIn[i].addressHash.hex();let t=[1,5].includes(this.vIn[i].nType);this.vIn[i].address=A.hashToAddress(this.vIn[i].addressHash,{testnet:this.testnet,scriptHash:t,witnessVersion:e})}I(this.vIn[i].scriptPubKey)&&(this.vIn[i].scriptPubKey=this.vIn[i].scriptPubKey.hex(),this.vIn[i].scriptPubKeyOpcodes=A.decodeScript(this.vIn[i].scriptPubKey),this.vIn[i].scriptPubKeyAsm=A.decodeScript(this.vIn[i].scriptPubKey,{asm:!0})),I(this.vIn[i].redeemScript)&&(this.vIn[i].redeemScript=this.vIn[i].redeemScript.hex(),this.vIn[i].redeemScriptOpcodes=A.decodeScript(this.vIn[i].redeemScript),this.vIn[i].redeemScriptAsm=A.decodeScript(this.vIn[i].redeemScript,{asm:!0})),this.coinbase||(I(this.vIn[i].scriptSig)&&(this.vIn[i].scriptSig=this.vIn[i].scriptSig.hex()),this.vIn[i].scriptSigOpcodes=A.decodeScript(this.vIn[i].scriptSig),this.vIn[i].scriptSigAsm=A.decodeScript(this.vIn[i].scriptSig,{asm:!0}))}for(let i in this.vOut){if(I(this.vOut[i].addressHash)){let e=this.vOut[i].nType<5?null:this.vOut[i].scriptPubKey[0];this.vOut[i].addressHash=this.vOut[i].addressHash.hex();let t=[1,5].includes(this.vOut[i].nType);this.vOut[i].address=A.hashToAddress(this.vOut[i].addressHash,{testnet:this.testnet,scriptHash:t,witnessVersion:e})}I(this.vOut[i].scriptPubKey)&&(this.vOut[i].scriptPubKey=this.vOut[i].scriptPubKey.hex(),this.vOut[i].scriptPubKeyOpcodes=A.decodeScript(this.vOut[i].scriptPubKey),this.vOut[i].scriptPubKeyAsm=A.decodeScript(this.vOut[i].scriptPubKey,{asm:!0}))}return I(this.data)&&(this.data=this.data.hex()),this},E.prototype.encode=function(){s(this.txId)&&(this.txId=i(this.txId)),s(this.flag)&&(this.flag=i(this.flag)),s(this.hash)&&(this.hash=i(this.hash)),s(this.rawTx)&&(this.rawTx=o(this.hash,"hex"));for(let A in this.vIn){if(s(this.vIn[A].txId)&&(this.vIn[A].txId=i(this.vIn[A].txId)),s(this.vIn[A].scriptSig)&&(this.vIn[A].scriptSig=o(this.vIn[A].scriptSig,"hex")),void 0!==this.vIn[A].txInWitness){let i=[];for(let e of this.vIn[A].txInWitness)i.push(s(e)?o(e,"hex"):e);this.vIn[A].txInWitness=i}s(this.vIn[A].addressHash)&&(this.vIn[A].addressHash=o(this.vIn[A].addressHash,"hex")),s(this.vIn[A].scriptPubKey)&&(this.vIn[A].scriptPubKey=o(this.vIn[A].scriptPubKey,"hex")),s(this.vIn[A].redeemScript)&&(this.vIn[A].redeemScript=o(this.vIn[A].redeemScript,"hex")),s(this.vIn[A].addressHash)&&(this.vIn[A].addressHash=o(this.vIn[A].addressHash,"hex")),delete this.vIn[A].scriptSigAsm,delete this.vIn[A].scriptSigOpcodes,delete this.vIn[A].scriptPubKeyOpcodes,delete this.vIn[A].scriptPubKeyAsm,delete this.vIn[A].redeemScriptOpcodes,delete this.vIn[A].redeemScriptAsm,delete this.vIn[A].address}for(let A in this.vOut)s(this.vOut[A].scriptPubKey)&&(this.vOut[A].scriptPubKey=o(this.vOut[A].scriptPubKey,"hex")),s(this.vOut[A].addressHash)&&(this.vOut[A].addressHash=o(this.vOut[A].addressHash,"hex")),delete this.address,delete this.vOut[A].scriptPubKeyOpcodes,delete this.vOut[A].scriptPubKeyAsm;return s(this.data)&&(this.data=o(this.data,"hex")),this.format="raw",this},E.prototype.serialize=function(e={}){g(e,{segwit:!0,hex:!0});let t=[];t.push(o(A.intToBytes(this.version,4))),e.segwit&&this.segwit&&t.push(o([0,1])),t.push(o(A.intToVarInt(Object.keys(this.vIn).length)));for(let e in this.vIn){s(this.vIn[e].txId)?t.push(i(this.vIn[e].txId)):t.push(this.vIn[e].txId),t.push(o(A.intToBytes(this.vIn[e].vOut,4)));let I=s(this.vIn[e].scriptSig)?o(this.vIn[e].scriptSig,"hex"):this.vIn[e].scriptSig;t.push(o(A.intToVarInt(I.length))),t.push(I),t.push(o(A.intToBytes(this.vIn[e].sequence,4)))}t.push(o(A.intToVarInt(Object.keys(this.vOut).length)));for(let i in this.vOut){t.push(o(A.intToBytes(this.vOut[i].value,8)));let e=s(this.vOut[i].scriptPubKey)?o(this.vOut[i].scriptPubKey,"hex"):this.vOut[i].scriptPubKey;t.push(o(A.intToVarInt(e.length))),t.push(e)}if(e.segwit&&this.segwit)for(let i in this.vIn){t.push(o(A.intToVarInt(this.vIn[i].txInWitness.length)));for(let e of this.vIn[i].txInWitness){let i=s(e)?o(e,"hex"):e;t.push(o(A.intToVarInt(i.length))),t.push(i)}}t.push(o(A.intToBytes(this.lockTime,4)));let I=n(t);return e.hex?I.hex():I},E.prototype.json=function(){let A;return"raw"===this.format?(this.decode(),A=JSON.stringify(this),this.encode()):A=JSON.stringify(this),A},E.prototype.addInput=function(r={}){g(r,{txId:null,vOut:0,sequence:4294967295,scriptSig:"",txInWitness:null,value:null,scriptPubKey:null,address:null,privateKey:null,redeemScript:null,inputVerify:!0});let B,n=[];if(null===r.txId&&(r.txId=t(32),r.vOut=4294967295,(4294967295!==r.sequence||Object.keys(this.vOut).length)&&r.inputVerify))throw new Error("invalid coinbase transaction");if(s(r.txId)){if(!A.isHex(r.txId))throw new Error("txId invalid");r.txId=i(r.txId)}if(!I(r.txId)||32!==r.txId.length)throw new Error("txId invalid");if(0===r.scriptSig.length&&(r.scriptSig=o([])),s(r.scriptSig)){if(!A.isHex(r.scriptSig))throw new Error("scriptSig invalid");r.scriptSig=o(r.scriptSig,"hex")}if(!I(r.scriptSig)||r.scriptSig.length>520&&r.inputVerify)throw new Error("scriptSig invalid");if(r.vOut<0||r.vOut>4294967295)throw new Error("vOut invalid");if(r.sequence<0||r.sequence>4294967295)throw new Error("vOut invalid");if(null===r.privateKey||r.privateKey instanceof A.PrivateKey||(r.privateKey=A.PrivateKey(r.privateKey)),null!==r.value&&(r.value<0||r.value>A.MAX_AMOUNT))throw new Error("amount invalid");if(null!==r.txInWitness){let A=0;for(let i of r.txInWitness)s(i)?n.push("raw"===this.format?o(i,"hex"):i):n.push("raw"===this.format?i:o(i,"hex")),A+=1+i.length}if(r.txId.equals(t.alloc(32))){if(!(4294967295===r.vOut&&4294967295===r.sequence&&r.scriptSig.length<=100)&&r.inputVerify)throw new Error("coinbase tx invalid");this.coinbase=!0}if(null!==r.scriptPubKey&&(s(r.scriptPubKey)&&(r.scriptPubKey=o(r.scriptPubKey,"hex")),!I(r.scriptPubKey)))throw new Error("scriptPubKey invalid");if(null!==r.redeemScript&&(s(r.redeemScript)&&(r.redeemScript=o(r.redeemScript,"hex")),!I(r.redeemScript)))throw new Error("scriptPubKey invalid");if(null!==r.address){if(s(r.address)){if("mainnet"===A.addressNetType(r.address)===this.testnet)throw new Error("address invalid");B=A.addressToScript(r.address)}else{if(void 0===r.address.address)throw new Error("address invalid");B=A.addressToScript(r.address.address)}if(null!==r.scriptPubKey){if(!r.scriptPubKey.equals(B))throw new Error("address not match script")}else r.scriptPubKey=B}let a=Object.keys(this.vIn).length;return this.vIn[a]={},this.vIn[a].vOut=r.vOut,this.vIn[a].sequence=r.sequence,"raw"===this.format?(this.vIn[a].txId=r.txId,this.vIn[a].scriptSig=r.scriptSig,null!==r.scriptPubKey&&(this.vIn[a].scriptPubKey=r.scriptPubKey),null!==r.redeemScript&&(this.vIn[a].redeemScript=r.redeemScript)):(this.vIn[a].txId=e(r.txId),this.vIn[a].scriptSig=r.scriptSig.hex(),this.vIn[a].scriptSigOpcodes=A.decodeScript(r.scriptSig),this.vIn[a].scriptSigAsm=A.decodeScript(r.scriptSig,{asm:!0}),null!==r.scriptPubKey&&(this.vIn[a].scriptPubKey=r.scriptPubKey.hex(),this.vIn[a].scriptPubKeyOpcodes=A.decodeScript(r.scriptPubKey),this.vIn[a].scriptPubKeyAsm=A.decodeScript(r.scriptPubKey,{asm:!0})),null!==r.redeemScript&&(this.vIn[a].redeemScript=r.redeemScript.hex(),this.vIn[a].redeemScriptOpcodes=A.decodeScript(r.redeemScript),this.vIn[a].redeemScriptAsm=A.decodeScript(r.redeemScript,{asm:!0}))),null!==r.txInWitness&&(this.segwit=!0,this.vIn[a].txInWitness=n),null!==r.value&&(this.vIn[a].value=r.value),0!==r.privateKey&&(this.vIn[a].privateKey=r.privateKey),this.autoCommit&&this.commit(),this},E.prototype.addOutput=function(i={}){if(g(i,{value:0,address:null,scriptPubKey:null}),null===i.address&&null===i.scriptPubKey)throw new Error("unable to add output, address or script required");if(i.value<0||i.value>A.MAX_AMOUNT)throw new Error(" amount value error");null!==i.scriptPubKey&&(s(i.scriptPubKey)?i.scriptPubKey=o(i.scriptPubKey,"hex"):null!==i.address&&void 0!==i.address.address&&(i.address=i.address.address)),null!==i.address&&(i.scriptPubKey=A.addressToScript(i.address));let e=Object.keys(this.vOut).length;this.vOut[e]={},this.vOut[e].value=i.value;let t=A.parseScript(i.scriptPubKey,{segwit:!0});if(this.vOut[e].nType=t.nType,this.vOut[e].type=t.type,"raw"===this.format)this.vOut[e].scriptPubKey=i.scriptPubKey,null===this.data&&3===t.nType&&(this.data=t.data),[3,4,7,8].includes(t.nType)||(this.vOut[e].addressHash=t.addressHash,this.vOut[e].reqSigs=t.reqSigs);else{this.vOut[e].scriptPubKey=i.scriptPubKey.hex(),null===this.data&&3===t.nType&&(this.data=t.data.hex()),[3,4,7,8].includes(t.nType)||(this.vOut[e].addressHash=t.addressHash.hex(),this.vOut[e].reqSigs=t.reqSigs),this.vOut[e].scriptPubKeyOpcodes=A.decodeScript(i.scriptPubKey),this.vOut[e].scriptPubKeyAsm=A.decodeScript(i.scriptPubKey,{asm:!0});let I=[1,5].includes(t.nType),g=t.nType<5?null:i.scriptPubKey[0];void 0!==this.vOut[e].addressHash&&(this.vOut[e].address=A.hashToAddress(this.vOut[e].addressHash,{testnet:this.testnet,scriptHash:I,witnessVersion:g}))}return this.autoCommit&&this.commit(),this},E.prototype.delOutput=function(A){let i=Object.keys(this.vOut).length;if(0===i)return this;void 0===A&&(A=i-1);let e={},t=0;for(let I=0;I<i;I++)I!==A&&(e[t]=this.vOut[I],t++);return this.vOut=e,this.autoCommit&&this.commit(),this},E.prototype.delInput=function(A){let i=Object.keys(this.vIn).length;if(0===i)return this;void 0===A&&(A=i-1);let e={},t=0;for(let I=0;I<i;I++)I!==A&&(e[t]=this.vIn[I],t++);return this.vOut=e,this.autoCommit&&this.commit(),this},E.prototype.commit=function(){if(0===Object.keys(this.vIn).length||0===Object.keys(this.vOut).length)return this;if(this.segwit)for(let A in this.vIn)void 0===this.vIn[A].txInWitness&&(this.vIn[A].txInWitness=[]);let i=this.serialize({segwit:!1,hex:!1});this.txId=A.sha256(i),this.rawTx=this.serialize({segwit:!0,hex:!1}),this.hash=A.sha256(this.rawTx),this.size=this.rawTx.length,this.bSize=i.length,this.weight=3*this.bSize+this.size,this.vSize=Math.ceil(this.weight/4),"raw"!==this.format&&(this.txId=e(this.txId),this.hash=e(this.hash),this.rawTx=this.rawTx.hex());let t=0,I=0;for(let A in this.vIn){if(void 0===this.vIn[A].value){t=null;break}t+=this.vIn[A].value;for(let A in this.vOut)void 0!==this.vOut[A].value&&(I+=this.vOut[A].value)}return this.amount=I,this.fee=I&&t?t-I:null,this},E.prototype.sigHash=function(t,I={}){if(g(I,{scriptPubKey:null,sigHashType:A.SIGHASH_ALL,preImage:!1}),void 0===this.vIn[t])throw new Error("input not exist");let E;if(null!==I.scriptPubKey)E=I.scriptPubKey;else{if(void 0===this.vIn[t].scriptPubKey)throw new Error("scriptPubKey required");E=this.vIn[t].scriptPubKey}if(E=r(E),(31&I.sigHashType)===A.SIGHASH_SINGLE&&t>=Object.keys(this.vOut).length){let A=n([o([1]),B(31)]);return"raw"===this.format?A:e(A)}E=A.deleteFromScript(E,o([a.OP_CODESEPARATOR]));let C,Q=[o(A.intToBytes(this.version,4))];Q.push(I.sigHashType&A.SIGHASH_ANYONECANPAY?o([1]):o(A.intToVarInt(Object.keys(this.vIn).length)));for(let e in this.vIn){if(e=parseInt(e),I.sigHashType&A.SIGHASH_ANYONECANPAY&&t!==e)continue;let g=this.vIn[e].sequence;[A.SIGHASH_SINGLE,A.SIGHASH_NONE].includes(31&I.sigHashType)&&t!==e&&(g=0);let r=s(this.vIn[e].txId)?i(this.vIn[e].txId):this.vIn[e].txId;Q.push(r),Q.push(o(A.intToBytes(this.vIn[e].vOut,4))),t===e?(Q.push(o(A.intToVarInt(E.length))),Q.push(E),Q.push(o(A.intToBytes(g,4)))):(Q.push(o([0])),Q.push(o(A.intToBytes(g,4))))}if((31&I.sigHashType)===A.SIGHASH_NONE?Q.push(o([0])):(31&I.sigHashType)===A.SIGHASH_SINGLE?Q.push(o(A.intToVarInt(t+1))):Q.push(o(A.intToVarInt(Object.keys(this.vOut).length))),(31&I.sigHashType)!==A.SIGHASH_NONE)for(let i in this.vOut)i=parseInt(i),C=this.vOut[i].scriptPubKey,C=s(C)?o(C,"hex"):C,i>t&&(31&I.sigHashType)===A.SIGHASH_SINGLE||((31&I.sigHashType)===A.SIGHASH_SINGLE&&t!==i?(Q.push(B(8,255)),Q.push(B(1,0))):(Q.push(o(A.intToBytes(this.vOut[i].value,8))),Q.push(o(A.intToVarInt(C.length))),Q.push(C)));return Q.push(o(A.intToBytes(this.lockTime,4))),Q.push(o(A.intToBytes(I.sigHashType,4))),Q=n(Q),I.preImage?"raw"===this.format?Q:Q.hex():(Q=A.doubleSha256(Q),"raw"===this.format?Q:e(Q))},E.prototype.sigHashSegwit=function(e,t={}){if(g(t,{value:null,scriptPubKey:null,sigHashType:A.SIGHASH_ALL,preImage:!1}),void 0===this.vIn[e])throw new Error("input not exist");let I,a;if(null!==t.scriptPubKey)I=t.scriptPubKey;else{if(void 0===this.vIn[e].scriptPubKey)throw new Error("scriptPubKey required");I=this.vIn[e].scriptPubKey}if(I=r(I),null!==t.value)a=t.value;else{if(void 0===this.vIn[e].value)throw new Error("value required");a=this.vIn[e].value}let E,C,Q=[],h=[],c=[];for(let I in this.vIn){I=parseInt(I);let g=this.vIn[I].txId;s(g)&&(g=i(g));let r=o(A.intToBytes(this.vIn[I].vOut,4));t.sigHashType&A.SIGHASH_ANYONECANPAY||(Q.push(g),Q.push(r),(31&t.sigHashType)!==A.SIGHASH_SINGLE&&(31&t.sigHashType)!==A.SIGHASH_NONE&&h.push(o(A.intToBytes(this.vIn[I].sequence,4)))),I===e&&(E=n([g,r]),C=o(A.intToBytes(this.vIn[I].sequence,4)))}let l=Q.length>0?A.sha3(n(Q)):B(32,0),u=h.length>0?A.sha3(n(h)):B(32,0);a=o(A.intToBytes(a,8));for(let i in this.vOut){i=parseInt(i);let I=r(this.vOut[i].scriptPubKey);[A.SIGHASH_SINGLE,A.SIGHASH_NONE].includes(31&t.sigHashType)?(31&t.sigHashType)===A.SIGHASH_SINGLE&&e<Object.keys(this.vOut).length&&i===e&&(c.push(o(A.intToBytes(this.vOut[i].value,8))),c.push(o(A.intToVarInt(I.length))),c.push(I)):(c.push(o(A.intToBytes(this.vOut[i].value,8))),c.push(o(A.intToVarInt(I.length))),c.push(I))}let d=c.length>0?A.sha3(n(c)):B(32,0),f=n([o(A.intToBytes(this.version,4)),l,u,E,I,a,C,d,o(A.intToBytes(this.lockTime,4)),o(A.intToBytes(t.sigHashType,4))]);return t.preImage?"raw"===this.format?f.hex():f:A.sha3(f,{hex:"raw"!==this.format})},E.prototype.signInput=function(i,e={}){if(g(e,{privateKey:null,scriptPubKey:null,redeemScript:null,sigHashType:A.SIGHASH_ALL,address:null,value:null,witnessVersion:0,p2sh_p2wsh:!1}),void 0===this.vIn[i])throw new Error("input not exist");if(null===e.privateKey){if(void 0===this.vIn[i].privateKey)throw new Error("no private key");e.privateKey=this.vIn[i].privateKey}if(e.privateKey instanceof Array){e.publicKey=[];let i=[];for(let t of e.privateKey)void 0!==t.key&&(t=t.wif),e.publicKey.push(A.privateToPublicKey(t,{hex:!1})),i.push(new A.PrivateKey(t).key);e.privateKey=i}else{if(void 0===e.privateKey.key){let i=new A.PrivateKey(e.privateKey);e.privateKey=i.key,e.privateKeyCompressed=i.compressed}else e.privateKeyCompressed=e.privateKey.compressed,e.privateKey=e.privateKey.key;e.publicKey=[A.privateToPublicKey(e.privateKey,{hex:!1,compressed:e.privateKeyCompressed})],e.privateKey=[e.privateKey]}if(null===e.address&&void 0!==this.vIn[i].address&&(e.address=this.vIn[i].address),null!==e.address){if(void 0!==e.address.address&&(e.address=e.address.address),this.testnet!==("testnet"===A.addressNetType(e.address)))throw new Error("address network invalid");e.scriptPubKey=A.addressToScript(e.address)}let t,I=null;if(null===e.redeemScript&&void 0!==this.vIn[i].redeemScript&&(e.redeemScript=this.vIn[i].redeemScript),null!==e.redeemScript&&(e.redeemScript=r(e.redeemScript)),null===e.scriptPubKey&&void 0!==this.vIn[i].scriptPubKey)e.scriptPubKey=this.vIn[i].scriptPubKey;else if(null===e.scriptPubKey&&null===e.redeemScript)throw new Error("no scriptPubKey key");if(null!==e.scriptPubKey){e.scriptPubKey=r(e.scriptPubKey);let i=A.parseScript(e.scriptPubKey);I=i.type,[5,6].includes(i.nType)&&(e.witnessVersion=e.scriptPubKey[0])}else null!==e.redeemScript&&(I=null===e.witnessVersion||e.p2sh_p2wsh?"P2SH":"P2WSH");switch(I){case"PUBKEY":t=this.__sign_PUBKEY(i,e);break;case"P2PKH":t=this.__sign_P2PKH(i,e);break;case"P2SH":t=this.__sign_P2SH(i,e);break;case"P2WPKH":t=this.__sign_P2WPKH(i,e);break;case"P2WSH":t=this.__sign_P2WSH(i,e);break;case"MULTISIG":t=this.__sign_MULTISIG(i,e);break;default:throw new Error("not implemented")}return"raw"===this.format?this.vIn[i].scriptSig=t:(this.vIn[i].scriptSig=t.hex(),this.vIn[i].scriptSigOpcodes=A.decodeScript(t),this.vIn[i].scriptSigAsm=A.decodeScript(t,{asm:!0})),this.autoCommit&&this.commit(),this},E.prototype.__sign_PUBKEY=function(e,t){let I=this.sigHash(e,t);s(I)&&(I=i(I));let g=n([A.signMessage(I,t.privateKey[0]).signature,o(A.intToBytes(t.sigHashType,1))]);return"raw"===this.format?this.vIn[e].signatures=[g]:this.vIn[e].signatures=[g.hex()],n([o([g.length]),g])},E.prototype.__sign_P2PKH=function(e,t){let I=this.sigHash(e,t);s(I)&&(I=i(I));let g=n([A.signMessage(I,t.privateKey[0]).signature,o(A.intToBytes(t.sigHashType,1))]);return"raw"===this.format?this.vIn[e].signatures=[g]:this.vIn[e].signatures=[g.hex()],n([o([g.length]),g,o([t.publicKey[0].length]),t.publicKey[0]])},E.prototype.__sign_P2SH=function(i,e){if(null===e.redeemScript)throw new Error("no redeem script");if(e.p2sh_p2wsh)return this.__sign_P2SH_P2WSH(i,e);switch(A.parseScript(e.redeemScript).type){case"MULTISIG":return this.__sign_P2SH_MULTISIG(i,e);case"P2WPKH":return this.__sign_P2SH_P2WPKH(i,e);default:throw new Error("not implemented")}},E.prototype.__sign_P2SH_MULTISIG=function(e,t){let I=this.sigHash(e,{scriptPubKey:t.redeemScript,sigHashType:t.sigHashType});s(I)&&(I=i(I));let g=[];this.vIn[e].signatures=[];for(let i of t.privateKey){let r=n([A.signMessage(I,i).signature,o(A.intToBytes(t.sigHashType,1))]);g.push(r),this.vIn[e].signatures.push("raw"===this.format?r:r.hex())}return this.__get_MULTISIG_scriptSig(e,t.publicKey,g,t.redeemScript,t.redeemScript)},E.prototype.__sign_P2SH_P2WPKH=function(i,e){let t=n([o([25]),o([a.OP_DUP,a.OP_HASH160]),A.opPushData(A.hash160(e.publicKey[0])),o([a.OP_EQUALVERIFY,a.OP_CHECKSIG])]);if(null===e.value){if(void 0===this.vIn[i].value)throw new Error("no input amount");e.value=this.vIn[i].value}let I=this.sigHashSegwit(i,{scriptPubKey:t,sigHashType:e.sigHashType,value:e.value});I=r(I);let g=n([A.signMessage(I,e.privateKey[0]).signature,o(A.intToBytes(e.sigHashType,1))]);return this.segwit=!0,"raw"===this.format?this.vIn[i].txInWitness=[g,e.publicKey[0]]:this.vIn[i].txInWitness=[g.hex(),e.publicKey[0].hex()],this.vIn[i].signatures="raw"===this.format?[g]:[g.hex()],A.opPushData(e.redeemScript)},E.prototype.__sign_P2SH_P2WSH=function(i,e){switch(A.parseScript(e.redeemScript).type){case"MULTISIG":return this.__sign_P2SH_P2WSH_MULTISIG(i,e);default:throw new Error("not implemented")}},E.prototype.__sign_P2SH_P2WSH_MULTISIG=function(i,e){this.segwit=!0;let t=n([o(A.intToVarInt(e.redeemScript.length)),e.redeemScript]),I=this.sigHashSegwit(i,{scriptPubKey:t,sigHashType:e.sigHashType,value:e.value});I=r(I),this.vIn[i].signatures=[];let g=[];for(let t of e.privateKey){let r=n([A.signMessage(I,t).signature,o(A.intToBytes(e.sigHashType,1))]);g.push(r),this.vIn[i].signatures.push("raw"===this.format?r:r.hex())}let B=this.__get_MULTISIG_scriptSig(i,e.publicKey,g,t,e.redeemScript,e.value);if("raw"===this.format)this.vIn[i].txInWitness=B;else{this.vIn[i].txInWitness=[];for(let A of B)this.vIn[i].txInWitness.push(A.hex())}return A.opPushData(n([o([0]),A.opPushData(A.sha256(e.redeemScript))]))},E.prototype.__sign_P2WPKH=function(i,e){let t=n([o([25]),o([a.OP_DUP,a.OP_HASH160]),e.scriptPubKey.slice(1),o([a.OP_EQUALVERIFY,a.OP_CHECKSIG])]);if(null===e.value){if(void 0===this.vIn[i].value)throw new Error("no input amount");e.value=this.vIn[i].value}let I=this.sigHashSegwit(i,{scriptPubKey:t,sigHashType:e.sigHashType,value:e.value});I=r(I);let g=n([A.signMessage(I,e.privateKey[0]).signature,o(A.intToBytes(e.sigHashType,1))]);return this.segwit=!0,"raw"===this.format?this.vIn[i].txInWitness=[g,e.publicKey[0]]:this.vIn[i].txInWitness=[g.hex(),e.publicKey[0].hex()],this.vIn[i].signatures="raw"===this.format?[g]:[g.hex()],o([])},E.prototype.__sign_P2WSH=function(i,e){if(