forked from jswallet/jswallet.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcoinjs.min.js
1 lines (1 loc) · 71.5 KB
/
bitcoinjs.min.js
1
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Bitcoin=e():"undefined"!=typeof global?global.Bitcoin=e():"undefined"!=typeof self&&(self.Bitcoin=e())}(function(){var e,t,n;return function r(e,t,n){function i(o,u){if(!t[o]){if(!e[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(s)return s(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=t[o]={exports:{}};e[o][0].call(f.exports,function(t){var n=e[o][1][t];return i(n?n:t)},f,f.exports,r,e,t,n)}return t[o].exports}var s=typeof require=="function"&&require;for(var o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,n){var r=e("./base58");var i=e("./crypto-js/crypto");var s=e("./convert");var o=e("./util");var u={prod:50,testnet:111};var a={prod:5,testnet:196};var f=function(e,t){t=50;if(arguments[0]instanceof f){this.hash=arguments[0].hash;this.version=arguments[0].version}else if(typeof e==="string"){this.hash=e.length<=34?r.checkDecode(e):e.length<=40?s.hexToBytes(e):o.error("Bad input");this.version=t||this.hash.version||0}else{this.hash=e;this.version=t||0}};f.prototype.toString=function(){return r.checkEncode(this.hash.slice(0),this.version)};f.prototype.getHash=function(){return s.bytesToHex(this.hash)};f.getVersion=function(e){return r.decode(e)[0]};f.validate=function(e){try{r.checkDecode(e);return true}catch(t){return false}};f.decodeString=function(e){return r.checkDecode(e)};t.exports=f},{"./base58":2,"./convert":4,"./crypto-js/crypto":5,"./util":22}],2:[function(e,t,n){var r=e("./jsbn/jsbn");var i=e("./crypto-js/crypto");var s=e("./convert");var o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var u=r.valueOf(58);var a={};for(var f=0;f<o.length;++f){a[o[f]]=f}t.exports.encode=function(e){var t=r.fromByteArrayUnsigned(e);var n=[];while(t.compareTo(u)>=0){var i=t.mod(u);n.push(o[i.intValue()]);t=t.subtract(i).divide(u)}n.push(o[t.intValue()]);for(var s=0;s<e.length;s++){if(e[s]==0){n.push(o[0])}else break}return n.reverse().join("")},t.exports.encodeHex=function(e){return s.bytesToHex(t.exports.encode(e))};t.exports.decode=function(e){var t=r.valueOf(58);var n=e.length;var i=r.valueOf(0);var s=0;var o=false;for(var u=0;u<n;++u){var f=e[u];var l=a[f];if(l===undefined){throw new Error("invalid base58 string: "+e)}i=i.multiply(t).add(r.valueOf(l));if(f=="1"&&!o){++s}else{o=true}}var c=i.toByteArrayUnsigned();while(s-->0){c.unshift(0)}return c};t.exports.decodeHex=function(e){return t.exports.decode(s.hexToBytes(e))};t.exports.checkEncode=function(e,n){n=n||0;var r=[n].concat(e);var s=i.SHA256(i.SHA256(r,{asBytes:true}),{asBytes:true}).slice(0,4);return t.exports.encode(r.concat(s))};t.exports.checkEncodeHex=function(e,n){return s.bytesToHex(t.exports.encode(e))};t.exports.checkDecode=function(e){var n=t.exports.decode(e),r=n.slice(0,n.length-4),s=n.slice(n.length-4);var o=i.SHA256(i.SHA256(r,{asBytes:true}),{asBytes:true}).slice(0,4);if(""+o!=""+s){throw new Error("Checksum failed")}var u=r.slice(1);u.version=r[0];return u};t.exports.checkDecodeHex=function(e){return t.exports.checkDecode(s.hexToBytes(e))}},{"./convert":4,"./crypto-js/crypto":5,"./jsbn/jsbn":14}],3:[function(e,t,n){var r=e("./script"),i=e("./util"),s=e("./convert"),o=e("./eckey"),u=e("./base58"),a=e("./crypto-js/crypto"),f=e("./jsbn/ec").ECPointFp,l=e("./jsbn/sec"),c=l("secp256k1");var h=function(e){if(!e)e={};if(typeof e=="string"){try{e=h.prototype.deserialize(e)}catch(t){e=h.prototype.fromMasterKey(e)}}this.vbytes=e.vbytes;this.depth=e.depth;this.fingerprint=e.fingerprint;this.i=e.i;this.chaincode=e.chaincode;this.key=e.key;this.type=s.bytesToString(this.vbytes)==p?"priv":"pub";return this};var p=h.PRIVDERIV="ä";var d=h.PUBDERIV="²";h.prototype.deserialize=function(e){var t=u.decode(e);var n=t.slice(0,t.length-4),r=t.slice(t.length-4);var f=a.SHA256(a.SHA256(n,{asBytes:true}),{asBytes:true}).slice(0,4);if(""+f!=""+r){throw new Error("Checksum failed")}var l=s.bytesToString(t.slice(0,4))==p?"priv":"pub";return new h({type:l,vbytes:t.slice(0,4),depth:t[4],fingerprint:t.slice(5,9),i:i.bytesToNum(t.slice(9,13).reverse()),chaincode:t.slice(13,45),key:new o(l=="priv"?t.slice(46,78).concat([1]):t.slice(45,78))})};h.prototype.serialize=function(){var e=this.vbytes.concat([this.depth],this.fingerprint,i.numToBytes(this.i,4).reverse(),this.chaincode,this.type=="priv"?[0].concat(this.key.export("bytes").slice(0,32)):this.key);var t=a.SHA256(a.SHA256(e,{asBytes:true}),{asBytes:true}).slice(0,4);return u.encode(e.concat(t))};h.prototype.ckd=function(e){var t,n,r,s,u,l;if(this.type=="priv"){t=this.key.export("bytes");n=this.key.getPub()}else n=this.key;if(e>=2147483648){if(this.priv)throw new Error("Can't do private derivation on public key!");u=[0].concat(t.slice(0,32),i.numToBytes(e,4).reverse())}else u=n.concat(i.numToBytes(e,4).reverse());l=a.HMAC(a.SHA512,u,this.chaincode,{asBytes:true});if(this.type=="priv"){Ikey=Bitcoin.BigInteger.fromByteArrayUnsigned(l.slice(0,32));r=new o(this.key.priv.add(Ikey));r.compressed=true;s=i.sha256ripe160(this.key.getPub()).slice(0,4)}else{r=f.decodeFrom(c.getCurve(),this.key).add((new o(l.slice(0,32).concat([1]))).getPubPoint()).getEncoded(true);s=i.sha256ripe160(this.key).slice(0,4)}return new h({vbytes:this.vbytes,type:this.type,depth:this.depth+1,fingerprint:s,i:e,chaincode:l.slice(32),key:r})};h.prototype.clone=function(){return new h(this)};h.prototype.privtopub=h.prototype.getPub=function(){if(this.type=="pub")return this.clone();return new h({vbytes:s.stringToBytes(d),type:"pub",depth:this.depth,fingerprint:this.fingerprint,i:this.i,chaincode:this.chaincode,key:this.key.getPub()})};h.prototype.fromMasterKey=function(e){var t=Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA512,e,"Bitcoin seed",{asBytes:true});return new h({vbytes:s.stringToBytes(p),type:"priv",depth:0,fingerprint:[0,0,0,0],i:0,chaincode:t.slice(32),key:new o(t.slice(0,32).concat([1]))})};h.prototype.getKey=function(){return this.key};t.exports=h},{"./base58":2,"./convert":4,"./crypto-js/crypto":5,"./eckey":11,"./jsbn/ec":13,"./jsbn/sec":17,"./script":20,"./util":22}],4:[function(e,t,n){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";String.prototype.lpad=function(e,t){var n=this;while(n.length<t)n=e+n;return n};t.exports.bytesToHex=function(e){return e.map(function(e){return e.toString(16).lpad("0",2)}).join("")};t.exports.hexToBytes=function(e){return e.match(/../g).map(function(e){return parseInt(e,16)})};t.exports.bytesToBase64=function(e){for(var t=[],n=0;n<e.length;n+=3){var i=e[n]<<16|e[n+1]<<8|e[n+2];for(var s=0;s<4;s++){if(n*8+s*6<=e.length*8)t.push(r.charAt(i>>>6*(3-s)&63));else t.push("=")}}return t.join("")};t.exports.base64ToBytes=function(e){e=e.replace(/[^A-Z0-9+\/]/gi,"");for(var t=[],n=0,i=0;n<e.length;i=++n%4){if(i==0)continue;t.push((r.indexOf(e.charAt(n-1))&Math.pow(2,-2*i+8)-1)<<i*2|r.indexOf(e.charAt(n))>>>6-i*2)}return t};t.exports.coerceToBytes=function(e){if(typeof e=="string")return t.exports.hexToBytes(e);return e};t.exports.binToBytes=function(e){return e.match(/......../g).map(function(e){return parseInt(e,2)})};t.exports.bytesToBin=function(e){return e.map(function(e){return e.toString(2).lpad("0",8)}).join("")};t.exports.bytesToString=function(e){return e.map(function(e){return String.fromCharCode(e)}).join("")};t.exports.stringToBytes=function(e){return e.split("").map(function(e){return e.charCodeAt(0)})}},{}],5:[function(e,t,n){var r=t.exports={};var i=r.util={randomBytes:function(e){for(var t=[];e>0;e--)t.push(Math.floor(Math.random()*256));return t}};r.mode={};var s=r.charenc={};var o=s.UTF8={stringToBytes:function(e){return u.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(u.bytesToString(e)))}};var u=s.Binary={stringToBytes:function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t},bytesToString:function(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return t.join("")}};t.exports.SHA256=e("./sha256");t.exports.SHA512=e("./sha512");t.exports.RIPEMD160=e("./ripemd160");t.exports.HMAC=e("./hmac")},{"./hmac":6,"./ripemd160":7,"./sha256":8,"./sha512":9}],6:[function(e,t,n){var r=e("../convert"),i=e("../util");t.exports=function(e,t,n,i){if(t.constructor==String)t=r.stringToBytes(t);if(n.constructor==String)n=r.stringToBytes(n);if(n.length>e._blocksize)n=e(n,{asBytes:true});var s=n.slice(0),o=n.slice(0);for(var u=0;u<e._blocksize;u++){s[u]^=92;o[u]^=54}var a=e(s.concat(e(o.concat(t),{asBytes:true})),{asBytes:true});return i&&i.asBytes?a:i&&i.asString?r.bytesToString(a):r.bytesToHex(a)}},{"../convert":4,"../util":22}],7:[function(e,t,n){function d(e,t,n){return e^t^n}function v(e,t,n){return e&t|~e&n}function m(e,t,n){return(e|~t)^n}function g(e,t,n){return e&n|t&~n}function y(e,t,n){return e^(t|~n)}function b(e,t){return e<<t|e>>>32-t}var r=e("../convert");var i=e("./crypto").charenc.UTF8;var s=[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 o=[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 u=[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 a=[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];var f=[0,1518500249,1859775393,2400959708,2840853838];var l=[1352829926,1548603684,1836072691,2053994217,0];var c=function(e){var t=[];for(var n=0,r=0;n<e.length;n++,r+=8){t[r>>>5]|=e[n]<<24-r%32}return t};var h=function(e){var t=[];for(var n=0;n<e.length*32;n+=8){t.push(e[n>>>5]>>>24-n%32&255)}return t};var p=function(e,t,n){for(var r=0;r<16;r++){var i=n+r;var c=t[i];t[i]=(c<<8|c>>>24)&16711935|(c<<24|c>>>8)&4278255360}var h,p,w,E,S;var x,T,N,C,k;x=h=e[0];T=p=e[1];N=w=e[2];C=E=e[3];k=S=e[4];var L;for(var r=0;r<80;r+=1){L=h+t[n+s[r]]|0;if(r<16){L+=d(p,w,E)+f[0]}else if(r<32){L+=v(p,w,E)+f[1]}else if(r<48){L+=m(p,w,E)+f[2]}else if(r<64){L+=g(p,w,E)+f[3]}else{L+=y(p,w,E)+f[4]}L=L|0;L=b(L,u[r]);L=L+S|0;h=S;S=E;E=b(w,10);w=p;p=L;L=x+t[n+o[r]]|0;if(r<16){L+=y(T,N,C)+l[0]}else if(r<32){L+=g(T,N,C)+l[1]}else if(r<48){L+=m(T,N,C)+l[2]}else if(r<64){L+=v(T,N,C)+l[3]}else{L+=d(T,N,C)+l[4]}L=L|0;L=b(L,a[r]);L=L+k|0;x=k;k=C;C=b(N,10);N=T;T=L}L=e[1]+w+C|0;e[1]=e[2]+E+k|0;e[2]=e[3]+S+x|0;e[3]=e[4]+h+T|0;e[4]=e[0]+p+N|0;e[0]=L};t.exports=function(e,t){if(e.constructor===String){e=i.stringToBytes(e)}var n=[1732584193,4023233417,2562383102,271733878,3285377520];var s=c(e);var o=e.length*8;var u=e.length*8;s[o>>>5]|=128<<24-o%32;s[(o+64>>>9<<4)+14]=(u<<8|u>>>24)&16711935|(u<<24|u>>>8)&4278255360;for(var a=0;a<s.length;a+=16){p(n,s,a)}for(var a=0;a<5;a++){var f=n[a];n[a]=(f<<8|f>>>24)&16711935|(f<<24|f>>>8)&4278255360}var l=h(n);return t&&t.asBytes?l:t&&t.asString?Binary.bytesToString(l):r.bytesToHex(l)}},{"../convert":4,"./crypto":5}],8:[function(e,t,n){var r=e("../convert"),i=e("../util");var s=[];(function(){function e(e){var t=Math.sqrt(e);for(var n=2;n<=t;n++){if(!(e%n)){return false}}return true}function t(e){return(e-(e|0))*4294967296|0}var n=2;var r=0;while(r<64){if(e(n)){s[r]=t(Math.pow(n,1/3));r++}n++}})();var o=[];var u=function(e,t,n){var r=e[0];var i=e[1];var u=e[2];var a=e[3];var f=e[4];var l=e[5];var c=e[6];var h=e[7];for(var p=0;p<64;p++){if(p<16){o[p]=t[n+p]|0}else{var d=o[p-15];var v=(d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3;var m=o[p-2];var g=(m<<15|m>>>17)^(m<<13|m>>>19)^m>>>10;o[p]=v+o[p-7]+g+o[p-16]}var y=f&l^~f&c;var b=r&i^r&u^i&u;var w=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22);var E=(f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25);var S=h+E+y+s[p]+o[p];var x=w+b;h=c;c=l;l=f;f=a+S|0;a=u;u=i;i=r;r=S+x|0}e[0]=e[0]+r|0;e[1]=e[1]+i|0;e[2]=e[2]+u|0;e[3]=e[3]+a|0;e[4]=e[4]+f|0;e[5]=e[5]+l|0;e[6]=e[6]+c|0;e[7]=e[7]+h|0};t.exports=function(e,t){var n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];if(e.constructor===String){e=r.stringToBytes(e)}var s=i.bytesToWords(e);var o=e.length*8;s[o>>5]|=128<<24-o%32;s[(o+64>>9<<4)+15]=o;for(var a=0;a<s.length;a+=16){u(n,s,a)}var f=i.wordsToBytes(n);return t&&t.asBytes?f:t&&t.asString?Binary.bytesToString(f):r.bytesToHex(f)};t.exports._blocksize=64},{"../convert":4,"../util":22}],9:[function(e,t,n){var r=e("../convert");var i=e("../util");var s=[[1116352408,3609767458],[1899447441,602891725],[3049323471,3964484399],[3921009573,2173295548],[961987163,4081628472],[1508970993,3053834265],[2453635748,2937671579],[2870763221,3664609560],[3624381080,2734883394],[310598401,1164996542],[607225278,1323610764],[1426881987,3590304994],[1925078388,4068182383],[2162078206,991336113],[2614888103,633803317],[3248222580,3479774868],[3835390401,2666613458],[4022224774,944711139],[264347078,2341262773],[604807628,2007800933],[770255983,1495990901],[1249150122,1856431235],[1555081692,3175218132],[1996064986,2198950837],[2554220882,3999719339],[2821834349,766784016],[2952996808,2566594879],[3210313671,3203337956],[3336571891,1034457026],[3584528711,2466948901],[113926993,3758326383],[338241895,168717936],[666307205,1188179964],[773529912,1546045734],[1294757372,1522805485],[1396182291,2643833823],[1695183700,2343527390],[1986661051,1014477480],[2177026350,1206759142],[2456956037,344077627],[2730485921,1290863460],[2820302411,3158454273],[3259730800,3505952657],[3345764771,106217008],[3516065817,3606008344],[3600352804,1432725776],[4094571909,1467031594],[275423344,851169720],[430227734,3100823752],[506948616,1363258195],[659060556,3750685593],[883997877,3785050280],[958139571,3318307427],[1322822218,3812723403],[1537002063,2003034995],[1747873779,3602036899],[1955562222,1575990012],[2024104815,1125592928],[2227730452,2716904306],[2361852424,442776044],[2428436474,593698344],[2756734187,3733110249],[3204031479,2999351573],[3329325298,3815920427],[3391569614,3928383900],[3515267271,566280711],[3940187606,3454069534],[4118630271,4000239992],[116418474,1914138554],[174292421,2731055270],[289380356,3203993006],[460393269,320620315],[685471733,587496836],[852142971,1086792851],[1017036298,365543100],[1126000580,2618297676],[1288033470,3409855158],[1501505948,4234509866],[1607167915,987167468],[1816402316,1246189591]];var o=[];for(var u=0;u<80;u++)o.push([0,0]);var a=function(e,t,n){var r=e[0];var i=e[1];var u=e[2];var a=e[3];var f=e[4];var l=e[5];var c=e[6];var h=e[7];var p=r[0];var d=r[1];var v=i[0];var m=i[1];var g=u[0];var y=u[1];var b=a[0];var w=a[1];var E=f[0];var S=f[1];var x=l[0];var T=l[1];var N=c[0];var C=c[1];var k=h[0];var L=h[1];var A=p;var O=d;var M=v;var _=m;var D=g;var P=y;var H=b;var B=w;var j=E;var F=S;var I=x;var q=T;var R=N;var U=C;var z=k;var X=L;for(var V=0;V<80;V++){var $=o[V];if(V<16){var J=$[0]=t[n+V*2]|0;var Q=$[1]=t[n+V*2+1]|0}else{var G=o[V-15];var Y=G[0];var Z=G[1];var et=(Y>>>1|Z<<31)^(Y>>>8|Z<<24)^Y>>>7;var tt=(Z>>>1|Y<<31)^(Z>>>8|Y<<24)^(Z>>>7|Y<<25);var nt=o[V-2];var rt=nt[0];var it=nt[1];var st=(rt>>>19|it<<13)^(rt<<3|it>>>29)^rt>>>6;var ot=(it>>>19|rt<<13)^(it<<3|rt>>>29)^(it>>>6|rt<<26);var ut=o[V-7];var at=ut[0];var ft=ut[1];var lt=o[V-16];var ct=lt[0];var ht=lt[1];var Q=tt+ft;var J=et+at+(Q>>>0<tt>>>0?1:0);var Q=Q+ot;var J=J+st+(Q>>>0<ot>>>0?1:0);var Q=Q+ht;var J=J+ct+(Q>>>0<ht>>>0?1:0);$[0]=J;$[1]=Q}var pt=j&I^~j&R;var dt=F&q^~F&U;var vt=A&M^A&D^M&D;var mt=O&_^O&P^_&P;var gt=(A>>>28|O<<4)^(A<<30|O>>>2)^(A<<25|O>>>7);var yt=(O>>>28|A<<4)^(O<<30|A>>>2)^(O<<25|A>>>7);var bt=(j>>>14|F<<18)^(j>>>18|F<<14)^(j<<23|F>>>9);var wt=(F>>>14|j<<18)^(F>>>18|j<<14)^(F<<23|j>>>9);var Et=s[V];var St=Et[0];var xt=Et[1];var Tt=X+wt;var Nt=z+bt+(Tt>>>0<X>>>0?1:0);var Tt=Tt+dt;var Nt=Nt+pt+(Tt>>>0<dt>>>0?1:0);var Tt=Tt+xt;var Nt=Nt+St+(Tt>>>0<xt>>>0?1:0);var Tt=Tt+Q;var Nt=Nt+J+(Tt>>>0<Q>>>0?1:0);var Ct=yt+mt;var kt=gt+vt+(Ct>>>0<yt>>>0?1:0);z=R;X=U;R=I;U=q;I=j;q=F;F=B+Tt|0;j=H+Nt+(F>>>0<B>>>0?1:0)|0;H=D;B=P;D=M;P=_;M=A;_=O;O=Tt+Ct|0;A=Nt+kt+(O>>>0<Tt>>>0?1:0)|0}d=r[1]=d+O;r[0]=p+A+(d>>>0<O>>>0?1:0);m=i[1]=m+_;i[0]=v+M+(m>>>0<_>>>0?1:0);y=u[1]=y+P;u[0]=g+D+(y>>>0<P>>>0?1:0);w=a[1]=w+B;a[0]=b+H+(w>>>0<B>>>0?1:0);S=f[1]=S+F;f[0]=E+j+(S>>>0<F>>>0?1:0);T=l[1]=T+q;l[0]=x+I+(T>>>0<q>>>0?1:0);C=c[1]=C+U;c[0]=N+R+(C>>>0<U>>>0?1:0);L=h[1]=L+X;h[0]=k+z+(L>>>0<X>>>0?1:0);return e};t.exports=function(e,t){var n=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]];if(e.constructor===String){e=r.stringToBytes(e)}var s=i.bytesToWords(e);var o=e.length*8;s[o>>5]|=128<<24-o%32;s[(o+64>>10<<5)+31]=o;for(var u=0;u<s.length;u+=32){a(n,s,u)}var f=i.wordsToBytes(Array.prototype.concat.apply([],n));return t&&t.asBytes?f:t&&t.asString?Binary.bytesToString(f):r.bytesToHex(f)};t.exports._blocksize=128},{"../convert":4,"../util":22}],10:[function(e,t,n){function c(e,t,n,r){var i=Math.max(t.bitLength(),r.bitLength());var s=e.add2D(n);var u=e.curve.getInfinity();for(var a=i-1;a>=0;--a){u=u.twice2D();u.z=o.ONE;if(t.testBit(a)){if(r.testBit(a)){u=u.add2D(s)}else{u=u.add2D(e)}}else{if(r.testBit(a)){u=u.add2D(n)}}}return u}var r=e("./jsbn/sec");var i=e("./util");var s=e("./jsbn/rng");var o=e("./jsbn/jsbn");var u=e("./jsbn/ec").ECPointFp;var a=new s;var f=r("secp256k1");var l=null;var h={getBigRandom:function(e){return(new o(e.bitLength(),a)).mod(e.subtract(o.ONE)).add(o.ONE)},sign:function(e,t){var n=t;var r=f.getN();var i=o.fromByteArrayUnsigned(e);do{var s=h.getBigRandom(r);var u=f.getG();var a=u.multiply(s);var l=a.getX().toBigInteger().mod(r)}while(l.compareTo(o.ZERO)<=0);var c=s.modInverse(r).multiply(i.add(n.multiply(l))).mod(r);return h.serializeSig(l,c)},verify:function(e,t,n){var r,s;if(i.isArray(t)){var a=h.parseSig(t);r=a.r;s=a.s}else if("object"===typeof t&&t.r&&t.s){r=t.r;s=t.s}else{throw new Error("Invalid value for signature")}var l;if(n instanceof u){l=n}else if(i.isArray(n)){l=u.decodeFrom(f.getCurve(),n)}else{throw new Error("Invalid format for pubkey value, must be byte array or ECPointFp")}var c=o.fromByteArrayUnsigned(e);return h.verifyRaw(c,r,s,l)},verifyRaw:function(e,t,n,r){var i=f.getN();var s=f.getG();if(t.compareTo(o.ONE)<0||t.compareTo(i)>=0)return false;if(n.compareTo(o.ONE)<0||n.compareTo(i)>=0)return false;var u=n.modInverse(i);var a=e.multiply(u).mod(i);var l=t.multiply(u).mod(i);var c=s.multiply(a).add(r.multiply(l));var h=c.getX().toBigInteger().mod(i);return h.equals(t)},serializeSig:function(e,t){var n=e.toByteArraySigned();var r=t.toByteArraySigned();var i=[];i.push(2);i.push(n.length);i=i.concat(n);i.push(2);i.push(r.length);i=i.concat(r);i.unshift(i.length);i.unshift(48);return i},parseSig:function(e){var t;if(e[0]!=48)throw new Error("Signature not a valid DERSequence");t=2;if(e[t]!=2)throw new Error("First element in signature must be a DERInteger");var n=e.slice(t+2,t+2+e[t+1]);t+=2+e[t+1];if(e[t]!=2)throw new Error("Second element in signature must be a DERInteger");var r=e.slice(t+2,t+2+e[t+1]);t+=2+e[t+1];var i=o.fromByteArrayUnsigned(n);var s=o.fromByteArrayUnsigned(r);return{r:i,s:s}},parseSigCompact:function(e){if(e.length!==65){throw new Error("Signature has the wrong length")}var t=e[0]-27;if(t<0||t>7){throw new Error("Invalid signature type")}var n=f.getN();var r=o.fromByteArrayUnsigned(e.slice(1,33)).mod(n);var i=o.fromByteArrayUnsigned(e.slice(33,65)).mod(n);return{r:r,s:i,i:t}},recoverPubKey:function(t,n,r,i){i=i&3;var s=i&1;var a=i>>1;var p=f.getN();var d=f.getG();var v=f.getCurve();var m=v.getQ();var g=v.getA().toBigInteger();var y=v.getB().toBigInteger();if(!l){l=m.add(o.ONE).divide(o.valueOf(4))}var b=a?t.add(p):t;var w=b.multiply(b).multiply(b).add(g.multiply(b)).add(y).mod(m);var E=w.modPow(l,m);var S=E.isEven()?i%2:(i+1)%2;var x=(E.isEven()?!s:s)?E:m.subtract(E);var T=new u(v,v.fromBigInteger(b),v.fromBigInteger(x));T.validate();var N=o.fromByteArrayUnsigned(r);var C=o.ZERO.subtract(N).mod(p);var k=t.modInverse(p);var L=c(T,n,d,C).multiply(k);L.validate();if(!h.verifyRaw(N,t,n,L)){throw new Error("Pubkey recovery unsuccessful")}var A=e("./eckey");var O=A();O.pub=L;return O},calcPubkeyRecoveryParam:function(e,t,n,r){for(var i=0;i<4;i++){var s=h.recoverPubKey(t,n,r,i);if(s.getBitcoinAddress().toString()==e){return i}}throw new Error("Unable to find valid recovery factor")}};t.exports=h},{"./eckey":11,"./jsbn/ec":13,"./jsbn/jsbn":14,"./jsbn/rng":16,"./jsbn/sec":17,"./util":22}],11:[function(e,t,n){var r=e("./jsbn/jsbn");var i=e("./jsbn/sec");var s=e("./base58");var o=e("./crypto-js/crypto");var u=e("./util");var a=e("./convert");var f=e("./address");var l=e("./ecdsa");var c=e("./jsbn/ec").ECPointFp;var h=i("secp256k1");var p=function(e){if(!(this instanceof p)){return new p(e)}this.compressed=!!p.compressByDefault;if(!e){var t=h.getN();this.priv=l.getBigRandom(t)}else this.import(e)};p.compressByDefault=false;p.prototype.setCompressed=function(e){this.compressed=!!e};p.prototype.getPub=function(){return this.getPubPoint().getEncoded(this.compressed)};p.prototype.getPubPoint=function(){if(!this.pub)this.pub=h.getG().multiply(this.priv);return this.pub};p.prototype.getPubKeyHash=function(){if(this.pubKeyHash)return this.pubKeyHash;return this.pubKeyHash=u.sha256ripe160(this.getPub())};p.prototype.getBitcoinAddress=function(){var e=this.getPubKeyHash();var t=new f(e);return t};p.prototype.setPub=function(e){this.pub=c.decodeFrom(h.getCurve(),e);this.compressed=e[0]<4;return this};p.prototype.export=function(e){var t=this.priv.toByteArrayUnsigned();if(this.compressed)t.push(1);return e==="base58"?s.checkEncode(t,178):e==="bin"?a.bytesToString(t):e==="bytes"?t:e==="hex"?a.bytesToHex(t):t};p.prototype.getExportedPrivateKey=p.prototype.export;p.prototype.toString=function(e){return""+this.export(e)};p.prototype.sign=function(e){return l.sign(e,this.priv)};p.prototype.verify=function(e,t){return l.verify(e,t,this.getPub())};p.prototype.import=function(e){if(e instanceof p){this.priv=e.priv;this.compressed=e.compressed}else if(e instanceof r){this.priv=e;this.compressed=p.compressByDefault}else if(u.isArray(e)){this.priv=r.fromByteArrayUnsigned(e.slice(0,32));this.compressed=e.length==33}else if("string"==typeof e){if(e.length==51&&e[0]=="5"){this.priv=r.fromByteArrayUnsigned(s.checkDecode(e));this.compressed=false}else if(e.length==52&&(e[0]==="K"||e[0]==="L")){this.priv=r.fromByteArrayUnsigned(s.checkDecode(e));this.compressed=true}else if(e.length>=64){this.priv=r.fromByteArrayUnsigned(a.hexToBytes(e.slice(0,64)));this.compressed=e.length==66}}};t.exports=p},{"./address":1,"./base58":2,"./convert":4,"./crypto-js/crypto":5,"./ecdsa":10,"./jsbn/ec":13,"./jsbn/jsbn":14,"./jsbn/sec":17,"./util":22}],12:[function(e,t,n){var r=function(e,t){return e<<t|e>>>32-t};var i=function(e,t){return e<<32-t|e>>>t};var s=function(e){if(e.constructor==Number){return r(e,8)&16711935|r(e,24)&4278255360}for(var t=0;t<e.length;t++){e[t]=s(e[t])}return e};t.exports={Address:e("./address"),Key:e("./eckey"),Message:e("./message"),BigInteger:e("./jsbn/jsbn"),Crypto:e("./crypto-js/crypto"),Script:e("./script"),Opcode:e("./opcode"),Transaction:e("./transaction").Transaction,Util:e("./util"),TransactionIn:e("./transaction").TransactionIn,TransactionOut:e("./transaction").TransactionOut,ECPointFp:e("./jsbn/ec").ECPointFp,Wallet:e("./wallet"),ecdsa:e("./ecdsa"),BIP32key:e("./bip32"),base58:e("./base58"),convert:e("./convert"),endian:s}},{"./address":1,"./base58":2,"./bip32":3,"./convert":4,"./crypto-js/crypto":5,"./ecdsa":10,"./eckey":11,"./jsbn/ec":13,"./jsbn/jsbn":14,"./message":18,"./opcode":19,"./script":20,"./transaction":21,"./util":22,"./wallet":23}],13:[function(e,t,n){function s(e,t){this.x=t;this.q=e}function o(e){if(e==this)return true;return this.q.equals(e.q)&&this.x.equals(e.x)}function u(){return this.x}function a(){return new s(this.q,this.x.negate().mod(this.q))}function f(e){return new s(this.q,this.x.add(e.toBigInteger()).mod(this.q))}function l(e){return new s(this.q,this.x.subtract(e.toBigInteger()).mod(this.q))}function c(e){return new s(this.q,this.x.multiply(e.toBigInteger()).mod(this.q))}function h(){return new s(this.q,this.x.square().mod(this.q))}function p(e){return new s(this.q,this.x.multiply(e.toBigInteger().modInverse(this.q)).mod(this.q))}function d(e,t,n,i){this.curve=e;this.x=t;this.y=n;if(i==null){this.z=r.ONE}else{this.z=i}this.zinv=null}function v(){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 m(){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 g(e){if(e==this)return true;if(this.isInfinity())return e.isInfinity();if(e.isInfinity())return this.isInfinity();var t,n;t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q);if(!t.equals(r.ZERO))return false;n=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q);return n.equals(r.ZERO)}function y(){if(this.x==null&&this.y==null)return true;return this.z.equals(r.ZERO)&&!this.y.toBigInteger().equals(r.ZERO)}function b(){return new d(this.curve,this.x,this.y.negate(),this.z)}function w(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q);var n=e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q);if(r.ZERO.equals(n)){if(r.ZERO.equals(t)){return this.twice()}return this.curve.getInfinity()}var i=new r("3");var s=this.x.toBigInteger();var o=this.y.toBigInteger();var u=e.x.toBigInteger();var a=e.y.toBigInteger();var f=n.square();var l=f.multiply(n);var c=s.multiply(f);var h=t.square().multiply(this.z);var p=h.subtract(c.shiftLeft(1)).multiply(e.z).subtract(l).multiply(n).mod(this.curve.q);var v=c.multiply(i).multiply(t).subtract(o.multiply(l)).subtract(h.multiply(t)).multiply(e.z).add(t.multiply(l)).mod(this.curve.q);var m=l.multiply(this.z).multiply(e.z).mod(this.curve.q);return new d(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(v),m)}function E(){if(this.isInfinity())return this;if(this.y.toBigInteger().signum()==0)return this.curve.getInfinity();var e=new r("3");var t=this.x.toBigInteger();var n=this.y.toBigInteger();var i=n.multiply(this.z);var s=i.multiply(n).mod(this.curve.q);var o=this.curve.a.toBigInteger();var u=t.square().multiply(e);if(!r.ZERO.equals(o)){u=u.add(this.z.square().multiply(o))}u=u.mod(this.curve.q);var a=u.square().subtract(t.shiftLeft(3).multiply(s)).shiftLeft(1).multiply(i).mod(this.curve.q);var f=u.multiply(e).multiply(t).subtract(s.shiftLeft(1)).shiftLeft(2).multiply(s).subtract(u.square().multiply(u)).mod(this.curve.q);var l=i.square().multiply(i).shiftLeft(3).mod(this.curve.q);return new d(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(f),l)}function S(e){if(this.isInfinity())return this;if(e.signum()==0)return this.curve.getInfinity();var t=e;var n=t.multiply(new r("3"));var i=this.negate();var s=this;var o;for(o=n.bitLength()-2;o>0;--o){s=s.twice();var u=n.testBit(o);var a=t.testBit(o);if(u!=a){s=s.add(u?this:i)}}return s}function x(e,t,n){var r;if(e.bitLength()>n.bitLength())r=e.bitLength()-1;else r=n.bitLength()-1;var i=this.curve.getInfinity();var s=this.add(t);while(r>=0){i=i.twice();if(e.testBit(r)){if(n.testBit(r)){i=i.add(s)}else{i=i.add(this)}}else{if(n.testBit(r)){i=i.add(t)}}--r}return i}function T(e,t,n){this.q=e;this.a=this.fromBigInteger(t);this.b=this.fromBigInteger(n);this.infinity=new d(this,null,null)}function N(){return this.q}function C(){return this.a}function k(){return this.b}function L(e){if(e==this)return true;return this.q.equals(e.q)&&this.a.equals(e.a)&&this.b.equals(e.b)}function A(){return this.infinity}function O(e){return new s(this.q,e)}function M(e){switch(parseInt(e.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var t=(e.length-2)/2;var n=e.substr(2,t);var i=e.substr(t+2,t);return new d(this,this.fromBigInteger(new r(n,16)),this.fromBigInteger(new r(i,16)));default:return null}}function _(e,t){var n=e.toByteArrayUnsigned();if(t<n.length){n=n.slice(n.length-t)}else while(t>n.length){n.unshift(0)}return n}var r=e("./jsbn"),i=e("./sec");s.prototype.equals=o;s.prototype.toBigInteger=u;s.prototype.negate=a;s.prototype.add=f;s.prototype.subtract=l;s.prototype.multiply=c;s.prototype.square=h;s.prototype.divide=p;d.prototype.getX=v;d.prototype.getY=m;d.prototype.equals=g;d.prototype.isInfinity=y;d.prototype.negate=b;d.prototype.add=w;d.prototype.twice=E;d.prototype.multiply=S;d.prototype.multiplyTwo=x;T.prototype.getQ=N;T.prototype.getA=C;T.prototype.getB=k;T.prototype.equals=L;T.prototype.getInfinity=A;T.prototype.fromBigInteger=O;T.prototype.decodePointHex=M;s.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)};d.prototype.getEncoded=function(e){var t=this.getX().toBigInteger();var n=this.getY().toBigInteger();var r=_(t,32);if(e){if(n.isEven()){r.unshift(2)}else{r.unshift(3)}}else{r.unshift(4);r=r.concat(_(n,32))}return r};d.decodeFrom=function(e,t){var n=t[0];var i=t.length-1;if(n==4){var s=t.slice(1,1+i/2),o=t.slice(1+i/2,1+i),u=r.fromByteArrayUnsigned(s),a=r.fromByteArrayUnsigned(o)}else{var s=t.slice(1),u=r.fromByteArrayUnsigned(s),f=e.getQ(),l=u.multiply(u).multiply(u).add(new Bitcoin.BigInteger("7")).mod(f),c=f.add(new Bitcoin.BigInteger("1")).divide(new Bitcoin.BigInteger("4")),a=l.modPow(c,f);if(a.mod(new Bitcoin.BigInteger("2")).toString()!=""+n%2){a=f.subtract(a)}}return new d(e,e.fromBigInteger(u),e.fromBigInteger(a))};d.prototype.add2D=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;if(this.x.equals(e.x)){if(this.y.equals(e.y)){return this.twice()}return this.curve.getInfinity()}var t=e.x.subtract(this.x);var n=e.y.subtract(this.y);var r=n.divide(t);var i=r.square().subtract(this.x).subtract(e.x);var s=r.multiply(this.x.subtract(i)).subtract(this.y);return new d(this.curve,i,s)};d.prototype.twice2D=function(){if(this.isInfinity())return this;if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var e=this.curve.fromBigInteger(r.valueOf(2));var t=this.curve.fromBigInteger(r.valueOf(3));var n=this.x.square().multiply(t).add(this.curve.a).divide(this.y.multiply(e));var i=n.square().subtract(this.x.multiply(e));var s=n.multiply(this.x.subtract(i)).subtract(this.y);return new d(this.curve,i,s)};d.prototype.multiply2D=function(e){if(this.isInfinity())return this;if(e.signum()==0)return this.curve.getInfinity();var t=e;var n=t.multiply(new r("3"));var i=this.negate();var s=this;var o;for(o=n.bitLength()-2;o>0;--o){s=s.twice();var u=n.testBit(o);var a=t.testBit(o);if(u!=a){s=s.add2D(u?this:i)}}return s};d.prototype.isOnCurve=function(){var e=this.getX().toBigInteger();var t=this.getY().toBigInteger();var n=this.curve.getA().toBigInteger();var r=this.curve.getB().toBigInteger();var i=this.curve.getQ();var s=t.multiply(t).mod(i);var o=e.multiply(e).multiply(e).add(n.multiply(e)).add(r).mod(i);return s.equals(o)};d.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"};d.prototype.validate=function(){var e=this.curve.getQ();if(this.isInfinity()){throw new Error("Point is at infinity.")}var t=this.getX().toBigInteger();var n=this.getY().toBigInteger();if(t.compareTo(r.ONE)<0||t.compareTo(e.subtract(r.ONE))>0){throw new Error("x coordinate out of bounds")}if(n.compareTo(r.ONE)<0||n.compareTo(e.subtract(r.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(e).isInfinity()){throw new Error("Point is not a scalar multiple of G.")}return true};t.exports=T;t.exports.ECPointFp=d},{"./jsbn":14,"./sec":17}],14:[function(e,t,n){function o(e,t,n){if(!(this instanceof o)){return new o(e,t,n)}if(e!=null){if("number"==typeof e)this.fromNumber(e,t,n);else if(t==null&&"string"!=typeof e)this.fromString(e,256);else this.fromString(e,t)}}function a(){return new o(null)}function f(e,t,n,r,i,s){while(--s>=0){var o=t*this[e++]+n[r]+i;i=Math.floor(o/67108864);n[r++]=o&67108863}return i}function l(e,t,n,r,i,s){var o=t&32767,u=t>>15;while(--s>=0){var a=this[e]&32767;var f=this[e++]>>15;var l=u*a+f*o;a=o*a+((l&32767)<<15)+n[r]+(i&1073741823);i=(a>>>30)+(l>>>15)+u*f+(i>>>30);n[r++]=a&1073741823}return i}function c(e,t,n,r,i,s){var o=t&16383,u=t>>14;while(--s>=0){var a=this[e]&16383;var f=this[e++]>>14;var l=u*a+f*o;a=o*a+((l&16383)<<14)+n[r]+i;i=(a>>28)+(l>>14)+u*f;n[r++]=a&268435455}return i}function y(e){return d.charAt(e)}function b(e,t){var n=v[e.charCodeAt(t)];return n==null?-1:n}function w(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t;e.s=this.s}function E(e){this.t=1;this.s=e<0?-1:0;if(e>0)this[0]=e;else if(e<-1)this[0]=e+h;else this.t=0}function S(e){var t=a();t.fromInt(e);return t}function x(e,t){var n=this;var r;if(t==16)r=4;else if(t==8)r=3;else if(t==256)r=8;else if(t==2)r=1;else if(t==32)r=5;else if(t==4)r=2;else{n.fromRadix(e,t);return}n.t=0;n.s=0;var i=e.length,s=false,u=0;while(--i>=0){var a=r==8?e[i]&255:b(e,i);if(a<0){if(e.charAt(i)=="-")s=true;continue}s=false;if(u==0)n[n.t++]=a;else if(u+r>n.DB){n[n.t-1]|=(a&(1<<n.DB-u)-1)<<u;n[n.t++]=a>>n.DB-u}else n[n.t-1]|=a<<u;u+=r;if(u>=n.DB)u-=n.DB}if(r==8&&(e[0]&128)!=0){n.s=-1;if(u>0)n[n.t-1]|=(1<<n.DB-u)-1<<u}n.clamp();if(s)o.ZERO.subTo(n,n)}function T(){var e=this.s&this.DM;while(this.t>0&&this[this.t-1]==e)--this.t}function N(e){var t=this;if(t.s<0)return"-"+t.negate().toString(e);var n;if(e==16)n=4;else if(e==8)n=3;else if(e==2)n=1;else if(e==32)n=5;else if(e==4)n=2;else return t.toRadix(e);var r=(1<<n)-1,i,s=false,o="",u=t.t;var a=t.DB-u*t.DB%n;if(u-->0){if(a<t.DB&&(i=t[u]>>a)>0){s=true;o=y(i)}while(u>=0){if(a<n){i=(t[u]&(1<<a)-1)<<n-a;i|=t[--u]>>(a+=t.DB-n)}else{i=t[u]>>(a-=n)&r;if(a<=0){a+=t.DB;--u}}if(i>0)s=true;if(s)o+=y(i)}}return s?o:"0"}function C(){var e=a();o.ZERO.subTo(this,e);return e}function k(){return this.s<0?this.negate():this}function L(e){var t=this.s-e.s;if(t!=0)return t;var n=this.t;t=n-e.t;if(t!=0)return this.s<0?-t:t;while(--n>=0)if((t=this[n]-e[n])!=0)return t;return 0}function A(e){var t=1,n;if((n=e>>>16)!=0){e=n;t+=16}if((n=e>>8)!=0){e=n;t+=8}if((n=e>>4)!=0){e=n;t+=4}if((n=e>>2)!=0){e=n;t+=2}if((n=e>>1)!=0){e=n;t+=1}return t}function O(){if(this.t<=0)return 0;return this.DB*(this.t-1)+A(this[this.t-1]^this.s&this.DM)}function M(e,t){var n;for(n=this.t-1;n>=0;--n)t[n+e]=this[n];for(n=e-1;n>=0;--n)t[n]=0;t.t=this.t+e;t.s=this.s}function _(e,t){for(var n=e;n<this.t;++n)t[n-e]=this[n];t.t=Math.max(this.t-e,0);t.s=this.s}function D(e,t){var n=this;var r=e%n.DB;var i=n.DB-r;var s=(1<<i)-1;var o=Math.floor(e/n.DB),u=n.s<<r&n.DM,a;for(a=n.t-1;a>=0;--a){t[a+o+1]=n[a]>>i|u;u=(n[a]&s)<<r}for(a=o-1;a>=0;--a)t[a]=0;t[o]=u;t.t=n.t+o+1;t.s=n.s;t.clamp()}function P(e,t){var n=this;t.s=n.s;var r=Math.floor(e/n.DB);if(r>=n.t){t.t=0;return}var i=e%n.DB;var s=n.DB-i;var o=(1<<i)-1;t[0]=n[r]>>i;for(var u=r+1;u<n.t;++u){t[u-r-1]|=(n[u]&o)<<s;t[u-r]=n[u]>>i}if(i>0)t[n.t-r-1]|=(n.s&o)<<s;t.t=n.t-r;t.clamp()}function H(e,t){var n=this;var r=0,i=0,s=Math.min(e.t,n.t);while(r<s){i+=n[r]-e[r];t[r++]=i&n.DM;i>>=n.DB}if(e.t<n.t){i-=e.s;while(r<n.t){i+=n[r];t[r++]=i&n.DM;i>>=n.DB}i+=n.s}else{i+=n.s;while(r<e.t){i-=e[r];t[r++]=i&n.DM;i>>=n.DB}i-=e.s}t.s=i<0?-1:0;if(i<-1)t[r++]=n.DV+i;else if(i>0)t[r++]=i;t.t=r;t.clamp()}function B(e,t){var n=this.abs(),r=e.abs();var i=n.t;t.t=i+r.t;while(--i>=0)t[i]=0;for(i=0;i<r.t;++i)t[i+n.t]=n.am(0,r[i],t,i,0,n.t);t.s=0;t.clamp();if(this.s!=e.s)o.ZERO.subTo(t,t)}function j(e){var t=this.abs();var n=e.t=2*t.t;while(--n>=0)e[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t[n],e,2*n,0,1);if((e[n+t.t]+=t.am(n+1,2*t[n],e,2*n+1,r,t.t-n-1))>=t.DV){e[n+t.t]-=t.DV;e[n+t.t+1]=1}}if(e.t>0)e[e.t-1]+=t.am(n,t[n],e,2*n,0,1);e.s=0;e.clamp()}function F(e,t,n){var r=this;var i=e.abs();if(i.t<=0)return;var s=r.abs();if(s.t<i.t){if(t!=null)t.fromInt(0);if(n!=null)r.copyTo(n);return}if(n==null)n=a();var u=a(),f=r.s,l=e.s;var c=r.DB-A(i[i.t-1]);if(c>0){i.lShiftTo(c,u);s.lShiftTo(c,n)}else{i.copyTo(u);s.copyTo(n)}var h=u.t;var p=u[h-1];if(p==0)return;var d=p*(1<<r.F1)+(h>1?u[h-2]>>r.F2:0);var v=r.FV/d,m=(1<<r.F1)/d,g=1<<r.F2;var y=n.t,b=y-h,w=t==null?a():t;u.dlShiftTo(b,w);if(n.compareTo(w)>=0){n[n.t++]=1;n.subTo(w,n)}o.ONE.dlShiftTo(h,w);w.subTo(u,u);while(u.t<h)u[u.t++]=0;while(--b>=0){var E=n[--y]==p?r.DM:Math.floor(n[y]*v+(n[y-1]+g)*m);if((n[y]+=u.am(0,E,n,b,0,h))<E){u.dlShiftTo(b,w);n.subTo(w,n);while(n[y]<--E)n.subTo(w,n)}}if(t!=null){n.drShiftTo(h,t);if(f!=l)o.ZERO.subTo(t,t)}n.t=h;n.clamp();if(c>0)n.rShiftTo(c,n);if(f<0)o.ZERO.subTo(n,n)}function I(e){var t=a();this.abs().divRemTo(e,null,t);if(this.s<0&&t.compareTo(o.ZERO)>0)e.subTo(t,t);return t}function q(e){this.m=e}function R(e){if(e.s<0||e.compareTo(this.m)>=0)return e.mod(this.m);else return e}function U(e){return e}function z(e){e.divRemTo(this.m,null,e)}function W(e,t,n){e.multiplyTo(t,n);this.reduce(n)}function X(e,t){e.squareTo(t);this.reduce(t)}function V(){if(this.t<1)return 0;var e=this[0];if((e&1)==0)return 0;var t=e&3;t=t*(2-(e&15)*t)&15;t=t*(2-(e&255)*t)&255;t=t*(2-((e&65535)*t&65535))&65535;t=t*(2-e*t%this.DV)%this.DV;return t>0?this.DV-t:-t}function $(e){this.m=e;this.mp=e.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<e.DB-15)-1;this.mt2=2*e.t}function J(e){var t=a();e.abs().dlShiftTo(this.m.t,t);t.divRemTo(this.m,null,t);if(e.s<0&&t.compareTo(o.ZERO)>0)this.m.subTo(t,t);return t}function K(e){var t=a();e.copyTo(t);this.reduce(t);return t}function Q(e){while(e.t<=this.mt2)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=e[t]&32767;var r=n*this.mpl+((n*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;n=t+this.m.t;e[n]+=this.m.am(0,r,e,t,0,this.m.t);while(e[n]>=e.DV){e[n]-=e.DV;e[++n]++}}e.clamp();e.drShiftTo(this.m.t,e);if(e.compareTo(this.m)>=0)e.subTo(this.m,e)}function G(e,t){e.squareTo(t);this.reduce(t)}function Y(e,t,n){e.multiplyTo(t,n);this.reduce(n)}function Z(){return(this.t>0?this[0]&1:this.s)==0}function et(e,t){if(e>4294967295||e<1)return o.ONE;var n=a(),r=a(),i=t.convert(this),s=A(e)-1;i.copyTo(n);while(--s>=0){t.sqrTo(n,r);if((e&1<<s)>0)t.mulTo(r,i,n);else{var u=n;n=r;r=u}}return t.revert(n)}function tt(e,t){var n;if(e<256||t.isEven())n=new q(t);else n=new $(t);return this.exp(e,n)}function a(){return new o(null)}function nt(){var e=a();this.copyTo(e);return e}function rt(){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 it(){return this.t==0?this.s:this[0]<<24>>24}function st(){return this.t==0?this.s:this[0]<<16>>16}function ot(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function ut(){if(this.s<0)return-1;else if(this.t<=0||this.t==1&&this[0]<=0)return 0;else return 1}function at(e){if(e==null)e=10;if(this.signum()==0||e<2||e>36)return"0";var t=this.chunkSize(e);var n=Math.pow(e,t);var r=S(n),i=a(),s=a(),o="";this.divRemTo(r,i,s);while(i.signum()>0){o=(n+s.intValue()).toString(e).substr(1)+o;i.divRemTo(r,i,s)}return s.intValue().toString(e)+o}function ft(e,t){var n=this;n.fromInt(0);if(t==null)t=10;var r=n.chunkSize(t);var i=Math.pow(t,r),s=false,u=0,a=0;for(var f=0;f<e.length;++f){var l=b(e,f);if(l<0){if(e.charAt(f)=="-"&&n.signum()==0)s=true;continue}a=t*a+l;if(++u>=r){n.dMultiply(i);n.dAddOffset(a,0);u=0;a=0}}if(u>0){n.dMultiply(Math.pow(t,u));n.dAddOffset(a,0)}if(s)o.ZERO.subTo(n,n)}function lt(e,t,n){var r=this;if("number"==typeof t){if(e<2)r.fromInt(1);else{r.fromNumber(e,n);if(!r.testBit(e-1))r.bitwiseTo(o.ONE.shiftLeft(e-1),yt,r);if(r.isEven())r.dAddOffset(1,0);while(!r.isProbablePrime(t)){r.dAddOffset(2,0);if(r.bitLength()>e)r.subTo(o.ONE.shiftLeft(e-1),r)}}}else{var i=new Array,s=e&7;i.length=(e>>3)+1;t.nextBytes(i);if(s>0)i[0]&=(1<<s)-1;else i[0]=0;r.fromString(i,256)}}function ct(){var e=this;var t=e.t,n=new Array;n[0]=e.s;var r=e.DB-t*e.DB%8,i,s=0;if(t-->0){if(r<e.DB&&(i=e[t]>>r)!=(e.s&e.DM)>>r)n[s++]=i|e.s<<e.DB-r;while(t>=0){if(r<8){i=(e[t]&(1<<r)-1)<<8-r;i|=e[--t]>>(r+=e.DB-8)}else{i=e[t]>>(r-=8)&255;if(r<=0){r+=e.DB;--t}}if((i&128)!=0)i|=-256;if(s===0&&(e.s&128)!=(i&128))++s;if(s>0||i!=e.s)n[s++]=i}}return n}function ht(e){return this.compareTo(e)==0}function pt(e){return this.compareTo(e)<0?this:e}function dt(e){return this.compareTo(e)>0?this:e}function vt(e,t,n){var r=this;var i,s,o=Math.min(e.t,r.t);for(i=0;i<o;++i)n[i]=t(r[i],e[i]);if(e.t<r.t){s=e.s&r.DM;for(i=o;i<r.t;++i)n[i]=t(r[i],s);n.t=r.t}else{s=r.s&r.DM;for(i=o;i<e.t;++i)n[i]=t(s,e[i]);n.t=e.t}n.s=t(r.s,e.s);n.clamp()}function mt(e,t){return e&t}function gt(e){var t=a();this.bitwiseTo(e,mt,t);return t}function yt(e,t){return e|t}function bt(e){var t=a();this.bitwiseTo(e,yt,t);return t}function wt(e,t){return e^t}function Et(e){var t=a();this.bitwiseTo(e,wt,t);return t}function St(e,t){return e&~t}function xt(e){var t=a();this.bitwiseTo(e,St,t);return t}function Tt(){var e=a();for(var t=0;t<this.t;++t)e[t]=this.DM&~this[t];e.t=this.t;e.s=~this.s;return e}function Nt(e){var t=a();if(e<0)this.rShiftTo(-e,t);else this.lShiftTo(e,t);return t}function Ct(e){var t=a();if(e<0)this.lShiftTo(-e,t);else this.rShiftTo(e,t);return t}function kt(e){if(e==0)return-1;var t=0;if((e&65535)==0){e>>=16;t+=16}if((e&255)==0){e>>=8;t+=8}if((e&15)==0){e>>=4;t+=4}if((e&3)==0){e>>=2;t+=2}if((e&1)==0)++t;return t}function Lt(){for(var e=0;e<this.t;++e)if(this[e]!=0)return e*this.DB+kt(this[e]);if(this.s<0)return this.t*this.DB;return-1}function At(e){var t=0;while(e!=0){e&=e-1;++t}return t}function Ot(){var e=0,t=this.s&this.DM;for(var n=0;n<this.t;++n)e+=At(this[n]^t);return e}function Mt(e){var t=Math.floor(e/this.DB);if(t>=this.t)return this.s!=0;return(this[t]&1<<e%this.DB)!=0}function _t(e,t){var n=o.ONE.shiftLeft(e);this.bitwiseTo(n,t,n);return n}function Dt(e){return this.changeBit(e,yt)}function Pt(e){return this.changeBit(e,St)}function Ht(e){return this.changeBit(e,wt)}function Bt(e,t){var n=this;var r=0,i=0,s=Math.min(e.t,n.t);while(r<s){i+=n[r]+e[r];t[r++]=i&n.DM;i>>=n.DB}if(e.t<n.t){i+=e.s;while(r<n.t){i+=n[r];t[r++]=i&n.DM;i>>=n.DB}i+=n.s}else{i+=n.s;while(r<e.t){i+=e[r];t[r++]=i&n.DM;i>>=n.DB}i+=e.s}t.s=i<0?-1:0;if(i>0)t[r++]=i;else if(i<-1)t[r++]=n.DV+i;t.t=r;t.clamp()}function jt(e){var t=a();this.addTo(e,t);return t}function Ft(e){var t=a();this.subTo(e,t);return t}function It(e){var t=a();this.multiplyTo(e,t);return t}function qt(){var e=a();this.squareTo(e);return e}function Rt(e){var t=a();this.divRemTo(e,t,null);return t}function Ut(e){var t=a();this.divRemTo(e,null,t);return t}function zt(e){var t=a(),n=a();this.divRemTo(e,t,n);return new Array(t,n)}function Wt(e){this[this.t]=this.am(0,e-1,this,0,0,this.t);++this.t;this.clamp()}function Xt(e,t){if(e==0)return;while(this.t<=t)this[this.t++]=0;this[t]+=e;while(this[t]>=this.DV){this[t]-=this.DV;if(++t>=this.t)this[this.t++]=0;++this[t]}}function Vt(){}function $t(e){return e}function Jt(e,t,n){e.multiplyTo(t,n)}function Kt(e,t){e.squareTo(t)}function Qt(e){return this.exp(e,new Vt)}function Gt(e,t,n){var r=Math.min(this.t+e.t,t);n.s=0;n.t=r;while(r>0)n[--r]=0;var i;for(i=n.t-this.t;r<i;++r)n[r+this.t]=this.am(0,e[r],n,r,0,this.t);for(i=Math.min(e.t,t);r<i;++r)this.am(0,e[r],n,r,0,t-r);n.clamp()}function Yt(e,t,n){--t;var r=n.t=this.t+e.t-t;n.s=0;while(--r>=0)n[r]=0;for(r=Math.max(t-this.t,0);r<e.t;++r)n[this.t+r-t]=this.am(t-r,e[r],n,0,0,this.t+r-t);n.clamp();n.drShiftTo(1,n)}function Zt(e){this.r2=a();this.q3=a();o.ONE.dlShiftTo(2*e.t,this.r2);this.mu=this.r2.divide(e);this.m=e}function en(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);else if(e.compareTo(this.m)<0)return e;else{var t=a();e.copyTo(t);this.reduce(t);return t}}function tn(e){return e}function nn(e){var t=this;e.drShiftTo(t.m.t-1,t.r2);if(e.t>t.m.t+1){e.t=t.m.t+1;e.clamp()}t.mu.multiplyUpperTo(t.r2,t.m.t+1,t.q3);t.m.multiplyLowerTo(t.q3,t.m.t+1,t.r2);while(e.compareTo(t.r2)<0)e.dAddOffset(1,t.m.t+1);e.subTo(t.r2,e);while(e.compareTo(t.m)>=0)e.subTo(t.m,e)}function rn(e,t){e.squareTo(t);this.reduce(t)}function sn(e,t,n){e.multiplyTo(t,n);this.reduce(n)}function on(e,t){var n=e.bitLength(),r,i=S(1),s;if(n<=0)return i;else if(n<18)r=1;else if(n<48)r=3;else if(n<144)r=4;else if(n<768)r=5;else r=6;if(n<8)s=new q(t);else if(t.isEven())s=new Zt(t);else s=new $(t);var o=new Array,u=3,f=r-1,l=(1<<r)-1;o[1]=s.convert(this);if(r>1){var c=a();s.sqrTo(o[1],c);while(u<=l){o[u]=a();s.mulTo(c,o[u-2],o[u]);u+=2}}var h=e.t-1,p,d=true,v=a(),m;n=A(e[h])-1;while(h>=0){if(n>=f)p=e[h]>>n-f&l;else{p=(e[h]&(1<<n+1)-1)<<f-n;if(h>0)p|=e[h-1]>>this.DB+n-f}u=r;while((p&1)==0){p>>=1;--u}if((n-=u)<0){n+=this.DB;--h}if(d){o[p].copyTo(i);d=false}else{while(u>1){s.sqrTo(i,v);s.sqrTo(v,i);u-=2}if(u>0)s.sqrTo(i,v);else{m=i;i=v;v=m}s.mulTo(v,o[p],i)}while(h>=0&&(e[h]&1<<n)==0){s.sqrTo(i,v);m=i;i=v;v=m;if(--n<0){n=this.DB-1;--h}}}return s.revert(i)}function un(e){var t=this.s<0?this.negate():this.clone();var n=e.s<0?e.negate():e.clone();if(t.compareTo(n)<0){var r=t;t=n;n=r}var i=t.getLowestSetBit(),s=n.getLowestSetBit();if(s<0)return t;if(i<s)s=i;if(s>0){t.rShiftTo(s,t);n.rShiftTo(s,n)}while(t.signum()>0){if((i=t.getLowestSetBit())>0)t.rShiftTo(i,t);if((i=n.getLowestSetBit())>0)n.rShiftTo(i,n);if(t.compareTo(n)>=0){t.subTo(n,t);t.rShiftTo(1,t)}else{n.subTo(t,n);n.rShiftTo(1,n)}}if(s>0)n.lShiftTo(s,n);return n}function an(e){if(e<=0)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0)if(t==0)n=this[0]%e;else for(var r=this.t-1;r>=0;--r)n=(t*n+this[r])%e;return n}function fn(e){var t=e.isEven();if(this.isEven()&&t||e.signum()==0)return o.ZERO;var n=e.clone(),r=this.clone();var i=S(1),s=S(0),u=S(0),a=S(1);while(n.signum()!=0){while(n.isEven()){n.rShiftTo(1,n);if(t){if(!i.isEven()||!s.isEven()){i.addTo(this,i);s.subTo(e,s)}i.rShiftTo(1,i)}else if(!s.isEven())s.subTo(e,s);s.rShiftTo(1,s)}while(r.isEven()){r.rShiftTo(1,r);if(t){if(!u.isEven()||!a.isEven()){u.addTo(this,u);a.subTo(e,a)}u.rShiftTo(1,u)}else if(!a.isEven())a.subTo(e,a);a.rShiftTo(1,a)}if(n.compareTo(r)>=0){n.subTo(r,n);if(t)i.subTo(u,i);s.subTo(a,s)}else{r.subTo(n,r);if(t)u.subTo(i,u);a.subTo(s,a)}}if(r.compareTo(o.ONE)!=0)return o.ZERO;if(a.compareTo(e)>=0)return a.subtract(e);if(a.signum()<0)a.addTo(e,a);else return a;if(a.signum()<0)return a.add(e);else return a}var r;var i=0xdeadbeefcafe;var s=(i&16777215)==15715070;var u=o.prototype;o.prototype.am=f;r=26;o.prototype.DB=r;o.prototype.DM=(1<<r)-1;var h=o.prototype.DV=1<<r;var p=52;o.prototype.FV=Math.pow(2,p);o.prototype.F1=p-r;o.prototype.F2=2*r-p;var d="0123456789abcdefghijklmnopqrstuvwxyz";var v=new Array;var m,g;m="0".charCodeAt(0);for(g=0;g<=9;++g)v[m++]=g;m="a".charCodeAt(0);for(g=10;g<36;++g)v[m++]=g;m="A".charCodeAt(0);for(g=10;g<36;++g)v[m++]=g;q.prototype.convert=R;q.prototype.revert=U;q.prototype.reduce=z;q.prototype.mulTo=W;q.prototype.sqrTo=X;$.prototype.convert=J;$.prototype.revert=K;$.prototype.reduce=Q;$.prototype.mulTo=Y;$.prototype.sqrTo=G;u.copyTo=w;u.fromInt=E;u.fromString=x;u.clamp=T;u.dlShiftTo=M;u.drShiftTo=_;u.lShiftTo=D;u.rShiftTo=P;u.subTo=H;u.multiplyTo=B;u.squareTo=j;u.divRemTo=F;u.invDigit=V;u.isEven=Z;u.exp=et;u.toString=N;u.negate=C;u.abs=k;u.compareTo=L;u.bitLength=O;u.mod=I;u.modPowInt=tt;Vt.prototype.convert=$t;Vt.prototype.revert=$t;Vt.prototype.mulTo=Jt;Vt.prototype.sqrTo=Kt;Zt.prototype.convert=en;Zt.prototype.revert=tn;Zt.prototype.reduce=nn;Zt.prototype.mulTo=sn;Zt.prototype.sqrTo=rn;u.chunkSize=ot;u.toRadix=at;u.fromRadix=ft;u.fromNumber=lt;u.bitwiseTo=vt;u.changeBit=_t;u.addTo=Bt;u.dMultiply=Wt;u.dAddOffset=Xt;u.multiplyLowerTo=Gt;u.multiplyUpperTo=Yt;u.modInt=an;u.clone=nt;u.intValue=rt;u.byteValue=it;u.shortValue=st;u.signum=ut;u.toByteArray=ct;u.equals=ht;u.min=pt;u.max=dt;u.and=gt;u.or=bt;u.xor=Et;u.andNot=xt;u.not=Tt;u.shiftLeft=Nt;u.shiftRight=Ct;u.getLowestSetBit=Lt;u.bitCount=Ot;u.testBit=Mt;u.setBit=Dt;u.clearBit=Pt;u.flipBit=Ht;u.add=jt;u.subtract=Ft;u.multiply=It;u.divide=Rt;u.remainder=Ut;u.divideAndRemainder=zt;u.modPow=on;u.modInverse=fn;u.pow=Qt;u.gcd=un;u.square=qt;o.ZERO=S(0);o.ONE=S(1);o.valueOf=S;o.fromByteArrayUnsigned=function(e){if(!e.length){return new o.valueOf(0)}else if(e[0]&128){return new o([0].concat(e))}else{return new o(e)}};o.fromByteArraySigned=function(e){if(e[0]&128){e[0]&=127;return o.fromByteArrayUnsigned(e).negate()}else{return o.fromByteArrayUnsigned(e)}};o.prototype.toByteArrayUnsigned=function(){var e=this.abs().toByteArray();if(!e.length){return e}if(e[0]===0){e=e.slice(1)}for(var t=0;t<e.length;++t){e[t]=e[t]<0?e[t]+256:e[t]}return e};o.prototype.toByteArraySigned=function(){var e=this.toByteArrayUnsigned();var t=this.s<0;if(e[0]&128){e.unshift(t?128:0)}else if(t){e[0]|=128}return e};t.exports=o},{}],15:[function(e,t,n){function r(){this.i=0;this.j=0;this.S=new Array}function i(e){var t,n,r;for(t=0;t<256;++t)this.S[t]=t;n=0;for(t=0;t<256;++t){n=n+this.S[t]+e[t%e.length]&255;r=this.S[t];this.S[t]=this.S[n];this.S[n]=r}this.i=0;this.j=0}function s(){var e;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;e=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=e;return this.S[e+this.S[this.i]&255]}r.prototype.init=i;r.prototype.next=s;t.exports=r},{}],16:[function(e,t,n){function i(){return new r}function f(e){u[a++]^=e&255;u[a++]^=e>>8&255;u[a++]^=e>>16&255;u[a++]^=e>>24&255;if(a>=s)a-=s}function l(){f((new Date).getTime())}function h(){if(o==null){l();o=i();o.init(u);for(a=0;a<u.length;++a)u[a]=0;a=0}return o.next()}function p(e){var t;for(t=0;t<e.length;++t)e[t]=h()}function d(){}var r=e("./prng4");var s=256;var o;var u;var a;if(u==null){u=new Array;a=0;var c;while(a<s){c=Math.floor(65536*Math.random());u[a++]=c>>>8;u[a++]=c&255}a=0;l()}d.prototype.nextBytes=p;t.exports=d},{"./prng4":15}],17:[function(e,t,n){function s(e,t,n,r){this.curve=e;this.g=t;this.n=n;this.h=r}function o(){return this.curve}function u(){return this.g}function a(){return this.n}function f(){return this.h}function l(e){return new i(e,16)}function c(){var e=l("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");var t=l("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC");var n=l("E87579C11079F43DD824993C2CEE5ED3");var o=l("FFFFFFFE0000000075A30D1B9038A115");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"161FF7528B899B2D0C28607CA52C5B86"+"CF5AC8395BAFEB13C02DA292DDED7A83");return new s(a,f,o,u)}function h(){var e=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");var t=i.ZERO;var n=l("7");var o=l("0100000000000000000001B8FA16DFAB9ACA16B6B3");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"+"938CF935318FDCED6BC28286531733C3F03C4FEE");return new s(a,f,o,u)}function p(){var e=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF");var t=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC");var n=l("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45");var o=l("0100000000000000000001F4C8F927AED3CA752257");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"4A96B5688EF573284664698968C38BB913CBFC82"+"23A628553168947D59DCC912042351377AC5FB32");return new s(a,f,o,u)}function d(){var e=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37");var t=i.ZERO;var n=l("3");var o=l("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D"+"9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D");return new s(a,f,o,u)}function v(){var e=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF");var t=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC");var n=l("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1");var o=l("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"+"07192B95FFC8DA78631011ED6B24CDD573F977A11E794811");return new s(a,f,o,u)}function m(){var e=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");var t=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");var n=l("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");var o=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"+"BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34");return new s(a,f,o,u)}function g(){var e=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");var t=i.ZERO;var n=l("7");var o=l("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"+"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new s(a,f,o,u)}function y(){var e=l("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");var t=l("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");var n=l("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");var o=l("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");var u=i.ONE;var a=new r(e,t,n);var f=a.decodePointHex("04"+"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"+"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");return;new s(a,f,o,u)}function b(e){if(e=="secp128r1")return c();if(e=="secp160k1")return h();if(e=="secp160r1")return p();if(e=="secp192k1")return d();if(e=="secp192r1")return v();if(e=="secp224r1")return m();if(e=="secp256k1")return g();if(e=="secp256r1")return y();return null}var r=e("./ec");var i=e("./jsbn");s.prototype.getCurve=o;s.prototype.getG=u;s.prototype.getN=a;s.prototype.getH=f;t.exports=b},{"./ec":13,"./jsbn":14}],18:[function(e,t,n){var r=e("./crypto-js/crypto");var i=e("./ecdsa");var s=e("./convert");var o=e("./util");var u={};u.magicPrefix="Bitcoin Signed Message:\n";u.makeMagicMessage=function(e){var t=s.stringToBytes(u.magicPrefix);var n=s.stringToBytes(e);var r=[];r=r.concat(o.numToVarInt(t.length));r=r.concat(t);r=r.concat(o.numToVarInt(n.length));r=r.concat(n);return r};u.getHash=function(e){var t=u.makeMagicMessage(e);return r.SHA256(r.SHA256(t,{asBytes:true}),{asBytes:true})};u.signMessage=function(e,t,n){var r=u.getHash(t);var o=e.sign(r);var a=i.parseSig(o);var f=e.getBitcoinAddress().toString();var l=i.calcPubkeyRecoveryParam(f,a.r,a.s,r);l+=27;if(n)l+=4;var c=a.r.toByteArrayUnsigned();var h=a.s.toByteArrayUnsigned();while(c.length<32)c.unshift(0);while(h.length<32)h.unshift(0);o=[l].concat(c).concat(h);return s.bytesToHex(o)};u.verifyMessage=function(e,t,n){t=s.hexToBytes(t);t=i.parseSigCompact(t);var r=u.getHash(n);var o=!!(t.i&4);var a=i.recoverPubKey(t.r,t.s,r,t.i);a.setCompressed(o);var f=a.getBitcoinAddress().toString();return e===f};t.exports=u},{"./convert":4,"./crypto-js/crypto":5,"./ecdsa":10,"./util":22}],19:[function(e,t,n){var r=function(e){this.code=e};r.prototype.toString=function(){return r.reverseMap[this.code]};r.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};r.reverseMap=[];for(var i in r.map){r.reverseMap[r.map[i]]=i}t.exports=r},{}],20:[function(e,t,n){var r=e("./opcode");var i=e("./util");var s=e("./convert");var o=e("./address");var u=function(e){if(!e){this.buffer=[]}else if("string"==typeof e){this.buffer=s.hexToBytes(e)}else if(i.isArray(e)){this.buffer=e}else if(e instanceof u){this.buffer=e.buffer}else{throw new Error("Invalid script")}this.parse()};u.fromPubKey=function(e){var t=new u;var n=e.split(" ");for(var i in n){if(r.map.hasOwnProperty(n[i])){t.writeOp(r.map[n[i]])}else{t.writeBytes(s.hexToBytes(n[i]))}}return t};u.fromScriptSig=function(e){var t=new u;var n=e.split(" ");for(var i in n){if(r.map.hasOwnProperty(n[i])){t.writeOp(r.map[n[i]])}else{t.writeBytes(s.hexToBytes(n[i]))}}return t};u.prototype.parse=function(){function n(n){e.chunks.push(e.buffer.slice(t,t+n));t+=n}var e=this;this.chunks=[];var t=0;while(t<this.buffer.length){var i=this.buffer[t++];if(i>=240){i=i<<8|this.buffer[t++]}var s;if(i>0&&i<r.map.OP_PUSHDATA1){n(i)}else if(i==r.map.OP_PUSHDATA1){s=this.buffer[t++];n(s)}else if(i==r.map.OP_PUSHDATA2){s=this.buffer[t++]<<8|this.buffer[t++];n(s)}else if(i==r.map.OP_PUSHDATA4){s=this.buffer[t++]<<24|this.buffer[t++]<<16|this.buffer[t++]<<8|this.buffer[t++];n(s)}else{this.chunks.push(i)}}};u.prototype.getOutType=function(){if(this.chunks[this.chunks.length-1]==r.map.OP_EQUAL&&this.chunks[0]==r.map.OP_HASH160&&this.chunks.length==3){return"P2SH"}else if(this.chunks.length==5&&this.chunks[0]==r.map.OP_DUP&&this.chunks[1]==r.map.OP_HASH160&&this.chunks[3]==r.map.OP_EQUALVERIFY&&this.chunks[4]==r.map.OP_CHECKSIG){return"Pubkey"}else{return"Strange"}};u.prototype.toScriptHash=function(){var e=this.getOutType();return e=="Pubkey"?this.chunks[2]:e=="P2SH"?i.sha256ripe160(this.buffer):i.sha256ripe160(this.buffer)};u.prototype.toAddress=function(){var e=this.getOutType();return;e=="Pubkey"?new o(this.chunks[2]):e=="P2SH"?new o(this.chunks[1],5):new o(this.chunks[1],5)};u.prototype.getInType=function(){if(this.chunks.length==1&&i.isArray(this.chunks[0])){return"Pubkey"}else if(this.chunks.length==2&&i.isArray(this.chunks[0])&&i.isArray(this.chunks[1])){return"Address"}else if(this.chunks[0]==r.map.OP_0&&this.chunks.slice(1).reduce(function(e,t,n){return e&&i.isArray(t)&&(t[0]==48||n==this.chunks.length-1)},true)){return"Multisig"}else{return"Strange"}};u.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")}};u.prototype.simpleInHash=function(){return i.sha256ripe160(this.simpleInPubKey())};u.prototype.simpleInPubKeyHash=u.prototype.simpleInHash;u.prototype.writeOp=function(e){this.buffer.push(e);this.chunks.push(e)};u.prototype.writeBytes=function(e){if(e.length<r.map.OP_PUSHDATA1){this.buffer.push(e.length)}else if(e.length<=255){this.buffer.push(r.map.OP_PUSHDATA1);this.buffer.push(e.length)}else if(e.length<=65535){this.buffer.push(r.map.OP_PUSHDATA2);this.buffer.push(e.length&255);this.buffer.push(e.length>>>8&255)}else{this.buffer.push(r.map.OP_PUSHDATA4);this.buffer.push(e.length&255);this.buffer.push(e.length>>>8&255);this.buffer.push(e.length>>>16&255);this.buffer.push(e.length>>>24&255)}this.buffer=this.buffer.concat(e);this.chunks.push(e)};u.createOutputScript=function(e){var t=new u;e=new o(e);if(!e.version){t.writeOp(r.map.OP_DUP);t.writeOp(r.map.OP_HASH160);t.writeBytes(e.hash);t.writeOp(r.map.OP_EQUALVERIFY);t.writeOp(r.map.OP_CHECKSIG)}else{t.writeOp(r.map.OP_HASH160);t.writeBytes(e.hash);t.writeOp(r.map.OP_EQUAL)}return t};u.prototype.extractPubkeys=function(){return this.chunks.filter(function(e){return e[0]==4&&e.length==65||e[0]<4&&e.length==33})};u.createMultiSigOutputScript=function(e,t){var n=new u;t=t.sort();n.writeOp(r.map.OP_1+e-1);for(var i=0;i<t.length;++i){n.writeBytes(t[i])}n.writeOp(r.map.OP_1+t.length-1);n.writeOp(r.map.OP_CHECKMULTISIG);return n};u.createInputScript=function(e,t){var n=new u;n.writeBytes(e);n.writeBytes(t);return n};u.createMultiSigInputScript=function(e,t){t=new u(t);var n=t.chunks[0][0];if(e.length<n)return false;var i=new u;i.writeOp(r.map.OP_0);e.map(function(e){i.writeBytes(e)});i.writeBytes(t.buffer);return i};u.prototype.clone=function(){return new u(this.buffer)};t.exports=u},{"./address":1,"./convert":4,"./opcode":19,"./util":22}],21:[function(e,t,n){var r=e("./jsbn/jsbn");var i=e("./script");var s=e("./util");var o=e("./convert");var u=e("./crypto-js/crypto");var a=e("./wallet");var f=e("./eckey");var l=e("./ecdsa");var c=e("./address");var h=function(e){this.version=1;this.lock_time=0;this.ins=[];this.outs=[];this.timestamp=null;this.block=null;if(e){if(typeof e=="string"||s.isArray(e)){e=h.deserialize(e)}if(e.hash)this.hash=e.hash;if(e.version)this.version=e.version;if(e.lock_time)this.lock_time=e.lock_time;if(e.ins&&e.ins.length){for(var t=0;t<e.ins.length;t++){this.addInput(new y(e.ins[t]))}}if(e.outs&&e.outs.length){for(var t=0;t<e.outs.length;t++){this.addOutput(new b(e.outs[t]))}}if(e.timestamp)this.timestamp=e.timestamp;if(e.block)this.block=e.block}};h.objectify=function(e){var t=[];for(var n=0;n<e.length;n++){t.push(new h(e[n]))}return t};h.prototype.addInput=function(e,t){if(arguments[0]instanceof y){this.ins.push(arguments[0])}else if(arguments[0].length>65){var n=arguments[0].split(":");return this.addInput(n[0],n[1])}else{this.ins.push(new y({outpoint:{hash:e.hash||e,index:t},script:new i,sequence:4294967295}))}};h.prototype.addOutput=function(e,t){if(arguments[0]instanceof b){this.outs.push(arguments[0]);return}if(arguments[0].indexOf(":")>=0){var n=arguments[0].split(":");e=n[0];t=parseInt(n[1])}this.outs.push(new b({value:t,script:i.createOutputScript(e)}))};h.prototype.serialize=function(){var e=[];e=e.concat(s.numToBytes(parseInt(this.version),4));e=e.concat(s.numToVarInt(this.ins.length));for(var t=0;t<this.ins.length;t++){var n=this.ins[t];e=e.concat(o.hexToBytes(n.outpoint.hash).reverse());e=e.concat(s.numToBytes(parseInt(n.outpoint.index),4));var r=n.script.buffer;e=e.concat(s.numToVarInt(r.length));e=e.concat(r);e=e.concat(s.numToBytes(parseInt(n.sequence),4))}e=e.concat(s.numToVarInt(this.outs.length));for(var t=0;t<this.outs.length;t++){var i=this.outs[t];e=e.concat(s.numToBytes(i.value,8));var r=i.script.buffer;e=e.concat(s.numToVarInt(r.length));e=e.concat(r)}e=e.concat(s.numToBytes(parseInt(this.lock_time),4));return e};h.prototype.serializeHex=function(){return o.bytesToHex(this.serialize())};var p=171;var d=1;var v=2;var m=3;var g=80;h.prototype.hashTransactionForSignature=function(e,t,n){var r=this.clone();for(var o=0;o<r.ins.length;o++){r.ins[o].script=new i}r.ins[t].script=e;if((n&31)==v){r.outs=[];for(var o=0;o<r.ins.length;o++)if(o!=t)r.ins[o].sequence=0}else if((n&31)==m){}if(n&g){r.ins=[r.ins[t]]}var a=r.serialize();a=a.concat(s.numToBytes(parseInt(n),4));var f=u.SHA256(a,{asBytes:true});return u.SHA256(f,{asBytes:true})};h.prototype.getHash=function(){var e=this.serialize();return u.SHA256(u.SHA256(e,{asBytes:true}),{asBytes:true}).reverse()};h.prototype.clone=function(){var e=new h;e.version=this.version;e.lock_time=this.lock_time;for(var t=0;t<this.ins.length;t++){var n=this.ins[t].clone();e.addInput(n)}for(var t=0;t<this.outs.length;t++){var r=this.outs[t].clone();e.addOutput(r)}return e};h.prototype.analyze=function(e){if(!(e instanceof a))return null;var t=true,n=true,r=null,i=null,s=null;for(var o=this.outs.length-1;o>=0;o--){var u=this.outs[o];var f=u.script.simpleOutPubKeyHash();if(!e.hasHash(f)){n=false}else{i=f}r=f}for(var o=this.ins.length-1;o>=0;o--){var l=this.ins[o];s=l.script.simpleInPubKeyHash();if(!e.hasHash(s)){t=false;break}}var h=this.calcImpact(e);var p={};p.impact=h;if(h.sign>0&&h.value>0){p.type="recv";p.addr=new c(i)}else if(t&&n){p.type="self"}else if(t){p.type="sent";p.addr=new c(r)}else{p.type="other"}return p};h.prototype.getDescription=function(e){var t=this.analyze(e);if(!t)return"";switch(t.type){case"recv":return"Received with "+t.addr;break;case"sent":return"Payment to "+t.addr;break;case"self":return"Payment to yourself";break;case"other":default:return""}};h.prototype.getTotalOutValue=function(){return this.outs.reduce(function(e,t){return e+t.value},0)};h.prototype.getTotalValue=h.prototype.getTotalOutValue;h.prototype.calcImpact=function(e){if(!(e instanceof a))return 0;var t=this.outs.filter(function(t){return e.hasHash(o.bytesToHex(t.script.simpleOutPubKeyHash()))}).reduce(function(e,t){return e+t.value},0);var n=this.ins.filter(function(t){return e.hasHash(o.bytesToHex(t.script.simpleInPubKeyHash()))&&e.txIndex[t.outpoint.hash]}).reduce(function(t,n){return t+e.txIndex[n.outpoint.hash].outs[n.outpoint.index].value},0);if(t>n){return{sign:1,value:t-n}}else{return{sign:-1,value:n-t}}};h.deserialize=function(e){if(typeof e=="string"){e=o.hexToBytes(e)}var t=0;var n=function(r){if(r==0)return 0;t++;return e[t-1]+n(r-1)*256};var r=function(){t++;if(e[t-1]<253){return e[t-1]}return n(e[t-1]-251)};var u=function(n){t+=n;return e.slice(t-n,t)};var a=function(){var e=r();return u(e)};var f={ins:[],outs:[]};f.version=n(4);var l=r();for(var c=0;c<l;c++){f.ins.push({outpoint:{hash:o.bytesToHex(u(32).reverse()),index:n(4)},script:new i(a()),sequence:n(4)})}var p=r();for(var c=0;c<p;c++){f.outs.push({value:s.bytesToNum(u(8)),script:new i(a())})}f.locktime=n(4);return new h(f)};h.prototype.sign=function(e,t,n){n=n||d;t=new f(t);var r=t.getPub(),o=s.sha256ripe160(r),u=i.createOutputScript(new c(o)),a=this.hashTransactionForSignature(u,e,n),l=t.sign(a).concat([n]);this.ins[e].script=i.createInputScript(l,r)};h.prototype.signWithKeys=function(e,t,n){n=n||d;var r=e.map(function(e){e=new f(e);return{key:e,address:e.getBitcoinAddress().toString()}});var i={};for(var s in t){i[t[s].output]=t[s]}for(var o=0;o<this.ins.length;o++){var u=this.ins[o].outpoint.hash+":"+this.ins[o].outpoint.index,a=i[u];if(!a)continue;var l=r.filter(function(e){return e.address==a.address});if(l.length==0)continue;this.sign(o,l[0].key)}};h.prototype.p2shsign=function(e,t,n,r){t=new i(t);n=new f(n);r=r||d;var s=this.hashTransactionForSignature(t,e,r),o=n.sign(s).concat([r]);return o};h.prototype.multisign=h.prototype.p2shsign;h.prototype.applyMultisigs=function(e,t,n,r){this.ins[e].script=i.createMultiSigInputScript(n,t)};h.prototype.validateSig=function(e,t,n,r){t=new i(t);var s=this.hashTransactionForSignature(t,e,1);return l.verify(s,o.coerceToBytes(n),o.coerceToBytes(r))};var y=function(e){if(typeof e=="string")this.outpoint={hash:e.split(":")[0],index:e.split(":")[1]};else if(e.outpoint)this.outpoint=e.outpoint;else this.outpoint={hash:e.hash,index:e.index};if(e.scriptSig)this.script=i.fromScriptSig(e.scriptSig);else this.script=new i(e.script);this.sequence=e.sequence||4294967295};y.prototype.clone=function(){return new y({outpoint:{hash:this.outpoint.hash,index:this.outpoint.index},script:this.script.clone(),sequence:this.sequence})};var b=function(e){this.script=e.script instanceof i?e.script.clone():s.isArray(e.script)?new i(e.script):typeof e.script=="string"?new i(o.hexToBytes(e.script)):e.scriptPubKey?i.fromScriptSig(e.scriptPubKey):e.address?i.createOutputScript(e.address):new i;if(this.script.buffer.length>0)this.address=this.script.toAddress();this.value=s.isArray(e.value)?s.bytesToNum(e.value):"string"==typeof e.value?parseInt(e.value):e.value instanceof r?parseInt(e.value.toString()):e.value};b.prototype.clone=function(){var e=new b({script:this.script.clone(),value:this.value});return e};t.exports.Transaction=h;t.exports.TransactionIn=y;t.exports.TransactionOut=b},{"./address":1,"./convert":4,"./crypto-js/crypto":5,"./ecdsa":10,"./eckey":11,"./jsbn/jsbn":14,"./script":20,"./util":22,"./wallet":23}],22:[function(e,t,n){var r=e("./jsbn/jsbn");var i=e("./crypto-js/crypto");t.exports={isArray:Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"},numToBytes:function(e,n){if(n===undefined)n=8;if(n==0)return[];else return[e%256].concat(t.exports.numToBytes(Math.floor(e/256),n-1))},bytesToNum:function(e){if(e.length==0)return 0;else return e[0]+256*t.exports.bytesToNum(e.slice(1))},numToVarInt:function(e){var n=t.exports;if(e<253)return[e];else if(e<65536)return[253].concat(n.numToBytes(e,2));else if(e<4294967296)return[254].concat(n.numToBytes(e,4));else return[253].concat(n.numToBytes(e,8))},bytesToWords:function(e){var t=[];for(var n=0,r=0;n<e.length;n++,r+=8){t[r>>>5]|=e[n]<<24-r%32}return t},wordsToBytes:function(e){var t=[];for(var n=0;n<e.length*32;n+=8){t.push(e[n>>>5]>>>24-n%32&255)}return t},sha256ripe160:function(e){return i.RIPEMD160(i.SHA256(e,{asBytes:true}),{asBytes:true})},error:function(e){throw new Error(e)}}},{"./crypto-js/crypto":5,"./jsbn/jsbn":14}],23:[function(e,t,n){var r=e("./script");var i=e("./eckey");var s=e("./convert");var u=e("./util");var a=e("./jsbn/jsbn");var f=e("./bip32");var l=e("./transaction").Transaction;var c=e("./transaction").TransactionIn;var h=e("./transaction").TransactionOut;var p=e("./jsbn/rng");var d=new p;var v=function(e){var t=[];var n=null;var r=this;this.addresses=[];this.outputs={};this.newMasterKey=function(e){if(!e){var r=new Array(32);d.nextBytes(r);e=s.bytesToString(r)}n=new f(e);t=[]};this.newMasterKey(e);this.generateAddress=function(){t.push(n.ckd(t.length).key);this.addresses.push(t[t.length-1].getBitcoinAddress().toString());return this.addresses[this.addresses.length-1]};this.processTx=function(e,t){var n=s.bytesToHex(e.getHash());for(var i=0;i<e.outs.length;i++){if(this.addresses.indexOf(e.outs[i].address.toString())>=0){r.outputs[n+":"+i]={output:n+":"+i,value:e.outs[i].value,address:e.outs[i].address.toString(),timestamp:(new Date).getTime()/1e3,pending:true}}}for(var i=0;i<e.ins.length;i++){var o=e.ins[i].outpoint;var u=r.outputs[o.hash+":"+o.index];if(u){u.spend=n+":"+i;u.spendpending=true;u.timestamp=(new Date).getTime()/1e3}}};this.processOutput=function(e){if(!this.outputs[e.output]||this.outputs[e.output].pending)this.outputs[e.output]=e};this.processExistingOutputs=function(){var e=(new Date).getTime()/1e3;for(var t in this.outputs){if(t.pending&&e>t.timestamp+1200)delete this.outputs[t];if(t.spendpending&&e>t.timestamp+1200){t.spendpending=false;t.spend=false;delete t.timestamp}}};var i=setInterval(this.processExistingOutputs,1e4);this.getUtxoToPay=function(e){var t=[];for(var n in this.outputs)t.push(this.outputs[n]);var r=t.filter(function(e){return!e.spend});var i=function(e,t){return e.value>t.value};var s=r.filter(function(t){return t.value>=e}).sort(i);if(s.length>0)return[s[0]];r.sort(i);var o=0;for(var u=0;u<r.length;u++){o+=r[u].value;if(o>=e)return r.slice(0,u+1)}throw"Not enough money to send funds including transaction fee. Have: "+o/1e8+", needed: "+e/1e8};this.mkSend=function(e,t,n){var r=this.getUtxoToPay(t+n);var i=r.reduce(function(e,t){return e+t.value},0),s=i-t-n;if(t<5430)throw new Error("Amount below dust threshold!");var o=0;for(var u in this.outputs){if(!this.outputs[u].spend)o+=1;if(o>=5)return}var a=this.addresses[this.addresses.length-1];var f={address:e,value:t},l={address:a,value:s};halfChangeOut={address:a,value:Math.floor(s/2)};var c=s<5430?[f]:s<10860?[f,l]:o==5?[f,l]:[f,halfChangeOut,halfChangeOut];var h=new Bitcoin.Transaction({ins:r.map(function(e){return e.output}),outs:c});this.sign(h);return h};this.mkSendToOutputs=function(e,t,n){var r=e.reduce(function(e,t){return e+t.value},0),i=this.getUtxoToPay(r+n),s=i.reduce(function(e,t){return e+o.value},0);i[t].value+=s-r-n;var u=new Bitcoin.Transaction({ins:i.map(function(e){return e.output}),outs:e});this.sign(u);return u};this.sign=function(e){e.ins.map(function(n,i){var n=n.outpoint.hash+":"+n.outpoint.index;if(r.outputs[n]){var s=r.outputs[n].address,o=r.addresses.indexOf(s);if(o>=0){var u=t[o];e.sign(o,u)}}});return e};this.getMasterKey=function(){return n};this.getPrivateKey=function(e){if(typeof e=="string")return t.filter(function(t,n){return addresses[t]==e})[0];else return t[e]};this.getPrivateKeys=function(){return t}};t.exports=v},{"./bip32":3,"./convert":4,"./eckey":11,"./jsbn/jsbn":14,"./jsbn/rng":16,"./script":20,"./transaction":21,"./util":22}]},{},[12])(12)})