-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathbitcoinjs.min.js
1 lines (1 loc) · 62.5 KB
/
bitcoinjs.min.js
1
var base64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";if(typeof window=="undefined"||!window){var _window={}}else{var _window=window}var Crypto=_window.Crypto={};var util=Crypto.util={rotl:function(c,a){return(c<<a)|(c>>>(32-a))},rotr:function(c,a){return(c<<(32-a))|(c>>>a)},endian:function(b){if(b.constructor==Number){return util.rotl(b,8)&16711935|util.rotl(b,24)&4278255360}for(var a=0;a<b.length;a++){b[a]=util.endian(b[a])}return b},randomBytes:function(b){for(var a=[];b>0;b--){a.push(Math.floor(Math.random()*256))}return a},bytesToWords:function(c){for(var e=[],d=0,a=0;d<c.length;d++,a+=8){e[a>>>5]|=c[d]<<(24-a%32)}return e},wordsToBytes:function(d){for(var c=[],a=0;a<d.length*32;a+=8){c.push((d[a>>>5]>>>(24-a%32))&255)}return c},bytesToHex:function(a){for(var c=[],b=0;b<a.length;b++){c.push((a[b]>>>4).toString(16));c.push((a[b]&15).toString(16))}return c.join("")},hexToBytes:function(b){for(var a=[],d=0;d<b.length;d+=2){a.push(parseInt(b.substr(d,2),16))}return a},bytesToBase64:function(b){if(typeof btoa=="function"){return btoa(Binary.bytesToString(b))}for(var a=[],d=0;d<b.length;d+=3){var e=(b[d]<<16)|(b[d+1]<<8)|b[d+2];for(var c=0;c<4;c++){if(d*8+c*6<=b.length*8){a.push(base64map.charAt((e>>>6*(3-c))&63))}else{a.push("=")}}}return a.join("")},base64ToBytes:function(b){if(typeof atob=="function"){return Binary.stringToBytes(atob(b))}b=b.replace(/[^A-Z0-9+\/]/ig,"");for(var a=[],c=0,d=0;c<b.length;d=++c%4){if(d==0){continue}a.push(((base64map.indexOf(b.charAt(c-1))&(Math.pow(2,-2*d+8)-1))<<(d*2))|(base64map.indexOf(b.charAt(c))>>>(6-d*2)))}return a}};Crypto.mode={};var charenc=Crypto.charenc={};var UTF8=charenc.UTF8={stringToBytes:function(a){return Binary.stringToBytes(unescape(encodeURIComponent(a)))},bytesToString:function(a){return decodeURIComponent(escape(Binary.bytesToString(a)))}};var Binary=charenc.Binary={stringToBytes:function(c){for(var a=[],b=0;b<c.length;b++){a.push(c.charCodeAt(b))}return a},bytesToString:function(a){for(var c=[],b=0;b<a.length;b++){c.push(String.fromCharCode(a[b]))}return c.join("")}};var C=Crypto,util=C.util,charenc=C.charenc,UTF8=charenc.UTF8,Binary=charenc.Binary;var K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];var SHA256=C.SHA256=function(c,a){var b=util.wordsToBytes(SHA256._sha256(c));return a&&a.asBytes?b:a&&a.asString?Binary.bytesToString(b):util.bytesToHex(b)};SHA256._sha256=function(q){if(q.constructor==String){q=UTF8.stringToBytes(q)}var A=util.bytesToWords(q),B=q.length*8,r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],s=[],O,N,M,L,J,I,G,F,E,D,p,o;A[B>>5]|=128<<(24-B%32);A[((B+64>>9)<<4)+15]=B;for(var E=0;E<A.length;E+=16){O=r[0];N=r[1];M=r[2];L=r[3];J=r[4];I=r[5];G=r[6];F=r[7];for(var D=0;D<64;D++){if(D<16){s[D]=A[D+E]}else{var n=s[D-15],v=s[D-2],Q=((n<<25)|(n>>>7))^((n<<14)|(n>>>18))^(n>>>3),P=((v<<15)|(v>>>17))^((v<<13)|(v>>>19))^(v>>>10);s[D]=Q+(s[D-7]>>>0)+P+(s[D-16]>>>0)}var u=J&I^~J&G,k=O&N^O&M^N&M,y=((O<<30)|(O>>>2))^((O<<19)|(O>>>13))^((O<<10)|(O>>>22)),x=((J<<26)|(J>>>6))^((J<<21)|(J>>>11))^((J<<7)|(J>>>25));p=(F>>>0)+x+u+(K[D])+(s[D]>>>0);o=y+k;F=G;G=I;I=J;J=L+p;L=M;M=N;N=O;O=p+o}r[0]+=O;r[1]+=N;r[2]+=M;r[3]+=L;r[4]+=J;r[5]+=I;r[6]+=G;r[7]+=F}return r};SHA256._blocksize=16;var C=Crypto,util=C.util,charenc=C.charenc,UTF8=charenc.UTF8,Binary=charenc.Binary;util.bytesToLWords=function(a){var b=Array(a.length>>2);for(var c=0;c<b.length;c++){b[c]=0}for(var c=0;c<a.length*8;c+=8){b[c>>5]|=(a[c/8]&255)<<(c%32)}return b};util.lWordsToBytes=function(c){var a=[];for(var b=0;b<c.length*32;b+=8){a.push((c[b>>5]>>>(b%32))&255)}return a};var RIPEMD160=C.RIPEMD160=function(c,a){var b=util.lWordsToBytes(RIPEMD160._rmd160(c));return a&&a.asBytes?b:a&&a.asString?Binary.bytesToString(b):util.bytesToHex(b)};RIPEMD160._rmd160=function(r){if(r.constructor==String){r=UTF8.stringToBytes(r)}var q=util.bytesToLWords(r),y=r.length*8;q[y>>5]|=128<<(y%32);q[(((y+64)>>>9)<<4)+14]=y;var l=1732584193;var k=4023233417;var h=2562383102;var g=271733878;var f=3285377520;for(var w=0;w<q.length;w+=16){var e;var c=l,o=k,v=h,d=g,p=f;var a=l,m=k,u=h,b=g,n=f;for(var s=0;s<=79;++s){e=safe_add(c,rmd160_f(s,o,v,d));e=safe_add(e,q[w+rmd160_r1[s]]);e=safe_add(e,rmd160_K1(s));e=safe_add(bit_rol(e,rmd160_s1[s]),p);c=p;p=d;d=bit_rol(v,10);v=o;o=e;e=safe_add(a,rmd160_f(79-s,m,u,b));e=safe_add(e,q[w+rmd160_r2[s]]);e=safe_add(e,rmd160_K2(s));e=safe_add(bit_rol(e,rmd160_s2[s]),n);a=n;n=b;b=bit_rol(u,10);u=m;m=e}e=safe_add(k,safe_add(v,b));k=safe_add(h,safe_add(d,n));h=safe_add(g,safe_add(p,a));g=safe_add(f,safe_add(c,m));f=safe_add(l,safe_add(o,u));l=e}return[l,k,h,g,f]};function rmd160_f(b,a,d,c){return(0<=b&&b<=15)?(a^d^c):(16<=b&&b<=31)?(a&d)|(~a&c):(32<=b&&b<=47)?(a|~d)^c:(48<=b&&b<=63)?(a&c)|(d&~c):(64<=b&&b<=79)?a^(d|~c):"rmd160_f: j out of range"}function rmd160_K1(a){return(0<=a&&a<=15)?0:(16<=a&&a<=31)?1518500249:(32<=a&&a<=47)?1859775393:(48<=a&&a<=63)?2400959708:(64<=a&&a<=79)?2840853838:"rmd160_K1: j out of range"}function rmd160_K2(a){return(0<=a&&a<=15)?1352829926:(16<=a&&a<=31)?1548603684:(32<=a&&a<=47)?1836072691:(48<=a&&a<=63)?2053994217:(64<=a&&a<=79)?0:"rmd160_K2: j out of range"}var rmd160_r1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13];var rmd160_r2=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11];var rmd160_s1=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6];var rmd160_s2=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))}function ECFieldElementFp(b,a){this.x=a;this.q=b}function feFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.x.equals(a.x))}function feFpToBigInteger(){return this.x}function feFpNegate(){return new ECFieldElementFp(this.q,this.x.negate().mod(this.q))}function feFpAdd(a){return new ECFieldElementFp(this.q,this.x.add(a.toBigInteger()).mod(this.q))}function feFpSubtract(a){return new ECFieldElementFp(this.q,this.x.subtract(a.toBigInteger()).mod(this.q))}function feFpMultiply(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger()).mod(this.q))}function feFpSquare(){return new ECFieldElementFp(this.q,this.x.square().mod(this.q))}function feFpDivide(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger().modInverse(this.q)).mod(this.q))}ECFieldElementFp.prototype.equals=feFpEquals;ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger;ECFieldElementFp.prototype.negate=feFpNegate;ECFieldElementFp.prototype.add=feFpAdd;ECFieldElementFp.prototype.subtract=feFpSubtract;ECFieldElementFp.prototype.multiply=feFpMultiply;ECFieldElementFp.prototype.square=feFpSquare;ECFieldElementFp.prototype.divide=feFpDivide;function ECPointFp(c,a,d,b){this.curve=c;this.x=a;this.y=d;if(b==null){this.z=BigInteger.ONE}else{this.z=b}this.zinv=null}function pointFpGetX(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpGetY(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpEquals(a){if(a==this){return true}if(this.isInfinity()){return a.isInfinity()}if(a.isInfinity()){return this.isInfinity()}var c,b;c=a.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(a.z)).mod(this.curve.q);if(!c.equals(BigInteger.ZERO)){return false}b=a.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(a.z)).mod(this.curve.q);return b.equals(BigInteger.ZERO)}function pointFpIsInfinity(){if((this.x==null)&&(this.y==null)){return true}return this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(m){if(this.isInfinity()){return m}if(m.isInfinity()){return this}var q=m.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(m.z)).mod(this.curve.q);var p=m.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(m.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(p)){if(BigInteger.ZERO.equals(q)){return this.twice()}return this.curve.getInfinity()}var k=new BigInteger("3");var e=this.x.toBigInteger();var o=this.y.toBigInteger();var c=m.x.toBigInteger();var l=m.y.toBigInteger();var n=p.square();var j=n.multiply(p);var d=e.multiply(n);var g=q.square().multiply(this.z);var a=g.subtract(d.shiftLeft(1)).multiply(m.z).subtract(j).multiply(p).mod(this.curve.q);var h=d.multiply(k).multiply(q).subtract(o.multiply(j)).subtract(g.multiply(q)).multiply(m.z).add(q.multiply(j)).mod(this.curve.q);var f=j.multiply(this.z).multiply(m.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(h),f)}function pointFpTwice(){if(this.isInfinity()){return this}if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var g=new BigInteger("3");var c=this.x.toBigInteger();var h=this.y.toBigInteger();var e=h.multiply(this.z);var k=e.multiply(h).mod(this.curve.q);var j=this.curve.a.toBigInteger();var l=c.square().multiply(g);if(!BigInteger.ZERO.equals(j)){l=l.add(this.z.square().multiply(j))}l=l.mod(this.curve.q);var b=l.square().subtract(c.shiftLeft(3).multiply(k)).shiftLeft(1).multiply(e).mod(this.curve.q);var f=l.multiply(g).multiply(c).subtract(k.shiftLeft(1)).shiftLeft(2).multiply(k).subtract(l.square().multiply(l)).mod(this.curve.q);var d=e.square().multiply(e).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(b),this.curve.fromBigInteger(f),d)}function pointFpMultiply(b){if(this.isInfinity()){return this}if(b.signum()==0){return this.curve.getInfinity()}var g=b;var f=g.multiply(new BigInteger("3"));var l=this.negate();var d=this;var c;for(c=f.bitLength()-2;c>0;--c){d=d.twice();var a=f.testBit(c);var j=g.testBit(c);if(a!=j){d=d.add(a?this:l)}}return d}function pointFpMultiplyTwo(c,a,b){var d;if(c.bitLength()>b.bitLength()){d=c.bitLength()-1}else{d=b.bitLength()-1}var f=this.curve.getInfinity();var e=this.add(a);while(d>=0){f=f.twice();if(c.testBit(d)){if(b.testBit(d)){f=f.add(e)}else{f=f.add(this)}}else{if(b.testBit(d)){f=f.add(a)}}--d}return f}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(e,d,c){this.q=e;this.a=this.fromBigInteger(d);this.b=this.fromBigInteger(c);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.a.equals(a.a)&&this.b.equals(a.b))}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(a){return new ECFieldElementFp(this.q,a)}function curveFpDecodePointHex(d){switch(parseInt(d.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var a=(d.length-2)/2;var c=d.substr(2,a);var b=d.substr(a+2,a);return new ECPointFp(this,this.fromBigInteger(new BigInteger(c,16)),this.fromBigInteger(new BigInteger(b,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger;ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex;var dbits;var canary=244837814094590;var j_lm=((canary&16777215)==15715070);function BigInteger(e,d,f){if(e!=null){if("number"==typeof e){this.fromNumber(e,d,f)}else{if(d==null&&"string"!=typeof e){this.fromString(e,256)}else{this.fromString(e,d)}}}}function nbi(){return new BigInteger(null)}function am1(f,a,b,e,h,g){while(--g>=0){var d=a*this[f++]+b[e]+h;h=Math.floor(d/67108864);b[e++]=d&67108863}return h}function am2(f,q,r,e,o,a){var k=q&32767,p=q>>15;while(--a>=0){var d=this[f]&32767;var g=this[f++]>>15;var b=p*d+g*k;d=k*d+((b&32767)<<15)+r[e]+(o&1073741823);o=(d>>>30)+(b>>>15)+p*g+(o>>>30);r[e++]=d&1073741823}return o}function am3(f,q,r,e,o,a){var k=q&16383,p=q>>14;while(--a>=0){var d=this[f]&16383;var g=this[f++]>>14;var b=p*d+g*k;d=k*d+((b&16383)<<14)+r[e]+o;o=(d>>28)+(b>>14)+p*g;r[e++]=d&268435455}return o}if(j_lm&&(navigator.appName=="Microsoft Internet Explorer")){BigInteger.prototype.am=am2;dbits=30}else{if(j_lm&&(navigator.appName!="Netscape")){BigInteger.prototype.am=am1;dbits=26}else{BigInteger.prototype.am=am3;dbits=28}}BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=((1<<dbits)-1);BigInteger.prototype.DV=(1<<dbits);var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP);BigInteger.prototype.F1=BI_FP-dbits;BigInteger.prototype.F2=2*dbits-BI_FP;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz";var BI_RC=new Array();var rr,vv;rr="0".charCodeAt(0);for(vv=0;vv<=9;++vv){BI_RC[rr++]=vv}rr="a".charCodeAt(0);for(vv=10;vv<36;++vv){BI_RC[rr++]=vv}rr="A".charCodeAt(0);for(vv=10;vv<36;++vv){BI_RC[rr++]=vv}function int2char(a){return BI_RM.charAt(a)}function intAt(b,a){var d=BI_RC[b.charCodeAt(a)];return(d==null)?-1:d}function bnpCopyTo(b){for(var a=this.t-1;a>=0;--a){b[a]=this[a]}b.t=this.t;b.s=this.s}function bnpFromInt(a){this.t=1;this.s=(a<0)?-1:0;if(a>0){this[0]=a}else{if(a<-1){this[0]=a+DV}else{this.t=0}}}function nbv(a){var b=nbi();b.fromInt(a);return b}function bnpFromString(h,c){var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==256){e=8}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{this.fromRadix(h,c);return}}}}}}this.t=0;this.s=0;var g=h.length,d=false,f=0;while(--g>=0){var a=(e==8)?h[g]&255:intAt(h,g);if(a<0){if(h.charAt(g)=="-"){d=true}continue}d=false;if(f==0){this[this.t++]=a}else{if(f+e>this.DB){this[this.t-1]|=(a&((1<<(this.DB-f))-1))<<f;this[this.t++]=(a>>(this.DB-f))}else{this[this.t-1]|=a<<f}}f+=e;if(f>=this.DB){f-=this.DB}}if(e==8&&(h[0]&128)!=0){this.s=-1;if(f>0){this[this.t-1]|=((1<<(this.DB-f))-1)<<f}}this.clamp();if(d){BigInteger.ZERO.subTo(this,this)}}function bnpClamp(){var a=this.s&this.DM;while(this.t>0&&this[this.t-1]==a){--this.t}}function bnToString(c){if(this.s<0){return"-"+this.negate().toString(c)}var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{return this.toRadix(c)}}}}}var g=(1<<e)-1,l,a=false,h="",f=this.t;var j=this.DB-(f*this.DB)%e;if(f-->0){if(j<this.DB&&(l=this[f]>>j)>0){a=true;h=int2char(l)}while(f>=0){if(j<e){l=(this[f]&((1<<j)-1))<<(e-j);l|=this[--f]>>(j+=this.DB-e)}else{l=(this[f]>>(j-=e))&g;if(j<=0){j+=this.DB;--f}}if(l>0){a=true}if(a){h+=int2char(l)}}}return a?h:"0"}function bnNegate(){var a=nbi();BigInteger.ZERO.subTo(this,a);return a}function bnAbs(){return(this.s<0)?this.negate():this}function bnCompareTo(b){var d=this.s-b.s;if(d!=0){return d}var c=this.t;d=c-b.t;if(d!=0){return d}while(--c>=0){if((d=this[c]-b[c])!=0){return d}}return 0}function nbits(a){var c=1,b;if((b=a>>>16)!=0){a=b;c+=16}if((b=a>>8)!=0){a=b;c+=8}if((b=a>>4)!=0){a=b;c+=4}if((b=a>>2)!=0){a=b;c+=2}if((b=a>>1)!=0){a=b;c+=1}return c}function bnBitLength(){if(this.t<=0){return 0}return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM))}function bnpDLShiftTo(c,b){var a;for(a=this.t-1;a>=0;--a){b[a+c]=this[a]}for(a=c-1;a>=0;--a){b[a]=0}b.t=this.t+c;b.s=this.s}function bnpDRShiftTo(c,b){for(var a=c;a<this.t;++a){b[a-c]=this[a]}b.t=Math.max(this.t-c,0);b.s=this.s}function bnpLShiftTo(j,e){var b=j%this.DB;var a=this.DB-b;var g=(1<<a)-1;var f=Math.floor(j/this.DB),h=(this.s<<b)&this.DM,d;for(d=this.t-1;d>=0;--d){e[d+f+1]=(this[d]>>a)|h;h=(this[d]&g)<<b}for(d=f-1;d>=0;--d){e[d]=0}e[f]=h;e.t=this.t+f+1;e.s=this.s;e.clamp()}function bnpRShiftTo(g,d){d.s=this.s;var e=Math.floor(g/this.DB);if(e>=this.t){d.t=0;return}var b=g%this.DB;var a=this.DB-b;var f=(1<<b)-1;d[0]=this[e]>>b;for(var c=e+1;c<this.t;++c){d[c-e-1]|=(this[c]&f)<<a;d[c-e]=this[c]>>b}if(b>0){d[this.t-e-1]|=(this.s&f)<<a}d.t=this.t-e;d.clamp()}function bnpSubTo(d,f){var e=0,g=0,b=Math.min(d.t,this.t);while(e<b){g+=this[e]-d[e];f[e++]=g&this.DM;g>>=this.DB}if(d.t<this.t){g-=d.s;while(e<this.t){g+=this[e];f[e++]=g&this.DM;g>>=this.DB}g+=this.s}else{g+=this.s;while(e<d.t){g-=d[e];f[e++]=g&this.DM;g>>=this.DB}g-=d.s}f.s=(g<0)?-1:0;if(g<-1){f[e++]=this.DV+g}else{if(g>0){f[e++]=g}}f.t=e;f.clamp()}function bnpMultiplyTo(c,e){var b=this.abs(),f=c.abs();var d=b.t;e.t=d+f.t;while(--d>=0){e[d]=0}for(d=0;d<f.t;++d){e[d+b.t]=b.am(0,f[d],e,d,0,b.t)}e.s=0;e.clamp();if(this.s!=c.s){BigInteger.ZERO.subTo(e,e)}}function bnpSquareTo(d){var a=this.abs();var b=d.t=2*a.t;while(--b>=0){d[b]=0}for(b=0;b<a.t-1;++b){var e=a.am(b,a[b],d,2*b,0,1);if((d[b+a.t]+=a.am(b+1,2*a[b],d,2*b+1,e,a.t-b-1))>=a.DV){d[b+a.t]-=a.DV;d[b+a.t+1]=1}}if(d.t>0){d[d.t-1]+=a.am(b,a[b],d,2*b,0,1)}d.s=0;d.clamp()}function bnpDivRemTo(n,h,g){var w=n.abs();if(w.t<=0){return}var k=this.abs();if(k.t<w.t){if(h!=null){h.fromInt(0)}if(g!=null){this.copyTo(g)}return}if(g==null){g=nbi()}var d=nbi(),a=this.s,l=n.s;var v=this.DB-nbits(w[w.t-1]);if(v>0){w.lShiftTo(v,d);k.lShiftTo(v,g)}else{w.copyTo(d);k.copyTo(g)}var p=d.t;var b=d[p-1];if(b==0){return}var o=b*(1<<this.F1)+((p>1)?d[p-2]>>this.F2:0);var B=this.FV/o,A=(1<<this.F1)/o,x=1<<this.F2;var u=g.t,s=u-p,f=(h==null)?nbi():h;d.dlShiftTo(s,f);if(g.compareTo(f)>=0){g[g.t++]=1;g.subTo(f,g)}BigInteger.ONE.dlShiftTo(p,f);f.subTo(d,d);while(d.t<p){d[d.t++]=0}while(--s>=0){var c=(g[--u]==b)?this.DM:Math.floor(g[u]*B+(g[u-1]+x)*A);if((g[u]+=d.am(0,c,g,s,0,p))<c){d.dlShiftTo(s,f);g.subTo(f,g);while(g[u]<--c){g.subTo(f,g)}}}if(h!=null){g.drShiftTo(p,h);if(a!=l){BigInteger.ZERO.subTo(h,h)}}g.t=p;g.clamp();if(v>0){g.rShiftTo(v,g)}if(a<0){BigInteger.ZERO.subTo(g,g)}}function bnMod(b){var c=nbi();this.abs().divRemTo(b,null,c);if(this.s<0&&c.compareTo(BigInteger.ZERO)>0){b.subTo(c,c)}return c}function Classic(a){this.m=a}function cConvert(a){if(a.s<0||a.compareTo(this.m)>=0){return a.mod(this.m)}else{return a}}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1){return 0}var a=this[0];if((a&1)==0){return 0}var b=a&3;b=(b*(2-(a&15)*b))&15;b=(b*(2-(a&255)*b))&255;b=(b*(2-(((a&65535)*b)&65535)))&65535;b=(b*(2-a*b%this.DV))%this.DV;return(b>0)?this.DV-b:-b}function Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(a.DB-15))-1;this.mt2=2*a.t}function montConvert(a){var b=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);if(a.s<0&&b.compareTo(BigInteger.ZERO)>0){this.m.subTo(b,b)}return b}function montRevert(a){var b=nbi();a.copyTo(b);this.reduce(b);return b}function montReduce(a){while(a.t<=this.mt2){a[a.t++]=0}for(var c=0;c<this.m.t;++c){var b=a[c]&32767;var d=(b*this.mpl+(((b*this.mph+(a[c]>>15)*this.mpl)&this.um)<<15))&a.DM;b=c+this.m.t;a[b]+=this.m.am(0,d,a,c,0,this.m.t);while(a[b]>=a.DV){a[b]-=a.DV;a[++b]++}}a.clamp();a.drShiftTo(this.m.t,a);if(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function montMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0}function bnpExp(h,j){if(h>4294967295||h<1){return BigInteger.ONE}var f=nbi(),a=nbi(),d=j.convert(this),c=nbits(h)-1;d.copyTo(f);while(--c>=0){j.sqrTo(f,a);if((h&(1<<c))>0){j.mulTo(a,d,f)}else{var b=f;f=a;a=b}}return j.revert(f)}function bnModPowInt(b,a){var c;if(b<256||a.isEven()){c=new Classic(a)}else{c=new Montgomery(a)}return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function bnClone(){var a=nbi();this.copyTo(a);return a}function bnIntValue(){if(this.s<0){if(this.t==1){return this[0]-this.DV}else{if(this.t==0){return -1}}}else{if(this.t==1){return this[0]}else{if(this.t==0){return 0}}}return((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0]}function bnByteValue(){return(this.t==0)?this.s:(this[0]<<24)>>24}function bnShortValue(){return(this.t==0)?this.s:(this[0]<<16)>>16}function bnpChunkSize(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function bnSigNum(){if(this.s<0){return -1}else{if(this.t<=0||(this.t==1&&this[0]<=0)){return 0}else{return 1}}}function bnpToRadix(c){if(c==null){c=10}if(this.signum()==0||c<2||c>36){return"0"}var f=this.chunkSize(c);var e=Math.pow(c,f);var j=nbv(e),k=nbi(),h=nbi(),g="";this.divRemTo(j,k,h);while(k.signum()>0){g=(e+h.intValue()).toString(c).substr(1)+g;k.divRemTo(j,k,h)}return h.intValue().toString(c)+g}function bnpFromRadix(m,h){this.fromInt(0);if(h==null){h=10}var f=this.chunkSize(h);var g=Math.pow(h,f),e=false,a=0,l=0;for(var c=0;c<m.length;++c){var k=intAt(m,c);if(k<0){if(m.charAt(c)=="-"&&this.signum()==0){e=true}continue}l=h*l+k;if(++a>=f){this.dMultiply(g);this.dAddOffset(l,0);a=0;l=0}}if(a>0){this.dMultiply(Math.pow(h,a));this.dAddOffset(l,0)}if(e){BigInteger.ZERO.subTo(this,this)}}function bnpFromNumber(f,e,h){if("number"==typeof e){if(f<2){this.fromInt(1)}else{this.fromNumber(f,h);if(!this.testBit(f-1)){this.bitwiseTo(BigInteger.ONE.shiftLeft(f-1),op_or,this)}if(this.isEven()){this.dAddOffset(1,0)}while(!this.isProbablePrime(e)){this.dAddOffset(2,0);if(this.bitLength()>f){this.subTo(BigInteger.ONE.shiftLeft(f-1),this)}}}}else{var d=new Array(),g=f&7;d.length=(f>>3)+1;e.nextBytes(d);if(g>0){d[0]&=((1<<g)-1)}else{d[0]=0}this.fromString(d,256)}}function bnToByteArray(){var b=this.t,c=new Array();c[0]=this.s;var e=this.DB-(b*this.DB)%8,f,a=0;if(b-->0){if(e<this.DB&&(f=this[b]>>e)!=(this.s&this.DM)>>e){c[a++]=f|(this.s<<(this.DB-e))}while(b>=0){if(e<8){f=(this[b]&((1<<e)-1))<<(8-e);f|=this[--b]>>(e+=this.DB-8)}else{f=(this[b]>>(e-=8))&255;if(e<=0){e+=this.DB;--b}}if((f&128)!=0){f|=-256}if(a==0&&(this.s&128)!=(f&128)){++a}if(a>0||f!=this.s){c[a++]=f}}}return c}function bnEquals(b){return(this.compareTo(b)==0)}function bnMin(b){return(this.compareTo(b)<0)?this:b}function bnMax(b){return(this.compareTo(b)>0)?this:b}function bnpBitwiseTo(c,h,e){var d,g,b=Math.min(c.t,this.t);for(d=0;d<b;++d){e[d]=h(this[d],c[d])}if(c.t<this.t){g=c.s&this.DM;for(d=b;d<this.t;++d){e[d]=h(this[d],g)}e.t=this.t}else{g=this.s&this.DM;for(d=b;d<c.t;++d){e[d]=h(g,c[d])}e.t=c.t}e.s=h(this.s,c.s);e.clamp()}function op_and(a,b){return a&b}function bnAnd(b){var c=nbi();this.bitwiseTo(b,op_and,c);return c}function op_or(a,b){return a|b}function bnOr(b){var c=nbi();this.bitwiseTo(b,op_or,c);return c}function op_xor(a,b){return a^b}function bnXor(b){var c=nbi();this.bitwiseTo(b,op_xor,c);return c}function op_andnot(a,b){return a&~b}function bnAndNot(b){var c=nbi();this.bitwiseTo(b,op_andnot,c);return c}function bnNot(){var b=nbi();for(var a=0;a<this.t;++a){b[a]=this.DM&~this[a]}b.t=this.t;b.s=~this.s;return b}function bnShiftLeft(b){var a=nbi();if(b<0){this.rShiftTo(-b,a)}else{this.lShiftTo(b,a)}return a}function bnShiftRight(b){var a=nbi();if(b<0){this.lShiftTo(-b,a)}else{this.rShiftTo(b,a)}return a}function lbit(a){if(a==0){return -1}var b=0;if((a&65535)==0){a>>=16;b+=16}if((a&255)==0){a>>=8;b+=8}if((a&15)==0){a>>=4;b+=4}if((a&3)==0){a>>=2;b+=2}if((a&1)==0){++b}return b}function bnGetLowestSetBit(){for(var a=0;a<this.t;++a){if(this[a]!=0){return a*this.DB+lbit(this[a])}}if(this.s<0){return this.t*this.DB}return -1}function cbit(a){var b=0;while(a!=0){a&=a-1;++b}return b}function bnBitCount(){var c=0,a=this.s&this.DM;for(var b=0;b<this.t;++b){c+=cbit(this[b]^a)}return c}function bnTestBit(b){var a=Math.floor(b/this.DB);if(a>=this.t){return(this.s!=0)}return((this[a]&(1<<(b%this.DB)))!=0)}function bnpChangeBit(c,b){var a=BigInteger.ONE.shiftLeft(c);this.bitwiseTo(a,b,a);return a}function bnSetBit(a){return this.changeBit(a,op_or)}function bnClearBit(a){return this.changeBit(a,op_andnot)}function bnFlipBit(a){return this.changeBit(a,op_xor)}function bnpAddTo(d,f){var e=0,g=0,b=Math.min(d.t,this.t);while(e<b){g+=this[e]+d[e];f[e++]=g&this.DM;g>>=this.DB}if(d.t<this.t){g+=d.s;while(e<this.t){g+=this[e];f[e++]=g&this.DM;g>>=this.DB}g+=this.s}else{g+=this.s;while(e<d.t){g+=d[e];f[e++]=g&this.DM;g>>=this.DB}g+=d.s}f.s=(g<0)?-1:0;if(g>0){f[e++]=g}else{if(g<-1){f[e++]=this.DV+g}}f.t=e;f.clamp()}function bnAdd(b){var c=nbi();this.addTo(b,c);return c}function bnSubtract(b){var c=nbi();this.subTo(b,c);return c}function bnMultiply(b){var c=nbi();this.multiplyTo(b,c);return c}function bnSquare(){var a=nbi();this.squareTo(a);return a}function bnDivide(b){var c=nbi();this.divRemTo(b,c,null);return c}function bnRemainder(b){var c=nbi();this.divRemTo(b,null,c);return c}function bnDivideAndRemainder(b){var d=nbi(),c=nbi();this.divRemTo(b,d,c);return new Array(d,c)}function bnpDMultiply(a){this[this.t]=this.am(0,a-1,this,0,0,this.t);++this.t;this.clamp()}function bnpDAddOffset(b,a){if(b==0){return}while(this.t<=a){this[this.t++]=0}this[a]+=b;while(this[a]>=this.DV){this[a]-=this.DV;if(++a>=this.t){this[this.t++]=0}++this[a]}}function NullExp(){}function nNop(a){return a}function nMulTo(a,c,b){a.multiplyTo(c,b)}function nSqrTo(a,b){a.squareTo(b)}NullExp.prototype.convert=nNop;NullExp.prototype.revert=nNop;NullExp.prototype.mulTo=nMulTo;NullExp.prototype.sqrTo=nSqrTo;function bnPow(a){return this.exp(a,new NullExp())}function bnpMultiplyLowerTo(b,f,e){var d=Math.min(this.t+b.t,f);e.s=0;e.t=d;while(d>0){e[--d]=0}var c;for(c=e.t-this.t;d<c;++d){e[d+this.t]=this.am(0,b[d],e,d,0,this.t)}for(c=Math.min(b.t,f);d<c;++d){this.am(0,b[d],e,d,0,f-d)}e.clamp()}function bnpMultiplyUpperTo(b,e,d){--e;var c=d.t=this.t+b.t-e;d.s=0;while(--c>=0){d[c]=0}for(c=Math.max(e-this.t,0);c<b.t;++c){d[this.t+c-e]=this.am(e-c,b[c],d,0,0,this.t+c-e)}d.clamp();d.drShiftTo(1,d)}function Barrett(a){this.r2=nbi();this.q3=nbi();BigInteger.ONE.dlShiftTo(2*a.t,this.r2);this.mu=this.r2.divide(a);this.m=a}function barrettConvert(a){if(a.s<0||a.t>2*this.m.t){return a.mod(this.m)}else{if(a.compareTo(this.m)<0){return a}else{var b=nbi();a.copyTo(b);this.reduce(b);return b}}}function barrettRevert(a){return a}function barrettReduce(a){a.drShiftTo(this.m.t-1,this.r2);if(a.t>this.m.t+1){a.t=this.m.t+1;a.clamp()}this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);while(a.compareTo(this.r2)<0){a.dAddOffset(1,this.m.t+1)}a.subTo(this.r2,a);while(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function barrettSqrTo(a,b){a.squareTo(b);this.reduce(b)}function barrettMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Barrett.prototype.convert=barrettConvert;Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;function bnModPow(q,f){var o=q.bitLength(),h,b=nbv(1),v;if(o<=0){return b}else{if(o<18){h=1}else{if(o<48){h=3}else{if(o<144){h=4}else{if(o<768){h=5}else{h=6}}}}}if(o<8){v=new Classic(f)}else{if(f.isEven()){v=new Barrett(f)}else{v=new Montgomery(f)}}var p=new Array(),d=3,s=h-1,a=(1<<h)-1;p[1]=v.convert(this);if(h>1){var A=nbi();v.sqrTo(p[1],A);while(d<=a){p[d]=nbi();v.mulTo(A,p[d-2],p[d]);d+=2}}var l=q.t-1,x,u=true,c=nbi(),y;o=nbits(q[l])-1;while(l>=0){if(o>=s){x=(q[l]>>(o-s))&a}else{x=(q[l]&((1<<(o+1))-1))<<(s-o);if(l>0){x|=q[l-1]>>(this.DB+o-s)}}d=h;while((x&1)==0){x>>=1;--d}if((o-=d)<0){o+=this.DB;--l}if(u){p[x].copyTo(b);u=false}else{while(d>1){v.sqrTo(b,c);v.sqrTo(c,b);d-=2}if(d>0){v.sqrTo(b,c)}else{y=b;b=c;c=y}v.mulTo(c,p[x],b)}while(l>=0&&(q[l]&(1<<o))==0){v.sqrTo(b,c);y=b;b=c;c=y;if(--o<0){o=this.DB-1;--l}}}return v.revert(b)}function bnGCD(c){var b=(this.s<0)?this.negate():this.clone();var h=(c.s<0)?c.negate():c.clone();if(b.compareTo(h)<0){var e=b;b=h;h=e}var d=b.getLowestSetBit(),f=h.getLowestSetBit();if(f<0){return b}if(d<f){f=d}if(f>0){b.rShiftTo(f,b);h.rShiftTo(f,h)}while(b.signum()>0){if((d=b.getLowestSetBit())>0){b.rShiftTo(d,b)}if((d=h.getLowestSetBit())>0){h.rShiftTo(d,h)}if(b.compareTo(h)>=0){b.subTo(h,b);b.rShiftTo(1,b)}else{h.subTo(b,h);h.rShiftTo(1,h)}}if(f>0){h.lShiftTo(f,h)}return h}function bnpModInt(e){if(e<=0){return 0}var c=this.DV%e,b=(this.s<0)?e-1:0;if(this.t>0){if(c==0){b=this[0]%e}else{for(var a=this.t-1;a>=0;--a){b=(c*b+this[a])%e}}}return b}function bnModInverse(f){var k=f.isEven();if((this.isEven()&&k)||f.signum()==0){return BigInteger.ZERO}var j=f.clone(),h=this.clone();var g=nbv(1),e=nbv(0),n=nbv(0),l=nbv(1);while(j.signum()!=0){while(j.isEven()){j.rShiftTo(1,j);if(k){if(!g.isEven()||!e.isEven()){g.addTo(this,g);e.subTo(f,e)}g.rShiftTo(1,g)}else{if(!e.isEven()){e.subTo(f,e)}}e.rShiftTo(1,e)}while(h.isEven()){h.rShiftTo(1,h);if(k){if(!n.isEven()||!l.isEven()){n.addTo(this,n);l.subTo(f,l)}n.rShiftTo(1,n)}else{if(!l.isEven()){l.subTo(f,l)}}l.rShiftTo(1,l)}if(j.compareTo(h)>=0){j.subTo(h,j);if(k){g.subTo(n,g)}e.subTo(l,e)}else{h.subTo(j,h);if(k){n.subTo(g,n)}l.subTo(e,l)}}if(h.compareTo(BigInteger.ONE)!=0){return BigInteger.ZERO}if(l.compareTo(f)>=0){return l.subtract(f)}if(l.signum()<0){l.addTo(f,l)}else{return l}if(l.signum()<0){return l.add(f)}else{return l}}var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];var lplim=(1<<26)/lowprimes[lowprimes.length-1];function bnIsProbablePrime(e){var d,b=this.abs();if(b.t==1&&b[0]<=lowprimes[lowprimes.length-1]){for(d=0;d<lowprimes.length;++d){if(b[0]==lowprimes[d]){return true}}return false}if(b.isEven()){return false}d=1;while(d<lowprimes.length){var a=lowprimes[d],c=d+1;while(c<lowprimes.length&&a<lplim){a*=lowprimes[c++]}a=b.modInt(a);while(d<c){if(a%lowprimes[d++]==0){return false}}}return b.millerRabin(e)}function bnpMillerRabin(f){var g=this.subtract(BigInteger.ONE);var c=g.getLowestSetBit();if(c<=0){return false}var h=g.shiftRight(c);f=(f+1)>>1;if(f>lowprimes.length){f=lowprimes.length}var b=nbi();for(var e=0;e<f;++e){b.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var l=b.modPow(h,this);if(l.compareTo(BigInteger.ONE)!=0&&l.compareTo(g)!=0){var d=1;while(d++<c&&l.compareTo(g)!=0){l=l.modPowInt(2,this);if(l.compareTo(BigInteger.ONE)==0){return false}}if(l.compareTo(g)!=0){return false}}}return true}BigInteger.prototype.chunkSize=bnpChunkSize;BigInteger.prototype.toRadix=bnpToRadix;BigInteger.prototype.fromRadix=bnpFromRadix;BigInteger.prototype.fromNumber=bnpFromNumber;BigInteger.prototype.bitwiseTo=bnpBitwiseTo;BigInteger.prototype.changeBit=bnpChangeBit;BigInteger.prototype.addTo=bnpAddTo;BigInteger.prototype.dMultiply=bnpDMultiply;BigInteger.prototype.dAddOffset=bnpDAddOffset;BigInteger.prototype.multiplyLowerTo=bnpMultiplyLowerTo;BigInteger.prototype.multiplyUpperTo=bnpMultiplyUpperTo;BigInteger.prototype.modInt=bnpModInt;BigInteger.prototype.millerRabin=bnpMillerRabin;BigInteger.prototype.clone=bnClone;BigInteger.prototype.intValue=bnIntValue;BigInteger.prototype.byteValue=bnByteValue;BigInteger.prototype.shortValue=bnShortValue;BigInteger.prototype.signum=bnSigNum;BigInteger.prototype.toByteArray=bnToByteArray;BigInteger.prototype.equals=bnEquals;BigInteger.prototype.min=bnMin;BigInteger.prototype.max=bnMax;BigInteger.prototype.and=bnAnd;BigInteger.prototype.or=bnOr;BigInteger.prototype.xor=bnXor;BigInteger.prototype.andNot=bnAndNot;BigInteger.prototype.not=bnNot;BigInteger.prototype.shiftLeft=bnShiftLeft;BigInteger.prototype.shiftRight=bnShiftRight;BigInteger.prototype.getLowestSetBit=bnGetLowestSetBit;BigInteger.prototype.bitCount=bnBitCount;BigInteger.prototype.testBit=bnTestBit;BigInteger.prototype.setBit=bnSetBit;BigInteger.prototype.clearBit=bnClearBit;BigInteger.prototype.flipBit=bnFlipBit;BigInteger.prototype.add=bnAdd;BigInteger.prototype.subtract=bnSubtract;BigInteger.prototype.multiply=bnMultiply;BigInteger.prototype.divide=bnDivide;BigInteger.prototype.remainder=bnRemainder;BigInteger.prototype.divideAndRemainder=bnDivideAndRemainder;BigInteger.prototype.modPow=bnModPow;BigInteger.prototype.modInverse=bnModInverse;BigInteger.prototype.pow=bnPow;BigInteger.prototype.gcd=bnGCD;BigInteger.prototype.isProbablePrime=bnIsProbablePrime;BigInteger.prototype.square=bnSquare;function Arcfour(){this.i=0;this.j=0;this.S=new Array()}function ARC4init(d){var c,a,b;for(c=0;c<256;++c){this.S[c]=c}a=0;for(c=0;c<256;++c){a=(a+this.S[c]+d[c%d.length])&255;b=this.S[c];this.S[c]=this.S[a];this.S[a]=b}this.i=0;this.j=0}function ARC4next(){var a;this.i=(this.i+1)&255;this.j=(this.j+this.S[this.i])&255;a=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=a;return this.S[(a+this.S[this.i])&255]}Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;function prng_newstate(){return new Arcfour()}var rng_psize=256;var rng_state;var rng_pool;var rng_pptr;function rng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=(a>>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=new Array();rng_pptr=0;var t;if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&_window.crypto){var z=_window.crypto.random(32);for(t=0;t<z.length;++t){rng_pool[rng_pptr++]=z.charCodeAt(t)&255}}while(rng_pptr<rng_psize){t=Math.floor(65536*Math.random());rng_pool[rng_pptr++]=t>>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr){rng_pool[rng_pptr]=0}rng_pptr=0}return rng_state.next()}function rng_get_bytes(b){var a;for(a=0;a<b.length;++a){b[a]=rng_get_byte()}}function SecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;function X9ECParameters(c,b,d,a){this.curve=c;this.g=b;this.n=d;this.h=a}function x9getCurve(){return this.curve}function x9getG(){return this.g}function x9getN(){return this.n}function x9getH(){return this.h}X9ECParameters.prototype.getCurve=x9getCurve;X9ECParameters.prototype.getG=x9getG;X9ECParameters.prototype.getN=x9getN;X9ECParameters.prototype.getH=x9getH;function fromHex(a){return new BigInteger(a,16)}function secp128r1(){var g=fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");var d=fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC");var c=fromHex("E87579C11079F43DD824993C2CEE5ED3");var k=fromHex("FFFFFFFE0000000075A30D1B9038A115");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("04161FF7528B899B2D0C28607CA52C5B86CF5AC8395BAFEB13C02DA292DDED7A83");return new X9ECParameters(j,e,k,f)}function secp160k1(){var g=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");var d=BigInteger.ZERO;var c=fromHex("7");var k=fromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("043B4C382CE37AA192A4019E763036F4F5DD4D7EBB938CF935318FDCED6BC28286531733C3F03C4FEE");return new X9ECParameters(j,e,k,f)}function secp160r1(){var g=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF");var d=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC");var c=fromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45");var k=fromHex("0100000000000000000001F4C8F927AED3CA752257");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("044A96B5688EF573284664698968C38BB913CBFC8223A628553168947D59DCC912042351377AC5FB32");return new X9ECParameters(j,e,k,f)}function secp192k1(){var g=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37");var d=BigInteger.ZERO;var c=fromHex("3");var k=fromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("04DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D");return new X9ECParameters(j,e,k,f)}function secp192r1(){var g=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF");var d=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC");var c=fromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1");var k=fromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("04188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF101207192B95FFC8DA78631011ED6B24CDD573F977A11E794811");return new X9ECParameters(j,e,k,f)}function secp224r1(){var g=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");var d=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");var c=fromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");var k=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("04B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34");return new X9ECParameters(j,e,k,f)}function secp256k1(){var g=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");var d=BigInteger.ZERO;var c=fromHex("7");var k=fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new X9ECParameters(j,e,k,f)}function secp256r1(){var g=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");var d=fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");var c=fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");var k=fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");var f=BigInteger.ONE;var j=new ECCurveFp(g,d,c);var e=j.decodePointHex("046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");return new X9ECParameters(j,e,k,f)}function getSECCurveByName(a){if(a=="secp128r1"){return secp128r1()}if(a=="secp160k1"){return secp160k1()}if(a=="secp160r1"){return secp160r1()}if(a=="secp192k1"){return secp192k1()}if(a=="secp192r1"){return secp192r1()}if(a=="secp224r1"){return secp224r1()}if(a=="secp256k1"){return secp256k1()}if(a=="secp256r1"){return secp256r1()}return null}var Bitcoin={};BigInteger.valueOf=nbv;BigInteger.prototype.toByteArrayUnsigned=function(){var a=this.toByteArray();if(a.length){if(a[0]==0){a=a.slice(1)}return a.map(function(b){return(b<0)?b+256:b})}else{return a}};BigInteger.fromByteArrayUnsigned=function(a){if(!a.length){return a.valueOf(0)}else{if(a[0]&128){return new BigInteger([0].concat(a))}else{return new BigInteger(a)}}};var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];if("undefined"==typeof _window.console){_window.console={}}for(var i=0;i<names.length;++i){if("undefined"==typeof _window.console[names[i]]){_window.console[names[i]]=function(){}}}Bitcoin.Util={isArray:Array.isArray||function(a){return Object.prototype.toString.call(a)==="[object Array]"},makeFilledArray:function(a,c){var d=[];var b=0;while(b<a){d[b++]=c}return d},numToVarInt:function(a){if(a<253){return[a]}else{if(a<=1<<16){return[253,a>>>8,a&255]}else{if(a<=1<<32){return[254].concat(Crypto.util.wordsToBytes([a]))}else{return[255].concat(Crypto.util.wordsToBytes([a>>>32,a]))}}}},valueToBigInt:function(a){if(a instanceof BigInteger){return a}return BigInteger.fromByteArrayUnsigned(a)},formatValue:function(a){var c=this.valueToBigInt(a).toString();var d=c.length>8?c.substr(0,c.length-8):"0";var b=c.length>8?c.substr(c.length-8):c;while(b.length<8){b="0"+b}b=b.replace(/0*$/,"");while(b.length<2){b+="0"}return d+"."+b},parseValue:function(a){var d=a.split(".");var e=d[0];var b=d[1]||"0";while(b.length<8){b+="0"}b=b.replace(/^0+/g,"");var c=BigInteger.valueOf(parseInt(e));c=c.multiply(BigInteger.valueOf(100000000));c=c.add(BigInteger.valueOf(parseInt(b)));return c},sha256ripe160:function(a){return Crypto.RIPEMD160(Crypto.SHA256(a,{asBytes:true}),{asBytes:true})}};for(var i in Crypto.util){if(Crypto.util.hasOwnProperty(i)){Bitcoin.Util[i]=Crypto.util[i]}}var B58={alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",base:BigInteger.valueOf(58),encode:function(b){var a=BigInteger.fromByteArrayUnsigned(b);var e=[];while(a.compareTo(B58.base)>=0){var d=a.mod(B58.base);e.unshift(B58.alphabet[d.intValue()]);a=a.subtract(d).divide(B58.base)}e.unshift(B58.alphabet[a.intValue()]);for(var c=0;c<b.length;c++){if(b[c]==0){e.unshift(B58.alphabet[0])}else{break}}return e.join("")},decode:function(c){var b=BigInteger.valueOf(0);var e=0;for(var d=c.length-1;d>=0;d--){var f=B58.alphabet.indexOf(c[d]);b=b.add(BigInteger.valueOf(f).multiply(B58.base.pow(c.length-1-d)));if(c[d]=="1"){e++}else{e=0}}var a=b.toByteArrayUnsigned();while(e-->0){a.unshift(0)}return a}};Bitcoin.Base58=B58;Bitcoin.Address=function(a){if("string"==typeof a){a=Bitcoin.Address.decodeString(a)}this.hash=a;this.version=0};Bitcoin.Address.prototype.toString=function(){var c=this.hash.slice(0);c.unshift(this.version);var b=Crypto.SHA256(Crypto.SHA256(c,{asBytes:true}),{asBytes:true});var a=c.concat(b.slice(0,4));return Bitcoin.Base58.encode(a)};Bitcoin.Address.prototype.getHashBase64=function(){return Crypto.util.bytesToBase64(this.hash)};Bitcoin.Address.decodeString=function(c){var b=Bitcoin.Base58.decode(c);var e=b.slice(0,21);var d=Crypto.SHA256(Crypto.SHA256(e,{asBytes:true}),{asBytes:true});if(d[0]!=b[21]||d[1]!=b[22]||d[2]!=b[23]||d[3]!=b[24]){throw"Checksum validation failed!"}var a=e.shift();if(a!=0){throw"Version "+a+" not supported!"}return e};function integerToBytes(c,a){var b=c.toByteArrayUnsigned();if(a<b.length){b=b.slice(b.length-a)}else{while(a>b.length){b.unshift(0)}}return b}ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)};ECPointFp.prototype.getEncoded=function(c){var a=this.getX().toBigInteger();var d=this.getY().toBigInteger();var b=integerToBytes(a,32);if(c){if(d.isEven()){b.unshift(2)}else{b.unshift(3)}}else{b.unshift(4);b=b.concat(integerToBytes(d,32))}return b};ECPointFp.decodeFrom=function(g,c){var f=c[0];var e=c.length-1;var d=c.slice(1,1+e/2);var b=c.slice(1+e/2,1+e);d.unshift(0);b.unshift(0);var a=new BigInteger(d);var h=new BigInteger(b);return new ECPointFp(g,g.fromBigInteger(a),g.fromBigInteger(h))};ECPointFp.prototype.add2D=function(c){if(this.isInfinity()){return c}if(c.isInfinity()){return this}if(this.x.equals(c.x)){if(this.y.equals(c.y)){return this.twice()}return this.curve.getInfinity()}var g=c.x.subtract(this.x);var e=c.y.subtract(this.y);var a=e.divide(g);var d=a.square().subtract(this.x).subtract(c.x);var f=a.multiply(this.x.subtract(d)).subtract(this.y);return new ECPointFp(this.curve,d,f)};ECPointFp.prototype.twice2D=function(){if(this.isInfinity()){return this}if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var b=this.curve.fromBigInteger(BigInteger.valueOf(2));var e=this.curve.fromBigInteger(BigInteger.valueOf(3));var a=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(b));var c=a.square().subtract(this.x.multiply(b));var d=a.multiply(this.x.subtract(c)).subtract(this.y);return new ECPointFp(this.curve,c,d)};ECPointFp.prototype.multiply2D=function(b){if(this.isInfinity()){return this}if(b.signum()==0){return this.curve.getInfinity()}var g=b;var f=g.multiply(new BigInteger("3"));var l=this.negate();var d=this;var c;for(c=f.bitLength()-2;c>0;--c){d=d.twice();var a=f.testBit(c);var j=g.testBit(c);if(a!=j){d=d.add2D(a?this:l)}}return d};ECPointFp.prototype.isOnCurve=function(){var d=this.getX().toBigInteger();var j=this.getY().toBigInteger();var f=this.curve.getA().toBigInteger();var c=this.curve.getB().toBigInteger();var h=this.curve.getQ();var e=j.multiply(j).mod(h);var g=d.multiply(d).multiply(d).add(f.multiply(d)).add(c).mod(h);return e.equals(g)};ECPointFp.prototype.validate=function(){var c=this.curve.getQ();if(this.isInfinity()){throw new Error("Point is at infinity.")}var a=this.getX().toBigInteger();var b=this.getY().toBigInteger();if(a.compareTo(BigInteger.ONE)<0||a.compareTo(c.subtract(BigInteger.ONE))>0){throw new Error("x coordinate out of bounds")}if(b.compareTo(BigInteger.ONE)<0||b.compareTo(c.subtract(BigInteger.ONE))>0){throw new Error("y coordinate out of bounds")}if(!this.isOnCurve()){throw new Error("Point is not on the curve.")}if(this.multiply(c).isInfinity()){throw new Error("Point is not a scalar multiple of G.")}return true};function dmp(a){if(!(a instanceof BigInteger)){a=a.toBigInteger()}return Crypto.util.bytesToHex(a.toByteArrayUnsigned())}Bitcoin.ECDSA=(function(){var d=getSECCurveByName("secp256k1");var a=new SecureRandom();function b(o,g,n,f){var e=Math.max(g.bitLength(),f.bitLength());var p=o.add2D(n);var j=o.curve.getInfinity();for(var h=e-1;h>=0;--h){j=j.twice2D();j.z=BigInteger.ONE;if(g.testBit(h)){if(f.testBit(h)){j=j.add2D(p)}else{j=j.add2D(o)}}else{if(f.testBit(h)){j=j.add2D(n)}}}return j}var c={getBigRandom:function(e){return new BigInteger(e.bitLength(),a).mod(e.subtract(BigInteger.ONE)).add(BigInteger.ONE)},sign:function(j,q){var o=q;var g=d.getN();var m=BigInteger.fromByteArrayUnsigned(j);do{var h=c.getBigRandom(g);var p=d.getG();var l=p.multiply(h);var f=l.getX().toBigInteger().mod(g)}while(f.compareTo(BigInteger.ZERO)<=0);var u=h.modInverse(g).multiply(m.add(o.multiply(f))).mod(g);return{r:f,s:u}},verify:function(k,y,o){var l=c.parseSig(y);var f=l.r;var A=l.s;var j=d.getN();var p=BigInteger.fromByteArrayUnsigned(k);if(f.compareTo(BigInteger.ONE)<0||f.compareTo(j)>=0){return false}if(A.compareTo(BigInteger.ONE)<0||A.compareTo(j)>=0){return false}var q=A.modInverse(j);var h=p.multiply(q).mod(j);var g=f.multiply(q).mod(j);var x=d.getG();var m=ECPointFp.decodeFrom(d.getCurve(),o);var u=b(x,h,m,g);var w=u.x.toBigInteger().mod(j);return w.equals(f)},serializeSig:function(g,f){var h=g.toByteArrayUnsigned();var e=f.toByteArrayUnsigned();var j=[];j.push(2);j.push(h.length);j=j.concat(h);j.push(2);j.push(e.length);j=j.concat(e);j.unshift(j.length);j.unshift(48);return j},parseSig:function(k){var j;if(k[0]!=48){throw new Error("Signature not a valid DERSequence")}j=2;if(k[j]!=2){throw new Error("First element in signature must be a DERInteger")}var h=k.slice(j+2,j+2+k[j+1]);j+=2+k[j+1];if(k[j]!=2){throw new Error("Second element in signature must be a DERInteger")}var e=k.slice(j+2,j+2+k[j+1]);j+=2+k[j+1];var g=BigInteger.fromByteArrayUnsigned(h);var f=BigInteger.fromByteArrayUnsigned(e);return{r:g,s:f}}};return c})();var ECDSA=Bitcoin.ECDSA;var ecparams=getSECCurveByName("secp256k1");var rng=new SecureRandom();var ECKey=function(a){if(!a){var b=ecparams.getN();this.priv=ECDSA.getBigRandom(b)}else{if(a instanceof BigInteger){this.priv=a}else{if(Bitcoin.Util.isArray(a)){this.priv=BigInteger.fromByteArrayUnsigned(a)}else{if("string"==typeof a){this.priv=BigInteger.fromByteArrayUnsigned(Crypto.util.base64ToBytes(a))}}}}};ECKey.prototype.getPubCompressed=function(){if(this.pubCompressed){return this.pubCompressed}return this.pubCompressed=ecparams.getG().multiply(this.priv).getEncoded(1)};ECKey.prototype.getPubKeyHashCompressed=function(){if(this.pubKeyHashCompressed){return this.pubKeyHashCompressed}return this.pubKeyHashCompressed=Bitcoin.Util.sha256ripe160(this.getPubCompressed())};ECKey.prototype.getBitcoinAddressCompressed=function(){var a=this.getPubKeyHashCompressed();var b=new Bitcoin.Address(a);return b.toString()};ECKey.prototype.getPub=function(){if(this.pub){return this.pub}return this.pub=ecparams.getG().multiply(this.priv).getEncoded()};ECKey.prototype.getPubKeyHash=function(){if(this.pubKeyHash){return this.pubKeyHash}return this.pubKeyHash=Bitcoin.Util.sha256ripe160(this.getPub())};ECKey.prototype.getBitcoinAddress=function(){var a=this.getPubKeyHash();var b=new Bitcoin.Address(a);return b};ECKey.prototype.setPub=function(a){this.pub=a};ECKey.prototype.toString=function(a){if(a==="base64"){return Crypto.util.bytesToBase64(this.priv.toByteArrayUnsigned())}else{return Crypto.util.bytesToHex(this.priv.toByteArrayUnsigned())}};ECKey.prototype.sign=function(a){return ECDSA.sign(a,this.priv)};ECKey.prototype.verify=function(a,b){return ECDSA.verify(a,b,this.getPub())};Bitcoin.ECKey=ECKey;var Opcode=Bitcoin.Opcode=function(a){this.code=a};Opcode.prototype.toString=function(){return Opcode.reverseMap[this.code]};Opcode.map={OP_0:0,OP_FALSE:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_1:81,OP_TRUE:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Opcode.reverseMap=[];for(var i in Opcode.map){Opcode.reverseMap[Opcode.map[i]]=i}var ECDSA=Bitcoin.ECDSA;var ecparams=getSECCurveByName("secp256k1");var rng=new SecureRandom();var ECKey=function(a){if(!a){var b=ecparams.getN();this.priv=ECDSA.getBigRandom(b)}else{if(a instanceof BigInteger){this.priv=a}else{if(Bitcoin.Util.isArray(a)){this.priv=BigInteger.fromByteArrayUnsigned(a)}else{if("string"==typeof a){this.priv=BigInteger.fromByteArrayUnsigned(Crypto.util.base64ToBytes(a))}}}}};ECKey.prototype.getPubCompressed=function(){if(this.pubCompressed){return this.pubCompressed}return this.pubCompressed=ecparams.getG().multiply(this.priv).getEncoded(1)};ECKey.prototype.getPubKeyHashCompressed=function(){if(this.pubKeyHashCompressed){return this.pubKeyHashCompressed}return this.pubKeyHashCompressed=Bitcoin.Util.sha256ripe160(this.getPubCompressed())};ECKey.prototype.getBitcoinAddressCompressed=function(){var a=this.getPubKeyHashCompressed();var b=new Bitcoin.Address(a);return b.toString()};ECKey.prototype.getPub=function(){if(this.pub){return this.pub}return this.pub=ecparams.getG().multiply(this.priv).getEncoded()};ECKey.prototype.getPubKeyHash=function(){if(this.pubKeyHash){return this.pubKeyHash}return this.pubKeyHash=Bitcoin.Util.sha256ripe160(this.getPub())};ECKey.prototype.getBitcoinAddress=function(){var a=this.getPubKeyHash();var b=new Bitcoin.Address(a);return b};ECKey.prototype.setPub=function(a){this.pub=a};ECKey.prototype.toString=function(a){if(a==="base64"){return Crypto.util.bytesToBase64(this.priv.toByteArrayUnsigned())}else{return Crypto.util.bytesToHex(this.priv.toByteArrayUnsigned())}};ECKey.prototype.sign=function(a){return ECDSA.sign(a,this.priv)};ECKey.prototype.verify=function(a,b){return ECDSA.verify(a,b,this.getPub())};Bitcoin.ECKey=ECKey;var Opcode=Bitcoin.Opcode;for(var i in Opcode.map){eval("var "+i+" = "+Opcode.map[i]+";")}var Script=Bitcoin.Script=function(a){if(!a){this.buffer=[]}else{if("string"==typeof a){this.buffer=Crypto.util.base64ToBytes(a)}else{if(Bitcoin.Util.isArray(a)){this.buffer=a}else{if(a.buffer){this.buffer=a.buffer}else{throw new Error("Invalid script")}}}}this.parse()};Script.prototype.parse=function(){var b=this;this.chunks=[];var d=0;function c(f){b.chunks.push(b.buffer.slice(d,d+f));d+=f}while(d<this.buffer.length){var e=this.buffer[d++];if(e>=240){e=(e<<8)|this.buffer[d++]}var a;if(e>0&&e<OP_PUSHDATA1){c(e)}else{if(e==OP_PUSHDATA1){a=this.buffer[d++];c(a)}else{if(e==OP_PUSHDATA2){a=(this.buffer[d++]<<8)|this.buffer[d++];c(a)}else{if(e==OP_PUSHDATA4){a=(this.buffer[d++]<<24)|(this.buffer[d++]<<16)|(this.buffer[d++]<<8)|this.buffer[d++];c(a)}else{this.chunks.push(e)}}}}}};Script.prototype.getOutType=function(){if(this.chunks[this.chunks.length-1]==OP_CHECKMULTISIG&&this.chunks[this.chunks.length-2]<=3){return"Multisig"}else{if(this.chunks.length==5&&this.chunks[0]==OP_DUP&&this.chunks[1]==OP_HASH160&&this.chunks[3]==OP_EQUALVERIFY&&this.chunks[4]==OP_CHECKSIG){return"Address"}else{if(this.chunks.length==2&&this.chunks[1]==OP_CHECKSIG){return"Pubkey"}else{return"Strange"}}}};Script.prototype.simpleOutHash=function(){switch(this.getOutType()){case"Address":return this.chunks[2];case"Pubkey":return Bitcoin.Util.sha256ripe160(this.chunks[0]);default:throw new Error("Encountered non-standard scriptPubKey")}};Script.prototype.simpleOutPubKeyHash=Script.prototype.simpleOutHash;Script.prototype.getInType=function(){if(this.chunks.length==1&&Bitcoin.Util.isArray(this.chunks[0])){return"Pubkey"}else{if(this.chunks.length==2&&Bitcoin.Util.isArray(this.chunks[0])&&Bitcoin.Util.isArray(this.chunks[1])){return"Address"}else{return"Strange"}}};Script.prototype.simpleInPubKey=function(){switch(this.getInType()){case"Address":return this.chunks[1];case"Pubkey":throw new Error("Script does not contain pubkey.");default:throw new Error("Encountered non-standard scriptSig")}};Script.prototype.simpleInHash=function(){return Bitcoin.Util.sha256ripe160(this.simpleInPubKey())};Script.prototype.simpleInPubKeyHash=Script.prototype.simpleInHash;Script.prototype.writeOp=function(a){this.buffer.push(a);this.chunks.push(a)};Script.prototype.writeBytes=function(a){if(a.length<OP_PUSHDATA1){this.buffer.push(a.length)}else{if(a.length<=255){this.buffer.push(OP_PUSHDATA1);this.buffer.push(a.length)}else{if(a.length<=65535){this.buffer.push(OP_PUSHDATA2);this.buffer.push(a.length&255);this.buffer.push((a.length>>>8)&255)}else{this.buffer.push(OP_PUSHDATA4);this.buffer.push(a.length&255);this.buffer.push((a.length>>>8)&255);this.buffer.push((a.length>>>16)&255);this.buffer.push((a.length>>>24)&255)}}}this.buffer=this.buffer.concat(a);this.chunks.push(a)};Script.createOutputScript=function(a){var b=new Script();b.writeOp(OP_DUP);b.writeOp(OP_HASH160);b.writeBytes(a.hash);b.writeOp(OP_EQUALVERIFY);b.writeOp(OP_CHECKSIG);return b};Script.prototype.extractAddresses=function(b){switch(this.getOutType()){case"Address":b.push(new Bitcoin.Address(this.chunks[2]));return 1;case"Pubkey":b.push(new Bitcoin.Address(Util.sha256ripe160(this.chunks[0])));return 1;case"Multisig":for(var a=1;a<this.chunks.length-2;++a){b.push(new Bitcoin.Address(Util.sha256ripe160(this.chunks[a])))}return this.chunks[0]-OP_1+1;default:throw new Error("Encountered non-standard scriptPubKey")}};Script.createMultiSigOutputScript=function(a,c){var b=new Bitcoin.Script();b.writeOp(OP_1+a-1);for(var d=0;d<c.length;++d){b.writeBytes(c[d])}b.writeOp(OP_1+c.length-1);b.writeOp(OP_CHECKMULTISIG);return b};Script.createInputScript=function(b,a){var c=new Script();c.writeBytes(b);c.writeBytes(a);return c};Script.prototype.clone=function(){return new Script(this.buffer)};(function(){var j=Bitcoin.Script;var g=Bitcoin.Transaction=function(l){this.version=1;this.lock_time=0;this.ins=[];this.outs=[];this.timestamp=null;this.block=null;if(l){if(l.hash){this.hash=l.hash}if(l.version){this.version=l.version}if(l.lock_time){this.lock_time=l.lock_time}if(l.ins&&l.ins.length){for(var k=0;k<l.ins.length;k++){this.addInput(new c(l.ins[k]))}}if(l.outs&&l.outs.length){for(var k=0;k<l.outs.length;k++){this.addOutput(new h(l.outs[k]))}}if(l.timestamp){this.timestamp=l.timestamp}if(l.block){this.block=l.block}}};g.objectify=function(k){var m=[];for(var l=0;l<k.length;l++){m.push(new g(k[l]))}return m};g.prototype.addInput=function(k,l){if(arguments[0] instanceof c){this.ins.push(arguments[0])}else{this.ins.push(new c({outpoint:{hash:k.hash,index:l},script:new Bitcoin.Script(),sequence:4294967295}))}};g.prototype.addOutput=function(k,l){if(arguments[0] instanceof h){this.outs.push(arguments[0])}else{if(l instanceof BigInteger){l=l.toByteArrayUnsigned().reverse();while(l.length<8){l.push(0)}}else{if(Bitcoin.Util.isArray(l)){}}this.outs.push(new h({value:l,script:j.createOutputScript(k)}))}};g.prototype.serialize=function(){var k=[];k=k.concat(Crypto.util.wordsToBytes([parseInt(this.version)]).reverse());k=k.concat(Bitcoin.Util.numToVarInt(this.ins.length));for(var l=0;l<this.ins.length;l++){var n=this.ins[l];k=k.concat(Crypto.util.base64ToBytes(n.outpoint.hash));k=k.concat(Crypto.util.wordsToBytes([parseInt(n.outpoint.index)]).reverse());var m=n.script.buffer;k=k.concat(Bitcoin.Util.numToVarInt(m.length));k=k.concat(m);k=k.concat(Crypto.util.wordsToBytes([parseInt(n.sequence)]).reverse())}k=k.concat(Bitcoin.Util.numToVarInt(this.outs.length));for(var l=0;l<this.outs.length;l++){var o=this.outs[l];k=k.concat(o.value);var m=o.script.buffer;k=k.concat(Bitcoin.Util.numToVarInt(m.length));k=k.concat(m)}k=k.concat(Crypto.util.wordsToBytes([parseInt(this.lock_time)]).reverse());return k};var f=171;var a=1;var d=2;var b=3;var e=80;g.prototype.hashTransactionForSignature=function(n,q,l){var o=this.clone();for(var m=0;m<o.ins.length;m++){o.ins[m].script=new j()}o.ins[q].script=n;if((l&31)==d){o.outs=[];for(var m=0;m<o.ins.length;m++){if(m!=q){o.ins[m].sequence=0}}}else{if((l&31)==b){}}if(l&e){o.ins=[o.ins[q]]}var k=o.serialize();k=k.concat(Crypto.util.wordsToBytes([parseInt(l)]).reverse());var p=Crypto.SHA256(k,{asBytes:true});return Crypto.SHA256(p,{asBytes:true})};g.prototype.getHash=function(){var k=this.serialize();return Crypto.SHA256(Crypto.SHA256(k,{asBytes:true}),{asBytes:true})};g.prototype.clone=function(){var l=new g();l.version=this.version;l.lock_time=this.lock_time;for(var k=0;k<this.ins.length;k++){var m=this.ins[k].clone();l.addInput(m)}for(var k=0;k<this.outs.length;k++){var n=this.outs[k].clone();l.addOutput(n)}return l};g.prototype.analyze=function(l){if(!(l instanceof Bitcoin.Wallet)){return null}var m=true,o=true,v=null,n=null,q=null;for(var r=this.outs.length-1;r>=0;r--){var w=this.outs[r];var p=w.script.simpleOutPubKeyHash();if(!l.hasHash(p)){o=false}else{n=p}v=p}for(var r=this.ins.length-1;r>=0;r--){var u=this.ins[r];q=u.script.simpleInPubKeyHash();if(!l.hasHash(q)){m=false;break}}var k=this.calcImpact(l);var s={};s.impact=k;if(k.sign>0&&k.value.compareTo(BigInteger.ZERO)>0){s.type="recv";s.addr=new Bitcoin.Address(n)}else{if(m&&o){s.type="self"}else{if(m){s.type="sent";s.addr=new Bitcoin.Address(v)}else{s.type="other"}}}return s};g.prototype.getDescription=function(k){var l=this.analyze(k);if(!l){return""}switch(l.type){case"recv":return"Received with "+l.addr;break;case"sent":return"Payment to "+l.addr;break;case"self":return"Payment to yourself";break;case"other":default:return""}};g.prototype.getTotalOutValue=function(){var k=BigInteger.ZERO;for(var l=0;l<this.outs.length;l++){var m=this.outs[l];k=k.add(Bitcoin.Util.valueToBigInt(m.value))}return k};g.prototype.getTotalValue=g.prototype.getTotalOutValue;g.prototype.calcImpact=function(m){if(!(m instanceof Bitcoin.Wallet)){return BigInteger.ZERO}var o=BigInteger.ZERO;for(var l=0;l<this.outs.length;l++){var r=this.outs[l];var q=Crypto.util.bytesToBase64(r.script.simpleOutPubKeyHash());if(m.hasHash(q)){o=o.add(Bitcoin.Util.valueToBigInt(r.value))}}var k=BigInteger.ZERO;for(var l=0;l<this.ins.length;l++){var p=this.ins[l];var q=Crypto.util.bytesToBase64(p.script.simpleInPubKeyHash());if(m.hasHash(q)){var n=m.txIndex[p.outpoint.hash];if(n){k=k.add(Bitcoin.Util.valueToBigInt(n.outs[p.outpoint.index].value))}}}if(o.compareTo(k)>=0){return{sign:1,value:o.subtract(k)}}else{return{sign:-1,value:k.subtract(o)}}};var c=Bitcoin.TransactionIn=function(k){this.outpoint=k.outpoint;if(k.script instanceof j){this.script=k.script}else{this.script=new j(k.script)}this.sequence=k.sequence};c.prototype.clone=function(){var k=new c({outpoint:{hash:this.outpoint.hash,index:this.outpoint.index},script:this.script.clone(),sequence:this.sequence});return k};var h=Bitcoin.TransactionOut=function(k){if(k.script instanceof j){this.script=k.script}else{this.script=new j(k.script)}if(Bitcoin.Util.isArray(k.value)){this.value=k.value}else{if("string"==typeof k.value){var l=(new BigInteger(k.value,10)).toString(16);while(l.length<16){l="0"+l}this.value=Crypto.util.hexToBytes(l)}}};h.prototype.clone=function(){var k=new h({script:this.script.clone(),value:this.value.slice(0)});return k}})();